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 |
|---|---|---|---|---|---|
Provide a correct Python 3 solution for this coding contest problem.
Write a program which identifies the number of combinations of three integers which satisfy the following conditions:
* You should select three distinct integers from 1 to n.
* A total sum of the three integers is x.
For example, there are two combinations for n = 5 and x = 9.
* 1 + 3 + 5 = 9
* 2 + 3 + 4 = 9
Note
解説
Constraints
* 3 ≤ n ≤ 100
* 0 ≤ x ≤ 300
Input
The input consists of multiple datasets. For each dataset, two integers n and x are given in a line.
The input ends with two zeros for n and x respectively. Your program should not process for these terminal symbols.
Output
For each dataset, print the number of combinations in a line.
Example
Input
5 9
0 0
Output
2 | instruction | 0 | 21,170 | 5 | 42,340 |
"Correct Solution:
```
while True:
n,x=map(int,input().split())
if(n,x)==(0,0):
break
y=0
for i in range(1,n-1):
for j in range(i+1,n):
for k in range(j+1,n+1):
if(i+j+k==x):
y+=1
print(y)
``` | output | 1 | 21,170 | 5 | 42,341 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which identifies the number of combinations of three integers which satisfy the following conditions:
* You should select three distinct integers from 1 to n.
* A total sum of the three integers is x.
For example, there are two combinations for n = 5 and x = 9.
* 1 + 3 + 5 = 9
* 2 + 3 + 4 = 9
Note
解説
Constraints
* 3 ≤ n ≤ 100
* 0 ≤ x ≤ 300
Input
The input consists of multiple datasets. For each dataset, two integers n and x are given in a line.
The input ends with two zeros for n and x respectively. Your program should not process for these terminal symbols.
Output
For each dataset, print the number of combinations in a line.
Example
Input
5 9
0 0
Output
2 | instruction | 0 | 21,171 | 5 | 42,342 |
"Correct Solution:
```
while True:
a,b= map(int,input().split())
if a+b == 0:
break
c=0
for i in range(1,a+1):
for j in range(i+1,a+1):
for k in range(j+1,a+1):
if i+j+k ==b:
c+=1
print(c)
``` | output | 1 | 21,171 | 5 | 42,343 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which identifies the number of combinations of three integers which satisfy the following conditions:
* You should select three distinct integers from 1 to n.
* A total sum of the three integers is x.
For example, there are two combinations for n = 5 and x = 9.
* 1 + 3 + 5 = 9
* 2 + 3 + 4 = 9
Note
解説
Constraints
* 3 ≤ n ≤ 100
* 0 ≤ x ≤ 300
Input
The input consists of multiple datasets. For each dataset, two integers n and x are given in a line.
The input ends with two zeros for n and x respectively. Your program should not process for these terminal symbols.
Output
For each dataset, print the number of combinations in a line.
Example
Input
5 9
0 0
Output
2 | instruction | 0 | 21,172 | 5 | 42,344 |
"Correct Solution:
```
while True:
n,x=map(int,input().split())
if n==0 and x==0:
break
ans=0
for a in range(1,n-1):
for b in range(a+1,n):
if b<x-a-b<=n:
ans+=1
print(ans)
``` | output | 1 | 21,172 | 5 | 42,345 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which identifies the number of combinations of three integers which satisfy the following conditions:
* You should select three distinct integers from 1 to n.
* A total sum of the three integers is x.
For example, there are two combinations for n = 5 and x = 9.
* 1 + 3 + 5 = 9
* 2 + 3 + 4 = 9
Note
解説
Constraints
* 3 ≤ n ≤ 100
* 0 ≤ x ≤ 300
Input
The input consists of multiple datasets. For each dataset, two integers n and x are given in a line.
The input ends with two zeros for n and x respectively. Your program should not process for these terminal symbols.
Output
For each dataset, print the number of combinations in a line.
Example
Input
5 9
0 0
Output
2
Submitted Solution:
```
while True:
n,x = map(int,input().split())
if n == 0 and x == 0:
break
cnt=0
for i in range(1,x//3):
for j in range(i+1,x//2):
k=x-i-j
if j<k<=n:
cnt+=1
print(cnt)
``` | instruction | 0 | 21,173 | 5 | 42,346 |
Yes | output | 1 | 21,173 | 5 | 42,347 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which identifies the number of combinations of three integers which satisfy the following conditions:
* You should select three distinct integers from 1 to n.
* A total sum of the three integers is x.
For example, there are two combinations for n = 5 and x = 9.
* 1 + 3 + 5 = 9
* 2 + 3 + 4 = 9
Note
解説
Constraints
* 3 ≤ n ≤ 100
* 0 ≤ x ≤ 300
Input
The input consists of multiple datasets. For each dataset, two integers n and x are given in a line.
The input ends with two zeros for n and x respectively. Your program should not process for these terminal symbols.
Output
For each dataset, print the number of combinations in a line.
Example
Input
5 9
0 0
Output
2
Submitted Solution:
```
n, x = map(int, input().split())
while n != 0 or x != 0:
count = 0
for i in range(1, n+1):
for j in range(i+1, n+1):
for k in range(j+1, n+1):
if i+j+k == x:
count += 1
print(count)
n, x = map(int, input().split())
``` | instruction | 0 | 21,174 | 5 | 42,348 |
Yes | output | 1 | 21,174 | 5 | 42,349 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which identifies the number of combinations of three integers which satisfy the following conditions:
* You should select three distinct integers from 1 to n.
* A total sum of the three integers is x.
For example, there are two combinations for n = 5 and x = 9.
* 1 + 3 + 5 = 9
* 2 + 3 + 4 = 9
Note
解説
Constraints
* 3 ≤ n ≤ 100
* 0 ≤ x ≤ 300
Input
The input consists of multiple datasets. For each dataset, two integers n and x are given in a line.
The input ends with two zeros for n and x respectively. Your program should not process for these terminal symbols.
Output
For each dataset, print the number of combinations in a line.
Example
Input
5 9
0 0
Output
2
Submitted Solution:
```
while 1:
n,x = map(int,input().split())
if n+x==0:break
cnt = 0
for a in range(1,n+1):
for b in range(a+1,n+1):
c = x-a-b
if c>b and c<=n:
cnt+=1
print(cnt)
``` | instruction | 0 | 21,175 | 5 | 42,350 |
Yes | output | 1 | 21,175 | 5 | 42,351 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which identifies the number of combinations of three integers which satisfy the following conditions:
* You should select three distinct integers from 1 to n.
* A total sum of the three integers is x.
For example, there are two combinations for n = 5 and x = 9.
* 1 + 3 + 5 = 9
* 2 + 3 + 4 = 9
Note
解説
Constraints
* 3 ≤ n ≤ 100
* 0 ≤ x ≤ 300
Input
The input consists of multiple datasets. For each dataset, two integers n and x are given in a line.
The input ends with two zeros for n and x respectively. Your program should not process for these terminal symbols.
Output
For each dataset, print the number of combinations in a line.
Example
Input
5 9
0 0
Output
2
Submitted Solution:
```
import itertools
while True:
n, x = map(int, input().split())
if n == x == 0:
break
result = 0
for i in itertools.combinations(range(1, n + 1), 3):
if sum(i) == x:
result += 1
print(result)
``` | instruction | 0 | 21,176 | 5 | 42,352 |
Yes | output | 1 | 21,176 | 5 | 42,353 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which identifies the number of combinations of three integers which satisfy the following conditions:
* You should select three distinct integers from 1 to n.
* A total sum of the three integers is x.
For example, there are two combinations for n = 5 and x = 9.
* 1 + 3 + 5 = 9
* 2 + 3 + 4 = 9
Note
解説
Constraints
* 3 ≤ n ≤ 100
* 0 ≤ x ≤ 300
Input
The input consists of multiple datasets. For each dataset, two integers n and x are given in a line.
The input ends with two zeros for n and x respectively. Your program should not process for these terminal symbols.
Output
For each dataset, print the number of combinations in a line.
Example
Input
5 9
0 0
Output
2
Submitted Solution:
```
N,M = map(int, input().split())
ans = 0
while not (N == 0 and M == 0):
for i in range(N):
for j in range(N):
for k in range(N):
if ( i==j or i==k or j==k):
elif(i + j + k == M): ans += 1
print(ans)
``` | instruction | 0 | 21,177 | 5 | 42,354 |
No | output | 1 | 21,177 | 5 | 42,355 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which identifies the number of combinations of three integers which satisfy the following conditions:
* You should select three distinct integers from 1 to n.
* A total sum of the three integers is x.
For example, there are two combinations for n = 5 and x = 9.
* 1 + 3 + 5 = 9
* 2 + 3 + 4 = 9
Note
解説
Constraints
* 3 ≤ n ≤ 100
* 0 ≤ x ≤ 300
Input
The input consists of multiple datasets. For each dataset, two integers n and x are given in a line.
The input ends with two zeros for n and x respectively. Your program should not process for these terminal symbols.
Output
For each dataset, print the number of combinations in a line.
Example
Input
5 9
0 0
Output
2
Submitted Solution:
```
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
??´?????????
"""
while True:
inp = input().strip().split(" ")
n = int(inp[0]) + 1
x = int(inp[1])
cnt = 0
if n < 1 and x < 1:
break
for i in range(1, n-2):
for j in range(i + 1, n-1):
for k in range(j + 1, n):
t = i + j + k
if t == x:
cnt = cnt + 1
elif t > x:
break
print(cnt)
``` | instruction | 0 | 21,178 | 5 | 42,356 |
No | output | 1 | 21,178 | 5 | 42,357 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which identifies the number of combinations of three integers which satisfy the following conditions:
* You should select three distinct integers from 1 to n.
* A total sum of the three integers is x.
For example, there are two combinations for n = 5 and x = 9.
* 1 + 3 + 5 = 9
* 2 + 3 + 4 = 9
Note
解説
Constraints
* 3 ≤ n ≤ 100
* 0 ≤ x ≤ 300
Input
The input consists of multiple datasets. For each dataset, two integers n and x are given in a line.
The input ends with two zeros for n and x respectively. Your program should not process for these terminal symbols.
Output
For each dataset, print the number of combinations in a line.
Example
Input
5 9
0 0
Output
2
Submitted Solution:
```
n, x = [int(temp) for temp in input().split()]
cen = x // 3
for temp in range(1,cen):
pass
print(temp)
``` | instruction | 0 | 21,179 | 5 | 42,358 |
No | output | 1 | 21,179 | 5 | 42,359 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which identifies the number of combinations of three integers which satisfy the following conditions:
* You should select three distinct integers from 1 to n.
* A total sum of the three integers is x.
For example, there are two combinations for n = 5 and x = 9.
* 1 + 3 + 5 = 9
* 2 + 3 + 4 = 9
Note
解説
Constraints
* 3 ≤ n ≤ 100
* 0 ≤ x ≤ 300
Input
The input consists of multiple datasets. For each dataset, two integers n and x are given in a line.
The input ends with two zeros for n and x respectively. Your program should not process for these terminal symbols.
Output
For each dataset, print the number of combinations in a line.
Example
Input
5 9
0 0
Output
2
Submitted Solution:
```
def dfs(i, j, s):
if j > 3:
return
if j == 3 and sum(s) == x:
res.append(1)
for k in range(1, i):
if k not in s:
dfs(k, j + 1, s + [k])
ans = []
while True:
res = []
n, x = map(int, input().split())
if n == x == 0:
break
for i in range(3, n + 1):
dfs(i, 1, [i])
ans.append(sum(res))
print("\n".join(map(str, ans)))
``` | instruction | 0 | 21,180 | 5 | 42,360 |
No | output | 1 | 21,180 | 5 | 42,361 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
qd ucyhf yi q fhycu dkcruh mxeiu huluhiu yi q tyvvuhudj fhycu dkcruh. oekh jqia yi je vydt jxu djx ucyhf.
Input
jxu ydfkj sediyiji ev q iydwbu ydjuwuh d (1 ≤ d ≤ 11184) — jxu edu-rqiut ydtun ev jxu ucyhf je vydt.
Output
ekjfkj q iydwbu dkcruh.
Examples
Input
1
Output
13
Submitted Solution:
```
x = int(input())
prime_list = []
for i in range(13, 10**9):
if i % 2 != 0 and i % 3 != 0 and i % 4 != 0 and i % 5 != 0 and i % 6 != 0 and i % 7 != 0 and i % 8 != 0 and i % 9 != 0 and i % 11 != 0:
rev = int(str(i)[::-1])
if rev % 2 != 0 and rev % 3 != 0 and rev % 4 != 0 and rev % 5 != 0 and rev % 6 != 0 and rev % 7 != 0 and rev % 8 != 0 and rev % 9 != 0 and rev % 11 != 0:
prime_list.append(i)
if x == len(prime_list):
break
print(prime_list[-1])
``` | instruction | 0 | 21,474 | 5 | 42,948 |
No | output | 1 | 21,474 | 5 | 42,949 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
qd ucyhf yi q fhycu dkcruh mxeiu huluhiu yi q tyvvuhudj fhycu dkcruh. oekh jqia yi je vydt jxu djx ucyhf.
Input
jxu ydfkj sediyiji ev q iydwbu ydjuwuh d (1 ≤ d ≤ 11184) — jxu edu-rqiut ydtun ev jxu ucyhf je vydt.
Output
ekjfkj q iydwbu dkcruh.
Examples
Input
1
Output
13
Submitted Solution:
```
from math import ceil,sqrt
def isPrime(n):
if n == 1 :
return False
if n == 2:
return True
upper = ceil(sqrt(n)) + 1
for num in range(2,upper):
if n % num == 0:
return False
return True
def check(n):
if isPrime(n):
if isPrime(int(str(n)[::-1])):
return True
def make(n):
ans = []
x = 13
while len(ans) < n:
if check(x):
ans.append(x)
x+=1
print(ans[-1])
make(int(input()))
``` | instruction | 0 | 21,475 | 5 | 42,950 |
No | output | 1 | 21,475 | 5 | 42,951 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For the given sequence with n different elements find the number of increasing subsequences with k + 1 elements. It is guaranteed that the answer is not greater than 8·1018.
Input
First line contain two integer values n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 10) — the length of sequence and the number of elements in increasing subsequences.
Next n lines contains one integer ai (1 ≤ ai ≤ n) each — elements of sequence. All values ai are different.
Output
Print one integer — the answer to the problem.
Examples
Input
5 2
1
2
3
5
4
Output
7
Submitted Solution:
```
import os
from io import BytesIO
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
n, k = map(int, input().split())
a = [int(input()) for i in range(n)]
dp = [[0] * (n + 1) for i in range(k + 1)]
def query(f, i):
r = 0
while i > 0:
r += f[i]
i -= i & -i
return r
def update(f, i, r):
while i <= n:
f[i] += r
i += i & -i
res = [1] * n
for i in range(n):
update(dp[0], a[i], 1)
for j in range(1, k + 1):
res[i] = query(dp[j - 1], a[i] - 1)
update(dp[j], a[i], res[i])
print(sum(res))
``` | instruction | 0 | 21,626 | 5 | 43,252 |
Yes | output | 1 | 21,626 | 5 | 43,253 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For the given sequence with n different elements find the number of increasing subsequences with k + 1 elements. It is guaranteed that the answer is not greater than 8·1018.
Input
First line contain two integer values n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 10) — the length of sequence and the number of elements in increasing subsequences.
Next n lines contains one integer ai (1 ≤ ai ≤ n) each — elements of sequence. All values ai are different.
Output
Print one integer — the answer to the problem.
Examples
Input
5 2
1
2
3
5
4
Output
7
Submitted Solution:
```
import sys, os
from io import BytesIO
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
def update(BIT, i, value):
while i <= len(BIT) - 1:
BIT[i] += value
i += i & -i
def query(BIT, start, end):
if start > 0:
return query(BIT, 0, end) - query(BIT, 0, start - 1)
res = 0
while end > 0:
res += BIT[end]
end -= end & -end
return res
n, k = list(map(int, input().split()))
a = [int(input()) for _ in range(n)]
dp = [[0] * (n+1) for i in range(k+1)]
res = [1] * n
for i in range(n):
update(dp[0], a[i], 1)
for j in range(1, k+1):
res[i] = query(dp[j-1], 0, a[i]-1)
update(dp[j], a[i], res[i])
print(sum(res))
``` | instruction | 0 | 21,627 | 5 | 43,254 |
Yes | output | 1 | 21,627 | 5 | 43,255 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For the given sequence with n different elements find the number of increasing subsequences with k + 1 elements. It is guaranteed that the answer is not greater than 8·1018.
Input
First line contain two integer values n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 10) — the length of sequence and the number of elements in increasing subsequences.
Next n lines contains one integer ai (1 ≤ ai ≤ n) each — elements of sequence. All values ai are different.
Output
Print one integer — the answer to the problem.
Examples
Input
5 2
1
2
3
5
4
Output
7
Submitted Solution:
```
def my_function(ind,steak,aind):
res = 0
if steak==k+1:
return 1
if aind==-1:
return 0
if a[aind]<a[aind+1]:
res += my_function(ind,steak+1,aind-1)
return res+my_function(ind,steak,aind-1)
n,k = map(int,input().rstrip().split())
a = []
res = 0
for i in range(n):
a.append(int(input().rstrip()))
res += my_function(i-1,1,i-1)
print(res)
``` | instruction | 0 | 21,629 | 5 | 43,258 |
No | output | 1 | 21,629 | 5 | 43,259 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For the given sequence with n different elements find the number of increasing subsequences with k + 1 elements. It is guaranteed that the answer is not greater than 8·1018.
Input
First line contain two integer values n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 10) — the length of sequence and the number of elements in increasing subsequences.
Next n lines contains one integer ai (1 ≤ ai ≤ n) each — elements of sequence. All values ai are different.
Output
Print one integer — the answer to the problem.
Examples
Input
5 2
1
2
3
5
4
Output
7
Submitted Solution:
```
from bisect import bisect_right
from collections import defaultdict
import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def sum(BIT, i):
s = 0
while i > 0:
s += BIT[i]
i -= i & (-i)
return s
def update(BIT, i, v):
while i < len(BIT):
BIT[i] += v
i += i & (-i)
def find(fen, k):
curr = 0
ans = 0
prevsum = 0
for i in range(19, -1, -1):
if ((curr + (1 << i) < n) and fen[curr + (1 << i)] + prevsum < k):
ans = curr + (1 << i)
curr = ans
prevsum += fen[curr]
return ans + 1
def Rank(x,BIT) :
return sum(BIT,x)
def least_significant_bit(i):
return ((i) & -(i))
def prefix_sum(index,BIT):
# 1-indexed
i = index + 1
result = 0
while i > 0:
result += BIT[i]
i -= least_significant_bit(i)
return result
def range_sum(start, end,BIT):
return (prefix_sum(end,BIT) - prefix_sum(start - 1,BIT))
n,k=map(int,input().split())
dp=[[0]*(n+1) for i in range(k+1)]
b=[]
for j in range(n):
b.append(int(input()))
ans=0
for i in range(n):
update(dp[0], b[i], 1)
p=0
for j in range(1,k+1):
p= sum(dp[j-1],b[i]-1)
update(dp[j],b[i],p)
ans+=p
print(ans)
``` | instruction | 0 | 21,630 | 5 | 43,260 |
No | output | 1 | 21,630 | 5 | 43,261 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For the given sequence with n different elements find the number of increasing subsequences with k + 1 elements. It is guaranteed that the answer is not greater than 8·1018.
Input
First line contain two integer values n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 10) — the length of sequence and the number of elements in increasing subsequences.
Next n lines contains one integer ai (1 ≤ ai ≤ n) each — elements of sequence. All values ai are different.
Output
Print one integer — the answer to the problem.
Examples
Input
5 2
1
2
3
5
4
Output
7
Submitted Solution:
```
import math
class Fenwick:
def __init__(self, n):
self.lst = [0] * int((math.pow(2, math.ceil(math.log2(n))) + 1))
def add(self, i, k):
i += 1
while i < len(self.lst):
self.lst[i - 1] += k
i += i & -i
def set(self, i, k):
self.add(i, k - self.get(i))
def prefix_sum(self, i):
s = 0
i += 1
while i > 0:
s += self.lst[i - 1]
i -= i & -i
return s
def get(self, i):
i += 1
return self.prefix_sum(i) - self.prefix_sum(i - 1)
n, k = list(map(int, input().split()))
lst = [int(input()) - 1 for i in range(n)]
pos = [-1 for i in range(n)]
for i in range(n):
pos[lst[i]] = i
fen = [Fenwick(n) for j in range(k + 1)]
for i in range(n):
fen[0].add(i, 1)
for i in range(2, n): # i = a[n]
for j in range(1, k + 1):
fen[j].set(pos[i], fen[j - 1].prefix_sum(pos[i - 1]))
print(fen[-1].prefix_sum(n - 1))
``` | instruction | 0 | 21,631 | 5 | 43,262 |
No | output | 1 | 21,631 | 5 | 43,263 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?
Given an integer sequence a1, a2, ..., an of length n. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers.
A subsegment is a contiguous slice of the whole sequence. For example, {3, 4, 5} and {1} are subsegments of sequence {1, 2, 3, 4, 5, 6}, while {1, 2, 4} and {7} are not.
Input
The first line of input contains a non-negative integer n (1 ≤ n ≤ 100) — the length of the sequence.
The second line contains n space-separated non-negative integers a1, a2, ..., an (0 ≤ ai ≤ 100) — the elements of the sequence.
Output
Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise.
You can output each letter in any case (upper or lower).
Examples
Input
3
1 3 5
Output
Yes
Input
5
1 0 1 5 1
Output
Yes
Input
3
4 3 1
Output
No
Input
4
3 9 9 3
Output
No
Note
In the first example, divide the sequence into 1 subsegment: {1, 3, 5} and the requirements will be met.
In the second example, divide the sequence into 3 subsegments: {1, 0, 1}, {5}, {1}.
In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met.
In the fourth example, the sequence can be divided into 2 subsegments: {3, 9, 9}, {3}, but this is not a valid solution because 2 is an even number.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
if len(a) % 2 == 0:
#if a[0] % 2 == 0 or a[-1] % 2 == 0:
print('no')
elif len(a) % 2 == 1:
if a[0] % 2 == 1 and a[-1] % 2 == 1:
print('yes')
else:
print('no')
``` | instruction | 0 | 21,693 | 5 | 43,386 |
Yes | output | 1 | 21,693 | 5 | 43,387 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?
Given an integer sequence a1, a2, ..., an of length n. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers.
A subsegment is a contiguous slice of the whole sequence. For example, {3, 4, 5} and {1} are subsegments of sequence {1, 2, 3, 4, 5, 6}, while {1, 2, 4} and {7} are not.
Input
The first line of input contains a non-negative integer n (1 ≤ n ≤ 100) — the length of the sequence.
The second line contains n space-separated non-negative integers a1, a2, ..., an (0 ≤ ai ≤ 100) — the elements of the sequence.
Output
Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise.
You can output each letter in any case (upper or lower).
Examples
Input
3
1 3 5
Output
Yes
Input
5
1 0 1 5 1
Output
Yes
Input
3
4 3 1
Output
No
Input
4
3 9 9 3
Output
No
Note
In the first example, divide the sequence into 1 subsegment: {1, 3, 5} and the requirements will be met.
In the second example, divide the sequence into 3 subsegments: {1, 0, 1}, {5}, {1}.
In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met.
In the fourth example, the sequence can be divided into 2 subsegments: {3, 9, 9}, {3}, but this is not a valid solution because 2 is an even number.
Submitted Solution:
```
n = int(input())
a = input().split()
if(int(a[0]) % 2 == 1 and int(a[-1]) % 2 == 1 and len(a) % 2 == 1):
print("Yes")
else:
print("No")
``` | instruction | 0 | 21,694 | 5 | 43,388 |
Yes | output | 1 | 21,694 | 5 | 43,389 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?
Given an integer sequence a1, a2, ..., an of length n. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers.
A subsegment is a contiguous slice of the whole sequence. For example, {3, 4, 5} and {1} are subsegments of sequence {1, 2, 3, 4, 5, 6}, while {1, 2, 4} and {7} are not.
Input
The first line of input contains a non-negative integer n (1 ≤ n ≤ 100) — the length of the sequence.
The second line contains n space-separated non-negative integers a1, a2, ..., an (0 ≤ ai ≤ 100) — the elements of the sequence.
Output
Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise.
You can output each letter in any case (upper or lower).
Examples
Input
3
1 3 5
Output
Yes
Input
5
1 0 1 5 1
Output
Yes
Input
3
4 3 1
Output
No
Input
4
3 9 9 3
Output
No
Note
In the first example, divide the sequence into 1 subsegment: {1, 3, 5} and the requirements will be met.
In the second example, divide the sequence into 3 subsegments: {1, 0, 1}, {5}, {1}.
In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met.
In the fourth example, the sequence can be divided into 2 subsegments: {3, 9, 9}, {3}, but this is not a valid solution because 2 is an even number.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split(' ')))
if (n & 1) and (a[0] & 1) and (a[-1] & 1):
print("Yes")
else:
print("No")
``` | instruction | 0 | 21,695 | 5 | 43,390 |
Yes | output | 1 | 21,695 | 5 | 43,391 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?
Given an integer sequence a1, a2, ..., an of length n. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers.
A subsegment is a contiguous slice of the whole sequence. For example, {3, 4, 5} and {1} are subsegments of sequence {1, 2, 3, 4, 5, 6}, while {1, 2, 4} and {7} are not.
Input
The first line of input contains a non-negative integer n (1 ≤ n ≤ 100) — the length of the sequence.
The second line contains n space-separated non-negative integers a1, a2, ..., an (0 ≤ ai ≤ 100) — the elements of the sequence.
Output
Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise.
You can output each letter in any case (upper or lower).
Examples
Input
3
1 3 5
Output
Yes
Input
5
1 0 1 5 1
Output
Yes
Input
3
4 3 1
Output
No
Input
4
3 9 9 3
Output
No
Note
In the first example, divide the sequence into 1 subsegment: {1, 3, 5} and the requirements will be met.
In the second example, divide the sequence into 3 subsegments: {1, 0, 1}, {5}, {1}.
In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met.
In the fourth example, the sequence can be divided into 2 subsegments: {3, 9, 9}, {3}, but this is not a valid solution because 2 is an even number.
Submitted Solution:
```
n=int(input().strip())
l=[int(i) for i in input().split()]
if(n%2==0):
print("NO")
elif(l[0]&1 == 0 or l[-1]&1==0):
print("NO")
else:
print("YES")
``` | instruction | 0 | 21,696 | 5 | 43,392 |
Yes | output | 1 | 21,696 | 5 | 43,393 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?
Given an integer sequence a1, a2, ..., an of length n. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers.
A subsegment is a contiguous slice of the whole sequence. For example, {3, 4, 5} and {1} are subsegments of sequence {1, 2, 3, 4, 5, 6}, while {1, 2, 4} and {7} are not.
Input
The first line of input contains a non-negative integer n (1 ≤ n ≤ 100) — the length of the sequence.
The second line contains n space-separated non-negative integers a1, a2, ..., an (0 ≤ ai ≤ 100) — the elements of the sequence.
Output
Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise.
You can output each letter in any case (upper or lower).
Examples
Input
3
1 3 5
Output
Yes
Input
5
1 0 1 5 1
Output
Yes
Input
3
4 3 1
Output
No
Input
4
3 9 9 3
Output
No
Note
In the first example, divide the sequence into 1 subsegment: {1, 3, 5} and the requirements will be met.
In the second example, divide the sequence into 3 subsegments: {1, 0, 1}, {5}, {1}.
In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met.
In the fourth example, the sequence can be divided into 2 subsegments: {3, 9, 9}, {3}, but this is not a valid solution because 2 is an even number.
Submitted Solution:
```
n = int(input().strip())
T= list(map(int,input().strip().split()))
last=0
count=0
for i,x in enumerate(T):
if x % 2 == 0:
if i == 0 or i == n-1:
print("No")
break
else:
continue
else:
if i-last % 2 == 1:
if i== n-1:
print("No")
break
else:
continue
elif i!=0:
last=i
count+=1
else:
if count%2: print("Yes")
else: print("No")
``` | instruction | 0 | 21,697 | 5 | 43,394 |
No | output | 1 | 21,697 | 5 | 43,395 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?
Given an integer sequence a1, a2, ..., an of length n. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers.
A subsegment is a contiguous slice of the whole sequence. For example, {3, 4, 5} and {1} are subsegments of sequence {1, 2, 3, 4, 5, 6}, while {1, 2, 4} and {7} are not.
Input
The first line of input contains a non-negative integer n (1 ≤ n ≤ 100) — the length of the sequence.
The second line contains n space-separated non-negative integers a1, a2, ..., an (0 ≤ ai ≤ 100) — the elements of the sequence.
Output
Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise.
You can output each letter in any case (upper or lower).
Examples
Input
3
1 3 5
Output
Yes
Input
5
1 0 1 5 1
Output
Yes
Input
3
4 3 1
Output
No
Input
4
3 9 9 3
Output
No
Note
In the first example, divide the sequence into 1 subsegment: {1, 3, 5} and the requirements will be met.
In the second example, divide the sequence into 3 subsegments: {1, 0, 1}, {5}, {1}.
In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met.
In the fourth example, the sequence can be divided into 2 subsegments: {3, 9, 9}, {3}, but this is not a valid solution because 2 is an even number.
Submitted Solution:
```
n=int(input())
l=[]
f=False
l=map(int,(input().split()))
for x in l:
if x%2==0:
f=True
break
if n%2==0:
print("No")
elif f==True and n%2==1:
print("No")
else:
print("Yes")
``` | instruction | 0 | 21,698 | 5 | 43,396 |
No | output | 1 | 21,698 | 5 | 43,397 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?
Given an integer sequence a1, a2, ..., an of length n. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers.
A subsegment is a contiguous slice of the whole sequence. For example, {3, 4, 5} and {1} are subsegments of sequence {1, 2, 3, 4, 5, 6}, while {1, 2, 4} and {7} are not.
Input
The first line of input contains a non-negative integer n (1 ≤ n ≤ 100) — the length of the sequence.
The second line contains n space-separated non-negative integers a1, a2, ..., an (0 ≤ ai ≤ 100) — the elements of the sequence.
Output
Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise.
You can output each letter in any case (upper or lower).
Examples
Input
3
1 3 5
Output
Yes
Input
5
1 0 1 5 1
Output
Yes
Input
3
4 3 1
Output
No
Input
4
3 9 9 3
Output
No
Note
In the first example, divide the sequence into 1 subsegment: {1, 3, 5} and the requirements will be met.
In the second example, divide the sequence into 3 subsegments: {1, 0, 1}, {5}, {1}.
In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met.
In the fourth example, the sequence can be divided into 2 subsegments: {3, 9, 9}, {3}, but this is not a valid solution because 2 is an even number.
Submitted Solution:
```
if __name__ == '__main__':
n = int(input())
x = list(map(int, input().split()))
if x[0] % 2 == 0:
print("No")
``` | instruction | 0 | 21,699 | 5 | 43,398 |
No | output | 1 | 21,699 | 5 | 43,399 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?
Given an integer sequence a1, a2, ..., an of length n. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers.
A subsegment is a contiguous slice of the whole sequence. For example, {3, 4, 5} and {1} are subsegments of sequence {1, 2, 3, 4, 5, 6}, while {1, 2, 4} and {7} are not.
Input
The first line of input contains a non-negative integer n (1 ≤ n ≤ 100) — the length of the sequence.
The second line contains n space-separated non-negative integers a1, a2, ..., an (0 ≤ ai ≤ 100) — the elements of the sequence.
Output
Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise.
You can output each letter in any case (upper or lower).
Examples
Input
3
1 3 5
Output
Yes
Input
5
1 0 1 5 1
Output
Yes
Input
3
4 3 1
Output
No
Input
4
3 9 9 3
Output
No
Note
In the first example, divide the sequence into 1 subsegment: {1, 3, 5} and the requirements will be met.
In the second example, divide the sequence into 3 subsegments: {1, 0, 1}, {5}, {1}.
In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met.
In the fourth example, the sequence can be divided into 2 subsegments: {3, 9, 9}, {3}, but this is not a valid solution because 2 is an even number.
Submitted Solution:
```
# in_x = input().split(" ")
#
# a, b = int(in_x[0]), int(in_x[1])
# while a != 0 and b != 0:
# if a >= 2 * b:
# a = a % (2 * b)
# continue
# elif b >= 2 * a:
# b = b % (2 * a)
# continue
# else:
# break
# print(a, b)
# s, v1, v2, t1, t2 = [int(x) for x in input().split(" ")]
#
# first = t1 + t1 + (s * v1)
# second = t2 + t2 + (s * v2)
# if first < second:
# print("First")
# elif first > second:
# print("Second")
# else:
# print("Friendship")
#
# length = int(input())
# vals = [int(x) for x in input().split(" ")]
#
# increasing = 0
# constant = 1
# decreasing = 0
# failed = False
# for i in range(length - 1):
# if vals[i + 1] > vals[i]:
# if decreasing == 1:
# failed = True
# if increasing == 2:
# failed = True
# break
# else:
# increasing = 1
# continue
# if vals[i + 1] == vals[i]:
# if decreasing == 1:
# failed = True
# break
# increasing = 2
# constant = 1
# continue
# if vals[i + 1] < vals[i]:
# if constant == 0:
# failed = True
# decreasing = 1
# constant = 2
# continue
#
# if failed:
# print("No")
# else:
# print("Yes")
length = int(input())
vals = [int(x) for x in input().split(" ")]
odds = 0
evens = 0
appending = False
for i in vals:
if i % 2 == 0:
evens += 1
else:
odds += 1
if evens == odds or evens + 1 == odds or length == 4 or (length ==1 and odds==1):
print("No")
else:
print("Yes")
``` | instruction | 0 | 21,700 | 5 | 43,400 |
No | output | 1 | 21,700 | 5 | 43,401 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
"We've tried solitary confinement, waterboarding and listening to Just In Beaver, to no avail. We need something extreme."
"Little Alena got an array as a birthday present..."
The array b of length n is obtained from the array a of length n and two integers l and r (l ≤ r) using the following procedure:
b1 = b2 = b3 = b4 = 0.
For all 5 ≤ i ≤ n:
* bi = 0 if ai, ai - 1, ai - 2, ai - 3, ai - 4 > r and bi - 1 = bi - 2 = bi - 3 = bi - 4 = 1
* bi = 1 if ai, ai - 1, ai - 2, ai - 3, ai - 4 < l and bi - 1 = bi - 2 = bi - 3 = bi - 4 = 0
* bi = bi - 1 otherwise
You are given arrays a and b' of the same length. Find two integers l and r (l ≤ r), such that applying the algorithm described above will yield an array b equal to b'.
It's guaranteed that the answer exists.
Input
The first line of input contains a single integer n (5 ≤ n ≤ 105) — the length of a and b'.
The second line of input contains n space separated integers a1, ..., an ( - 109 ≤ ai ≤ 109) — the elements of a.
The third line of input contains a string of n characters, consisting of 0 and 1 — the elements of b'. Note that they are not separated by spaces.
Output
Output two integers l and r ( - 109 ≤ l ≤ r ≤ 109), conforming to the requirements described above.
If there are multiple solutions, output any of them.
It's guaranteed that the answer exists.
Examples
Input
5
1 2 3 4 5
00001
Output
6 15
Input
10
-10 -9 -8 -7 -6 6 7 8 9 10
0000111110
Output
-5 5
Note
In the first test case any pair of l and r pair is valid, if 6 ≤ l ≤ r ≤ 109, in that case b5 = 1, because a1, ..., a5 < l.
Submitted Solution:
```
def solve():
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, list(input())))
# print(A, B)
LMIN = -10**9
LMAX = 10**9
RMIN = -10**9
RMAX = 10**9
for i in range(4, n):
if b[i-1] == 0 and b[i-2] == 0 and b[i-3] == 0 and b[i-4] == 0:
if b[i] == 1:
LMIN = max(LMIN, max(a[i],a[i-1],a[i-2],a[i-3],a[i-4])+1)
elif b[i] == 0:
LMAX = min(LMAX, max(a[i],a[i-1],a[i-2],a[i-3],a[i-4]))
elif b[i-1] == 1 and b[i-2] == 1 and b[i-3] == 1 and b[i-4] == 1:
if b[i] == 1:
RMIN = max(RMIN, min(a[i],a[i-1],a[i-2],a[i-3],a[i-4]))
elif b[i] == 0:
RMAX = min(RMAX, min(a[i],a[i-1],a[i-2],a[i-3],a[i-4])-1)
else:
pass
# print(LMIN, LMAX, RMIN, RMAX)
# l = (LMIN + LMAX)//2
print(LMIN, RMAX)
if __name__ == "__main__":
solve()
``` | instruction | 0 | 21,735 | 5 | 43,470 |
Yes | output | 1 | 21,735 | 5 | 43,471 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
"We've tried solitary confinement, waterboarding and listening to Just In Beaver, to no avail. We need something extreme."
"Little Alena got an array as a birthday present..."
The array b of length n is obtained from the array a of length n and two integers l and r (l ≤ r) using the following procedure:
b1 = b2 = b3 = b4 = 0.
For all 5 ≤ i ≤ n:
* bi = 0 if ai, ai - 1, ai - 2, ai - 3, ai - 4 > r and bi - 1 = bi - 2 = bi - 3 = bi - 4 = 1
* bi = 1 if ai, ai - 1, ai - 2, ai - 3, ai - 4 < l and bi - 1 = bi - 2 = bi - 3 = bi - 4 = 0
* bi = bi - 1 otherwise
You are given arrays a and b' of the same length. Find two integers l and r (l ≤ r), such that applying the algorithm described above will yield an array b equal to b'.
It's guaranteed that the answer exists.
Input
The first line of input contains a single integer n (5 ≤ n ≤ 105) — the length of a and b'.
The second line of input contains n space separated integers a1, ..., an ( - 109 ≤ ai ≤ 109) — the elements of a.
The third line of input contains a string of n characters, consisting of 0 and 1 — the elements of b'. Note that they are not separated by spaces.
Output
Output two integers l and r ( - 109 ≤ l ≤ r ≤ 109), conforming to the requirements described above.
If there are multiple solutions, output any of them.
It's guaranteed that the answer exists.
Examples
Input
5
1 2 3 4 5
00001
Output
6 15
Input
10
-10 -9 -8 -7 -6 6 7 8 9 10
0000111110
Output
-5 5
Note
In the first test case any pair of l and r pair is valid, if 6 ≤ l ≤ r ≤ 109, in that case b5 = 1, because a1, ..., a5 < l.
Submitted Solution:
```
from sys import stdin as cin
def main():
n = int(input())
a = list(map(int, input().split()))
b = input()
l, r = '?', '?'
for i in range(1, n):
if b[i] == '1' and b[i-1] == '0':
if l == '?':
l = 1 + max(a[i], a[i-1], a[i-2], a[i-3])
else:
l = max(l, 1 + max(a[i], a[i-1], a[i-2], a[i-3]))
if b[i] == '0' and b[i-1] == '1':
if r == '?':
r = min(a[i], a[i-1], a[i-2], a[i-3]) - 1
else:
r = min(r, min(a[i], a[i-1], a[i-2], a[i-3]) - 1)
if l == '?':
l = 0
if r == '?':
r = 0
print(l, r)
main()
``` | instruction | 0 | 21,738 | 5 | 43,476 |
No | output | 1 | 21,738 | 5 | 43,477 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi is a teacher responsible for a class of N students.
The students are given distinct student numbers from 1 to N.
Today, all the students entered the classroom at different times.
According to Takahashi's record, there were A_i students in the classroom when student number i entered the classroom (including student number i).
From these records, reconstruct the order in which the students entered the classroom.
Constraints
* 1 \le N \le 10^5
* 1 \le A_i \le N
* A_i \neq A_j (i \neq j)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 \ldots A_N
Output
Print the student numbers of the students in the order the students entered the classroom.
Examples
Input
3
2 3 1
Output
3 1 2
Input
5
1 2 3 4 5
Output
1 2 3 4 5
Input
8
8 2 7 3 4 5 6 1
Output
8 2 4 5 6 7 3 1 | instruction | 0 | 21,804 | 5 | 43,608 |
"Correct Solution:
```
N = int(input())
A = list(map(int,input().split()))
ls = [0]*N
for i in range(N):
ls[A[i]-1] = i+1
print(*ls)
``` | output | 1 | 21,804 | 5 | 43,609 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi is a teacher responsible for a class of N students.
The students are given distinct student numbers from 1 to N.
Today, all the students entered the classroom at different times.
According to Takahashi's record, there were A_i students in the classroom when student number i entered the classroom (including student number i).
From these records, reconstruct the order in which the students entered the classroom.
Constraints
* 1 \le N \le 10^5
* 1 \le A_i \le N
* A_i \neq A_j (i \neq j)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 \ldots A_N
Output
Print the student numbers of the students in the order the students entered the classroom.
Examples
Input
3
2 3 1
Output
3 1 2
Input
5
1 2 3 4 5
Output
1 2 3 4 5
Input
8
8 2 7 3 4 5 6 1
Output
8 2 4 5 6 7 3 1 | instruction | 0 | 21,805 | 5 | 43,610 |
"Correct Solution:
```
N=int(input())
A=list(map(int,input().split()))
B=[0]*N
for i in range (0,N):
B[A[i]-1]=i+1
print(*B)
``` | output | 1 | 21,805 | 5 | 43,611 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi is a teacher responsible for a class of N students.
The students are given distinct student numbers from 1 to N.
Today, all the students entered the classroom at different times.
According to Takahashi's record, there were A_i students in the classroom when student number i entered the classroom (including student number i).
From these records, reconstruct the order in which the students entered the classroom.
Constraints
* 1 \le N \le 10^5
* 1 \le A_i \le N
* A_i \neq A_j (i \neq j)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 \ldots A_N
Output
Print the student numbers of the students in the order the students entered the classroom.
Examples
Input
3
2 3 1
Output
3 1 2
Input
5
1 2 3 4 5
Output
1 2 3 4 5
Input
8
8 2 7 3 4 5 6 1
Output
8 2 4 5 6 7 3 1 | instruction | 0 | 21,806 | 5 | 43,612 |
"Correct Solution:
```
N = int(input())
A = sorted((a,i) for i,a in enumerate(map(int,input().split())))
print(*(i+1 for a,i in A))
``` | output | 1 | 21,806 | 5 | 43,613 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi is a teacher responsible for a class of N students.
The students are given distinct student numbers from 1 to N.
Today, all the students entered the classroom at different times.
According to Takahashi's record, there were A_i students in the classroom when student number i entered the classroom (including student number i).
From these records, reconstruct the order in which the students entered the classroom.
Constraints
* 1 \le N \le 10^5
* 1 \le A_i \le N
* A_i \neq A_j (i \neq j)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 \ldots A_N
Output
Print the student numbers of the students in the order the students entered the classroom.
Examples
Input
3
2 3 1
Output
3 1 2
Input
5
1 2 3 4 5
Output
1 2 3 4 5
Input
8
8 2 7 3 4 5 6 1
Output
8 2 4 5 6 7 3 1 | instruction | 0 | 21,807 | 5 | 43,614 |
"Correct Solution:
```
n = int(input())
a = list(map(int,input().split()))
b = [0] * n
for i in range(n):
b[a[i]-1] = i+1
print(*b)
``` | output | 1 | 21,807 | 5 | 43,615 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi is a teacher responsible for a class of N students.
The students are given distinct student numbers from 1 to N.
Today, all the students entered the classroom at different times.
According to Takahashi's record, there were A_i students in the classroom when student number i entered the classroom (including student number i).
From these records, reconstruct the order in which the students entered the classroom.
Constraints
* 1 \le N \le 10^5
* 1 \le A_i \le N
* A_i \neq A_j (i \neq j)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 \ldots A_N
Output
Print the student numbers of the students in the order the students entered the classroom.
Examples
Input
3
2 3 1
Output
3 1 2
Input
5
1 2 3 4 5
Output
1 2 3 4 5
Input
8
8 2 7 3 4 5 6 1
Output
8 2 4 5 6 7 3 1 | instruction | 0 | 21,808 | 5 | 43,616 |
"Correct Solution:
```
n = int(input())
A = list(map(int, input().split()))
b = [0]*n
for i, a in enumerate(A):
b[a-1] = i+1
print(*b)
``` | output | 1 | 21,808 | 5 | 43,617 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi is a teacher responsible for a class of N students.
The students are given distinct student numbers from 1 to N.
Today, all the students entered the classroom at different times.
According to Takahashi's record, there were A_i students in the classroom when student number i entered the classroom (including student number i).
From these records, reconstruct the order in which the students entered the classroom.
Constraints
* 1 \le N \le 10^5
* 1 \le A_i \le N
* A_i \neq A_j (i \neq j)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 \ldots A_N
Output
Print the student numbers of the students in the order the students entered the classroom.
Examples
Input
3
2 3 1
Output
3 1 2
Input
5
1 2 3 4 5
Output
1 2 3 4 5
Input
8
8 2 7 3 4 5 6 1
Output
8 2 4 5 6 7 3 1 | instruction | 0 | 21,809 | 5 | 43,618 |
"Correct Solution:
```
n=int(input())
li=list(map(int,input().split()))
an=[0]*n
for i in range(n):
an[li[i]-1]=i+1
print(*an)
``` | output | 1 | 21,809 | 5 | 43,619 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi is a teacher responsible for a class of N students.
The students are given distinct student numbers from 1 to N.
Today, all the students entered the classroom at different times.
According to Takahashi's record, there were A_i students in the classroom when student number i entered the classroom (including student number i).
From these records, reconstruct the order in which the students entered the classroom.
Constraints
* 1 \le N \le 10^5
* 1 \le A_i \le N
* A_i \neq A_j (i \neq j)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 \ldots A_N
Output
Print the student numbers of the students in the order the students entered the classroom.
Examples
Input
3
2 3 1
Output
3 1 2
Input
5
1 2 3 4 5
Output
1 2 3 4 5
Input
8
8 2 7 3 4 5 6 1
Output
8 2 4 5 6 7 3 1 | instruction | 0 | 21,810 | 5 | 43,620 |
"Correct Solution:
```
input()
l=sorted([(i,e+1) for e,i in enumerate(map(int,input().split()))])
print(*list(zip(*l))[1])
``` | output | 1 | 21,810 | 5 | 43,621 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi is a teacher responsible for a class of N students.
The students are given distinct student numbers from 1 to N.
Today, all the students entered the classroom at different times.
According to Takahashi's record, there were A_i students in the classroom when student number i entered the classroom (including student number i).
From these records, reconstruct the order in which the students entered the classroom.
Constraints
* 1 \le N \le 10^5
* 1 \le A_i \le N
* A_i \neq A_j (i \neq j)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 \ldots A_N
Output
Print the student numbers of the students in the order the students entered the classroom.
Examples
Input
3
2 3 1
Output
3 1 2
Input
5
1 2 3 4 5
Output
1 2 3 4 5
Input
8
8 2 7 3 4 5 6 1
Output
8 2 4 5 6 7 3 1 | instruction | 0 | 21,811 | 5 | 43,622 |
"Correct Solution:
```
n,*a=map(int,open(0).read().split())
s=[[j,i] for i,j in zip(range(1,n+1),a)]
s.sort()
print(*[i[1] for i in s])
``` | output | 1 | 21,811 | 5 | 43,623 |
Provide a correct Python 3 solution for this coding contest problem.
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R.
Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan.
Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
Constraints
* 1\leq A,B,C,D \leq 10
* All input values are integers.
Input
Input is given from Standard Input in the following format:
A B C D
Output
Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
Examples
Input
3 8 7 1
Output
Left
Input
3 4 5 2
Output
Balanced
Input
1 7 6 4
Output
Right | instruction | 0 | 21,868 | 5 | 43,736 |
"Correct Solution:
```
a,b,c,d = map(int,input().split())
print("Left" if a+b > c+d else "Right" if a+b < c+d else "Balanced")
``` | output | 1 | 21,868 | 5 | 43,737 |
Provide a correct Python 3 solution for this coding contest problem.
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R.
Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan.
Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
Constraints
* 1\leq A,B,C,D \leq 10
* All input values are integers.
Input
Input is given from Standard Input in the following format:
A B C D
Output
Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
Examples
Input
3 8 7 1
Output
Left
Input
3 4 5 2
Output
Balanced
Input
1 7 6 4
Output
Right | instruction | 0 | 21,869 | 5 | 43,738 |
"Correct Solution:
```
A,B,C,D=map(int,input().split())
print(["Balanced","Left","Right"][(A+B>C+D)-(A+B<C+D)])
``` | output | 1 | 21,869 | 5 | 43,739 |
Provide a correct Python 3 solution for this coding contest problem.
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R.
Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan.
Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
Constraints
* 1\leq A,B,C,D \leq 10
* All input values are integers.
Input
Input is given from Standard Input in the following format:
A B C D
Output
Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
Examples
Input
3 8 7 1
Output
Left
Input
3 4 5 2
Output
Balanced
Input
1 7 6 4
Output
Right | instruction | 0 | 21,870 | 5 | 43,740 |
"Correct Solution:
```
a,b,c,d=map(int,input().split())
print('Left' if((a+b)>(c+d)) else 'Right' if((a+b)<(c+d)) else 'Balanced' )
``` | output | 1 | 21,870 | 5 | 43,741 |
Provide a correct Python 3 solution for this coding contest problem.
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R.
Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan.
Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
Constraints
* 1\leq A,B,C,D \leq 10
* All input values are integers.
Input
Input is given from Standard Input in the following format:
A B C D
Output
Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
Examples
Input
3 8 7 1
Output
Left
Input
3 4 5 2
Output
Balanced
Input
1 7 6 4
Output
Right | instruction | 0 | 21,871 | 5 | 43,742 |
"Correct Solution:
```
a,b,c,d=map(int,input().split())
A=a+b
C=c+d
print("Left" if A>C else "Balanced" if A==C else "Right")
``` | output | 1 | 21,871 | 5 | 43,743 |
Provide a correct Python 3 solution for this coding contest problem.
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R.
Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan.
Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
Constraints
* 1\leq A,B,C,D \leq 10
* All input values are integers.
Input
Input is given from Standard Input in the following format:
A B C D
Output
Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
Examples
Input
3 8 7 1
Output
Left
Input
3 4 5 2
Output
Balanced
Input
1 7 6 4
Output
Right | instruction | 0 | 21,872 | 5 | 43,744 |
"Correct Solution:
```
a,b,c,d=map(int,input().split())
if a+b>c+d:print('Left')
elif a+b<c+d:print('Right')
else:print('Balanced')
``` | output | 1 | 21,872 | 5 | 43,745 |
Provide a correct Python 3 solution for this coding contest problem.
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R.
Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan.
Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
Constraints
* 1\leq A,B,C,D \leq 10
* All input values are integers.
Input
Input is given from Standard Input in the following format:
A B C D
Output
Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
Examples
Input
3 8 7 1
Output
Left
Input
3 4 5 2
Output
Balanced
Input
1 7 6 4
Output
Right | instruction | 0 | 21,873 | 5 | 43,746 |
"Correct Solution:
```
a,b,c,d=map(int,input().split())
A=a+b
B=c+d
print("Left" if A>B else "Right" if A<B else "Balanced")
``` | output | 1 | 21,873 | 5 | 43,747 |
Provide a correct Python 3 solution for this coding contest problem.
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R.
Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan.
Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
Constraints
* 1\leq A,B,C,D \leq 10
* All input values are integers.
Input
Input is given from Standard Input in the following format:
A B C D
Output
Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
Examples
Input
3 8 7 1
Output
Left
Input
3 4 5 2
Output
Balanced
Input
1 7 6 4
Output
Right | instruction | 0 | 21,874 | 5 | 43,748 |
"Correct Solution:
```
A, B, C, D = map( int, input().split())
L = A + B
R = C
print(["Balanced","Left","Right"][((C+D)<(A + B)) - ((C+D)>(A + B))])
``` | output | 1 | 21,874 | 5 | 43,749 |
Provide a correct Python 3 solution for this coding contest problem.
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R.
Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan.
Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
Constraints
* 1\leq A,B,C,D \leq 10
* All input values are integers.
Input
Input is given from Standard Input in the following format:
A B C D
Output
Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
Examples
Input
3 8 7 1
Output
Left
Input
3 4 5 2
Output
Balanced
Input
1 7 6 4
Output
Right | instruction | 0 | 21,875 | 5 | 43,750 |
"Correct Solution:
```
a,b,c,d=map(int,input().split())
if a+b>c+d:
ans="Left"
elif a+b<c+d:
ans="Right"
else:
ans="Balanced"
print(ans)
``` | output | 1 | 21,875 | 5 | 43,751 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a set $T$, which is a subset of $U$. The set $U$ consists of $0, 1, ... n-1$. Print all sets, each of which is a subset of $U$ and includes $T$ as a subset. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a subset is calculated by bitwise OR of existing elements.
Constraints
* $1 \leq n \leq 18$
* $0 \leq k \leq n$
* $0 \leq b_i < n$
Input
The input is given in the following format.
$n$
$k \; b_0 \; b_1 \; ... \; b_{k-1}$
$k$ is the number of elements in $T$, and $b_i$ represents elements in $T$.
Output
Print the subsets ordered by their decimal integers. Print a subset in the following format.
$d$: $e_0$ $e_1$ ...
Print ':' after the integer value $d$, then print elements $e_i$ in the subset in ascending order. Separate two adjacency elements by a space character.
Example
Input
4
2 0 2
Output
5: 0 2
7: 0 1 2
13: 0 2 3
15: 0 1 2 3 | instruction | 0 | 21,991 | 5 | 43,982 |
"Correct Solution:
```
n = int(input())
k, *b = map(int, input().split())
t = sum(1<<i for i in b)
for i in range(1 << n):
if i & t != t:
continue
rs = [str(i) + ":"]
for j in range(n):
if i & (1 << j) != 0:
rs.append(j)
print(*rs)
``` | output | 1 | 21,991 | 5 | 43,983 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a set $T$, which is a subset of $U$. The set $U$ consists of $0, 1, ... n-1$. Print all sets, each of which is a subset of $U$ and includes $T$ as a subset. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a subset is calculated by bitwise OR of existing elements.
Constraints
* $1 \leq n \leq 18$
* $0 \leq k \leq n$
* $0 \leq b_i < n$
Input
The input is given in the following format.
$n$
$k \; b_0 \; b_1 \; ... \; b_{k-1}$
$k$ is the number of elements in $T$, and $b_i$ represents elements in $T$.
Output
Print the subsets ordered by their decimal integers. Print a subset in the following format.
$d$: $e_0$ $e_1$ ...
Print ':' after the integer value $d$, then print elements $e_i$ in the subset in ascending order. Separate two adjacency elements by a space character.
Example
Input
4
2 0 2
Output
5: 0 2
7: 0 1 2
13: 0 2 3
15: 0 1 2 3 | instruction | 0 | 21,992 | 5 | 43,984 |
"Correct Solution:
```
#!/usr/bin/env python3
# Bitset 2 - Enumeration of Subsets 2
def subset(n, mask):
for i in range(2**n):
if i & mask == mask:
yield i, [v for v in range(n) if i & (1 << v) > 0]
def run():
n = int(input())
mask = 0 & 2**n
for i in input().split()[1:]:
mask |= 1 << int(i)
for i, vs in subset(n, mask):
print("{}:{}".format(i, "".join([" {}".format(v) for v in vs])))
if __name__ == '__main__':
run()
``` | output | 1 | 21,992 | 5 | 43,985 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a set $T$, which is a subset of $U$. The set $U$ consists of $0, 1, ... n-1$. Print all sets, each of which is a subset of $U$ and includes $T$ as a subset. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a subset is calculated by bitwise OR of existing elements.
Constraints
* $1 \leq n \leq 18$
* $0 \leq k \leq n$
* $0 \leq b_i < n$
Input
The input is given in the following format.
$n$
$k \; b_0 \; b_1 \; ... \; b_{k-1}$
$k$ is the number of elements in $T$, and $b_i$ represents elements in $T$.
Output
Print the subsets ordered by their decimal integers. Print a subset in the following format.
$d$: $e_0$ $e_1$ ...
Print ':' after the integer value $d$, then print elements $e_i$ in the subset in ascending order. Separate two adjacency elements by a space character.
Example
Input
4
2 0 2
Output
5: 0 2
7: 0 1 2
13: 0 2 3
15: 0 1 2 3 | instruction | 0 | 21,993 | 5 | 43,986 |
"Correct Solution:
```
n = int(input())
k, *l = [int(x) for x in input().split()]
m = 0
for i in l:
m |= 1<<i
for i in range( 2**n ):
if i & m != m:
continue
if i == 0:
print("{}:".format(i))
continue
else:
print("{}: ".format(i), end="")
l = []
for j in range(n):
if i & (1<<j) != 0:
l.append(j)
print(*l)
``` | output | 1 | 21,993 | 5 | 43,987 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a set $T$, which is a subset of $U$. The set $U$ consists of $0, 1, ... n-1$. Print all sets, each of which is a subset of $U$ and includes $T$ as a subset. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a subset is calculated by bitwise OR of existing elements.
Constraints
* $1 \leq n \leq 18$
* $0 \leq k \leq n$
* $0 \leq b_i < n$
Input
The input is given in the following format.
$n$
$k \; b_0 \; b_1 \; ... \; b_{k-1}$
$k$ is the number of elements in $T$, and $b_i$ represents elements in $T$.
Output
Print the subsets ordered by their decimal integers. Print a subset in the following format.
$d$: $e_0$ $e_1$ ...
Print ':' after the integer value $d$, then print elements $e_i$ in the subset in ascending order. Separate two adjacency elements by a space character.
Example
Input
4
2 0 2
Output
5: 0 2
7: 0 1 2
13: 0 2 3
15: 0 1 2 3 | instruction | 0 | 21,994 | 5 | 43,988 |
"Correct Solution:
```
n = int(input())
_, *B = map(int, input().split())
B = set(B)
for x in range(2**n):
if all([x&1<<s for s in B]):
if x == 0:
print('0:')
else:
bits = [i for i, b in enumerate(f'{x:b}'[::-1]) if b == '1']
print(f'{x}: {" ".join(map(str, bits))}')
``` | output | 1 | 21,994 | 5 | 43,989 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a set $T$, which is a subset of $U$. The set $U$ consists of $0, 1, ... n-1$. Print all sets, each of which is a subset of $U$ and includes $T$ as a subset. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a subset is calculated by bitwise OR of existing elements.
Constraints
* $1 \leq n \leq 18$
* $0 \leq k \leq n$
* $0 \leq b_i < n$
Input
The input is given in the following format.
$n$
$k \; b_0 \; b_1 \; ... \; b_{k-1}$
$k$ is the number of elements in $T$, and $b_i$ represents elements in $T$.
Output
Print the subsets ordered by their decimal integers. Print a subset in the following format.
$d$: $e_0$ $e_1$ ...
Print ':' after the integer value $d$, then print elements $e_i$ in the subset in ascending order. Separate two adjacency elements by a space character.
Example
Input
4
2 0 2
Output
5: 0 2
7: 0 1 2
13: 0 2 3
15: 0 1 2 3 | instruction | 0 | 21,995 | 5 | 43,990 |
"Correct Solution:
```
n = int(input())
k, *list_b = map(int, input().split())
t = 0
for i in list_b:
t += 2 ** i
for d in range(2 ** n):
# all(m)
if (d & t) != t:
continue
d_bin = "{:b}".format(d)
list_e = []
for cnt, bit in enumerate(reversed(d_bin)):
if bit == "1":
list_e.append(cnt)
if list_e:
print(f"{d}: ", end="")
print(*list_e)
else:
print(f"{d}:")
``` | output | 1 | 21,995 | 5 | 43,991 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a set $T$, which is a subset of $U$. The set $U$ consists of $0, 1, ... n-1$. Print all sets, each of which is a subset of $U$ and includes $T$ as a subset. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a subset is calculated by bitwise OR of existing elements.
Constraints
* $1 \leq n \leq 18$
* $0 \leq k \leq n$
* $0 \leq b_i < n$
Input
The input is given in the following format.
$n$
$k \; b_0 \; b_1 \; ... \; b_{k-1}$
$k$ is the number of elements in $T$, and $b_i$ represents elements in $T$.
Output
Print the subsets ordered by their decimal integers. Print a subset in the following format.
$d$: $e_0$ $e_1$ ...
Print ':' after the integer value $d$, then print elements $e_i$ in the subset in ascending order. Separate two adjacency elements by a space character.
Example
Input
4
2 0 2
Output
5: 0 2
7: 0 1 2
13: 0 2 3
15: 0 1 2 3 | instruction | 0 | 21,996 | 5 | 43,992 |
"Correct Solution:
```
n = int(input())
nn = pow(2, n)
k = list(map(int, input().split()))
mask = k[1:k[0]+1]
if k[0] == 0:
for i in range(nn):
if i == 0:
print("0:")
else:
bin_str = "0" + str(n) + "b"
bin_i = format(i, bin_str)
ilist = list(bin_i)
tmplist = []
for j, bini in enumerate(ilist):
if bini == '1':
tmplist.append(n - j - 1)
tmplist.sort()
tmp_str = ' '.join(str(tmp) for tmp in tmplist)
print(str(i) + ": " + tmp_str)
else:
for i in range(nn):
if i == 0:
continue
bin_str = "0" + str(n) + "b"
bin_i = format(i, bin_str)
ilist = list(bin_i)
tmplist = []
for j, bini in enumerate(ilist):
if bini == '1':
tmplist.append(n - j - 1)
if len(set(mask) & set(tmplist)) == k[0]:
tmplist.sort()
tmp_str = ' '.join(str(tmp) for tmp in tmplist)
print(str(i) + ": " + tmp_str)
``` | output | 1 | 21,996 | 5 | 43,993 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.