message stringlengths 2 44.5k | message_type stringclasses 2
values | message_id int64 0 1 | conversation_id int64 42 109k | cluster float64 5 5 | __index_level_0__ int64 84 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given three sequences: a_1, a_2, …, a_n; b_1, b_2, …, b_n; c_1, c_2, …, c_n.
For each i, a_i ≠ b_i, a_i ≠ c_i, b_i ≠ c_i.
Find a sequence p_1, p_2, …, p_n, that satisfy the following conditions:
* p_i ∈ \\{a_i, b_i, c_i\}
* p_i ≠ p_{(i mod n) + 1}.
In other words, for each element, you need to choose one of the three possible values, such that no two adjacent elements (where we consider elements i,i+1 adjacent for i<n and also elements 1 and n) will have equal value.
It can be proved that in the given constraints solution always exists. You don't need to minimize/maximize anything, you need to find any proper sequence.
Input
The first line of input contains one integer t (1 ≤ t ≤ 100): the number of test cases.
The first line of each test case contains one integer n (3 ≤ n ≤ 100): the number of elements in the given sequences.
The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 100).
The third line contains n integers b_1, b_2, …, b_n (1 ≤ b_i ≤ 100).
The fourth line contains n integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 100).
It is guaranteed that a_i ≠ b_i, a_i ≠ c_i, b_i ≠ c_i for all i.
Output
For each test case, print n integers: p_1, p_2, …, p_n (p_i ∈ \\{a_i, b_i, c_i\}, p_i ≠ p_{i mod n + 1}).
If there are several solutions, you can print any.
Example
Input
5
3
1 1 1
2 2 2
3 3 3
4
1 2 1 2
2 1 2 1
3 4 3 4
7
1 3 3 1 1 1 1
2 4 4 3 2 2 4
4 2 2 2 4 4 2
3
1 2 1
2 3 3
3 1 2
10
1 1 1 2 2 2 3 3 3 1
2 2 2 3 3 3 1 1 1 2
3 3 3 1 1 1 2 2 2 3
Output
1 2 3
1 2 1 2
1 3 4 3 2 4 2
1 3 2
1 2 3 1 2 3 1 2 3 2
Note
In the first test case p = [1, 2, 3].
It is a correct answer, because:
* p_1 = 1 = a_1, p_2 = 2 = b_2, p_3 = 3 = c_3
* p_1 ≠ p_2 , p_2 ≠ p_3 , p_3 ≠ p_1
All possible correct answers to this test case are: [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1].
In the second test case p = [1, 2, 1, 2].
In this sequence p_1 = a_1, p_2 = a_2, p_3 = a_3, p_4 = a_4. Also we can see, that no two adjacent elements of the sequence are equal.
In the third test case p = [1, 3, 4, 3, 2, 4, 2].
In this sequence p_1 = a_1, p_2 = a_2, p_3 = b_3, p_4 = b_4, p_5 = b_5, p_6 = c_6, p_7 = c_7. Also we can see, that no two adjacent elements of the sequence are equal.
Submitted Solution:
```
num = int(input())
for x in range(num):
n = int(input())
a = input().split(" ")
b = input().split(" ")
c = input().split(" ")
alltogether = [a, b, c]
res = []
res.append(int(a[0]))
for i in range(n-1):
pickfrom = [int(a[i+1]),int(b[i+1]),int(c[i+1])]
for y in pickfrom:
if y != res[i]:
res.append(y)
break
result = ""
for e in res:
result += str(e) + " "
print(result[:-1])
``` | instruction | 0 | 59,915 | 5 | 119,830 |
No | output | 1 | 59,915 | 5 | 119,831 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima got into number sequences. Now he's got sequence a1, a2, ..., an, consisting of n positive integers. Also, Dima has got a function f(x), which can be defined with the following recurrence:
* f(0) = 0;
* f(2·x) = f(x);
* f(2·x + 1) = f(x) + 1.
Dima wonders, how many pairs of indexes (i, j) (1 ≤ i < j ≤ n) are there, such that f(ai) = f(aj). Help him, count the number of such pairs.
Input
The first line contains integer n (1 ≤ n ≤ 105). The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).
The numbers in the lines are separated by single spaces.
Output
In a single line print the answer to the problem.
Please, don't use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 4
Output
3
Input
3
5 3 1
Output
1
Note
In the first sample any pair (i, j) will do, so the answer is 3.
In the second sample only pair (1, 2) will do.
Submitted Solution:
```
def C(x):
s=bin(x)[2:]
c=0
for t in s:
if t=='1':
c+=1
return c
n = input();
ar=list(map(int,input().split()))
bu={}
for e in ar:
c=C(e)
if c not in bu:
bu[c]=0
bu[c]+=1
S = 0
for v in bu.values():
S += v*(v-1)//2
print(S)
``` | instruction | 0 | 60,063 | 5 | 120,126 |
Yes | output | 1 | 60,063 | 5 | 120,127 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima got into number sequences. Now he's got sequence a1, a2, ..., an, consisting of n positive integers. Also, Dima has got a function f(x), which can be defined with the following recurrence:
* f(0) = 0;
* f(2·x) = f(x);
* f(2·x + 1) = f(x) + 1.
Dima wonders, how many pairs of indexes (i, j) (1 ≤ i < j ≤ n) are there, such that f(ai) = f(aj). Help him, count the number of such pairs.
Input
The first line contains integer n (1 ≤ n ≤ 105). The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).
The numbers in the lines are separated by single spaces.
Output
In a single line print the answer to the problem.
Please, don't use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 4
Output
3
Input
3
5 3 1
Output
1
Note
In the first sample any pair (i, j) will do, so the answer is 3.
In the second sample only pair (1, 2) will do.
Submitted Solution:
```
from collections import defaultdict
p, n = defaultdict(int), int(input())
for i in map(int, input().split()):
p[bin(i).count('1')] += 1
print(sum(x * (x - 1) for x in p.values()) // 2)
``` | instruction | 0 | 60,064 | 5 | 120,128 |
Yes | output | 1 | 60,064 | 5 | 120,129 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima got into number sequences. Now he's got sequence a1, a2, ..., an, consisting of n positive integers. Also, Dima has got a function f(x), which can be defined with the following recurrence:
* f(0) = 0;
* f(2·x) = f(x);
* f(2·x + 1) = f(x) + 1.
Dima wonders, how many pairs of indexes (i, j) (1 ≤ i < j ≤ n) are there, such that f(ai) = f(aj). Help him, count the number of such pairs.
Input
The first line contains integer n (1 ≤ n ≤ 105). The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).
The numbers in the lines are separated by single spaces.
Output
In a single line print the answer to the problem.
Please, don't use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 4
Output
3
Input
3
5 3 1
Output
1
Note
In the first sample any pair (i, j) will do, so the answer is 3.
In the second sample only pair (1, 2) will do.
Submitted Solution:
```
n = int(input())
lis=list(map(int,input().split()))
ans=[0]*(n)
for i in range(n):
k=lis[i]
c=0
while k>0:
if k%2!=0:
c+=1
k=k//2
ans[i]=c
ans.sort()
c=1
fin=0
#print(ans)
for i in range(1,n):
if ans[i-1]==ans[i]:
c+=1
else:
fin+=((c*(c-1))//2)
c=1
fin+=((c*(c-1))//2)
print(fin)
``` | instruction | 0 | 60,065 | 5 | 120,130 |
Yes | output | 1 | 60,065 | 5 | 120,131 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima got into number sequences. Now he's got sequence a1, a2, ..., an, consisting of n positive integers. Also, Dima has got a function f(x), which can be defined with the following recurrence:
* f(0) = 0;
* f(2·x) = f(x);
* f(2·x + 1) = f(x) + 1.
Dima wonders, how many pairs of indexes (i, j) (1 ≤ i < j ≤ n) are there, such that f(ai) = f(aj). Help him, count the number of such pairs.
Input
The first line contains integer n (1 ≤ n ≤ 105). The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).
The numbers in the lines are separated by single spaces.
Output
In a single line print the answer to the problem.
Please, don't use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 4
Output
3
Input
3
5 3 1
Output
1
Note
In the first sample any pair (i, j) will do, so the answer is 3.
In the second sample only pair (1, 2) will do.
Submitted Solution:
```
def main():
def f(x):
if x < L:
return prec[x]
return f(x // 2) + x % 2
n = int(input())
a = [int(i) for i in input().split()]
L = 10**5
prec = [0]
for i in range(1, L):
if i % 2 == 1:
prec.append(prec[i - 1] + 1)
else:
prec.append(prec[i // 2])
d = {}
for i in a:
value = f(i)
if value not in d:
d[value] = 0
d[value] += 1
result = 0
for i in d.values():
result += i * (i - 1) // 2
print(result)
main()
``` | instruction | 0 | 60,066 | 5 | 120,132 |
Yes | output | 1 | 60,066 | 5 | 120,133 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima got into number sequences. Now he's got sequence a1, a2, ..., an, consisting of n positive integers. Also, Dima has got a function f(x), which can be defined with the following recurrence:
* f(0) = 0;
* f(2·x) = f(x);
* f(2·x + 1) = f(x) + 1.
Dima wonders, how many pairs of indexes (i, j) (1 ≤ i < j ≤ n) are there, such that f(ai) = f(aj). Help him, count the number of such pairs.
Input
The first line contains integer n (1 ≤ n ≤ 105). The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).
The numbers in the lines are separated by single spaces.
Output
In a single line print the answer to the problem.
Please, don't use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 4
Output
3
Input
3
5 3 1
Output
1
Note
In the first sample any pair (i, j) will do, so the answer is 3.
In the second sample only pair (1, 2) will do.
Submitted Solution:
```
n = int(input())
def norm(a):
if a % 2 == 0:
while a % 2 == 0:
a //= 2
if a > 1:
while (a - 1) % 4 == 0:
a = (a - 1) // 2 + 1
return a
m = sorted([norm(int(x)) for x in input().split()])
s = 0
w = 0
for i in range(len(m)-1):
if m[i] == m[i+1]:
w +=1
else:
s+= w*(w+1)//2
w=0
s+= w*(w+1)//2
print(s)
``` | instruction | 0 | 60,067 | 5 | 120,134 |
No | output | 1 | 60,067 | 5 | 120,135 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima got into number sequences. Now he's got sequence a1, a2, ..., an, consisting of n positive integers. Also, Dima has got a function f(x), which can be defined with the following recurrence:
* f(0) = 0;
* f(2·x) = f(x);
* f(2·x + 1) = f(x) + 1.
Dima wonders, how many pairs of indexes (i, j) (1 ≤ i < j ≤ n) are there, such that f(ai) = f(aj). Help him, count the number of such pairs.
Input
The first line contains integer n (1 ≤ n ≤ 105). The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).
The numbers in the lines are separated by single spaces.
Output
In a single line print the answer to the problem.
Please, don't use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 4
Output
3
Input
3
5 3 1
Output
1
Note
In the first sample any pair (i, j) will do, so the answer is 3.
In the second sample only pair (1, 2) will do.
Submitted Solution:
```
def main():
def f(x):
if x < L:
return prec[x]
return f(x >> 1) + x & 1
L = 10**5
prec = [0]
for i in range(1, L):
if i % 2 == 1:
prec.append(prec[i - 1] + 1)
else:
prec.append(prec[i // 2])
n = int(input())
a = [int(i) for i in input().split()]
result = 0
d = [0 for i in range(65)]
for i in a:
value = f(i)
result += d[value]
d[value] += 1
print(result)
main()
``` | instruction | 0 | 60,068 | 5 | 120,136 |
No | output | 1 | 60,068 | 5 | 120,137 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima got into number sequences. Now he's got sequence a1, a2, ..., an, consisting of n positive integers. Also, Dima has got a function f(x), which can be defined with the following recurrence:
* f(0) = 0;
* f(2·x) = f(x);
* f(2·x + 1) = f(x) + 1.
Dima wonders, how many pairs of indexes (i, j) (1 ≤ i < j ≤ n) are there, such that f(ai) = f(aj). Help him, count the number of such pairs.
Input
The first line contains integer n (1 ≤ n ≤ 105). The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).
The numbers in the lines are separated by single spaces.
Output
In a single line print the answer to the problem.
Please, don't use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 4
Output
3
Input
3
5 3 1
Output
1
Note
In the first sample any pair (i, j) will do, so the answer is 3.
In the second sample only pair (1, 2) will do.
Submitted Solution:
```
n = int(input())
def norm(a):
if a > 0 and a % 2 == 0:
while a % 2 == 0:
a //= 2
if a > 1:
while (a - 1) % 4 == 0:
a = (a - 1) // 2 + 1
return a
m = sorted([norm(int(x)) for x in input().split()])
s = 0
w = 0
for i in range(len(m)-1):
if m[i] == m[i+1]:
w +=1
else:
s += w*(w+1)//2
w = 0
s += w*(w+1)//2
print(s)
``` | instruction | 0 | 60,069 | 5 | 120,138 |
No | output | 1 | 60,069 | 5 | 120,139 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima got into number sequences. Now he's got sequence a1, a2, ..., an, consisting of n positive integers. Also, Dima has got a function f(x), which can be defined with the following recurrence:
* f(0) = 0;
* f(2·x) = f(x);
* f(2·x + 1) = f(x) + 1.
Dima wonders, how many pairs of indexes (i, j) (1 ≤ i < j ≤ n) are there, such that f(ai) = f(aj). Help him, count the number of such pairs.
Input
The first line contains integer n (1 ≤ n ≤ 105). The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).
The numbers in the lines are separated by single spaces.
Output
In a single line print the answer to the problem.
Please, don't use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 4
Output
3
Input
3
5 3 1
Output
1
Note
In the first sample any pair (i, j) will do, so the answer is 3.
In the second sample only pair (1, 2) will do.
Submitted Solution:
```
p, n = {}, int(input())
t = list(map(int, input().split()))
for i in t:
j = format(i, 'b').count('1')
p[j] = p.get(j, 0) + 1
print(sum(x * (x + 1) for x in p.values()) // 2)
``` | instruction | 0 | 60,070 | 5 | 120,140 |
No | output | 1 | 60,070 | 5 | 120,141 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.
Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all its values are integers from 1 to y.
Now then, you are given a function f: [n] → [n]. Your task is to find a positive integer m, and two functions g: [n] → [m], h: [m] → [n], such that g(h(x)) = x for all <image>, and h(g(x)) = f(x) for all <image>, or determine that finding these is impossible.
Input
The first line contains an integer n (1 ≤ n ≤ 105).
The second line contains n space-separated integers — values f(1), ..., f(n) (1 ≤ f(i) ≤ n).
Output
If there is no answer, print one integer -1.
Otherwise, on the first line print the number m (1 ≤ m ≤ 106). On the second line print n numbers g(1), ..., g(n). On the third line print m numbers h(1), ..., h(m).
If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer exists, then there is an answer satisfying the above restrictions.
Examples
Input
3
1 2 3
Output
3
1 2 3
1 2 3
Input
3
2 2 2
Output
1
1 1 1
2
Input
2
2 1
Output
-1 | instruction | 0 | 60,268 | 5 | 120,536 |
Tags: constructive algorithms, dsu, math
Correct Solution:
```
import sys
from collections import defaultdict
def debug(x, table):
for name, val in table.items():
if x is val:
print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
return None
def solve():
n = int(input())
f = [int(i) for i in input().split()]
inv = defaultdict(set)
for i, y in enumerate(f, start=1):
inv[y].add(i)
# debug(inv, locals())
m = len(inv)
g = [0] * (n + 1)
h = [0] * (m + 1)
for i, x in enumerate(inv, start=1):
if x not in inv[x]:
print(-1)
return
for a in inv[x]:
g[a] = i
h[i] = x
print(m)
print(*g[1:])
print(*h[1:])
if __name__ == '__main__':
solve()
``` | output | 1 | 60,268 | 5 | 120,537 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.
Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all its values are integers from 1 to y.
Now then, you are given a function f: [n] → [n]. Your task is to find a positive integer m, and two functions g: [n] → [m], h: [m] → [n], such that g(h(x)) = x for all <image>, and h(g(x)) = f(x) for all <image>, or determine that finding these is impossible.
Input
The first line contains an integer n (1 ≤ n ≤ 105).
The second line contains n space-separated integers — values f(1), ..., f(n) (1 ≤ f(i) ≤ n).
Output
If there is no answer, print one integer -1.
Otherwise, on the first line print the number m (1 ≤ m ≤ 106). On the second line print n numbers g(1), ..., g(n). On the third line print m numbers h(1), ..., h(m).
If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer exists, then there is an answer satisfying the above restrictions.
Examples
Input
3
1 2 3
Output
3
1 2 3
1 2 3
Input
3
2 2 2
Output
1
1 1 1
2
Input
2
2 1
Output
-1 | instruction | 0 | 60,269 | 5 | 120,538 |
Tags: constructive algorithms, dsu, math
Correct Solution:
```
n = int(input())
f = [int(x) - 1 for x in input().split()]
p = [-1] * n
g = [0] * n
h = [0] * n
m = 0
for i in range(n):
if f[i] == i:
p[i] = m
h[m] = i + 1
m += 1
h = h[:m]
for i in range(n):
if p[f[i]] == -1:
print(-1)
exit()
g[i] = p[f[i]] + 1
print(m)
print(" ".join([str(x) for x in g]))
print(" ".join([str(x) for x in h]))
``` | output | 1 | 60,269 | 5 | 120,539 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.
Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all its values are integers from 1 to y.
Now then, you are given a function f: [n] → [n]. Your task is to find a positive integer m, and two functions g: [n] → [m], h: [m] → [n], such that g(h(x)) = x for all <image>, and h(g(x)) = f(x) for all <image>, or determine that finding these is impossible.
Input
The first line contains an integer n (1 ≤ n ≤ 105).
The second line contains n space-separated integers — values f(1), ..., f(n) (1 ≤ f(i) ≤ n).
Output
If there is no answer, print one integer -1.
Otherwise, on the first line print the number m (1 ≤ m ≤ 106). On the second line print n numbers g(1), ..., g(n). On the third line print m numbers h(1), ..., h(m).
If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer exists, then there is an answer satisfying the above restrictions.
Examples
Input
3
1 2 3
Output
3
1 2 3
1 2 3
Input
3
2 2 2
Output
1
1 1 1
2
Input
2
2 1
Output
-1 | instruction | 0 | 60,270 | 5 | 120,540 |
Tags: constructive algorithms, dsu, math
Correct Solution:
```
import bisect
n = int(input())
f = [0] + list(map(int, input().split()))
possible = True
for x in range(1, n + 1):
if f[f[x]] != f[x]:
possible = False
break
if possible:
h = sorted(set(f))
g = [0]
for x in range(1, n+1):
# g.append(h.index(f[x]))
g.append(bisect.bisect_left(h, f[x]))
print(len(h) - 1)
print(*g[1:])
print(*h[1:])
else:
print(-1)
``` | output | 1 | 60,270 | 5 | 120,541 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.
Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all its values are integers from 1 to y.
Now then, you are given a function f: [n] → [n]. Your task is to find a positive integer m, and two functions g: [n] → [m], h: [m] → [n], such that g(h(x)) = x for all <image>, and h(g(x)) = f(x) for all <image>, or determine that finding these is impossible.
Input
The first line contains an integer n (1 ≤ n ≤ 105).
The second line contains n space-separated integers — values f(1), ..., f(n) (1 ≤ f(i) ≤ n).
Output
If there is no answer, print one integer -1.
Otherwise, on the first line print the number m (1 ≤ m ≤ 106). On the second line print n numbers g(1), ..., g(n). On the third line print m numbers h(1), ..., h(m).
If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer exists, then there is an answer satisfying the above restrictions.
Examples
Input
3
1 2 3
Output
3
1 2 3
1 2 3
Input
3
2 2 2
Output
1
1 1 1
2
Input
2
2 1
Output
-1 | instruction | 0 | 60,271 | 5 | 120,542 |
Tags: constructive algorithms, dsu, math
Correct Solution:
```
n = int(input())
f = [-1] + list(map(int, input().split()))
g = [-1]*(n+1)
h = [-1]
c = 1
for i in range(1, n+1):
if(f[i] == i):
g[i] = c
h += [i]
c += 1
hinv = {}
m = len(h)-1
for i in range(1, m+1):
hinv[h[i]] = i
for i in range(1, n+1):
if(g[i] == -1):
try:
g[i] = hinv[f[i]]
except:
print(-1)
exit()
print(m)
print(*g[1:])
print(*h[1:])
``` | output | 1 | 60,271 | 5 | 120,543 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.
Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all its values are integers from 1 to y.
Now then, you are given a function f: [n] → [n]. Your task is to find a positive integer m, and two functions g: [n] → [m], h: [m] → [n], such that g(h(x)) = x for all <image>, and h(g(x)) = f(x) for all <image>, or determine that finding these is impossible.
Input
The first line contains an integer n (1 ≤ n ≤ 105).
The second line contains n space-separated integers — values f(1), ..., f(n) (1 ≤ f(i) ≤ n).
Output
If there is no answer, print one integer -1.
Otherwise, on the first line print the number m (1 ≤ m ≤ 106). On the second line print n numbers g(1), ..., g(n). On the third line print m numbers h(1), ..., h(m).
If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer exists, then there is an answer satisfying the above restrictions.
Examples
Input
3
1 2 3
Output
3
1 2 3
1 2 3
Input
3
2 2 2
Output
1
1 1 1
2
Input
2
2 1
Output
-1 | instruction | 0 | 60,272 | 5 | 120,544 |
Tags: constructive algorithms, dsu, math
Correct Solution:
```
import sys
n = int(input())
s = input().split()
a = [int(i) for i in s]
a.insert(0,0)
hash = [0 for i in range(n+1)]
g = [0 for i in range(n+1)]
h = [0 for i in range(n+1)]
index = 1
for i in range(1, n+1):
if hash[a[i]] == 0:
if index>n:
print(-1)
exit()
hash[a[i]]=index
g[i] = index
h[index] = a[i]
index+=1
else:
g[i] = hash[a[i]]
for i in range(1,index):
if g[h[i]]!=i:
print(-1)
exit()
print(index-1)
print(' '.join([str(i) for i in g[1:n+1]]))
print(' '.join([str(i) for i in h[1:index]]))
``` | output | 1 | 60,272 | 5 | 120,545 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.
Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all its values are integers from 1 to y.
Now then, you are given a function f: [n] → [n]. Your task is to find a positive integer m, and two functions g: [n] → [m], h: [m] → [n], such that g(h(x)) = x for all <image>, and h(g(x)) = f(x) for all <image>, or determine that finding these is impossible.
Input
The first line contains an integer n (1 ≤ n ≤ 105).
The second line contains n space-separated integers — values f(1), ..., f(n) (1 ≤ f(i) ≤ n).
Output
If there is no answer, print one integer -1.
Otherwise, on the first line print the number m (1 ≤ m ≤ 106). On the second line print n numbers g(1), ..., g(n). On the third line print m numbers h(1), ..., h(m).
If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer exists, then there is an answer satisfying the above restrictions.
Examples
Input
3
1 2 3
Output
3
1 2 3
1 2 3
Input
3
2 2 2
Output
1
1 1 1
2
Input
2
2 1
Output
-1 | instruction | 0 | 60,275 | 5 | 120,550 |
Tags: constructive algorithms, dsu, math
Correct Solution:
```
n = int(input())
f = [y for y in map(int, input().split())]
im_f = list(set(f))
ok = True
for y in im_f:
index = y - 1
ok &= f[index] == y
if ok:
m = len(im_f)
ind = {}
for i, y in enumerate(im_f):
ind[y] = i + 1
print(m)
values = []
for y in f:
values.append(ind[y])
print(' '.join(map(str, values)))
print(' '.join(map(str, im_f)))
else:
print(-1)
``` | output | 1 | 60,275 | 5 | 120,551 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.
Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all its values are integers from 1 to y.
Now then, you are given a function f: [n] → [n]. Your task is to find a positive integer m, and two functions g: [n] → [m], h: [m] → [n], such that g(h(x)) = x for all <image>, and h(g(x)) = f(x) for all <image>, or determine that finding these is impossible.
Input
The first line contains an integer n (1 ≤ n ≤ 105).
The second line contains n space-separated integers — values f(1), ..., f(n) (1 ≤ f(i) ≤ n).
Output
If there is no answer, print one integer -1.
Otherwise, on the first line print the number m (1 ≤ m ≤ 106). On the second line print n numbers g(1), ..., g(n). On the third line print m numbers h(1), ..., h(m).
If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer exists, then there is an answer satisfying the above restrictions.
Examples
Input
3
1 2 3
Output
3
1 2 3
1 2 3
Input
3
2 2 2
Output
1
1 1 1
2
Input
2
2 1
Output
-1
Submitted Solution:
```
n = int(input())
f = list(map(int, input().split()))
h = []
ind_h = [-1] * (n + 1)
g = [0] * n
occs = {}
for i in range(len(f)):
if f[i] not in occs:
occs[f[i]] = {i + 1}
h.append(f[i])
ind_h[f[i]] = len(h) - 1
g[i] = len(h)
else:
g[i] = ind_h[f[i]] + 1
occs[f[i]].add(i + 1)
for k in occs:
if k not in occs[k]:
print(-1)
exit()
print(len(h))
print(*g)
print(*h)
``` | instruction | 0 | 60,276 | 5 | 120,552 |
Yes | output | 1 | 60,276 | 5 | 120,553 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.
Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all its values are integers from 1 to y.
Now then, you are given a function f: [n] → [n]. Your task is to find a positive integer m, and two functions g: [n] → [m], h: [m] → [n], such that g(h(x)) = x for all <image>, and h(g(x)) = f(x) for all <image>, or determine that finding these is impossible.
Input
The first line contains an integer n (1 ≤ n ≤ 105).
The second line contains n space-separated integers — values f(1), ..., f(n) (1 ≤ f(i) ≤ n).
Output
If there is no answer, print one integer -1.
Otherwise, on the first line print the number m (1 ≤ m ≤ 106). On the second line print n numbers g(1), ..., g(n). On the third line print m numbers h(1), ..., h(m).
If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer exists, then there is an answer satisfying the above restrictions.
Examples
Input
3
1 2 3
Output
3
1 2 3
1 2 3
Input
3
2 2 2
Output
1
1 1 1
2
Input
2
2 1
Output
-1
Submitted Solution:
```
n = int(input())
f = [None] + list(map(int, input().split(' ')))
invalid = False
g = [None] + [0] * n
h = [None]
x_is_f_which = [None] + [0] * n
m = 0
vis = [None] + [False] * n
for i in range(1, n + 1):
x = f[i]
if f[x] != x:
invalid = True
break
if not vis[x]:
vis[x] = True
m = m + 1
h.append(x)
x_is_f_which[x] = m
if invalid:
print('-1')
else:
for i in range(1, n + 1):
g[i] = x_is_f_which[f[i]]
print(m)
def print_list(l):
print(' '.join(list(map(str, l[1:]))))
print_list(g)
print_list(h)
``` | instruction | 0 | 60,277 | 5 | 120,554 |
Yes | output | 1 | 60,277 | 5 | 120,555 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.
Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all its values are integers from 1 to y.
Now then, you are given a function f: [n] → [n]. Your task is to find a positive integer m, and two functions g: [n] → [m], h: [m] → [n], such that g(h(x)) = x for all <image>, and h(g(x)) = f(x) for all <image>, or determine that finding these is impossible.
Input
The first line contains an integer n (1 ≤ n ≤ 105).
The second line contains n space-separated integers — values f(1), ..., f(n) (1 ≤ f(i) ≤ n).
Output
If there is no answer, print one integer -1.
Otherwise, on the first line print the number m (1 ≤ m ≤ 106). On the second line print n numbers g(1), ..., g(n). On the third line print m numbers h(1), ..., h(m).
If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer exists, then there is an answer satisfying the above restrictions.
Examples
Input
3
1 2 3
Output
3
1 2 3
1 2 3
Input
3
2 2 2
Output
1
1 1 1
2
Input
2
2 1
Output
-1
Submitted Solution:
```
import sys
n = int(input())
f = [int(x) for x in input().split(' ')]
image = set()
h = []
for i, x in enumerate(f):
if x not in image:
image.add(x)
h.append(x)
inv_h = [None for _ in range(n+1)]
for i, x in enumerate(h, 1):
inv_h[x] = i
for val in h:
if f[val-1] != val:
print(-1)
sys.exit()
print(len(h))
g = [None for _ in range(n)]
for i in range(n):
g[i] = inv_h[f[i]]
for x in g:
print(x, end=' ')
print('')
for x in h:
print(x, end=' ')
print('')
``` | instruction | 0 | 60,278 | 5 | 120,556 |
Yes | output | 1 | 60,278 | 5 | 120,557 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.
Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all its values are integers from 1 to y.
Now then, you are given a function f: [n] → [n]. Your task is to find a positive integer m, and two functions g: [n] → [m], h: [m] → [n], such that g(h(x)) = x for all <image>, and h(g(x)) = f(x) for all <image>, or determine that finding these is impossible.
Input
The first line contains an integer n (1 ≤ n ≤ 105).
The second line contains n space-separated integers — values f(1), ..., f(n) (1 ≤ f(i) ≤ n).
Output
If there is no answer, print one integer -1.
Otherwise, on the first line print the number m (1 ≤ m ≤ 106). On the second line print n numbers g(1), ..., g(n). On the third line print m numbers h(1), ..., h(m).
If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer exists, then there is an answer satisfying the above restrictions.
Examples
Input
3
1 2 3
Output
3
1 2 3
1 2 3
Input
3
2 2 2
Output
1
1 1 1
2
Input
2
2 1
Output
-1
Submitted Solution:
```
a = int(input())
b = list(map(int,input().split()))
count = 1
s = set()
d = list()
f = dict()
suc = list()
succ = True
for i in b:
if i in f:
d.append(f[i])
else:
f[i] = count
suc.append(i)
d.append(count)
count+=1
for i in range(len(suc)):
if d[suc[i]-1] != i+1:
print(-1)
exit(0)
print(count-1)
print(*d)
print(*suc)
``` | instruction | 0 | 60,279 | 5 | 120,558 |
Yes | output | 1 | 60,279 | 5 | 120,559 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.
Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all its values are integers from 1 to y.
Now then, you are given a function f: [n] → [n]. Your task is to find a positive integer m, and two functions g: [n] → [m], h: [m] → [n], such that g(h(x)) = x for all <image>, and h(g(x)) = f(x) for all <image>, or determine that finding these is impossible.
Input
The first line contains an integer n (1 ≤ n ≤ 105).
The second line contains n space-separated integers — values f(1), ..., f(n) (1 ≤ f(i) ≤ n).
Output
If there is no answer, print one integer -1.
Otherwise, on the first line print the number m (1 ≤ m ≤ 106). On the second line print n numbers g(1), ..., g(n). On the third line print m numbers h(1), ..., h(m).
If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer exists, then there is an answer satisfying the above restrictions.
Examples
Input
3
1 2 3
Output
3
1 2 3
1 2 3
Input
3
2 2 2
Output
1
1 1 1
2
Input
2
2 1
Output
-1
Submitted Solution:
```
import sys
n = int(input())
f = [int(x) - 1 for x in input().split()]
g, h = [], [x for i, x in enumerate(f) if x == i]
d = {}
cur = 0
for f_i in f:
if f_i not in d:
d[f_i] = cur
cur += 1
g.append(d[f_i])
m = len(h)
if m == 0:
print(-1)
sys.exit(0)
for i in range(m):
if g[h[i]] != i:
print(-1)
sys.exit(0)
try:
for i in range(n):
if h[g[i]] != f[i]:
print(-1)
sys.exit(0)
except IndexError:
print(-1)
sys.exit(0)
print(m)
print(' '.join(str(x + 1) for x in g))
print(' '.join(str(x + 1) for x in h))
``` | instruction | 0 | 60,280 | 5 | 120,560 |
No | output | 1 | 60,280 | 5 | 120,561 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.
Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all its values are integers from 1 to y.
Now then, you are given a function f: [n] → [n]. Your task is to find a positive integer m, and two functions g: [n] → [m], h: [m] → [n], such that g(h(x)) = x for all <image>, and h(g(x)) = f(x) for all <image>, or determine that finding these is impossible.
Input
The first line contains an integer n (1 ≤ n ≤ 105).
The second line contains n space-separated integers — values f(1), ..., f(n) (1 ≤ f(i) ≤ n).
Output
If there is no answer, print one integer -1.
Otherwise, on the first line print the number m (1 ≤ m ≤ 106). On the second line print n numbers g(1), ..., g(n). On the third line print m numbers h(1), ..., h(m).
If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer exists, then there is an answer satisfying the above restrictions.
Examples
Input
3
1 2 3
Output
3
1 2 3
1 2 3
Input
3
2 2 2
Output
1
1 1 1
2
Input
2
2 1
Output
-1
Submitted Solution:
```
n = int(input())
f = list(map(int, input().split()))
s = set(f)
m = len(s)
first = set(f[:m])
if(m > len(first)):
print(-1)
exit()
g = [-1 for i in range(n+1)]
h = [-1] + list(first)
for i in range(m):
g[h[i+1]] = i+1
hinv = {}
for i in range(m):
hinv[h[i+1]] = i+1
for i in range(n):
g[i+1] = hinv[f[i]]
for i in range(m):
if(g[h[i+1]] != i+1):
print(-1)
exit()
for i in range(n):
if(h[g[i+1]] != f[i]):
print(-1)
exit()
for i in range(1, n+1):
g[i] = max(g[i], 1)
print(m)
print(*g[1:])
print(*h[1:])
``` | instruction | 0 | 60,281 | 5 | 120,562 |
No | output | 1 | 60,281 | 5 | 120,563 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.
Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all its values are integers from 1 to y.
Now then, you are given a function f: [n] → [n]. Your task is to find a positive integer m, and two functions g: [n] → [m], h: [m] → [n], such that g(h(x)) = x for all <image>, and h(g(x)) = f(x) for all <image>, or determine that finding these is impossible.
Input
The first line contains an integer n (1 ≤ n ≤ 105).
The second line contains n space-separated integers — values f(1), ..., f(n) (1 ≤ f(i) ≤ n).
Output
If there is no answer, print one integer -1.
Otherwise, on the first line print the number m (1 ≤ m ≤ 106). On the second line print n numbers g(1), ..., g(n). On the third line print m numbers h(1), ..., h(m).
If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer exists, then there is an answer satisfying the above restrictions.
Examples
Input
3
1 2 3
Output
3
1 2 3
1 2 3
Input
3
2 2 2
Output
1
1 1 1
2
Input
2
2 1
Output
-1
Submitted Solution:
```
n = int(input())
arr = list(map(int, input().split()))
if arr != sorted(arr):
print(-1)
exit()
kek = set()
for i in arr:
kek.add(i)
ans = len(kek)
g = list(range(1, n + 1))
h = list(range(1, ans + 1))
print(ans + 1)
for i in g:
print(i, end=" ")
print()
for i in h:
print(i, end=" ")
``` | instruction | 0 | 60,282 | 5 | 120,564 |
No | output | 1 | 60,282 | 5 | 120,565 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.
Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all its values are integers from 1 to y.
Now then, you are given a function f: [n] → [n]. Your task is to find a positive integer m, and two functions g: [n] → [m], h: [m] → [n], such that g(h(x)) = x for all <image>, and h(g(x)) = f(x) for all <image>, or determine that finding these is impossible.
Input
The first line contains an integer n (1 ≤ n ≤ 105).
The second line contains n space-separated integers — values f(1), ..., f(n) (1 ≤ f(i) ≤ n).
Output
If there is no answer, print one integer -1.
Otherwise, on the first line print the number m (1 ≤ m ≤ 106). On the second line print n numbers g(1), ..., g(n). On the third line print m numbers h(1), ..., h(m).
If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer exists, then there is an answer satisfying the above restrictions.
Examples
Input
3
1 2 3
Output
3
1 2 3
1 2 3
Input
3
2 2 2
Output
1
1 1 1
2
Input
2
2 1
Output
-1
Submitted Solution:
```
import bisect
n = int(input())
f = [0] + list(map(int, input().split()))
possible = True
for x in range(1, n + 1):
if f[f[x]] != f[x]:
possible = False
break
if possible:
h = sorted(set(f))
g = [0]
for x in range(1, n+1):
# g.append(h.index(f[x]))
g.append(bisect.bisect_left(h, f[x]))
print(len(g) - 1)
print(*g[1:])
print(*h[1:])
else:
print(-1)
``` | instruction | 0 | 60,283 | 5 | 120,566 |
No | output | 1 | 60,283 | 5 | 120,567 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's denote a function
<image>
You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
Input
The first line contains one integer n (1 ≤ n ≤ 200000) — the number of elements in a.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — elements of the array.
Output
Print one integer — the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
Examples
Input
5
1 2 3 1 3
Output
4
Input
4
6 6 5 5
Output
0
Input
4
6 6 4 4
Output
-8
Note
In the first example:
1. d(a1, a2) = 0;
2. d(a1, a3) = 2;
3. d(a1, a4) = 0;
4. d(a1, a5) = 2;
5. d(a2, a3) = 0;
6. d(a2, a4) = 0;
7. d(a2, a5) = 0;
8. d(a3, a4) = - 2;
9. d(a3, a5) = 0;
10. d(a4, a5) = 2.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
ans = 0
mus = 0
for i in range(n - 1, -1, -1):
ans += mus - a[i] * (n - 1 - i)
mus += a[i]
cnt = dict()
for i in range(n - 1, -1, -1):
if (a[i] + 1) not in cnt:
cnt[a[i] + 1] = 0
ans -= cnt[a[i] + 1]
if (a[i] - 1) not in cnt:
cnt[a[i] - 1] = 0
ans += cnt[a[i] - 1]
if a[i] not in cnt:
cnt[a[i]] = 0
cnt[a[i]] += 1
print(ans)
``` | instruction | 0 | 60,356 | 5 | 120,712 |
Yes | output | 1 | 60,356 | 5 | 120,713 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's denote a function
<image>
You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
Input
The first line contains one integer n (1 ≤ n ≤ 200000) — the number of elements in a.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — elements of the array.
Output
Print one integer — the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
Examples
Input
5
1 2 3 1 3
Output
4
Input
4
6 6 5 5
Output
0
Input
4
6 6 4 4
Output
-8
Note
In the first example:
1. d(a1, a2) = 0;
2. d(a1, a3) = 2;
3. d(a1, a4) = 0;
4. d(a1, a5) = 2;
5. d(a2, a3) = 0;
6. d(a2, a4) = 0;
7. d(a2, a5) = 0;
8. d(a3, a4) = - 2;
9. d(a3, a5) = 0;
10. d(a4, a5) = 2.
Submitted Solution:
```
n=int(input())
arr=input()
arr=arr.split()
for i in range(n):
arr[i]=int(arr[i])
ans=0
sm=arr[0]
m={}
m[sm]=1
for i in range(1,n):
a=0
b=0
c=0
d=0
x=arr[i]
if not x in m:
m[x]=0
m[x]+=1
if x-1 in m:
a=m[x-1]
if x+1 in m:
b=m[x+1]
ans = ans + x*(i-a-b) - (sm - a*(x-1) - b*(x+1))
sm += x;
print(ans)
``` | instruction | 0 | 60,357 | 5 | 120,714 |
Yes | output | 1 | 60,357 | 5 | 120,715 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's denote a function
<image>
You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
Input
The first line contains one integer n (1 ≤ n ≤ 200000) — the number of elements in a.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — elements of the array.
Output
Print one integer — the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
Examples
Input
5
1 2 3 1 3
Output
4
Input
4
6 6 5 5
Output
0
Input
4
6 6 4 4
Output
-8
Note
In the first example:
1. d(a1, a2) = 0;
2. d(a1, a3) = 2;
3. d(a1, a4) = 0;
4. d(a1, a5) = 2;
5. d(a2, a3) = 0;
6. d(a2, a4) = 0;
7. d(a2, a5) = 0;
8. d(a3, a4) = - 2;
9. d(a3, a5) = 0;
10. d(a4, a5) = 2.
Submitted Solution:
```
vcnt = {}
n = int(input())
a = list(map(int , input().split()))
ans = 0
for i in range(0,n) :
ans += a[i] * (i*2+1-n)
for i in range(0,n) :
v = a[i]
if v-1 in vcnt :
ans -= vcnt[v-1]
if v+1 in vcnt :
ans += vcnt[v+1]
if not(v in vcnt) :
vcnt[v] = 1
else:
vcnt[v] += 1
print(ans)
``` | instruction | 0 | 60,358 | 5 | 120,716 |
Yes | output | 1 | 60,358 | 5 | 120,717 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's denote a function
<image>
You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
Input
The first line contains one integer n (1 ≤ n ≤ 200000) — the number of elements in a.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — elements of the array.
Output
Print one integer — the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
Examples
Input
5
1 2 3 1 3
Output
4
Input
4
6 6 5 5
Output
0
Input
4
6 6 4 4
Output
-8
Note
In the first example:
1. d(a1, a2) = 0;
2. d(a1, a3) = 2;
3. d(a1, a4) = 0;
4. d(a1, a5) = 2;
5. d(a2, a3) = 0;
6. d(a2, a4) = 0;
7. d(a2, a5) = 0;
8. d(a3, a4) = - 2;
9. d(a3, a5) = 0;
10. d(a4, a5) = 2.
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split(' ')))
summ=0
diff=0
d={}
for i in range(0,n):
diff+=i*a[i]-summ
summ+=a[i]
d[a[i]]=0
d[a[i]-1]=0
d[a[i]+1]=0
for i in range(0,n):
diff-=d[a[i]-1]-d[a[i]+1]
d[a[i]]+=1
print(diff)
``` | instruction | 0 | 60,359 | 5 | 120,718 |
Yes | output | 1 | 60,359 | 5 | 120,719 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's denote a function
<image>
You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
Input
The first line contains one integer n (1 ≤ n ≤ 200000) — the number of elements in a.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — elements of the array.
Output
Print one integer — the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
Examples
Input
5
1 2 3 1 3
Output
4
Input
4
6 6 5 5
Output
0
Input
4
6 6 4 4
Output
-8
Note
In the first example:
1. d(a1, a2) = 0;
2. d(a1, a3) = 2;
3. d(a1, a4) = 0;
4. d(a1, a5) = 2;
5. d(a2, a3) = 0;
6. d(a2, a4) = 0;
7. d(a2, a5) = 0;
8. d(a3, a4) = - 2;
9. d(a3, a5) = 0;
10. d(a4, a5) = 2.
Submitted Solution:
```
from collections import defaultdict
int(input())
mp, sum, res = defaultdict(int), 0, 0
for i, x in enumerate(map(int, input().split()), start =1):
mp[x] += 1
sum += x
res = x*i - sum - mp[x-1] + mp[x+1]
print(res)
``` | instruction | 0 | 60,360 | 5 | 120,720 |
No | output | 1 | 60,360 | 5 | 120,721 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's denote a function
<image>
You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
Input
The first line contains one integer n (1 ≤ n ≤ 200000) — the number of elements in a.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — elements of the array.
Output
Print one integer — the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
Examples
Input
5
1 2 3 1 3
Output
4
Input
4
6 6 5 5
Output
0
Input
4
6 6 4 4
Output
-8
Note
In the first example:
1. d(a1, a2) = 0;
2. d(a1, a3) = 2;
3. d(a1, a4) = 0;
4. d(a1, a5) = 2;
5. d(a2, a3) = 0;
6. d(a2, a4) = 0;
7. d(a2, a5) = 0;
8. d(a3, a4) = - 2;
9. d(a3, a5) = 0;
10. d(a4, a5) = 2.
Submitted Solution:
```
def func(x, y):
if abs(x - y) > 1:
return y - x
else:
return 0
n = int(input())
mas = list(map(int, input().split()))
s = 0
if n != 200000:
for i1 in range(n):
for i2 in range(i1 + 1, n):
s += func(mas[i1], mas[i2])
print(s)
if mas[0] == 3245683046:
print(3245683046)
else:
print(109099188)
``` | instruction | 0 | 60,361 | 5 | 120,722 |
No | output | 1 | 60,361 | 5 | 120,723 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's denote a function
<image>
You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
Input
The first line contains one integer n (1 ≤ n ≤ 200000) — the number of elements in a.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — elements of the array.
Output
Print one integer — the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
Examples
Input
5
1 2 3 1 3
Output
4
Input
4
6 6 5 5
Output
0
Input
4
6 6 4 4
Output
-8
Note
In the first example:
1. d(a1, a2) = 0;
2. d(a1, a3) = 2;
3. d(a1, a4) = 0;
4. d(a1, a5) = 2;
5. d(a2, a3) = 0;
6. d(a2, a4) = 0;
7. d(a2, a5) = 0;
8. d(a3, a4) = - 2;
9. d(a3, a5) = 0;
10. d(a4, a5) = 2.
Submitted Solution:
```
import math
n = int(input())
a = list(map(int,input().split()))
dp = [0]*n
pre = [0]*n
pre[0] = a[0]
ans,n1,p1 = 0,0,0
mp = dict()
for i in range(1,n):
dp[i] = i*a[i]-pre[i-1]
ans+=dp[i]
pre[i] = pre[i-1]+a[i]
for i in range(1,n):
if a[i]-1 in mp:
p1+=mp[a[i]-1]
if a[i]+1 in mp:
n1+=mp[a[i]+1]
if a[i] not in mp:
mp[a[i]]=1
mp[a[i]]+=1
print(ans+n1-p1)
``` | instruction | 0 | 60,362 | 5 | 120,724 |
No | output | 1 | 60,362 | 5 | 120,725 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's denote a function
<image>
You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
Input
The first line contains one integer n (1 ≤ n ≤ 200000) — the number of elements in a.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — elements of the array.
Output
Print one integer — the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
Examples
Input
5
1 2 3 1 3
Output
4
Input
4
6 6 5 5
Output
0
Input
4
6 6 4 4
Output
-8
Note
In the first example:
1. d(a1, a2) = 0;
2. d(a1, a3) = 2;
3. d(a1, a4) = 0;
4. d(a1, a5) = 2;
5. d(a2, a3) = 0;
6. d(a2, a4) = 0;
7. d(a2, a5) = 0;
8. d(a3, a4) = - 2;
9. d(a3, a5) = 0;
10. d(a4, a5) = 2.
Submitted Solution:
```
import math
n = int(input())
a = list(map(int,input().split()))
dp = [0]*n
pre = [0]*n
pre[0] = a[0]
ans,n1,p1 = 0,0,0
mp = dict()
for i in range(1,n):
dp[i] = i*a[i]-pre[i-1]
ans+=dp[i]
pre[i] = pre[i-1]+a[i]
for i in range(1,n):
if a[i]-1 in mp:
p1+=mp[a[i]-1]
if a[i]+1 in mp:
n1+=mp[a[i]+1]
if a[i] not in mp:
mp[a[i]]=0
mp[a[i]]+=1
print(ans+n1-p1)
``` | instruction | 0 | 60,363 | 5 | 120,726 |
No | output | 1 | 60,363 | 5 | 120,727 |
Provide a correct Python 3 solution for this coding contest problem.
Given is a positive integer N. How many tuples (A,B,C) of positive integers satisfy A \times B + C = N?
Constraints
* 2 \leq N \leq 10^6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
3
Output
3
Input
100
Output
473
Input
1000000
Output
13969985 | instruction | 0 | 60,383 | 5 | 120,766 |
"Correct Solution:
```
n = int(input())
ans=0
for i in range(1,n):
ans+=int((n-1)/i)
print(ans)
``` | output | 1 | 60,383 | 5 | 120,767 |
Provide a correct Python 3 solution for this coding contest problem.
Given is a positive integer N. How many tuples (A,B,C) of positive integers satisfy A \times B + C = N?
Constraints
* 2 \leq N \leq 10^6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
3
Output
3
Input
100
Output
473
Input
1000000
Output
13969985 | instruction | 0 | 60,384 | 5 | 120,768 |
"Correct Solution:
```
N=int(input())
s=0
for i in range(1,N):
s+=(N-1)//i
print(s)
``` | output | 1 | 60,384 | 5 | 120,769 |
Provide a correct Python 3 solution for this coding contest problem.
Given is a positive integer N. How many tuples (A,B,C) of positive integers satisfy A \times B + C = N?
Constraints
* 2 \leq N \leq 10^6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
3
Output
3
Input
100
Output
473
Input
1000000
Output
13969985 | instruction | 0 | 60,385 | 5 | 120,770 |
"Correct Solution:
```
N=int(input())
ans=0
for i in range(1,N):
ans+=(N-1)//i
#print(N//i)
print(ans)
``` | output | 1 | 60,385 | 5 | 120,771 |
Provide a correct Python 3 solution for this coding contest problem.
Given is a positive integer N. How many tuples (A,B,C) of positive integers satisfy A \times B + C = N?
Constraints
* 2 \leq N \leq 10^6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
3
Output
3
Input
100
Output
473
Input
1000000
Output
13969985 | instruction | 0 | 60,386 | 5 | 120,772 |
"Correct Solution:
```
n=int(input())
count=0
for i in range(1,n):
count+=int((n-1)/i)
print(int(count))
``` | output | 1 | 60,386 | 5 | 120,773 |
Provide a correct Python 3 solution for this coding contest problem.
Given is a positive integer N. How many tuples (A,B,C) of positive integers satisfy A \times B + C = N?
Constraints
* 2 \leq N \leq 10^6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
3
Output
3
Input
100
Output
473
Input
1000000
Output
13969985 | instruction | 0 | 60,387 | 5 | 120,774 |
"Correct Solution:
```
n=int(input())
ans=0
for i in range(1,n):
ans+=-(-n//i)-1
print(ans)
``` | output | 1 | 60,387 | 5 | 120,775 |
Provide a correct Python 3 solution for this coding contest problem.
Given is a positive integer N. How many tuples (A,B,C) of positive integers satisfy A \times B + C = N?
Constraints
* 2 \leq N \leq 10^6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
3
Output
3
Input
100
Output
473
Input
1000000
Output
13969985 | instruction | 0 | 60,388 | 5 | 120,776 |
"Correct Solution:
```
n=int(input())
ar=0
for i in range(1,n+1):
ar+=(n-1)//i
print(ar)
``` | output | 1 | 60,388 | 5 | 120,777 |
Provide a correct Python 3 solution for this coding contest problem.
Given is a positive integer N. How many tuples (A,B,C) of positive integers satisfy A \times B + C = N?
Constraints
* 2 \leq N \leq 10^6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
3
Output
3
Input
100
Output
473
Input
1000000
Output
13969985 | instruction | 0 | 60,389 | 5 | 120,778 |
"Correct Solution:
```
n = int(input())
a = 0
for i in range(1,n):
for j in range(i,n,i):
a+=1
print(a)
``` | output | 1 | 60,389 | 5 | 120,779 |
Provide a correct Python 3 solution for this coding contest problem.
Given is a positive integer N. How many tuples (A,B,C) of positive integers satisfy A \times B + C = N?
Constraints
* 2 \leq N \leq 10^6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
3
Output
3
Input
100
Output
473
Input
1000000
Output
13969985 | instruction | 0 | 60,390 | 5 | 120,780 |
"Correct Solution:
```
n=int(input())
s=0
for c in range(1,n):
s+=(n-1)//c
print(s)
``` | output | 1 | 60,390 | 5 | 120,781 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a positive integer N. How many tuples (A,B,C) of positive integers satisfy A \times B + C = N?
Constraints
* 2 \leq N \leq 10^6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
3
Output
3
Input
100
Output
473
Input
1000000
Output
13969985
Submitted Solution:
```
n = int(input())
c = 0
for i in range(1, n):
c += (n-1) // i
print(c)
``` | instruction | 0 | 60,391 | 5 | 120,782 |
Yes | output | 1 | 60,391 | 5 | 120,783 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a positive integer N. How many tuples (A,B,C) of positive integers satisfy A \times B + C = N?
Constraints
* 2 \leq N \leq 10^6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
3
Output
3
Input
100
Output
473
Input
1000000
Output
13969985
Submitted Solution:
```
n = int(input())
count = 0
for i in range(1,n):
count += (n-1) // i
print(count)
``` | instruction | 0 | 60,392 | 5 | 120,784 |
Yes | output | 1 | 60,392 | 5 | 120,785 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a positive integer N. How many tuples (A,B,C) of positive integers satisfy A \times B + C = N?
Constraints
* 2 \leq N \leq 10^6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
3
Output
3
Input
100
Output
473
Input
1000000
Output
13969985
Submitted Solution:
```
n=int(input())
print(sum([n//a+(0 if n%a else -1) for a in range(1,n)]))
``` | instruction | 0 | 60,393 | 5 | 120,786 |
Yes | output | 1 | 60,393 | 5 | 120,787 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a positive integer N. How many tuples (A,B,C) of positive integers satisfy A \times B + C = N?
Constraints
* 2 \leq N \leq 10^6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
3
Output
3
Input
100
Output
473
Input
1000000
Output
13969985
Submitted Solution:
```
N=int(input())
s=0
for i in range(1,N+1):
s+=int(N/i)
if N%i==0:
s-=1
print(s)
``` | instruction | 0 | 60,394 | 5 | 120,788 |
Yes | output | 1 | 60,394 | 5 | 120,789 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a positive integer N. How many tuples (A,B,C) of positive integers satisfy A \times B + C = N?
Constraints
* 2 \leq N \leq 10^6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
3
Output
3
Input
100
Output
473
Input
1000000
Output
13969985
Submitted Solution:
```
n = int(input())
a = 1
ans = 0
while a < n:
b = 1
while a * b < n:
ans += 1
b += 1
a += 1
print(ans)
``` | instruction | 0 | 60,396 | 5 | 120,792 |
No | output | 1 | 60,396 | 5 | 120,793 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a positive integer N. How many tuples (A,B,C) of positive integers satisfy A \times B + C = N?
Constraints
* 2 \leq N \leq 10^6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
3
Output
3
Input
100
Output
473
Input
1000000
Output
13969985
Submitted Solution:
```
n = int(input())
ans = 0
for c in range(1,n):
if ((n-c)**(1/2)).is_integer():
ans+=1
for ab in range(1,int(1+(n-c+1)**(1/2))):
if ((n-c)/(ab)).is_integer() and ((n-c)/(ab))!=(ab):
ans+=2
print(ans)
``` | instruction | 0 | 60,397 | 5 | 120,794 |
No | output | 1 | 60,397 | 5 | 120,795 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a positive integer N. How many tuples (A,B,C) of positive integers satisfy A \times B + C = N?
Constraints
* 2 \leq N \leq 10^6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
3
Output
3
Input
100
Output
473
Input
1000000
Output
13969985
Submitted Solution:
```
n=int(input())
count=0
for a in range(1,n+1):
for b in range(1,n//a+1):
c=n-(a*b)
if c>0:
count+=1
else:
continue
print(count)
``` | instruction | 0 | 60,398 | 5 | 120,796 |
No | output | 1 | 60,398 | 5 | 120,797 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a positive integer N. Find the number of the pairs of integers u and v (0≦u,v≦N) such that there exist two non-negative integers a and b satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR. Since it can be extremely large, compute the answer modulo 10^9+7.
Constraints
* 1≦N≦10^{18}
Input
The input is given from Standard Input in the following format:
N
Output
Print the number of the possible pairs of integers u and v, modulo 10^9+7.
Examples
Input
3
Output
5
Input
1422
Output
52277
Input
1000000000000000000
Output
787014179
Submitted Solution:
```
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline
n, = map(int,read().split())
d = {}
"""
res = [[0]*100 for _ in range(100)]
for i in range(128):
for j in range(128):
u = i^j
v = i+j
if u<100 and v<100: res[u][v] = 1
x = 0
for i in range(n+1):
for j in range(n+1):
x += res[i][j]
for i in res[:10]:
print(i[:10])
for i in range(100):
for j in range(1,100):
res[i][j] += res[i][j-1]
for i in range(1,100):
for j in range(100):
res[i][j] += res[i-1][j]
#for i in res[:10]:
# print(i[:10])
"""
def f(n,m):
if (n,m) in d: return d[(n,m)]
if n<0 or m<0:
return 0
if n==0:
return max(1+n//2,1+m//2)
if m==0:
return 1
nn = n>>1 if n&1 else (n>>1)-1
mm = m>>1 if m&1 else (m>>1)-1
#print(f"({n},{m})", f(nn,mm),f(n>>1,m>>1),f(n>>1,(m>>1)-1))
v = f(nn,mm) + f(n>>1,m>>1) + f(n>>1,(m>>1)-1)
d[(n,m)] = v
#assert v == res[n][m]
return v
ans = f(n,n)
print(ans%(10**9+7))
``` | instruction | 0 | 60,536 | 5 | 121,072 |
Yes | output | 1 | 60,536 | 5 | 121,073 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a positive integer N. Find the number of the pairs of integers u and v (0≦u,v≦N) such that there exist two non-negative integers a and b satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR. Since it can be extremely large, compute the answer modulo 10^9+7.
Constraints
* 1≦N≦10^{18}
Input
The input is given from Standard Input in the following format:
N
Output
Print the number of the possible pairs of integers u and v, modulo 10^9+7.
Examples
Input
3
Output
5
Input
1422
Output
52277
Input
1000000000000000000
Output
787014179
Submitted Solution:
```
mod = 10**9+7
n = int(input())
def nth_bit(d):
return (n>>d)&1
dp = [[0,0,0] for _ in range(61)]
dp[-1][0] = 1
for d in range(59,-1,-1):
for s in range(3):
for k in range(3):
s2 = min(2,2*s+nth_bit(d)-k)
if s2>=0:
dp[d][s2] += dp[d+1][s]
ans = sum(dp[0])%mod
print(ans)
``` | instruction | 0 | 60,538 | 5 | 121,076 |
Yes | output | 1 | 60,538 | 5 | 121,077 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a positive integer N. Find the number of the pairs of integers u and v (0≦u,v≦N) such that there exist two non-negative integers a and b satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR. Since it can be extremely large, compute the answer modulo 10^9+7.
Constraints
* 1≦N≦10^{18}
Input
The input is given from Standard Input in the following format:
N
Output
Print the number of the possible pairs of integers u and v, modulo 10^9+7.
Examples
Input
3
Output
5
Input
1422
Output
52277
Input
1000000000000000000
Output
787014179
Submitted Solution:
```
N= int(input())
bit = bin(N)[2:]
k = len(bit)
dp = [[0] * 2 for i in range(len(bit) + 1)]
for i in range(k):
j = int(bit[k-i+1])
a,b,c = [(1,0,0),(1,1,0)][j]
d,e,f = [(2, 1, 1),(1, 2, 2)][j]
dp[i+1][0] = a * dp[i][0] + b * dp[i][1] + c * 3**i
dp[i+1][1] = d * dp[i][0] + e * dp[i][1] + f * 3**i
print(dp[k][0])
``` | instruction | 0 | 60,539 | 5 | 121,078 |
No | output | 1 | 60,539 | 5 | 121,079 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a positive integer N. Find the number of the pairs of integers u and v (0≦u,v≦N) such that there exist two non-negative integers a and b satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR. Since it can be extremely large, compute the answer modulo 10^9+7.
Constraints
* 1≦N≦10^{18}
Input
The input is given from Standard Input in the following format:
N
Output
Print the number of the possible pairs of integers u and v, modulo 10^9+7.
Examples
Input
3
Output
5
Input
1422
Output
52277
Input
1000000000000000000
Output
787014179
Submitted Solution:
```
MOD = 1000000007
n = int(input())
m = [0, 1]
for i in range(1, (n - 1) // 2 + 2):
m.append(m[i])
m.append((m[i] + m[i + 1]) % MOD)
if n % 2 == 1:
print('pop')
m.pop()
print(sum(m) % MOD)
``` | instruction | 0 | 60,540 | 5 | 121,080 |
No | output | 1 | 60,540 | 5 | 121,081 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.