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 |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A widely known among some people Belarusian sport programmer Lesha decided to make some money to buy a one square meter larger flat. To do this, he wants to make and carry out a Super Rated Match (SRM) on the site Torcoder.com. But there's a problem β a severe torcoder coordinator Ivan does not accept any Lesha's problem, calling each of them an offensive word "duped" (that is, duplicated). And one day they nearely quarrelled over yet another problem Ivan wouldn't accept.
You are invited to act as a fair judge and determine whether the problem is indeed brand new, or Ivan is right and the problem bears some resemblance to those used in the previous SRMs.
You are given the descriptions of Lesha's problem and each of Torcoder.com archive problems. The description of each problem is a sequence of words. Besides, it is guaranteed that Lesha's problem has no repeated words, while the description of an archive problem may contain any number of repeated words.
The "similarity" between Lesha's problem and some archive problem can be found as follows. Among all permutations of words in Lesha's problem we choose the one that occurs in the archive problem as a subsequence. If there are multiple such permutations, we choose the one with the smallest number of inversions. Then the "similarity" of a problem can be written as <image>, where n is the number of words in Lesha's problem and x is the number of inversions in the chosen permutation. Note that the "similarity" p is always a positive integer.
The problem is called brand new if there is not a single problem in Ivan's archive which contains a permutation of words from Lesha's problem as a subsequence.
Help the boys and determine whether the proposed problem is new, or specify the problem from the archive which resembles Lesha's problem the most, otherwise.
Input
The first line contains a single integer n (1 β€ n β€ 15) β the number of words in Lesha's problem. The second line contains n space-separated words β the short description of the problem.
The third line contains a single integer m (1 β€ m β€ 10) β the number of problems in the Torcoder.com archive. Next m lines contain the descriptions of the problems as "k s1 s2 ... sk", where k (1 β€ k β€ 500000) is the number of words in the problem and si is a word of the problem description.
All words from all problem descriptions contain no more than 10 lowercase English letters. It is guaranteed that the total length of words in all problem descriptions does not exceed 500015.
Output
If Lesha's problem is brand new, print string "Brand new problem!" (without quotes).
Otherwise, on the first line print the index of the archive problem which resembles Lesha's problem most. If there are multiple such problems, print the one with the smallest index. On the second line print a string consisting of characters [:, character | repeated p times, and characters :], where p is the "similarity" between this problem and Lesha's one. The archive problems are numbered starting from one in the order in which they are given in the input.
Examples
Input
4
find the next palindrome
1
10 find the previous palindrome or print better luck next time
Output
1
[:||||||:]
Input
3
add two numbers
3
1 add
2 two two
3 numbers numbers numbers
Output
Brand new problem!
Input
4
these papers are formulas
3
6 what are these formulas and papers
5 papers are driving me crazy
4 crazy into the night
Output
1
[:||||:]
Input
3
add two decimals
5
4 please two decimals add
5 decimals want to be added
4 two add decimals add
4 add one two three
7 one plus two plus three equals six
Output
3
[:|||:]
Note
Let us remind you that the number of inversions is the number of pairs of words that follow in the permutation not in their original order. Thus, for example, if the original problem is "add two numbers", then permutation "numbers add two" contains two inversions β pairs of words "numbers" and "add", "numbers" and "two".
Sequence b1, b2, ..., bk is a subsequence of sequence a1, a2, ..., an if there exists such a set of indices 1 β€ i1 < i2 < ... < ik β€ n that aij = bj (in other words, if sequence b can be obtained from a by deleting some of its elements).
In the first test case the first problem contains the "find the palindrome next" permutation as a subsequence, in which the number of inversions equals 1 (words "palindrome" and "next").
In the second test case there is no problem that contains a permutation of words from Lesha's problem as a subsequence.
Submitted Solution:
```
data = []
i = int(input())
words = list(map(str, input().split(' ')))
j = int(input())
for t in range(j):
ok = list(map(str, input().split(' ')))
data.append([int(ok[0]), ok[1:]])
if i == 1:
inv = []
for x in range(len(data)):
if words[0] in data[x][1]:
print(x)
print('[:|:]')
quit()
print("Brand new problem!")
elif i == 2:
inv = []
a = words[0]
b = words[1]
for x in range(len(data)):
invx = 0
for i in range(data[x][0]):
for j in range(data[x][0]):
if i != j:
if data[x][1][i] == a and data[x][1][j] == b:
if i > j:
invx+=1
inv.append([x, invx])
inv.sort(key = lambda x : x[1])
if inv == []:
print("Brand new problem!")
else:
print(inv[0][0]+1)
print('[:' + (1+1-inv[0][1]) * '|' + ':]')
elif i == 3:
inv = []
a = words[0]
b = words[1]
c = words[2]
for x in range(len(data)):
invx = 0
for i in range(data[x][0]):
for j in range(data[x][0]):
for k in range(data[x][0]):
if i != j and j != k and i != k:
if data[x][1][i] == a and data[x][1][j] == b and data[x][1][k] == c:
if i > j:
invx+=1
if i > k:
invx += 1
if j > k:
invx += 1
inv.append([x, invx])
inv.sort(key = lambda x : x[1])
if inv == []:
print("Brand new problem!")
else:
print(inv[0][0]+1)
print('[:' + (3+1-inv[0][1]) * '|' + ':]')
elif i == 4:
inv = []
a = words[0]
b = words[1]
c = words[2]
d = words[3]
for x in range(len(data)):
invx = 0
for i in range(data[x][0]):
for j in range(data[x][0]):
for k in range(data[x][0]):
for l in range(data[x][0]):
if i != j and j != k and i != k and i != l and j != l and k != l:
if data[x][1][i] == a and data[x][1][j] == b and data[x][1][k] == c and data[x][1][l] == d:
if i > j:
invx+=1
if i > k:
invx += 1
if j > k:
invx += 1
if j > l:
invx += 1
if i > l:
invx += 1
if k > l:
invx += 1
inv.append([x, invx])
inv.sort(key = lambda x : x[1])
if inv == []:
print("Brand new problem!")
else:
print(inv[0][0]+1)
print('[:' + (6+1-inv[0][1]) * '|' + ':]')
``` | instruction | 0 | 97,265 | 11 | 194,530 |
No | output | 1 | 97,265 | 11 | 194,531 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A widely known among some people Belarusian sport programmer Lesha decided to make some money to buy a one square meter larger flat. To do this, he wants to make and carry out a Super Rated Match (SRM) on the site Torcoder.com. But there's a problem β a severe torcoder coordinator Ivan does not accept any Lesha's problem, calling each of them an offensive word "duped" (that is, duplicated). And one day they nearely quarrelled over yet another problem Ivan wouldn't accept.
You are invited to act as a fair judge and determine whether the problem is indeed brand new, or Ivan is right and the problem bears some resemblance to those used in the previous SRMs.
You are given the descriptions of Lesha's problem and each of Torcoder.com archive problems. The description of each problem is a sequence of words. Besides, it is guaranteed that Lesha's problem has no repeated words, while the description of an archive problem may contain any number of repeated words.
The "similarity" between Lesha's problem and some archive problem can be found as follows. Among all permutations of words in Lesha's problem we choose the one that occurs in the archive problem as a subsequence. If there are multiple such permutations, we choose the one with the smallest number of inversions. Then the "similarity" of a problem can be written as <image>, where n is the number of words in Lesha's problem and x is the number of inversions in the chosen permutation. Note that the "similarity" p is always a positive integer.
The problem is called brand new if there is not a single problem in Ivan's archive which contains a permutation of words from Lesha's problem as a subsequence.
Help the boys and determine whether the proposed problem is new, or specify the problem from the archive which resembles Lesha's problem the most, otherwise.
Input
The first line contains a single integer n (1 β€ n β€ 15) β the number of words in Lesha's problem. The second line contains n space-separated words β the short description of the problem.
The third line contains a single integer m (1 β€ m β€ 10) β the number of problems in the Torcoder.com archive. Next m lines contain the descriptions of the problems as "k s1 s2 ... sk", where k (1 β€ k β€ 500000) is the number of words in the problem and si is a word of the problem description.
All words from all problem descriptions contain no more than 10 lowercase English letters. It is guaranteed that the total length of words in all problem descriptions does not exceed 500015.
Output
If Lesha's problem is brand new, print string "Brand new problem!" (without quotes).
Otherwise, on the first line print the index of the archive problem which resembles Lesha's problem most. If there are multiple such problems, print the one with the smallest index. On the second line print a string consisting of characters [:, character | repeated p times, and characters :], where p is the "similarity" between this problem and Lesha's one. The archive problems are numbered starting from one in the order in which they are given in the input.
Examples
Input
4
find the next palindrome
1
10 find the previous palindrome or print better luck next time
Output
1
[:||||||:]
Input
3
add two numbers
3
1 add
2 two two
3 numbers numbers numbers
Output
Brand new problem!
Input
4
these papers are formulas
3
6 what are these formulas and papers
5 papers are driving me crazy
4 crazy into the night
Output
1
[:||||:]
Input
3
add two decimals
5
4 please two decimals add
5 decimals want to be added
4 two add decimals add
4 add one two three
7 one plus two plus three equals six
Output
3
[:|||:]
Note
Let us remind you that the number of inversions is the number of pairs of words that follow in the permutation not in their original order. Thus, for example, if the original problem is "add two numbers", then permutation "numbers add two" contains two inversions β pairs of words "numbers" and "add", "numbers" and "two".
Sequence b1, b2, ..., bk is a subsequence of sequence a1, a2, ..., an if there exists such a set of indices 1 β€ i1 < i2 < ... < ik β€ n that aij = bj (in other words, if sequence b can be obtained from a by deleting some of its elements).
In the first test case the first problem contains the "find the palindrome next" permutation as a subsequence, in which the number of inversions equals 1 (words "palindrome" and "next").
In the second test case there is no problem that contains a permutation of words from Lesha's problem as a subsequence.
Submitted Solution:
```
import itertools
def check(curr_words, line):
if curr_words == []:
return True
for i in range(len(line)):
if line[i] == curr_words[0]:
return check(curr_words[1:], line[i+1:])
return False
n = int(input())
words = input().split()
m = int(input())
res, idx = 0, 0
for i in range(m):
line = input().split()[1:]
for p in itertools.permutations(range(n)):
curr_words = [words[j] for j in p]
cnt = 0
for j in range(n):
cnt += len([k for k in range(j+1, n) if p[k] < p[j]])
v = n * (n-1) // 2 - cnt + 1
if check(curr_words, line[:]) and v > res:
res, idx = v, i+1
if res > 0:
print(idx)
print('[:'+str('|'*res)+':]')
else:
print('Brand new wordslem!')
``` | instruction | 0 | 97,266 | 11 | 194,532 |
No | output | 1 | 97,266 | 11 | 194,533 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integer arrays a_0, a_1, ..., a_{N - 1} and b_0, b_1, ..., b_{M - 1}. Calculate the array c_0, c_1, ..., c_{(N - 1) + (M - 1)}, defined by c_i = \sum_{j = 0}^i a_j b_{i - j} \bmod 998244353.
Constraints
* 1 \leq N, M \leq 524288
* 0 \leq a_i, b_i < 998244353
* All values in Input are integer.
Input
Input is given from Standard Input in the following format:
N M
a_0 a_1 ... a_{N-1}
b_0 b_1 ... b_{M-1}
Output
Print the answer in the following format:
c_0 c_1 ... c_{(N - 1) + (M - 1)}
Output
Print the answer in the following format:
c_0 c_1 ... c_{(N - 1) + (M - 1)}
Examples
Input
4 5
1 2 3 4
5 6 7 8 9
Output
5 16 34 60 70 70 59 36
Input
1 1
10000000
10000000
Output
871938225
Submitted Solution:
```
import types
_atcoder_code = """
# Python port of AtCoder Library.
__version__ = '0.0.1'
"""
atcoder = types.ModuleType('atcoder')
exec(_atcoder_code, atcoder.__dict__)
_atcoder__bit_code = """
def _ceil_pow2(n: int) -> int:
x = 0
while (1 << x) < n:
x += 1
return x
def _bsf(n: int) -> int:
x = 0
while n % 2 == 0:
x += 1
n //= 2
return x
"""
atcoder._bit = types.ModuleType('atcoder._bit')
exec(_atcoder__bit_code, atcoder._bit.__dict__)
_atcoder__math_code = """
import typing
def _is_prime(n: int) -> bool:
'''
Reference:
M. Forisek and J. Jancina,
Fast Primality Testing for Integers That Fit into a Machine Word
'''
if n <= 1:
return False
if n == 2 or n == 7 or n == 61:
return True
if n % 2 == 0:
return False
d = n - 1
while d % 2 == 0:
d //= 2
for a in (2, 7, 61):
t = d
y = pow(a, t, n)
while t != n - 1 and y != 1 and y != n - 1:
y = y * y % n
t <<= 1
if y != n - 1 and t % 2 == 0:
return False
return True
def _inv_gcd(a: int, b: int) -> typing.Tuple[int, int]:
a %= b
if a == 0:
return (b, 0)
# Contracts:
# [1] s - m0 * a = 0 (mod b)
# [2] t - m1 * a = 0 (mod b)
# [3] s * |m1| + t * |m0| <= b
s = b
t = a
m0 = 0
m1 = 1
while t:
u = s // t
s -= t * u
m0 -= m1 * u # |m1 * u| <= |m1| * s <= b
# [3]:
# (s - t * u) * |m1| + t * |m0 - m1 * u|
# <= s * |m1| - t * u * |m1| + t * (|m0| + |m1| * u)
# = s * |m1| + t * |m0| <= b
s, t = t, s
m0, m1 = m1, m0
# by [3]: |m0| <= b/g
# by g != b: |m0| < b/g
if m0 < 0:
m0 += b // s
return (s, m0)
def _primitive_root(m: int) -> int:
if m == 2:
return 1
if m == 167772161:
return 3
if m == 469762049:
return 3
if m == 754974721:
return 11
if m == 998244353:
return 3
divs = [2] + [0] * 19
cnt = 1
x = (m - 1) // 2
while x % 2 == 0:
x //= 2
i = 3
while i * i <= x:
if x % i == 0:
divs[cnt] = i
cnt += 1
while x % i == 0:
x //= i
i += 2
if x > 1:
divs[cnt] = x
cnt += 1
g = 2
while True:
for i in range(cnt):
if pow(g, (m - 1) // divs[i], m) == 1:
break
else:
return g
g += 1
"""
atcoder._math = types.ModuleType('atcoder._math')
exec(_atcoder__math_code, atcoder._math.__dict__)
_atcoder_modint_code = """
from __future__ import annotations
import typing
# import atcoder._math
class ModContext:
context = []
def __init__(self, mod: int) -> None:
assert 1 <= mod
self.mod = mod
def __enter__(self) -> None:
self.context.append(self.mod)
def __exit__(self, exc_type: typing.Any, exc_value: typing.Any,
traceback: typing.Any) -> None:
self.context.pop()
@classmethod
def get_mod(cls) -> int:
return cls.context[-1]
class Modint:
def __init__(self, v: int = 0) -> None:
self._mod = ModContext.get_mod()
if v == 0:
self._v = 0
else:
self._v = v % self._mod
def val(self) -> int:
return self._v
def __iadd__(self, rhs: typing.Union[Modint, int]) -> Modint:
if isinstance(rhs, Modint):
self._v += rhs._v
else:
self._v += rhs
if self._v >= self._mod:
self._v -= self._mod
return self
def __isub__(self, rhs: typing.Union[Modint, int]) -> Modint:
if isinstance(rhs, Modint):
self._v -= rhs._v
else:
self._v -= rhs
if self._v < 0:
self._v += self._mod
return self
def __imul__(self, rhs: typing.Union[Modint, int]) -> Modint:
if isinstance(rhs, Modint):
self._v = self._v * rhs._v % self._mod
else:
self._v = self._v * rhs % self._mod
return self
def __ifloordiv__(self, rhs: typing.Union[Modint, int]) -> Modint:
if isinstance(rhs, Modint):
inv = rhs.inv()._v
else:
inv = atcoder._math._inv_gcd(rhs, self._mod)[1]
self._v = self._v * inv % self._mod
return self
def __pos__(self) -> Modint:
return self
def __neg__(self) -> Modint:
return Modint() - self
def __pow__(self, n: int) -> Modint:
assert 0 <= n
return Modint(pow(self._v, n, self._mod))
def inv(self) -> Modint:
eg = atcoder._math._inv_gcd(self._v, self._mod)
assert eg[0] == 1
return Modint(eg[1])
def __add__(self, rhs: typing.Union[Modint, int]) -> Modint:
if isinstance(rhs, Modint):
result = self._v + rhs._v
if result >= self._mod:
result -= self._mod
return raw(result)
else:
return Modint(self._v + rhs)
def __sub__(self, rhs: typing.Union[Modint, int]) -> Modint:
if isinstance(rhs, Modint):
result = self._v - rhs._v
if result < 0:
result += self._mod
return raw(result)
else:
return Modint(self._v - rhs)
def __mul__(self, rhs: typing.Union[Modint, int]) -> Modint:
if isinstance(rhs, Modint):
return Modint(self._v * rhs._v)
else:
return Modint(self._v * rhs)
def __floordiv__(self, rhs: typing.Union[Modint, int]) -> Modint:
if isinstance(rhs, Modint):
inv = rhs.inv()._v
else:
inv = atcoder._math._inv_gcd(rhs, self._mod)[1]
return Modint(self._v * inv)
def __eq__(self, rhs: typing.Union[Modint, int]) -> bool:
if isinstance(rhs, Modint):
return self._v == rhs._v
else:
return self._v == rhs
def __ne__(self, rhs: typing.Union[Modint, int]) -> bool:
if isinstance(rhs, Modint):
return self._v != rhs._v
else:
return self._v != rhs
def raw(v: int) -> Modint:
x = Modint()
x._v = v
return x
"""
atcoder.modint = types.ModuleType('atcoder.modint')
atcoder.modint.__dict__['atcoder'] = atcoder
atcoder.modint.__dict__['atcoder._math'] = atcoder._math
exec(_atcoder_modint_code, atcoder.modint.__dict__)
ModContext = atcoder.modint.ModContext
Modint = atcoder.modint.Modint
_atcoder_convolution_code = """
import typing
# import atcoder._bit
# import atcoder._math
# from atcoder.modint import ModContext, Modint
_sum_e = {} # _sum_e[i] = ies[0] * ... * ies[i - 1] * es[i]
def _butterfly(a: typing.List[Modint]) -> None:
g = atcoder._math._primitive_root(a[0].mod())
n = len(a)
h = atcoder._bit._ceil_pow2(n)
if a[0].mod() not in _sum_e:
es = [0] * 30 # es[i]^(2^(2+i)) == 1
ies = [0] * 30
cnt2 = atcoder._bit._bsf(a[0].mod() - 1)
e = Modint(g).pow((a[0].mod() - 1) >> cnt2)
ie = e.inv()
for i in range(cnt2, 1, -1):
# e^(2^i) == 1
es[i - 2] = e
ies[i - 2] = ie
e *= e
ie *= ie
sum_e = [0] * 30
now = Modint(1)
for i in range(cnt2 - 2):
sum_e[i] = es[i] * now
now *= ies[i]
_sum_e[a[0].mod()] = sum_e
else:
sum_e = _sum_e[a[0].mod()]
for ph in (1, h + 1):
w = 1 << (ph - 1)
p = 1 << (h - ph)
now = Modint(1)
for s in range(w):
offset = s << (h - ph + 1)
for i in range(p):
left = a[i + offset]
right = a[i + offset + p] * now
a[i + offset] = left + right
a[i + offset + p] = left - right
now *= sum_e[atcoder._bit._bsf(~s)]
_sum_ie = {} # _sum_ie[i] = es[0] * ... * es[i - 1] * ies[i]
def _butterfly_inv(a: typing.List[Modint]) -> None:
g = atcoder._math._primitive_root(a[0].mod())
n = len(a)
h = atcoder._bit.ceil_pow2(n)
if a[0].mod() not in _sum_ie:
es = [0] * 30 # es[i]^(2^(2+i)) == 1
ies = [0] * 30
cnt2 = atcoder._bit._bsf(a[0].mod() - 1)
e = Modint(g).pow((a[0].mod() - 1) >> cnt2)
ie = e.inv()
for i in range(cnt2, 1, -1):
# e^(2^i) == 1
es[i - 2] = e
ies[i - 2] = ie
e *= e
ie *= ie
sum_ie = [0] * 30
now = Modint(1)
for i in range(cnt2 - 2):
sum_ie[i] = ies[i] * now
now *= es[i]
_sum_ie[a[0].mod()] = sum_ie
else:
sum_ie = _sum_ie[a[0].mod()]
for ph in range(h, 0, -1):
w = 1 << (ph - 1)
p = 1 << (h - ph)
inow = Modint(1)
for s in range(w):
offset = s << (h - ph + 1)
for i in range(p):
left = a[i + offset]
right = a[i + offset + p]
a[i + offset] = left + right
a[i + offset + p] = (a[0].mod() +
left.val() - right.val()) * inow.val()
inow *= sum_ie[atcoder._bit._bsf(~s)]
def convolution_mod(a: typing.List[Modint],
b: typing.List[Modint]) -> typing.List[Modint]:
n = len(a)
m = len(b)
if n == 0 or m == 0:
return []
if min(n, m) <= 60:
if n < m:
n, m = m, n
a, b = b, a
ans = [Modint(0) for _ in range(n + m - 1)]
for i in range(n):
for j in range(m):
ans[i + j] += a[i] * b[j]
return ans
z = 1 << atcoder._bit._ceil_pow2(n + m - 1)
while len(a) < z:
a.append(Modint(0))
_butterfly(a)
while len(b) < z:
b.append(Modint(0))
_butterfly(b)
for i in range(z):
a[i] *= b[i]
_butterfly_inv(a)
a = a[:n + m - 1]
iz = Modint(z).inv()
for i in range(n + m - 1):
a[i] *= iz
return a
def convolution(mod: int, a: typing.List[typing.Any],
b: typing.List[typing.Any]) -> typing.List[typing.Any]:
n = len(a)
m = len(b)
if n == 0 or m == 0:
return []
with ModContext(mod):
a2 = list(map(Modint, a))
b2 = list(map(Modint, b))
return list(map(lambda c: c.val(), convolution_mod(a2, b2)))
def convolution_int(
a: typing.List[int], b: typing.List[int]) -> typing.List[int]:
n = len(a)
m = len(b)
if n == 0 or m == 0:
return []
mod1 = 754974721 # 2^24
mod2 = 167772161 # 2^25
mod3 = 469762049 # 2^26
m2m3 = mod2 * mod3
m1m3 = mod1 * mod3
m1m2 = mod1 * mod2
m1m2m3 = mod1 * mod2 * mod3
i1 = atcoder._math._inv_gcd(mod2 * mod3, mod1)[1]
i2 = atcoder._math._inv_gcd(mod1 * mod3, mod2)[1]
i3 = atcoder._math._inv_gcd(mod1 * mod2, mod3)[1]
c1 = convolution(mod1, a, b)
c2 = convolution(mod2, a, b)
c3 = convolution(mod3, a, b)
c = [0] * (n + m - 1)
for i in range(n + m - 1):
c[i] += (c1[i] * i1) % mod1 * m2m3
c[i] += (c2[i] * i2) % mod2 * m1m3
c[i] += (c3[i] * i3) % mod3 * m1m2
c[i] %= m1m2m3
return c
"""
atcoder.convolution = types.ModuleType('atcoder.convolution')
atcoder.convolution.__dict__['atcoder'] = atcoder
atcoder.convolution.__dict__['atcoder._bit'] = atcoder._bit
atcoder.convolution.__dict__['atcoder._math'] = atcoder._math
atcoder.convolution.__dict__['ModContext'] = atcoder.modint.ModContext
atcoder.convolution.__dict__['Modint'] = atcoder.modint.Modint
exec(_atcoder_convolution_code, atcoder.convolution.__dict__)
convolution_int = atcoder.convolution.convolution_int
# https://atcoder.jp/contests/practice2/tasks/practice2_f
import sys
# from atcoder.convolution import convolution_int
def main() -> None:
n, m = map(int, sys.stdin.readline().split())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
c = convolution_int(a, b)
print(' '.join([str(ci % 998244353) for ci in c]))
if __name__ == '__main__':
main()
``` | instruction | 0 | 97,604 | 11 | 195,208 |
No | output | 1 | 97,604 | 11 | 195,209 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:
<image>
In the above formula, 1 β€ l < r β€ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
Input
The first line contains single integer n (2 β€ n β€ 105) β the size of the array a.
The second line contains n integers a1, a2, ..., an (-109 β€ ai β€ 109) β the array elements.
Output
Print the only integer β the maximum value of f.
Examples
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
Note
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
Submitted Solution:
```
n = int(input())
R = [int(i) for i in input().split()]
L = [abs(R[i]-R[i+1]) for i in range(n-1)]
ans = [0 for _ in range(n)]
ans[0] = L[0]
for i in range(1, n-1):
ans[i] = max(L[i], L[i]-ans[i-1])
if i - 2 >= 0:
ans[i] = max(ans[i], L[i]-L[i-1]+ans[i-2])
print(max(ans))
``` | instruction | 0 | 98,320 | 11 | 196,640 |
Yes | output | 1 | 98,320 | 11 | 196,641 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:
<image>
In the above formula, 1 β€ l < r β€ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
Input
The first line contains single integer n (2 β€ n β€ 105) β the size of the array a.
The second line contains n integers a1, a2, ..., an (-109 β€ ai β€ 109) β the array elements.
Output
Print the only integer β the maximum value of f.
Examples
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
Note
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
Submitted Solution:
```
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
ALPHA='abcdefghijklmnopqrstuvwxyz'
M=998244353
EPS=1e-6
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]
#-------------------------code---------------------------#
# vsInput()
def Answer(a):
till=0
ans=-inf
for i in a:
till+=i
ans=max(till,ans)
till=max(0,till)
return ans
n=Int()
a=array()
a=[abs(a[i]-a[i+1]) for i in range(n-1)]
# print(*a)
n-=1
a=[a[i]*(-1)**i for i in range(n)]
b=[-i for i in a]
print(max(Answer(a),Answer(b)))
``` | instruction | 0 | 98,321 | 11 | 196,642 |
Yes | output | 1 | 98,321 | 11 | 196,643 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:
<image>
In the above formula, 1 β€ l < r β€ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
Input
The first line contains single integer n (2 β€ n β€ 105) β the size of the array a.
The second line contains n integers a1, a2, ..., an (-109 β€ ai β€ 109) β the array elements.
Output
Print the only integer β the maximum value of f.
Examples
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
Note
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
Submitted Solution:
```
def f(l, r, p):
if l > r: return 0
return p[r] - p[l - 1] if l % 2 == 1 else -f(l - 1, r, p) + p[l - 1]
def main():
read = lambda: tuple(map(int, input().split()))
n = read()[0]
v = read()
p = [0]
pv = 0
for i in range(n - 1):
cp = abs(v[i] - v[i + 1]) * (-1) ** i
pv += cp
p += [pv]
mxc, mxn = 0, 0
mnc, mnn = 0, 0
for i in range(n):
cc, cn = f(1, i, p), f(2, i, p)
mxc, mxn = max(mxc, cc - mnc), max(mxn, cn - mnn)
mnc, mnn = min(mnc, cc), min(mnn, cn)
return max(mxc, mxn)
print(main())
``` | instruction | 0 | 98,322 | 11 | 196,644 |
Yes | output | 1 | 98,322 | 11 | 196,645 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:
<image>
In the above formula, 1 β€ l < r β€ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
Input
The first line contains single integer n (2 β€ n β€ 105) β the size of the array a.
The second line contains n integers a1, a2, ..., an (-109 β€ ai β€ 109) β the array elements.
Output
Print the only integer β the maximum value of f.
Examples
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
Note
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
Submitted Solution:
```
from sys import stdin, stdout
n = int(stdin.readline())
values = list(map(int, stdin.readline().split()))
first = []
second = []
ans = float('-inf')
for i in range(n - 1):
first.append(abs(values[i] - values[i + 1]) * (-1) ** i)
second.append(abs(values[i] - values[i + 1]) * (-1) ** (i + 1))
cnt = 0
for i in range(n - 1):
cnt += first[i]
ans = max(ans, cnt)
if cnt < 0:
cnt = 0
cnt = 0
for i in range(n - 1):
cnt += second[i]
ans = max(ans, cnt)
if cnt < 0:
cnt = 0
stdout.write(str(ans))
``` | instruction | 0 | 98,323 | 11 | 196,646 |
Yes | output | 1 | 98,323 | 11 | 196,647 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:
<image>
In the above formula, 1 β€ l < r β€ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
Input
The first line contains single integer n (2 β€ n β€ 105) β the size of the array a.
The second line contains n integers a1, a2, ..., an (-109 β€ ai β€ 109) β the array elements.
Output
Print the only integer β the maximum value of f.
Examples
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
Note
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
Submitted Solution:
```
n = int(input())
a = list(map(int,input().strip().split()))
b = [0]*(n-1)
c = [0]*(n-1)
for i in range(n-1):
if (i+1)%2 == 0:
b[i] = (abs(a[i] - a[i+1]))
else:
b[i] = (abs(a[i] - a[i+1]))*(-1)
for i in range(1,n-1):
if i%2 == 0:
c[i] = (abs(a[i] - a[i+1]))
else:
c[i] = (abs(a[i] - a[i+1]))*(-1)
d1 = [-1000000001]*(n-1)
d2 = [-1000000001]*(n-1)
for i in range(n-1):
if i > 0:
d1[i] = max(b[i]+d1[i-1],max(0,b[i]))
else:
d1[i] = max(b[i],0)
for i in range(n-1):
if i > 0:
d2[i] = max(c[i]+d2[i-1],max(0,c[i]))
else:
d2[i] = max(c[i],0)
print(max(max(d1),max(d2)))
## print(b)
## print(d1)
## print(c)
## print(d2)
``` | instruction | 0 | 98,324 | 11 | 196,648 |
No | output | 1 | 98,324 | 11 | 196,649 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:
<image>
In the above formula, 1 β€ l < r β€ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
Input
The first line contains single integer n (2 β€ n β€ 105) β the size of the array a.
The second line contains n integers a1, a2, ..., an (-109 β€ ai β€ 109) β the array elements.
Output
Print the only integer β the maximum value of f.
Examples
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
Note
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
Submitted Solution:
```
from collections import defaultdict as dd
def main():
n = int(input())
A = list(map(int, input().split()))
# print(A)
B = []
for i in range(1, len(A)):
B.append(abs(A[i]-A[i-1]))
# print(B)
Dp = dd(int)
Dm = dd(int)
Dp[0]=0
for i in range(n-1):
Dm[i] = Dp[i-1] + B[i]
Dp[i] = max(Dm[i-1] - B[i], 0)
print(max(Dm[n-2], Dp[n-2]))
if __name__ == "__main__":
main()
``` | instruction | 0 | 98,325 | 11 | 196,650 |
No | output | 1 | 98,325 | 11 | 196,651 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:
<image>
In the above formula, 1 β€ l < r β€ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
Input
The first line contains single integer n (2 β€ n β€ 105) β the size of the array a.
The second line contains n integers a1, a2, ..., an (-109 β€ ai β€ 109) β the array elements.
Output
Print the only integer β the maximum value of f.
Examples
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
Note
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
def LI(): return [int(x) 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 main():
n = I()
a = LI()
r = t = abs(a[0]-a[1])
for i in range(3,n,2):
t += abs(a[i]-a[i-1]) - abs(a[i-1]-a[i-2])
if r < t:
r = t
elif t < 0:
t = 0
if n < 3:
return r
t = abs(a[1]-a[2])
for i in range(4,n,2):
t += abs(a[i]-a[i-1]) - abs(a[i-1]-a[i-2])
if r < t:
r = t
elif t < 0:
t = 0
return r
print(main())
``` | instruction | 0 | 98,326 | 11 | 196,652 |
No | output | 1 | 98,326 | 11 | 196,653 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:
<image>
In the above formula, 1 β€ l < r β€ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
Input
The first line contains single integer n (2 β€ n β€ 105) β the size of the array a.
The second line contains n integers a1, a2, ..., an (-109 β€ ai β€ 109) β the array elements.
Output
Print the only integer β the maximum value of f.
Examples
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
Note
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
def LI(): return [int(x) 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 main():
n = I()
a = LI()
r = t = abs(a[0]-a[1])
for i in range(3,n,2):
t += abs(a[i]-a[i-1]) - abs(a[i-1]-a[i-2])
if r < t:
r = t
elif t < 0:
t = 0
t = 0
for i in range(2,n,2):
t += abs(a[i]-a[i-1]) - abs(a[i-1]-a[i-2])
if r < t:
r = t
elif t < 0:
t = 0
return r
print(main())
``` | instruction | 0 | 98,327 | 11 | 196,654 |
No | output | 1 | 98,327 | 11 | 196,655 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your task is to develop a tiny little part of spreadsheet software.
Write a program which adds up columns and rows of given table as shown in the following figure:
<image>
Input
The input consists of several datasets. Each dataset consists of:
n (the size of row and column of the given table)
1st row of the table
2nd row of the table
:
:
nth row of the table
The input ends with a line consisting of a single 0.
Output
For each dataset, print the table with sums of rows and columns. Each item of the table should be aligned to the right with a margin for five digits. Please see the sample output for details.
Example
Input
4
52 96 15 20
86 22 35 45
45 78 54 36
16 86 74 55
4
52 96 15 20
86 22 35 45
45 78 54 36
16 86 74 55
0
Output
52 96 15 20 183
86 22 35 45 188
45 78 54 36 213
16 86 74 55 231
199 282 178 156 815
52 96 15 20 183
86 22 35 45 188
45 78 54 36 213
16 86 74 55 231
199 282 178 156 815
Submitted Solution:
```
while True:
N = int(input())
if N == 0:
break
table = [[0 for i in range(N+1)] for j in range(N+1)]
for i in range(N):
n = [int(i) for i in input().split()]
for j in range(N):
table[i][j] = n[j]
for i in range(N):
for j in range(N):
table[i][N] += table[i][j]
table[N][j] += table[i][j]
for i in range(N):
table[N][N] += table[i][N]
for i in range(N+1):
for j in range(N+1):
print(str(table[i][j]).rjust(5), end="")
print("")
``` | instruction | 0 | 98,521 | 11 | 197,042 |
Yes | output | 1 | 98,521 | 11 | 197,043 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your task is to develop a tiny little part of spreadsheet software.
Write a program which adds up columns and rows of given table as shown in the following figure:
<image>
Input
The input consists of several datasets. Each dataset consists of:
n (the size of row and column of the given table)
1st row of the table
2nd row of the table
:
:
nth row of the table
The input ends with a line consisting of a single 0.
Output
For each dataset, print the table with sums of rows and columns. Each item of the table should be aligned to the right with a margin for five digits. Please see the sample output for details.
Example
Input
4
52 96 15 20
86 22 35 45
45 78 54 36
16 86 74 55
4
52 96 15 20
86 22 35 45
45 78 54 36
16 86 74 55
0
Output
52 96 15 20 183
86 22 35 45 188
45 78 54 36 213
16 86 74 55 231
199 282 178 156 815
52 96 15 20 183
86 22 35 45 188
45 78 54 36 213
16 86 74 55 231
199 282 178 156 815
Submitted Solution:
```
# AOJ 0102: Matrix-like Computation
# Python3 2018.6.17 bal4u
while True:
n = int(input())
if n == 0: break
arr = [[0 for r in range(n+2)] for c in range(n+2)]
for r in range(n):
arr[r] = list(map(int, input().split()))
arr[r].append(sum(arr[r]))
for c in range(n+1):
s = 0
for r in range(n): s += arr[r][c]
arr[n][c] = s
for r in range(n+1):
for c in range(n+1): print(format(arr[r][c], '5d'), end='')
print()
``` | instruction | 0 | 98,522 | 11 | 197,044 |
Yes | output | 1 | 98,522 | 11 | 197,045 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your task is to develop a tiny little part of spreadsheet software.
Write a program which adds up columns and rows of given table as shown in the following figure:
<image>
Input
The input consists of several datasets. Each dataset consists of:
n (the size of row and column of the given table)
1st row of the table
2nd row of the table
:
:
nth row of the table
The input ends with a line consisting of a single 0.
Output
For each dataset, print the table with sums of rows and columns. Each item of the table should be aligned to the right with a margin for five digits. Please see the sample output for details.
Example
Input
4
52 96 15 20
86 22 35 45
45 78 54 36
16 86 74 55
4
52 96 15 20
86 22 35 45
45 78 54 36
16 86 74 55
0
Output
52 96 15 20 183
86 22 35 45 188
45 78 54 36 213
16 86 74 55 231
199 282 178 156 815
52 96 15 20 183
86 22 35 45 188
45 78 54 36 213
16 86 74 55 231
199 282 178 156 815
Submitted Solution:
```
while True:
n = int(input())
if n==0:
break
A=[]
for a in range(n):
x =list(map(int, input().split()))
x.append(sum(x))
A.append(x)
Y=[]
for j in range(n+1):
y=0
for i in range(n):
y+=A[i][j]
Y.append(y)
A.append(Y)
for i in range(n+1):
for j in range(n+1):
a=A[i][j]
a=str(a)
a=a.rjust(5)
print(a,end="")
print()
``` | instruction | 0 | 98,523 | 11 | 197,046 |
Yes | output | 1 | 98,523 | 11 | 197,047 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your task is to develop a tiny little part of spreadsheet software.
Write a program which adds up columns and rows of given table as shown in the following figure:
<image>
Input
The input consists of several datasets. Each dataset consists of:
n (the size of row and column of the given table)
1st row of the table
2nd row of the table
:
:
nth row of the table
The input ends with a line consisting of a single 0.
Output
For each dataset, print the table with sums of rows and columns. Each item of the table should be aligned to the right with a margin for five digits. Please see the sample output for details.
Example
Input
4
52 96 15 20
86 22 35 45
45 78 54 36
16 86 74 55
4
52 96 15 20
86 22 35 45
45 78 54 36
16 86 74 55
0
Output
52 96 15 20 183
86 22 35 45 188
45 78 54 36 213
16 86 74 55 231
199 282 178 156 815
52 96 15 20 183
86 22 35 45 188
45 78 54 36 213
16 86 74 55 231
199 282 178 156 815
Submitted Solution:
```
while True:
inputCount = int(input())
if inputCount == 0:
break
table = []
for lp in range(inputCount):
content = [int(item) for item in input().split(" ")]
content.append(sum(content))
table.append(content)
table.append([])
for col in range(inputCount + 1):
total = 0
for row in range(inputCount):
total += table[row][col]
table[inputCount].append(total)
for array in table:
print("".join("{:>5}".format(item) for item in array))
``` | instruction | 0 | 98,524 | 11 | 197,048 |
Yes | output | 1 | 98,524 | 11 | 197,049 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your task is to develop a tiny little part of spreadsheet software.
Write a program which adds up columns and rows of given table as shown in the following figure:
<image>
Input
The input consists of several datasets. Each dataset consists of:
n (the size of row and column of the given table)
1st row of the table
2nd row of the table
:
:
nth row of the table
The input ends with a line consisting of a single 0.
Output
For each dataset, print the table with sums of rows and columns. Each item of the table should be aligned to the right with a margin for five digits. Please see the sample output for details.
Example
Input
4
52 96 15 20
86 22 35 45
45 78 54 36
16 86 74 55
4
52 96 15 20
86 22 35 45
45 78 54 36
16 86 74 55
0
Output
52 96 15 20 183
86 22 35 45 188
45 78 54 36 213
16 86 74 55 231
199 282 178 156 815
52 96 15 20 183
86 22 35 45 188
45 78 54 36 213
16 86 74 55 231
199 282 178 156 815
Submitted Solution:
```
while True:
n = int(input())
if n != 0:
sum_col = [0 for i in range(n+1)]
for i in range(n):
list_row = list(map(int,input().split(" ")))
sum_row = sum(list_row)
list_row.append(sum_row)
for j in range(len(list_row)):
sum_col[j] += list_row[j]
print((" ").join(list(map(str,list_row))))
print((" ").join(list(map(str,sum_col))))
else:
break
``` | instruction | 0 | 98,525 | 11 | 197,050 |
No | output | 1 | 98,525 | 11 | 197,051 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your task is to develop a tiny little part of spreadsheet software.
Write a program which adds up columns and rows of given table as shown in the following figure:
<image>
Input
The input consists of several datasets. Each dataset consists of:
n (the size of row and column of the given table)
1st row of the table
2nd row of the table
:
:
nth row of the table
The input ends with a line consisting of a single 0.
Output
For each dataset, print the table with sums of rows and columns. Each item of the table should be aligned to the right with a margin for five digits. Please see the sample output for details.
Example
Input
4
52 96 15 20
86 22 35 45
45 78 54 36
16 86 74 55
4
52 96 15 20
86 22 35 45
45 78 54 36
16 86 74 55
0
Output
52 96 15 20 183
86 22 35 45 188
45 78 54 36 213
16 86 74 55 231
199 282 178 156 815
52 96 15 20 183
86 22 35 45 188
45 78 54 36 213
16 86 74 55 231
199 282 178 156 815
Submitted Solution:
```
while True:
n=int(input())
if not n: break
a=[list(map(int,input().split())) for _ in range(n)]
t=[[0 for _ in range(n+1)] for _ in range(n+1)]
for i in range(n):
for j in range(n):
t[i][j]=a[i][j]
t[i][n]+=a[i][j]
t[n][j]+=a[i][j]
t[n][n]+=a[i][j]
print(t)
``` | instruction | 0 | 98,526 | 11 | 197,052 |
No | output | 1 | 98,526 | 11 | 197,053 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your task is to develop a tiny little part of spreadsheet software.
Write a program which adds up columns and rows of given table as shown in the following figure:
<image>
Input
The input consists of several datasets. Each dataset consists of:
n (the size of row and column of the given table)
1st row of the table
2nd row of the table
:
:
nth row of the table
The input ends with a line consisting of a single 0.
Output
For each dataset, print the table with sums of rows and columns. Each item of the table should be aligned to the right with a margin for five digits. Please see the sample output for details.
Example
Input
4
52 96 15 20
86 22 35 45
45 78 54 36
16 86 74 55
4
52 96 15 20
86 22 35 45
45 78 54 36
16 86 74 55
0
Output
52 96 15 20 183
86 22 35 45 188
45 78 54 36 213
16 86 74 55 231
199 282 178 156 815
52 96 15 20 183
86 22 35 45 188
45 78 54 36 213
16 86 74 55 231
199 282 178 156 815
Submitted Solution:
```
while True:
n = int(input())
if n == 0:
break
total = [0] * (n + 1)
for i in range(n):
a = [int(i) for i in input().split()]
a.append(sum(a))
print(" ".join(map(str, a)))
for j in range(n + 1):
total[j] += a[j]
print(" ".join(map(str, total)))
``` | instruction | 0 | 98,527 | 11 | 197,054 |
No | output | 1 | 98,527 | 11 | 197,055 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your task is to develop a tiny little part of spreadsheet software.
Write a program which adds up columns and rows of given table as shown in the following figure:
<image>
Input
The input consists of several datasets. Each dataset consists of:
n (the size of row and column of the given table)
1st row of the table
2nd row of the table
:
:
nth row of the table
The input ends with a line consisting of a single 0.
Output
For each dataset, print the table with sums of rows and columns. Each item of the table should be aligned to the right with a margin for five digits. Please see the sample output for details.
Example
Input
4
52 96 15 20
86 22 35 45
45 78 54 36
16 86 74 55
4
52 96 15 20
86 22 35 45
45 78 54 36
16 86 74 55
0
Output
52 96 15 20 183
86 22 35 45 188
45 78 54 36 213
16 86 74 55 231
199 282 178 156 815
52 96 15 20 183
86 22 35 45 188
45 78 54 36 213
16 86 74 55 231
199 282 178 156 815
Submitted Solution:
```
def main():
while True:
n = int(input())
if n == 0:
break
for i in range(n):
num = 0
m = map(int, input().split())
for j in m:
print("{:5}".format(j), end='')
num += j
print("{:5}".format(num))
if __name__ == '__main__':
main()
``` | instruction | 0 | 98,528 | 11 | 197,056 |
No | output | 1 | 98,528 | 11 | 197,057 |
Provide a correct Python 3 solution for this coding contest problem.
You are a student looking for a job. Today you had an employment examination for an IT company. They asked you to write an efficient program to perform several operations. First, they showed you an N \times N square matrix and a list of operations. All operations but one modify the matrix, and the last operation outputs the character in a specified cell. Please remember that you need to output the final matrix after you finish all the operations.
Followings are the detail of the operations:
WR r c v
(Write operation) write a integer v into the cell (r,c) (1 \leq v \leq 1,000,000)
CP r1 c1 r2 c2
(Copy operation) copy a character in the cell (r1,c1) into the cell (r2,c2)
SR r1 r2
(Swap Row operation) swap the r1-th row and r2-th row
SC c1 c2
(Swap Column operation) swap the c1-th column and c2-th column
RL
(Rotate Left operation) rotate the whole matrix in counter-clockwise direction by 90 degrees
RR
(Rotate Right operation) rotate the whole matrix in clockwise direction by 90 degrees
RH
(Reflect Horizontal operation) reverse the order of the rows
RV
(Reflect Vertical operation) reverse the order of the columns
Input
First line of each testcase contains nine integers. First two integers in the line, N and Q, indicate the size of matrix and the number of queries, respectively (1 \leq N,Q \leq 40,000). Next three integers, A B, and C, are coefficients to calculate values in initial matrix (1 \leq A,B,C \leq 1,000,000), and they are used as follows: A_{r,c} = (r * A + c * B) mod C where r and c are row and column indices, respectively (1\leq r,c\leq N). Last four integers, D, E, F, and G, are coefficients to compute the final hash value mentioned in the next section (1 \leq D \leq E \leq N, 1 \leq F \leq G \leq N, E - D \leq 1,000, G - F \leq 1,000). Each of next Q lines contains one operation in the format as described above.
Output
Output a hash value h computed from the final matrix B by using following pseudo source code.
h <- 314159265
for r = D...E
for c = F...G
h <- (31 * h + B_{r,c}) mod 1,000,000,007
where "<-" is a destructive assignment operator, "for i = S...T" indicates a loop for i from S to T (both inclusive), and "mod" is a remainder operation.
Examples
Input
2 1 3 6 12 1 2 1 2
WR 1 1 1
Output
676573821
Input
2 1 3 6 12 1 2 1 2
RL
Output
676636559
Input
2 1 3 6 12 1 2 1 2
RH
Output
676547189
Input
39989 6 999983 999979 999961 1 1000 1 1000
SR 1 39989
SC 1 39989
RL
RH
RR
RV
Output
458797120 | instruction | 0 | 98,549 | 11 | 197,098 |
"Correct Solution:
```
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N, Q, A, B, C, D, E, F, G = map(int, readline().split())
d = 0; rx = 0; ry = 0
*X, = range(N)
*Y, = range(N)
def fc(d, x, y):
if d == 0:
return x, y
if d == 1:
return y, N-1-x
if d == 2:
return N-1-x, N-1-y
return N-1-y, x
mp = {}
for i in range(Q):
c, *g = readline().strip().split()
c0, c1 = c
if c0 == "R":
if c1 == "L":
d = (d - 1) % 4
elif c1 == "R":
d = (d + 1) % 4
elif c1 == "H":
if d & 1:
rx ^= 1
else:
ry ^= 1
else: #c1 == "V":
if d & 1:
ry ^= 1
else:
rx ^= 1
elif c0 == "S":
a, b = map(int, g); a -= 1; b -= 1
if c1 == "R":
if d & 1:
if rx != ((d & 2) > 0):
a = N-1-a; b = N-1-b
X[a], X[b] = X[b], X[a]
else:
if ry != ((d & 2) > 0):
a = N-1-a; b = N-1-b
Y[a], Y[b] = Y[b], Y[a]
else: #c1 == "C":
if d & 1:
if ((d & 2) == 0) != ry:
a = N-1-a; b = N-1-b
Y[a], Y[b] = Y[b], Y[a]
else:
if ((d & 2) > 0) != rx:
a = N-1-a; b = N-1-b
X[a], X[b] = X[b], X[a]
elif c0 == "C": #c == "CP":
y1, x1, y2, x2 = map(int, g); x1 -= 1; y1 -= 1; x2 -= 1; y2 -= 1
x1, y1 = fc(d, x1, y1)
x2, y2 = fc(d, x2, y2)
if rx:
x1 = N-1-x1; x2 = N-1-x2
if ry:
y1 = N-1-y1; y2 = N-1-y2
key1 = (X[x1], Y[y1]); key2 = (X[x2], Y[y2])
if key1 not in mp:
xa, ya = key1
mp[key2] = (ya*A + xa*B + A + B) % C
else:
mp[key2] = mp[key1]
else: #c == "WR":
y, x, v = map(int, g); x -= 1; y -= 1
x, y = fc(d, x, y)
if rx:
x = N-1-x
if ry:
y = N-1-y
key = (X[x], Y[y])
mp[key] = v
MOD = 10**9 + 7
h = 314159265
for y in range(D-1, E):
for x in range(F-1, G):
x0, y0 = fc(d, x, y)
if rx:
x0 = N-1-x0
if ry:
y0 = N-1-y0
x0 = X[x0]; y0 = Y[y0]
key = (x0, y0)
if key in mp:
v = mp[key]
else:
v = ((y0+1)*A + (x0+1)*B) % C
h = (31 * h + v) % MOD
write("%d\n" % h)
solve()
``` | output | 1 | 98,549 | 11 | 197,099 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The next lecture in a high school requires two topics to be discussed. The i-th topic is interesting by a_i units for the teacher and by b_i units for the students.
The pair of topics i and j (i < j) is called good if a_i + a_j > b_i + b_j (i.e. it is more interesting for the teacher).
Your task is to find the number of good pairs of topics.
Input
The first line of the input contains one integer n (2 β€ n β€ 2 β
10^5) β the number of topics.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the interestingness of the i-th topic for the teacher.
The third line of the input contains n integers b_1, b_2, ..., b_n (1 β€ b_i β€ 10^9), where b_i is the interestingness of the i-th topic for the students.
Output
Print one integer β the number of good pairs of topic.
Examples
Input
5
4 8 2 6 2
4 5 4 1 3
Output
7
Input
4
1 3 2 4
1 3 2 4
Output
0
Submitted Solution:
```
import sys
#sys.stdin = open("input.txt")
#T = int(input())
def trova(a,b,x):
if x>=a:
return a
if x <= b:
while x==C[b]:
b = b-1
return b
m = (a+b)//2
if x == C[m]:
while x == C[m]:
m = m-1
return m
if a == b:
while C[a] == x:
a = a-1
return a
if x < C[m]:
trova(m,b,x)
return
if x > C[m]:
trova(a,m,x)
return
T = 1
t = 0
while t<T:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
n = 0
C = []
while n<N:
C.append(A[n]-B[n])
n +=1
C.sort(reverse = True)
n = 0
out = 0
#print (C)
inizio = 0
fine = N-1
while inizio<fine:
if C[inizio]+C[fine] > 0:
out += fine - inizio
inizio +=1
else:
fine -=1
print (out)
t +=1
``` | instruction | 0 | 98,766 | 11 | 197,532 |
Yes | output | 1 | 98,766 | 11 | 197,533 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The next lecture in a high school requires two topics to be discussed. The i-th topic is interesting by a_i units for the teacher and by b_i units for the students.
The pair of topics i and j (i < j) is called good if a_i + a_j > b_i + b_j (i.e. it is more interesting for the teacher).
Your task is to find the number of good pairs of topics.
Input
The first line of the input contains one integer n (2 β€ n β€ 2 β
10^5) β the number of topics.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the interestingness of the i-th topic for the teacher.
The third line of the input contains n integers b_1, b_2, ..., b_n (1 β€ b_i β€ 10^9), where b_i is the interestingness of the i-th topic for the students.
Output
Print one integer β the number of good pairs of topic.
Examples
Input
5
4 8 2 6 2
4 5 4 1 3
Output
7
Input
4
1 3 2 4
1 3 2 4
Output
0
Submitted Solution:
```
from bisect import bisect_right as left
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
m=[]
ans=0
for i in range(n):
m.append(a[i]-b[i])
m.sort()
p,ne=[],[]
ans=0
for i in range(n):
if m[i]>0:
ans-=1
ans+=n-left(m,-m[i])
print(ans//2)
``` | instruction | 0 | 98,767 | 11 | 197,534 |
Yes | output | 1 | 98,767 | 11 | 197,535 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The next lecture in a high school requires two topics to be discussed. The i-th topic is interesting by a_i units for the teacher and by b_i units for the students.
The pair of topics i and j (i < j) is called good if a_i + a_j > b_i + b_j (i.e. it is more interesting for the teacher).
Your task is to find the number of good pairs of topics.
Input
The first line of the input contains one integer n (2 β€ n β€ 2 β
10^5) β the number of topics.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the interestingness of the i-th topic for the teacher.
The third line of the input contains n integers b_1, b_2, ..., b_n (1 β€ b_i β€ 10^9), where b_i is the interestingness of the i-th topic for the students.
Output
Print one integer β the number of good pairs of topic.
Examples
Input
5
4 8 2 6 2
4 5 4 1 3
Output
7
Input
4
1 3 2 4
1 3 2 4
Output
0
Submitted Solution:
```
import sys
# from math import ceil,floor,tan
import bisect
RI = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
n = int(ri())
a = RI()
b= RI()
c = [a[i]-b[i] for i in range(n)]
c.sort()
i=0
while i < len(c) and c[i] < 0 :
i+=1
ans = 0
for i in range(i,n):
pos = bisect.bisect_left(c,1-c[i])
if pos < i:
ans+=(i-pos)
print(ans)
``` | instruction | 0 | 98,768 | 11 | 197,536 |
Yes | output | 1 | 98,768 | 11 | 197,537 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The next lecture in a high school requires two topics to be discussed. The i-th topic is interesting by a_i units for the teacher and by b_i units for the students.
The pair of topics i and j (i < j) is called good if a_i + a_j > b_i + b_j (i.e. it is more interesting for the teacher).
Your task is to find the number of good pairs of topics.
Input
The first line of the input contains one integer n (2 β€ n β€ 2 β
10^5) β the number of topics.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the interestingness of the i-th topic for the teacher.
The third line of the input contains n integers b_1, b_2, ..., b_n (1 β€ b_i β€ 10^9), where b_i is the interestingness of the i-th topic for the students.
Output
Print one integer β the number of good pairs of topic.
Examples
Input
5
4 8 2 6 2
4 5 4 1 3
Output
7
Input
4
1 3 2 4
1 3 2 4
Output
0
Submitted Solution:
```
n = int(input())
l = list(map(int, input().split()))
m = list(map(int, input().split()))
for i in range(n):
l[i] -= m[i]
l.sort()
i = 0
j = n - 1
count = 0
while j > i:
if l[j] + l[i] > 0:
count += j - i
j -= 1
else:
i += 1
print(count)
``` | instruction | 0 | 98,769 | 11 | 197,538 |
Yes | output | 1 | 98,769 | 11 | 197,539 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The next lecture in a high school requires two topics to be discussed. The i-th topic is interesting by a_i units for the teacher and by b_i units for the students.
The pair of topics i and j (i < j) is called good if a_i + a_j > b_i + b_j (i.e. it is more interesting for the teacher).
Your task is to find the number of good pairs of topics.
Input
The first line of the input contains one integer n (2 β€ n β€ 2 β
10^5) β the number of topics.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the interestingness of the i-th topic for the teacher.
The third line of the input contains n integers b_1, b_2, ..., b_n (1 β€ b_i β€ 10^9), where b_i is the interestingness of the i-th topic for the students.
Output
Print one integer β the number of good pairs of topic.
Examples
Input
5
4 8 2 6 2
4 5 4 1 3
Output
7
Input
4
1 3 2 4
1 3 2 4
Output
0
Submitted Solution:
```
from bisect import *
qtd = int(input())
dif = sorted([int(a) - int(b) for a, b in zip([int(x) for x in input().split()],[int(x) for x in input().split()])])
#todas as combinacoes dos positivos:
totalpos = qtd
for el in dif:
if el <= 0:
totalpos -= 1
else:
break
output = int(totalpos*(totalpos-1)/2)
i = 0
while(dif[i] < 0):
maisDir = bisect_left(dif, -dif[i], i, qtd)-1
output += qtd - maisDir
i += 1
print(output)
``` | instruction | 0 | 98,770 | 11 | 197,540 |
No | output | 1 | 98,770 | 11 | 197,541 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The next lecture in a high school requires two topics to be discussed. The i-th topic is interesting by a_i units for the teacher and by b_i units for the students.
The pair of topics i and j (i < j) is called good if a_i + a_j > b_i + b_j (i.e. it is more interesting for the teacher).
Your task is to find the number of good pairs of topics.
Input
The first line of the input contains one integer n (2 β€ n β€ 2 β
10^5) β the number of topics.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the interestingness of the i-th topic for the teacher.
The third line of the input contains n integers b_1, b_2, ..., b_n (1 β€ b_i β€ 10^9), where b_i is the interestingness of the i-th topic for the students.
Output
Print one integer β the number of good pairs of topic.
Examples
Input
5
4 8 2 6 2
4 5 4 1 3
Output
7
Input
4
1 3 2 4
1 3 2 4
Output
0
Submitted Solution:
```
from bisect import bisect_left as bisect
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[a[i]-b[i] for i in range(n)]
c.sort()
cu=0
for i in c:
x=1-i
z=bisect(c,x)
if x<0:
cu+=(n-z)-1
else:
cu+=(n-z)
print(cu//2)
``` | instruction | 0 | 98,771 | 11 | 197,542 |
No | output | 1 | 98,771 | 11 | 197,543 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The next lecture in a high school requires two topics to be discussed. The i-th topic is interesting by a_i units for the teacher and by b_i units for the students.
The pair of topics i and j (i < j) is called good if a_i + a_j > b_i + b_j (i.e. it is more interesting for the teacher).
Your task is to find the number of good pairs of topics.
Input
The first line of the input contains one integer n (2 β€ n β€ 2 β
10^5) β the number of topics.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the interestingness of the i-th topic for the teacher.
The third line of the input contains n integers b_1, b_2, ..., b_n (1 β€ b_i β€ 10^9), where b_i is the interestingness of the i-th topic for the students.
Output
Print one integer β the number of good pairs of topic.
Examples
Input
5
4 8 2 6 2
4 5 4 1 3
Output
7
Input
4
1 3 2 4
1 3 2 4
Output
0
Submitted Solution:
```
all_data = input()
n = int(all_data)
print(n)
x1 = input()
x2 = input()
l1 = [int(x) for x in x1.split(' ')]
l2 = [int(x) for x in x2.split(' ')]
print(l1, l2)
cnt = 0
for i in range(n):
for j in range(i + 1, n):
if l1[i] + l1[j] > l2[i] + l2[j]:
cnt += 1
print(cnt)
``` | instruction | 0 | 98,772 | 11 | 197,544 |
No | output | 1 | 98,772 | 11 | 197,545 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The next lecture in a high school requires two topics to be discussed. The i-th topic is interesting by a_i units for the teacher and by b_i units for the students.
The pair of topics i and j (i < j) is called good if a_i + a_j > b_i + b_j (i.e. it is more interesting for the teacher).
Your task is to find the number of good pairs of topics.
Input
The first line of the input contains one integer n (2 β€ n β€ 2 β
10^5) β the number of topics.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the interestingness of the i-th topic for the teacher.
The third line of the input contains n integers b_1, b_2, ..., b_n (1 β€ b_i β€ 10^9), where b_i is the interestingness of the i-th topic for the students.
Output
Print one integer β the number of good pairs of topic.
Examples
Input
5
4 8 2 6 2
4 5 4 1 3
Output
7
Input
4
1 3 2 4
1 3 2 4
Output
0
Submitted Solution:
```
# limit for array size
N = 100001;
# Max size of tree
tree = [0] * (2 * N);
# function to build the tree
def build(arr) :
# insert leaf nodes in tree
for i in range(n) :
tree[n + i] = arr[i];
# build the tree by calculating parents
for i in range(n - 1, 0, -1) :
tree[i] = tree[i << 1] + tree[i << 1 | 1];
# function to update a tree node
def updateTreeNode(p, value) :
# set value at position p
tree[p + n] = value;
p = p + n;
# move upward and update parents
i = p;
while i > 1 :
tree[i >> 1] = tree[i] + tree[i ^ 1];
i >>= 1;
# function to get sum on interval [l, r)
def query(l, r) :
res = 0;
# loop to find the sum in the range
l += n;
r += n;
while l < r :
if (l & 1) :
res += tree[l];
l += 1
if (r & 1) :
r -= 1;
res += tree[r];
l >>= 1;
r >>= 1
return res;
from collections import defaultdict
import bisect
#a,b = map(int,input().strip().split())
n = int(input().strip())
a = [int(i) for i in input().strip().split()]
b = [int(i) for i in input().strip().split()]
minus = [(a[i] - b[i],i) for i in range(n)]
minus.sort()
order = [i[1] for i in minus]
minus = [i[0] for i in minus]
total = 0
temp = [0 for i in range(n)]
build(temp)
#print(minus)
for i in range(n):
result = a[i] - b[i]
ans = bisect.bisect_right(minus,result)
#print(i,result,ans)
total += n - ans
if ans < n:
total -= query(ans + 1,n + 1)
updateTreeNode(order[i], 1)
#print(tree[:10])
print(total)
``` | instruction | 0 | 98,773 | 11 | 197,546 |
No | output | 1 | 98,773 | 11 | 197,547 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Enter a positive integer n of 4,000 or less, with a pair of integers a, b, c, d in the range 0-1000.
a + b + c + d = n
Create a program that outputs the number of combinations that satisfy the conditions.
Input
Given multiple datasets. Each dataset is given n on one row. Please process until the end of the input.
The number of datasets does not exceed 50.
Output
For each data set, output the number of combinations of a, b, c, and d on one line.
Example
Input
2
3
35
Output
10
20
8436
Submitted Solution:
```
def Kosuu(n,sak):
if n <= sak:
kazu = n + 1
sta = 0
end = n
else:
kazu = sak * 2 + 1 - n
sta = n - sak
end = sak
return [kazu,sta,end]
while True:
try:
Sum = 0
n = int(input())
ABl = Kosuu(n,2000)
for i in range(ABl[1],ABl[2] + 1):
Sum += Kosuu(i,1000)[0] * Kosuu(n -i,1000)[0]
print(Sum)
except EOFError:
break
``` | instruction | 0 | 99,353 | 11 | 198,706 |
Yes | output | 1 | 99,353 | 11 | 198,707 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Enter a positive integer n of 4,000 or less, with a pair of integers a, b, c, d in the range 0-1000.
a + b + c + d = n
Create a program that outputs the number of combinations that satisfy the conditions.
Input
Given multiple datasets. Each dataset is given n on one row. Please process until the end of the input.
The number of datasets does not exceed 50.
Output
For each data set, output the number of combinations of a, b, c, and d on one line.
Example
Input
2
3
35
Output
10
20
8436
Submitted Solution:
```
ab = [0 for _ in range(2001)]
for a in range(1001):
for b in range(1001):
ab[a+b] += 1
while True:
try:
n = int(input())
except:
break
ans = sum(ab[i]*ab[n-i] for i in range(2001) if n-i >= 0 and n-i <= 2000)
print(ans)
``` | instruction | 0 | 99,354 | 11 | 198,708 |
Yes | output | 1 | 99,354 | 11 | 198,709 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Enter a positive integer n of 4,000 or less, with a pair of integers a, b, c, d in the range 0-1000.
a + b + c + d = n
Create a program that outputs the number of combinations that satisfy the conditions.
Input
Given multiple datasets. Each dataset is given n on one row. Please process until the end of the input.
The number of datasets does not exceed 50.
Output
For each data set, output the number of combinations of a, b, c, and d on one line.
Example
Input
2
3
35
Output
10
20
8436
Submitted Solution:
```
import sys
hist = [0 for i in range(4001)]
for i in range(1001):
for j in range(1001):
hist[i + j] += 1
for line in sys.stdin:
ans = 0
n = int(line)
for i in range(min(n, 2000) + 1):
ans += (hist[i] * hist[n-i])
print(ans)
``` | instruction | 0 | 99,356 | 11 | 198,712 |
Yes | output | 1 | 99,356 | 11 | 198,713 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Enter a positive integer n of 4,000 or less, with a pair of integers a, b, c, d in the range 0-1000.
a + b + c + d = n
Create a program that outputs the number of combinations that satisfy the conditions.
Input
Given multiple datasets. Each dataset is given n on one row. Please process until the end of the input.
The number of datasets does not exceed 50.
Output
For each data set, output the number of combinations of a, b, c, and d on one line.
Example
Input
2
3
35
Output
10
20
8436
Submitted Solution:
```
while True:
m = 0
try:
n = int(input().strip())
for a in range(10001):
if n - a <0:
break
for b in range(10001):
if n - (a+b) <0:
break
for c in range(10001):
if n - (a+b+c) <0:
break
for d in range(10001):
if n - (a+b+c+d) <0:
break
if a+b+c+d == n:
m += 1
print(m)
except EOFError:
break
``` | instruction | 0 | 99,357 | 11 | 198,714 |
No | output | 1 | 99,357 | 11 | 198,715 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Enter a positive integer n of 4,000 or less, with a pair of integers a, b, c, d in the range 0-1000.
a + b + c + d = n
Create a program that outputs the number of combinations that satisfy the conditions.
Input
Given multiple datasets. Each dataset is given n on one row. Please process until the end of the input.
The number of datasets does not exceed 50.
Output
For each data set, output the number of combinations of a, b, c, and d on one line.
Example
Input
2
3
35
Output
10
20
8436
Submitted Solution:
```
import sys
for line in sys.stdin.readlines():
n = int(line.rstrip())
count = 0
for i in range(min(2001,n+1)):
if n - i >= 0:
count += (i+1)*(n-i+1)
print(count)
``` | instruction | 0 | 99,358 | 11 | 198,716 |
No | output | 1 | 99,358 | 11 | 198,717 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Enter a positive integer n of 4,000 or less, with a pair of integers a, b, c, d in the range 0-1000.
a + b + c + d = n
Create a program that outputs the number of combinations that satisfy the conditions.
Input
Given multiple datasets. Each dataset is given n on one row. Please process until the end of the input.
The number of datasets does not exceed 50.
Output
For each data set, output the number of combinations of a, b, c, and d on one line.
Example
Input
2
3
35
Output
10
20
8436
Submitted Solution:
```
def solve(n):
ans=0
for a in range(n+1):
for b in range(n+1):
if a+b>n:
break
for c in range(n+1):
if n-(a+b+c)>=0:
ans+=1
else:
break
return ans
while True:
try:
n=int(input())
print(solve(n))
except EOFError:
break
``` | instruction | 0 | 99,359 | 11 | 198,718 |
No | output | 1 | 99,359 | 11 | 198,719 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful.
Therefore, Sasha decided to upsolve the following problem:
You have an array a with n integers. You need to count the number of funny pairs (l, r) (l β€ r). To check if a pair (l, r) is a funny pair, take mid = (l + r - 1)/(2), then if r - l + 1 is an even number and a_l β a_{l+1} β β¦ β a_{mid} = a_{mid + 1} β a_{mid + 2} β β¦ β a_r, then the pair is funny. In other words, β of elements of the left half of the subarray from l to r should be equal to β of elements of the right half. Note that β denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
It is time to continue solving the contest, so Sasha asked you to solve this task.
Input
The first line contains one integer n (2 β€ n β€ 3 β
10^5) β the size of the array.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_i < 2^{20}) β array itself.
Output
Print one integer β the number of funny pairs. You should consider only pairs where r - l + 1 is even number.
Examples
Input
5
1 2 3 4 5
Output
1
Input
6
3 2 2 3 7 6
Output
3
Input
3
42 4 2
Output
0
Note
Be as cool as Sasha, upsolve problems!
In the first example, the only funny pair is (2, 5), as 2 β 3 = 4 β 5 = 1.
In the second example, funny pairs are (2, 3), (1, 4), and (3, 6).
In the third example, there are no funny pairs.
Submitted Solution:
```
input()
d={(0,0):1}
r=s=i=0
for x in map(int,input().split()):s^=x;i^=1;c=d.get((s,i),0);r+=c;d[s,i]=c+1
print(r)
``` | instruction | 0 | 99,527 | 11 | 199,054 |
Yes | output | 1 | 99,527 | 11 | 199,055 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful.
Therefore, Sasha decided to upsolve the following problem:
You have an array a with n integers. You need to count the number of funny pairs (l, r) (l β€ r). To check if a pair (l, r) is a funny pair, take mid = (l + r - 1)/(2), then if r - l + 1 is an even number and a_l β a_{l+1} β β¦ β a_{mid} = a_{mid + 1} β a_{mid + 2} β β¦ β a_r, then the pair is funny. In other words, β of elements of the left half of the subarray from l to r should be equal to β of elements of the right half. Note that β denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
It is time to continue solving the contest, so Sasha asked you to solve this task.
Input
The first line contains one integer n (2 β€ n β€ 3 β
10^5) β the size of the array.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_i < 2^{20}) β array itself.
Output
Print one integer β the number of funny pairs. You should consider only pairs where r - l + 1 is even number.
Examples
Input
5
1 2 3 4 5
Output
1
Input
6
3 2 2 3 7 6
Output
3
Input
3
42 4 2
Output
0
Note
Be as cool as Sasha, upsolve problems!
In the first example, the only funny pair is (2, 5), as 2 β 3 = 4 β 5 = 1.
In the second example, funny pairs are (2, 3), (1, 4), and (3, 6).
In the third example, there are no funny pairs.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
xor = [a[0]]
for i in range(1, n):
xor.append(xor[-1]^a[i])
d = {0: [1, 0]}
for i in range(n):
if xor[i] not in d:
d[xor[i]] = [0, 0]
d[xor[i]][(i+1)%2] += 1
#for k in d: print(d[k])
funny = 0
for k in d:
odd = d[k][1]
even = d[k][0]
funny += (odd*(odd-1))//2
funny += (even*(even-1))//2
print(funny)
``` | instruction | 0 | 99,528 | 11 | 199,056 |
Yes | output | 1 | 99,528 | 11 | 199,057 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful.
Therefore, Sasha decided to upsolve the following problem:
You have an array a with n integers. You need to count the number of funny pairs (l, r) (l β€ r). To check if a pair (l, r) is a funny pair, take mid = (l + r - 1)/(2), then if r - l + 1 is an even number and a_l β a_{l+1} β β¦ β a_{mid} = a_{mid + 1} β a_{mid + 2} β β¦ β a_r, then the pair is funny. In other words, β of elements of the left half of the subarray from l to r should be equal to β of elements of the right half. Note that β denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
It is time to continue solving the contest, so Sasha asked you to solve this task.
Input
The first line contains one integer n (2 β€ n β€ 3 β
10^5) β the size of the array.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_i < 2^{20}) β array itself.
Output
Print one integer β the number of funny pairs. You should consider only pairs where r - l + 1 is even number.
Examples
Input
5
1 2 3 4 5
Output
1
Input
6
3 2 2 3 7 6
Output
3
Input
3
42 4 2
Output
0
Note
Be as cool as Sasha, upsolve problems!
In the first example, the only funny pair is (2, 5), as 2 β 3 = 4 β 5 = 1.
In the second example, funny pairs are (2, 3), (1, 4), and (3, 6).
In the third example, there are no funny pairs.
Submitted Solution:
```
# -*- coding: utf-8 -*-
import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul, xor
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
N = INT()
A = LIST()
acc = [0] + list(accumulate(A, xor))
C1 = Counter()
for i in range(0, N+1, 2):
C1[acc[i]] += 1
C2 = Counter()
for i in range(1, N+1, 2):
C2[acc[i]] += 1
ans = 0
for k, v in C1.items():
if v >= 2:
ans += v * (v-1) // 2
for k, v in C2.items():
if v >= 2:
ans += v * (v-1) // 2
print(ans)
``` | instruction | 0 | 99,529 | 11 | 199,058 |
Yes | output | 1 | 99,529 | 11 | 199,059 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful.
Therefore, Sasha decided to upsolve the following problem:
You have an array a with n integers. You need to count the number of funny pairs (l, r) (l β€ r). To check if a pair (l, r) is a funny pair, take mid = (l + r - 1)/(2), then if r - l + 1 is an even number and a_l β a_{l+1} β β¦ β a_{mid} = a_{mid + 1} β a_{mid + 2} β β¦ β a_r, then the pair is funny. In other words, β of elements of the left half of the subarray from l to r should be equal to β of elements of the right half. Note that β denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
It is time to continue solving the contest, so Sasha asked you to solve this task.
Input
The first line contains one integer n (2 β€ n β€ 3 β
10^5) β the size of the array.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_i < 2^{20}) β array itself.
Output
Print one integer β the number of funny pairs. You should consider only pairs where r - l + 1 is even number.
Examples
Input
5
1 2 3 4 5
Output
1
Input
6
3 2 2 3 7 6
Output
3
Input
3
42 4 2
Output
0
Note
Be as cool as Sasha, upsolve problems!
In the first example, the only funny pair is (2, 5), as 2 β 3 = 4 β 5 = 1.
In the second example, funny pairs are (2, 3), (1, 4), and (3, 6).
In the third example, there are no funny pairs.
Submitted Solution:
```
import sys
from collections import defaultdict
input = sys.stdin.readline
if __name__ == '__main__':
n = int(input())
arr = list(map(int, input().strip().split()))
xr = 0
ev = defaultdict(int)
od = defaultdict(int)
od[0] += 1
ans = 0
for i in range(n):
xr ^= arr[i]
if i & 1:
ans += od[xr]
od[xr] += 1
else:
ans += ev[xr]
ev[xr] += 1
print(ans)
``` | instruction | 0 | 99,530 | 11 | 199,060 |
Yes | output | 1 | 99,530 | 11 | 199,061 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful.
Therefore, Sasha decided to upsolve the following problem:
You have an array a with n integers. You need to count the number of funny pairs (l, r) (l β€ r). To check if a pair (l, r) is a funny pair, take mid = (l + r - 1)/(2), then if r - l + 1 is an even number and a_l β a_{l+1} β β¦ β a_{mid} = a_{mid + 1} β a_{mid + 2} β β¦ β a_r, then the pair is funny. In other words, β of elements of the left half of the subarray from l to r should be equal to β of elements of the right half. Note that β denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
It is time to continue solving the contest, so Sasha asked you to solve this task.
Input
The first line contains one integer n (2 β€ n β€ 3 β
10^5) β the size of the array.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_i < 2^{20}) β array itself.
Output
Print one integer β the number of funny pairs. You should consider only pairs where r - l + 1 is even number.
Examples
Input
5
1 2 3 4 5
Output
1
Input
6
3 2 2 3 7 6
Output
3
Input
3
42 4 2
Output
0
Note
Be as cool as Sasha, upsolve problems!
In the first example, the only funny pair is (2, 5), as 2 β 3 = 4 β 5 = 1.
In the second example, funny pairs are (2, 3), (1, 4), and (3, 6).
In the third example, there are no funny pairs.
Submitted Solution:
```
count=0;cc={}
def work(a,i,j):
global cc,count
if j==i:return a[i]
if (i,j) in cc:return cc[(i,j)]
m=(j+i-1)//2
a1=work(a,i,m)
a2=work(a,m+1,j)
#print((i,j),a1,a2)
if a1==a2:
if (i,j) not in cc:
count+=1
cc[(i,j)]=a1^a2
return a1^a2
n=int(input())
a=list(map(int,input().split()))
if n%2==0:
work(a,0,n-1)
if n>4:work(a,0,n-3);work(a,2,n-1)
else:
work(a,1,n-1)
work(a,0,n-2)
print(count)
``` | instruction | 0 | 99,531 | 11 | 199,062 |
No | output | 1 | 99,531 | 11 | 199,063 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful.
Therefore, Sasha decided to upsolve the following problem:
You have an array a with n integers. You need to count the number of funny pairs (l, r) (l β€ r). To check if a pair (l, r) is a funny pair, take mid = (l + r - 1)/(2), then if r - l + 1 is an even number and a_l β a_{l+1} β β¦ β a_{mid} = a_{mid + 1} β a_{mid + 2} β β¦ β a_r, then the pair is funny. In other words, β of elements of the left half of the subarray from l to r should be equal to β of elements of the right half. Note that β denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
It is time to continue solving the contest, so Sasha asked you to solve this task.
Input
The first line contains one integer n (2 β€ n β€ 3 β
10^5) β the size of the array.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_i < 2^{20}) β array itself.
Output
Print one integer β the number of funny pairs. You should consider only pairs where r - l + 1 is even number.
Examples
Input
5
1 2 3 4 5
Output
1
Input
6
3 2 2 3 7 6
Output
3
Input
3
42 4 2
Output
0
Note
Be as cool as Sasha, upsolve problems!
In the first example, the only funny pair is (2, 5), as 2 β 3 = 4 β 5 = 1.
In the second example, funny pairs are (2, 3), (1, 4), and (3, 6).
In the third example, there are no funny pairs.
Submitted Solution:
```
# Bismillahirahmanirahim
# Soru 1
#
# nv = list(map(int, input().split()))
#
# n = nv[0] - 1
# v = nv[1]
# if v >= n:
# print(n)
# quit()
# k = 2
# money = v
# while n - v > 0:
# n = n - 1
# money += k
# k += 1
# print(money)
#Soru2
# def carpan(n):
# lst = []
# sq = n**0.5 + 1
# for i in range(2,int(sq)+1):
# if n%i == 0:
# lst.append(i)
# return lst
#
#
# n = int(input())
# lst = list(map(int, input().split()))
# lst = sorted(lst, reverse=True)
# mn = lst[-1]
# total = sum(lst)
# large = 0
# for i in lst:
# mx = i
# lst1 = carpan(mx)
# for j in lst1:
# if mx + mn - (mx/j + mn*j) > large:
# large = mx + mn - (mx/j + mn*j)
# print(int(total-large))
# Soru 3
n = int(input())
lst = list(map(int, input().split()))
total = 0
for i in range(1,n):
lst[i] = lst[i] ^ lst[i - 1]
def ikili(n):
return n *(n-1)/2
dct = {0:[0, 0]}
for i in lst:
dct[i] = [0, 0]
for i in range(n):
if i %2 == 0:
dct[lst[i]][0] += 1
else:
dct[lst[i]][1] += 1
total += dct[0][1]
dct.pop(0)
for i in dct:
total += ikili(dct[i][0]) + ikili(dct[i][1])
print(int(total))
``` | instruction | 0 | 99,532 | 11 | 199,064 |
No | output | 1 | 99,532 | 11 | 199,065 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful.
Therefore, Sasha decided to upsolve the following problem:
You have an array a with n integers. You need to count the number of funny pairs (l, r) (l β€ r). To check if a pair (l, r) is a funny pair, take mid = (l + r - 1)/(2), then if r - l + 1 is an even number and a_l β a_{l+1} β β¦ β a_{mid} = a_{mid + 1} β a_{mid + 2} β β¦ β a_r, then the pair is funny. In other words, β of elements of the left half of the subarray from l to r should be equal to β of elements of the right half. Note that β denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
It is time to continue solving the contest, so Sasha asked you to solve this task.
Input
The first line contains one integer n (2 β€ n β€ 3 β
10^5) β the size of the array.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_i < 2^{20}) β array itself.
Output
Print one integer β the number of funny pairs. You should consider only pairs where r - l + 1 is even number.
Examples
Input
5
1 2 3 4 5
Output
1
Input
6
3 2 2 3 7 6
Output
3
Input
3
42 4 2
Output
0
Note
Be as cool as Sasha, upsolve problems!
In the first example, the only funny pair is (2, 5), as 2 β 3 = 4 β 5 = 1.
In the second example, funny pairs are (2, 3), (1, 4), and (3, 6).
In the third example, there are no funny pairs.
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
x,cnt=0,0
for i in range(n-1):
x^=a[i]
y=0
for j in range(n):
y^=a[j]
if((j-i+1)%2==0) and (x==y):
cnt+=1
x=0
print(cnt)
``` | instruction | 0 | 99,533 | 11 | 199,066 |
No | output | 1 | 99,533 | 11 | 199,067 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful.
Therefore, Sasha decided to upsolve the following problem:
You have an array a with n integers. You need to count the number of funny pairs (l, r) (l β€ r). To check if a pair (l, r) is a funny pair, take mid = (l + r - 1)/(2), then if r - l + 1 is an even number and a_l β a_{l+1} β β¦ β a_{mid} = a_{mid + 1} β a_{mid + 2} β β¦ β a_r, then the pair is funny. In other words, β of elements of the left half of the subarray from l to r should be equal to β of elements of the right half. Note that β denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
It is time to continue solving the contest, so Sasha asked you to solve this task.
Input
The first line contains one integer n (2 β€ n β€ 3 β
10^5) β the size of the array.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_i < 2^{20}) β array itself.
Output
Print one integer β the number of funny pairs. You should consider only pairs where r - l + 1 is even number.
Examples
Input
5
1 2 3 4 5
Output
1
Input
6
3 2 2 3 7 6
Output
3
Input
3
42 4 2
Output
0
Note
Be as cool as Sasha, upsolve problems!
In the first example, the only funny pair is (2, 5), as 2 β 3 = 4 β 5 = 1.
In the second example, funny pairs are (2, 3), (1, 4), and (3, 6).
In the third example, there are no funny pairs.
Submitted Solution:
```
n = int(input())
arr_str = input().split()
arr = [int(x) for x in arr_str]
cum_sum_arr = []
cum_sum_arr.append(0)
cum_sum = 0
for i in range(0, len(arr)):
cum_sum = cum_sum^arr[i]
cum_sum_arr.append(cum_sum)
print(cum_sum_arr)
count_pair = 0
sum2ind = dict()
sum2ind[0] = [0]
for r in range(1, len(cum_sum_arr)):
if cum_sum_arr[r] in sum2ind:
for l_minus_1 in sum2ind[cum_sum_arr[r]]:
if (r - l_minus_1) % 2 == 0:
count_pair += 1
sum2ind[cum_sum_arr[r]].append(r)
else:
sum2ind[cum_sum_arr[r]] = [r]
print(count_pair)
``` | instruction | 0 | 99,534 | 11 | 199,068 |
No | output | 1 | 99,534 | 11 | 199,069 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Uh oh! Applications to tech companies are due soon, and you've been procrastinating by doing contests instead! (Let's pretend for now that it is actually possible to get a job in these uncertain times.)
You have completed many programming projects. In fact, there are exactly n types of programming projects, and you have completed a_i projects of type i. Your rΓ©sumΓ© has limited space, but you want to carefully choose them in such a way that maximizes your chances of getting hired.
You want to include several projects of the same type to emphasize your expertise, but you also don't want to include so many that the low-quality projects start slipping in. Specifically, you determine the following quantity to be a good indicator of your chances of getting hired:
$$$ f(b_1,β¦,b_n)=β_{i=1}^n b_i(a_i-b_i^2). $$$
Here, b_i denotes the number of projects of type i you include in your rΓ©sumΓ©. Of course, you cannot include more projects than you have completed, so you require 0β€ b_i β€ a_i for all i.
Your rΓ©sumΓ© only has enough room for k projects, and you will absolutely not be hired if your rΓ©sumΓ© has empty space, so you require β_{i=1}^n b_i=k.
Find values for b_1,β¦, b_n that maximize the value of f(b_1,β¦,b_n) while satisfying the above two constraints.
Input
The first line contains two integers n and k (1β€ nβ€ 10^5, 1β€ kβ€ β_{i=1}^n a_i) β the number of types of programming projects and the rΓ©sumΓ© size, respectively.
The next line contains n integers a_1,β¦,a_n (1β€ a_iβ€ 10^9) β a_i is equal to the number of completed projects of type i.
Output
In a single line, output n integers b_1,β¦, b_n that achieve the maximum value of f(b_1,β¦,b_n), while satisfying the requirements 0β€ b_iβ€ a_i and β_{i=1}^n b_i=k. If there are multiple solutions, output any.
Note that you do not have to output the value f(b_1,β¦,b_n).
Examples
Input
10 32
1 2 3 4 5 5 5 5 5 5
Output
1 2 3 3 3 4 4 4 4 4
Input
5 8
4 4 8 2 1
Output
2 2 2 1 1
Note
For the first test, the optimal answer is f=-269. Note that a larger f value is possible if we ignored the constraint β_{i=1}^n b_i=k.
For the second test, the optimal answer is f=9. | instruction | 0 | 99,593 | 11 | 199,186 |
Tags: binary search, greedy, math
Correct Solution:
```
import sys
import heapq as hq
readline = sys.stdin.readline
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
eps = 10**-7
def solve():
n, k = nm()
a = nl()
ans = [0]*n
ok = 10**9; ng = -4*10**18
while ok - ng > 1:
mid = (ok + ng) // 2
ck = 0
for i in range(n):
d = 9 - 12 * (mid + 1 - a[i])
if d < 0:
continue
ck += min(a[i], int((3 + d**.5) / 6 + eps))
# print(mid, ck)
if ck > k:
ng = mid
else:
ok = mid
for i in range(n):
d = 9 - 12 * (ok + 1 - a[i])
if d < 0:
continue
ans[i] = min(a[i], int((3 + d**.5) / 6 + eps))
# print(ans)
rk = k - sum(ans)
l = list()
for i in range(n):
if ans[i] < a[i]:
hq.heappush(l, (-a[i] + 3 * ans[i]**2 - 3 * ans[i] + 1, i))
for _ in range(rk):
v, i = hq.heappop(l)
ans[i] += 1
if ans[i] < a[i]:
hq.heappush(l, (-a[i] + 3 * ans[i]**2 - 3 * ans[i] + 1, i))
print(*ans)
return
solve()
``` | output | 1 | 99,593 | 11 | 199,187 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries of the following types.
* `0 p x`: a_p \gets a_p + x
* `1 l r`: Print \sum_{i = l}^{r - 1}{a_i}.
Constraints
* 1 \leq N, Q \leq 500,000
* 0 \leq a_i, x \leq 10^9
* 0 \leq p < N
* 0 \leq l_i < r_i \leq N
* All values in Input are integer.
Input
Input is given from Standard Input in the following format:
N Q
a_0 a_1 ... a_{N - 1}
\textrm{Query}_0
\textrm{Query}_1
:
\textrm{Query}_{Q - 1}
Output
For each query of the latter type, print the answer.
Example
Input
5 5
1 2 3 4 5
1 0 5
1 2 4
0 3 10
1 0 5
1 0 3
Output
15
7
25
6
Submitted Solution:
```
import sys
input = sys.stdin.buffer.readline
class FenwickTree:
"""FenwickTree (Binary Indexed Tree, 0-index)
Queries:
1. add(i, val): add val to i-th value
2. sum(n): sum(bit[0] + ... + bit[n-1])
complexity: O(log n)
See: http://hos.ac/slides/20140319_bit.pdf
"""
def __init__(self, a_list):
self.N = len(a_list)
self.bit = a_list[:]
for _ in range(self.N, 1 << (self.N - 1).bit_length()):
self.bit.append(0)
for i in range(self.N-1):
self.bit[i | (i+1)] += self.bit[i]
def add(self, i, val):
while i < self.N:
self.bit[i] += val
i |= i + 1
def sum(self, n):
ret = 0
while n >= 0:
ret += self.bit[n]
n = (n & (n + 1)) - 1
return ret
def query(self, low, high):
return self.sum(high) - self.sum(low)
def yosupo():
# https://judge.yosupo.jp/problem/point_add_range_sum
_, Q = map(int, input().split())
fwt = FenwickTree([int(x) for x in input().split()])
ans = []
for _ in range(Q):
type_, l, r = map(int, input().split())
if type_ == 0:
fwt.add(l, r)
else:
ans.append(fwt.query(l-1, r-1))
print(*ans, sep="\n")
def aoj():
# https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/2/DSL_2_B
N, Q = map(int, input().split())
fwt = FenwickTree([0] * N)
for _ in range(Q):
type_, l, r = map(int, input().split())
if type_ == 0:
fwt.add(l-1, r)
else:
print(fwt.query(l-2, r-1))
if __name__ == "__main__":
yosupo()
# aoj()
``` | instruction | 0 | 100,085 | 11 | 200,170 |
Yes | output | 1 | 100,085 | 11 | 200,171 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries of the following types.
* `0 p x`: a_p \gets a_p + x
* `1 l r`: Print \sum_{i = l}^{r - 1}{a_i}.
Constraints
* 1 \leq N, Q \leq 500,000
* 0 \leq a_i, x \leq 10^9
* 0 \leq p < N
* 0 \leq l_i < r_i \leq N
* All values in Input are integer.
Input
Input is given from Standard Input in the following format:
N Q
a_0 a_1 ... a_{N - 1}
\textrm{Query}_0
\textrm{Query}_1
:
\textrm{Query}_{Q - 1}
Output
For each query of the latter type, print the answer.
Example
Input
5 5
1 2 3 4 5
1 0 5
1 2 4
0 3 10
1 0 5
1 0 3
Output
15
7
25
6
Submitted Solution:
```
import sys
class Fenwick_Tree:
def __init__(self, n):
self._n = n
self.data = [0] * n
def add(self, p, x):
assert 0 <= p < self._n
p += 1
while p <= self._n:
self.data[p - 1] += x
p += p & -p
def sum(self, l, r):
assert 0 <= l <= r <= self._n
return self._sum(r) - self._sum(l)
def _sum(self, r):
s = 0
while r > 0:
s += self.data[r - 1]
r -= r & -r
return s
def main():
input = sys.stdin.readline
n, q = map(int, input().split())
fw = Fenwick_Tree(n)
for i, a in enumerate(map(int, input().split())): fw.add(i, a)
for _ in range(q):
t, a, b = map(int, input().split())
if t == 0:
fw.add(a, b)
else:
print(fw.sum(a, b))
if __name__ == "__main__":
main()
``` | instruction | 0 | 100,086 | 11 | 200,172 |
Yes | output | 1 | 100,086 | 11 | 200,173 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries of the following types.
* `0 p x`: a_p \gets a_p + x
* `1 l r`: Print \sum_{i = l}^{r - 1}{a_i}.
Constraints
* 1 \leq N, Q \leq 500,000
* 0 \leq a_i, x \leq 10^9
* 0 \leq p < N
* 0 \leq l_i < r_i \leq N
* All values in Input are integer.
Input
Input is given from Standard Input in the following format:
N Q
a_0 a_1 ... a_{N - 1}
\textrm{Query}_0
\textrm{Query}_1
:
\textrm{Query}_{Q - 1}
Output
For each query of the latter type, print the answer.
Example
Input
5 5
1 2 3 4 5
1 0 5
1 2 4
0 3 10
1 0 5
1 0 3
Output
15
7
25
6
Submitted Solution:
```
class SegmentTree:
def __init__(self, a):
self.padding = 0
self.n = len(a)
self.N = 2 ** (self.n-1).bit_length()
self.seg_data = [self.padding]*(self.N-1) + a + [self.padding]*(self.N-self.n)
for i in range(2*self.N-2, 0, -2):
self.seg_data[(i-1)//2] = self.seg_data[i] + self.seg_data[i-1]
def __len__(self):
return self.n
def update(self, i, x):
idx = self.N - 1 + i
self.seg_data[idx] += x
while idx:
idx = (idx-1) // 2
self.seg_data[idx] = self.seg_data[2*idx+1] + self.seg_data[2*idx+2]
def query(self, i, j):
# [i, j)
if i == j:
return self.seg_data[self.N - 1 + i]
else:
idx1 = self.N - 1 + i
idx2 = self.N - 2 + j # ιεΊιγ«γγ
result = self.padding
while idx1 < idx2 + 1:
if idx1&1 == 0: # idx1γεΆζ°
result = result + self.seg_data[idx1]
if idx2&1 == 1: # idx2γε₯ζ°
result = result + self.seg_data[idx2]
idx2 -= 1
idx1 //= 2
idx2 = (idx2 - 1)//2
return result
@property
def data(self):
return self.seg_data[self.N-1:self.N-1+self.n]
N, Q = map(int, input().split())
A = list(map(int, input().split()))
st = SegmentTree(A)
ans = []
for _ in range(Q):
t, i, j = map(int, input().split())
if t:
ans.append(st.query(i, j))
else:
st.update(i, j)
print(*ans, sep='\n')
``` | instruction | 0 | 100,087 | 11 | 200,174 |
Yes | output | 1 | 100,087 | 11 | 200,175 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries of the following types.
* `0 p x`: a_p \gets a_p + x
* `1 l r`: Print \sum_{i = l}^{r - 1}{a_i}.
Constraints
* 1 \leq N, Q \leq 500,000
* 0 \leq a_i, x \leq 10^9
* 0 \leq p < N
* 0 \leq l_i < r_i \leq N
* All values in Input are integer.
Input
Input is given from Standard Input in the following format:
N Q
a_0 a_1 ... a_{N - 1}
\textrm{Query}_0
\textrm{Query}_1
:
\textrm{Query}_{Q - 1}
Output
For each query of the latter type, print the answer.
Example
Input
5 5
1 2 3 4 5
1 0 5
1 2 4
0 3 10
1 0 5
1 0 3
Output
15
7
25
6
Submitted Solution:
```
class FenwickTree():
def __init__(self, n):
self.n = n
self.data = [0] * n
def build(self, arr):
#assert len(arr) <= n
for i, a in enumerate(arr):
self.data[i] = a
for i in range(1, self.n + 1):
if i + (i & -i) < self.n:
self.data[i + (i & -i) - 1] += self.data[i - 1]
def add(self, p, x):
#assert 0 <= p < self.n
p += 1
while p <= self.n:
self.data[p - 1] += x
p += p & -p
def sum(self, r):
s = 0
while r:
s += self.data[r - 1]
r -= r & -r
return s
def range_sum(self, l, r):
#assert 0 <= l <= r <= self.n
return self.sum(r) - self.sum(l)
import sys
input = sys.stdin.buffer.readline
N, Q = map(int, input().split())
A = tuple(map(int, input().split()))
ft = FenwickTree(N)
ft.build(A)
res = []
for _ in range(Q):
q, x, y = map(int, input().split())
if q:
res.append(str(ft.range_sum(x, y)))
else:
ft.add(x, y)
print('\n'.join(res))
``` | instruction | 0 | 100,092 | 11 | 200,184 |
No | output | 1 | 100,092 | 11 | 200,185 |
Provide a correct Python 3 solution for this coding contest problem.
10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th.
The score of a participant is the product of his/her ranks in the two contests.
Process the following Q queries:
* In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's.
Constraints
* 1 \leq Q \leq 100
* 1\leq A_i,B_i\leq 10^9(1\leq i\leq Q)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
Q
A_1 B_1
:
A_Q B_Q
Output
For each query, print the maximum possible number of participants whose scores are smaller than Takahashi's.
Example
Input
8
1 4
10 5
3 3
4 11
8 9
22 40
8 36
314159265 358979323
Output
1
12
4
11
14
57
31
671644785 | instruction | 0 | 100,161 | 11 | 200,322 |
"Correct Solution:
```
q=int(input())
def check(t,a,b):
k=(2*a+t)//2
return k*(2*a+t-k)<a*b
for i in range(q):
a,b=sorted(map(int,input().split()))
if a==b or a==b-1:
print(2*a-2)
continue
l,r=1,b-a
while l+1<r:
t=(l+r)//2
if check(t,a,b):
l=t
else:
r=t
if check(r,a,b):
print(2*a-2+r)
elif check(l,a,b):
print(2*a-2+l)
else:
print(2*a-1)
``` | output | 1 | 100,161 | 11 | 200,323 |
Provide a correct Python 3 solution for this coding contest problem.
10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th.
The score of a participant is the product of his/her ranks in the two contests.
Process the following Q queries:
* In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's.
Constraints
* 1 \leq Q \leq 100
* 1\leq A_i,B_i\leq 10^9(1\leq i\leq Q)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
Q
A_1 B_1
:
A_Q B_Q
Output
For each query, print the maximum possible number of participants whose scores are smaller than Takahashi's.
Example
Input
8
1 4
10 5
3 3
4 11
8 9
22 40
8 36
314159265 358979323
Output
1
12
4
11
14
57
31
671644785 | instruction | 0 | 100,162 | 11 | 200,324 |
"Correct Solution:
```
from math import sqrt
import sys
sdin = sys.stdin.readline
q = int(sdin())
ab = []
for i in range(q):
ab.append(tuple(map(int, sdin().split())))
for a, b in ab:
if b-a >= 0 and b-a <= 1:
print(2*a - 2)
else:
if not (sqrt(a*b) - int(sqrt(a*b))):
c = int(sqrt(a*b) - 1)
else:
c = int(sqrt(a*b))
if c*(c+1) >= a*b:
print(2*c - 2)
else:
print(2*c - 1)
``` | output | 1 | 100,162 | 11 | 200,325 |
Provide a correct Python 3 solution for this coding contest problem.
10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th.
The score of a participant is the product of his/her ranks in the two contests.
Process the following Q queries:
* In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's.
Constraints
* 1 \leq Q \leq 100
* 1\leq A_i,B_i\leq 10^9(1\leq i\leq Q)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
Q
A_1 B_1
:
A_Q B_Q
Output
For each query, print the maximum possible number of participants whose scores are smaller than Takahashi's.
Example
Input
8
1 4
10 5
3 3
4 11
8 9
22 40
8 36
314159265 358979323
Output
1
12
4
11
14
57
31
671644785 | instruction | 0 | 100,163 | 11 | 200,326 |
"Correct Solution:
```
from math import sqrt
Q = int(input())
for i in range(Q):
A, B = list(map(int, input().split()))
sq = sqrt(A*B)
sq_int = int(sq)
ans = sq_int*2 - 2
if sq_int**2==A*B and A!=B:
ans -= 1
if sq_int*(sq_int+1)<A*B:
ans += 1
#print(A*B, sq_int)
print(ans)
``` | output | 1 | 100,163 | 11 | 200,327 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.