description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
m = 1000000007 for t in range(int(input())): n = int(input()) B = list(map(int, input().split())) if B != sorted(B): print(0) else: freq = [(B[i] & B[i + 1]) for i in range(n - 1)] p = 0 for b in freq: b = bin(b) p += b.count("1") print(pow(2, p, m))
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) ans = 1 d = 0 for i in range(n - 1): if l[i] & l[i + 1] != l[i]: print(0) d = 1 break if d == 1: continue c = 0 for i in l: c += bin(i)[2:].count("1") c -= bin(i)[2:].count("1") print(2**c % 1000000007)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
import sys sys.setrecursionlimit(10**3) def fast_expo(n): mod = 10**9 + 7 if n == 1: return 2 x = fast_expo(n // 2) % mod if n % 2 == 0: return x * x % (10**9 + 7) else: return x * x * 2 % (10**9 + 7) for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) p = 0 c = 0 flag = 0 mod = 10**9 + 7 for i in range(len(l) - 1): t_1 = list(bin(l[i])[2:]).count("1") if c <= t_1: c = t_1 else: flag = 1 p += t_1 if flag == 1: print(0) continue t_2 = fast_expo(p) % mod print(t_2)
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER STRING IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
t = int(input()) mod = pow(10, 9) + 7 while t > 0: t -= 1 n = int(input()) b = [int(x) for x in input().split()] bprev = b[0] ans = 1 for i in range(1, n): if bin(~b[i] & b[i - 1]).count("1"): ans = 0 break ans += bin(b[i] & b[i - 1]).count("1") if ans == 0: print(ans) else: ans -= 1 print(2**ans % 1000000007)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
import sys f = sys.stdin readline = lambda: map(int, f.readline().rstrip().split(" ")) (T,) = readline() for i in range(T): (N,) = readline() B = list(readline()) ans = 0 impossible = False for i in range(len(B) - 1): ans += bin(B[i] & B[i + 1]).count("1") if bin(B[i] & ~B[i + 1]).count("1") > 0: impossible = True ans = 2**ans % 1000000007 print(0 if impossible else ans)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING IF FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
T = int(input()) mod = 10**9 + 7 for z in range(T): N = int(input()) arr = [int(x) for x in input().split()] count = 1 flag = False for i in range(1, N): if arr[i] | arr[i - 1] > arr[i]: flag = True break count_1 = bin(arr[i - 1]).count("1") count = count * 2**count_1 % mod if flag == True: print(0) else: print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
m = pow(10, 9) + 7 for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) t = 1 for i in range(n - 1): if l[i] <= l[i + 1] and l[i] & l[i + 1] == l[i]: y = bin(l[i]).count("1") t = t * pow(2, y, m) % m else: t = 0 break print(t % m)
ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
def solve(n, b): for i in range(n - 1): if b[i] & b[i + 1] != b[i]: print(0) return x = 0 for i in range(n - 1): x += bin(b[i]).count("1") print(pow(2, x, mod)) mod = 10**9 + 7 for _ in range(int(input())): n = int(input()) b = list(map(int, input().split())) solve(n, b)
FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
const = 10**9 + 7 T = int(input()) for _ in range(T): N = int(input()) ans = 1 Bi = list(map(int, input().split())) for i in range(N - 1): if str(bin(Bi[i])).count("1") - str(bin(Bi[i + 1])).count("1") > 0: ans = 0 break ans = ans % const * pow(2, str(bin(Bi[i])).count("1")) % const % const print(ans)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING VAR VAR EXPR FUNC_CALL VAR VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
m = 10**9 m += 7 def calc(i): a = 0 while i > 0: q = i % 2 a += q i = i // 2 return a for tst in range(int(input())): n = int(input()) a = [int(x) for x in input().split()] ans = 1 for k in range(n - 1): if a[k] & a[k + 1] == a[k]: kk = calc(a[k]) ans = ans * 2**kk % m else: ans = 0 break print(ans)
ASSIGN VAR BIN_OP NUMBER NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
mod = 10**9 + 7 def pow2(x): p, n = 1, 2 while x: if x & 1: p = p % mod * (n % mod) % mod n = n % mod * (n % mod) % mod x //= 2 return p def count_bit(val): bit = 0 for i in range(30): if val >> i & 1: bit += 1 return bit def answer(): val = b[0] po2 = 0 for i in range(1, len(b)): if val > b[i]: return 0 po2 += count_bit(val & b[i]) val = b[i] return pow2(po2) % mod for T in range(int(input())): n = int(input()) b = list(map(int, input().split())) print(answer())
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER WHILE VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR RETURN NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
M = 1000000007 T = int(input()) for _ in range(T): n = int(input()) l = [int(i) for i in input().split()] count1 = 0 for i in range(1, n): if l[i - 1] & l[i] != l[i - 1]: count1 = 0 break else: count1 += bin(l[i - 1] & l[i]).count("1") if count1 == 0: print(count1) else: print(2**count1 % M)
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
def countSetBits(n): total = 0 while n: total += n & 1 n = n >> 1 return total def totalWays(bArr, n): valid = True for i in range(1, len(bArr)): if bArr[i] & bArr[i - 1] != bArr[i - 1]: valid = False if not valid: return 0 mod = int(1000000000.0 + 7) total_ways = 1 for i in range(1, len(bArr)): setbits = countSetBits(bArr[i - 1]) total_ways *= pow(2, setbits, mod) total_ways %= mod return total_ways % mod def main(): t = int(input()) while t: n = int(input()) bArr = [int(x) for x in input().split()] print(totalWays(bArr, n)) t -= 1 main()
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
import sys readline = lambda: map(int, sys.stdin.readline().split(" ")) (T,) = readline() for _ in range(T): (N,) = readline() B = list(readline()) A0 = B[0] B1 = None setbits = 0 no = False for j in range(1, N): B1 = B[j] if A0 & ~B1 > 0: print(0) no = True break else: setbits += bin(A0 & B1).count("1") A0 = B[j] if no: pass else: print((1 << setbits) % 1000000007)
IMPORT ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR VAR IF VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
def get_num_of_ones(x): c = 0 while x: x &= x - 1 c += 1 return c mod = 10**9 + 7 twopow = {x: (pow(2, x) % mod) for x in range(35)} for _ in range(int(input())): n = int(input()) b = list(map(int, input().split())) ones_in_prev = 0 ones_in_current = 0 ans = 1 flag = True ones_in_current = get_num_of_ones(b[0]) ones_in_prev = ones_in_current for i in range(1, n): ans *= twopow[ones_in_prev] ans %= mod ones_in_current = get_num_of_ones(b[i]) ones_in_prev = ones_in_current if b[i] < b[i - 1]: flag = False break if flag: print(ans % mod) else: print(0)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR NUMBER VAR VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
t = int(input()) for i in range(t): n = int(input()) a = list([int(j) for j in input().split()]) count = 1 res = 1 if n > 1: for j in range(n - 1): if a[j + 1] | a[j] > a[j + 1]: res = 0 break x = str(bin(a[j + 1])[2:]).count("1") y = str(bin(a[j + 1] - a[j])[2:]).count("1") count *= pow(2, x - y, 1000000007) count %= 1000000007 if res == 0: print(0 % 1000000007) else: print(count % 1000000007)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER STRING VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
def cb(n): c = 0 while n: if n & 1: c += 1 n >>= 1 return c for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) ans = 1 d = 0 for i in range(n - 1): if l[i] & l[i + 1] != l[i]: print(0) d = 1 break if d == 1: continue c = 0 for i in l: c += cb(i) c -= cb(l[n - 1]) print(2**c % 1000000007)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
def main(): N, X = map(int, input().split()) L = 2**N - 1 if X <= L: P = [0] checked = [False] * (L + 1) checked[0] = True for n in range(1, L + 1): inv = n ^ X if not checked[inv]: P.append(n) checked[n] = True checked[inv] = True else: P = [0] for n in range(1, L + 1): P.append(n) ans = [] for i in range(len(P) - 1): ans.append(P[i + 1] ^ P[i]) if not ans: print(0) else: print(len(ans)) print(" ".join([str(a) for a in ans])) main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
import sys input = sys.stdin.readline n, x = map(int, input().split()) b = [0] for i in range(1, 2**n): if i ^ x > i: b.append(i) a = [(b[i] ^ b[i - 1]) for i in range(1, len(b))] print(len(a)) print(*a)
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
n, x = map(int, input().split()) if x >= 2**n: print(2**n - 1) print(*([1] + [(i ^ i + 1) for i in range(1, 2**n - 1)])) else: print(2 ** (n - 1) - 1) if n == 1: exit() a = [] bad = [0] * 2**n bad[0], bad[x] = 1, 1 for i in range(2**n): if bad[i] == 0: a.append(i) bad[i] = 1 bad[i ^ x] = 1 print(*([a[0]] + [(a[i] ^ a[i + 1]) for i in range(len(a) - 1)]))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
N, X = map(int, input().split()) ex = [False] * 2**18 ex[0] = True ans = [0] for i in range(1, 2**N): if ex[i ^ X]: continue else: ans.append(i) ex[i] = True print(len(ans) - 1) for i in range(1, len(ans)): print(ans[i] ^ ans[i - 1], end=" ")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
n, x = map(int, input().split()) if x >= 2**n: prefix_array = [] for i in range(1, 2**n): prefix_array.append(i) else: prefix_array = [] compl = {} for i in range(1, 2**n): if i == x: continue try: if compl[i]: pass except: prefix_array.append(i) compl[i ^ x] = True if prefix_array == []: print(0) else: res = [prefix_array[0]] for i in range(len(prefix_array) - 1): res.append(prefix_array[i] ^ prefix_array[i + 1]) print(len(res)) for i in res: print(i, end=" ") print()
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR LIST EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
def main(): buf = input() buflist = buf.split() n = int(buflist[0]) x = int(buflist[1]) npow2 = int(2**n) if n == 1: if x == 1: print(0) else: print(1) print(1) return mask = x if x >= npow2: mask = 0 available = set() for i in range(1, npow2): if i != x: available.add(i) a = [] while available: new_elem = available.pop() new_elem = new_elem ^ mask a.append(new_elem) if x < npow2: elem_to_remove = new_elem ^ x available.remove(elem_to_remove ^ mask) mask = mask ^ new_elem print(len(a)) print(" ".join(list(map(str, a)))) def __starting_point(): main() __starting_point()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST WHILE VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
n, x = list(map(int, input().split())) a = [] d = {(0): True} d1 = [0] if x < 1 << n: for t in range(1, 1 << n): if not d.get(t ^ x, False): a.append(t ^ d1[-1]) d[t] = True d1.append(t) print(len(a)) print(" ".join(map(str, a))) else: for t in range(1, 1 << n): a.append(t ^ t - 1) print(len(a)) print(" ".join(map(str, a)))
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR LIST NUMBER IF VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
n, x = [int(x) for x in input().split(" ")] b = [] if x >= 2**n: b = list(range(0, 2**n, 1)) else: forb = {} for i in range(2**n): if i not in forb: b.append(i) forb[i ^ x] = 1 a = [(b[i] ^ b[i - 1]) for i in range(1, len(b))] print(len(a)) print(" ".join([str(x) for x in a]))
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST IF VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
n, x = list(map(int, input().split())) mark = [(0) for x in range(1 << 18 + 1)] mark[x] = 1 cur = 0 MAXN = 1 << n ans = [] for i in range(1, MAXN): if i != x: res = i ^ x if mark[i] == 0: ans.append(i ^ cur) mark[res] = 1 mark[i] = 1 cur = i print(len(ans)) print(*ans)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
n, x = list(map(int, input().split())) n = 1 << n ans = (n >> (x < n)) - 1 print(ans) q, t = 0, 0 a = [0] * n for i in range(1, n): if i < i ^ x: a[t] = i ^ q q, t = i, t + 1 print(*a[:t])
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
n, x = map(int, input().split()) flag = [True] * (1 << n) flag[0] = False if x <= (1 << n) - 1: flag[x] = False for S in range(1 << n): if not flag[S]: continue flag[S ^ x] = False xor = [0] for S in range(1 << n): if flag[S]: xor.append(S) ans = [] for i in range(len(xor) - 1): ans.append(xor[i] ^ xor[i + 1]) print(len(ans)) print(*ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
n, x = map(int, input().split()) d = {} for i in range(2**n): if not d.get(i, False): d[i ^ x] = 1 k = 0 print(len(d) - 1) for i in range(1, 2**n): if i not in d: print(i ^ k, end=" ") k = i
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
v = [0] n, x = map(int, input().split()) e = [0] * (1 << 18) e[0] = 1 for i in range(1, 1 << n): if e[x ^ i] == 1: continue e[i] = 1 v.append(i) print(len(v) - 1) print(*[(v[i] ^ v[i - 1]) for i in range(1, len(v))])
ASSIGN VAR LIST NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
n, x = map(int, input().split()) if x >= 2**n: print(2**n - 1) print(*[(t ^ t + 1) for t in range(2**n - 1)]) else: used = [False] * 2**n r = [0] used[0] = True used[x] = True for i in range(1, 2**n): if not used[i]: used[i] = used[i ^ x] = True r.append(i) print(len(r) - 1) for i in range(len(r) - 1): print(r[i] ^ r[i + 1], end=" ")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
n, x = map(int, input().split()) ans = [] total = 1 << n vis = [0] * (1 << 18) for i in range(total): if vis[i] == 0: ans.append(i) vis[i] = 1 vis[i ^ x] = 1 print(len(ans) - 1) for i in range(1, len(ans)): print(ans[i] ^ ans[i - 1], end=" ")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
import sys input = sys.stdin.readline n, x = list(map(int, input().split())) if n == x == 1: print(0) return ANS = [] for i in range(n): if i + 1 == x.bit_length(): continue ANS = ANS + [1 << i] + ANS print(len(ANS)) print(*ANS)
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR LIST BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
n, x = map(int, input().split()) t = 2**n ans = [0] if x >= t: ans = [*range(t)] else: c = set([0]) for i in range(1, t): if i ^ x in c: continue ans.append(i) c.add(i) print(len(ans) - 1) print(*[(ans[i] ^ ans[i - 1]) for i in range(1, len(ans))])
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR LIST NUMBER IF VAR VAR ASSIGN VAR LIST FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
from sys import stdin input = stdin.readline n, x = map(int, input().split()) x = 1 << len(bin(x)) - 3 a = [i for i in range(1, 1 << n) if i >> len(bin(x)) - 3 & 1 == 0] + [0] b = [(a[i] ^ a[i - 1]) for i in range(len(a) - 1)] print(len(b), *b)
ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER LIST NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
n, x = map(int, input().split()) def creat(n, x): if x > 2**n: arr = [i for i in range(1, 2**n)] return arr used = {i: (False) for i in range(1, 2**n)} arr = [] for i in range(1, 2**n): if i == x: continue if used[i] == True: continue used[i] = True used[i ^ x] = True arr.append(i) return arr a = creat(n, x) if len(a) == 0: print(0) else: a_ = [a[0]] a_.extend([(u ^ v) for u, v in zip(a[1:], a[:-1])]) print(len(a_)) print(" ".join([str(i) for i in a_]))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR RETURN VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR IF VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
from sys import stdout n, x = list(map(int, input().split())) t = pow(2, n) if x >= t: print(t - 1) for i in range(1, t): stdout.write(str(i ^ i - 1) + " ") exit(0) ans = [0] * pow(2, n) ans[x] = -1 for i in range(1, len(ans)): if ans[i] != -1: ans[x ^ i] = -1 last = 0 print(pow(2, n - 1) - 1) for i in range(1, len(ans)): if ans[i] == 0: stdout.write(str(i ^ last) + " ") last = i
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
n, x = list(map(int, input().split())) a = [] lst = 0 for i in range(1, 1 << n): if i ^ x > i: a.append(i ^ lst) lst = i print(len(a)) print(" ".join(str(i) for i in a))
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
n, x = map(int, input().split()) mark = [(0) for x in range(1 << 18 + 1)] mark[x] = 1 curent = 0 maxA = 1 << n ans = [] for i in range(1, maxA): if i != x: result = i ^ x if mark[i] == 0: ans.append(i ^ curent) mark[result] = 1 mark[i] = 1 curent = i elif mark[result] == 0 and result < maxA: ans.append(curent ^ result) mark[result] = 1 curent = result print(len(ans)) print(*ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
n, x = map(int, input().split()) d = {} N = 2**n d[0] = 1 b = [0] for i in range(1, N): if i ^ x in d: continue else: d[i] = 1 b.append(i) ans = [] for i in range(1, len(b)): ans.append(b[i] ^ b[i - 1]) print(len(ans)) print(*ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
n, x = map(int, input().split()) res = [] s = {x} prev = 0 for i in range(1, 1 << n): curr = prev ^ i if curr in s: continue res.append(curr) prev = i s.add(x ^ i) print(len(res)) print(*res)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
n, x = map(int, input().split()) d = [] for i in range(2**n): if i < i ^ x: d.append(i) print(len(d) - 1) for i in range(1, len(d)): print(d[i] ^ d[i - 1], end=" ")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
def main(): n, x = list(map(int, input().split())) f = [] n = 1 << n cx = [(0) for _ in range(n + 299)] for i in range(n): if Find_x(int(x ^ i), f) == False: f.append(i) print(len(f) - 1) for i in range(len(f) - 1): print(f[i] ^ f[i + 1], end=" ") def Find_x(x, a): l = 0 r = len(a) - 1 while l <= r: m = int((l + r) / 2) if a[m] == x: return True if a[m] > x: r = m - 1 else: l = m + 1 return False def __starting_point(): main() __starting_point()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
n, x = map(int, input().split()) markings = [(0) for i in range(2**n - 1)] for i in range(1, 2**n): if markings[i - 1] == 0 and x ^ i < 2**n and i != x: markings[(x ^ i) - 1] = 1 if x < 2**n: markings[x - 1] = 1 arr = [] for i in range(2**n - 1): if markings[i] == 0: arr.append(i + 1) print(len(arr)) if len(arr) > 0: print(arr[0], end=" ") for i in range(1, len(arr)): print(arr[i] ^ arr[i - 1], end=" ") print("")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR IF VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
N, X = map(int, input().split()) if X == 0 or X >= 2**N: A = [a for a in range(N)] else: for i in range(N): if 1 << i & X: A = [a for a in range(N) if a != i] break def calc(B): if B: b = B[-1] t = calc(B[:-1]) return t + [1 << b] + t return [] ca = calc(A) print(len(ca)) if len(ca): print(*ca)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR LIST BIN_OP NUMBER VAR VAR RETURN LIST ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
def gns(): return [int(x) for x in input().split()] n, x = gns() if n == 1: if x == 1: print(0) quit() print(1) print(1) quit() b = len(bin(x)) - 2 if x != 1: ans = [1] else: ans = [2] cur = 1 for i in range(n - 2): if cur == b - 1: cur += 1 ans = ans + [1 << cur] + ans cur += 1 if x >= 1 << n: ans = ans + [1 << cur] + ans y = x print(len(ans)) print(" ".join(map(str, ans)))
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR LIST BIN_OP NUMBER VAR VAR VAR NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR LIST BIN_OP NUMBER VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
n, x = map(int, input().split()) vis = set([0]) res = [] cur = 0 for c in range(1, 1 << n): v = c ^ x if c in vis or v in vis: continue vis.add(c) res.append(c ^ cur) cur = c print(len(res)) if res: print(" ".join(map(str, res)))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
d = dict() def solve(n): if n == 0: return [] if n == 1: d[1] = [1] return d[1] if n in d: return d[n] else: d[n] = solve(n - 1) + [2**n - 1] + solve(n - 1) return d[n] def solve2(n, x): if 2 ** (n - 1) <= x: return solve(n - 1) else: L = solve2(n - 1, x) return L + [2 ** (n - 1)] + L solve(18) n, x = map(int, input().split()) if x >= 2**n: L = solve(n) print(len(L)) for i in L: print(i, end=" ") else: L = solve2(n, x) print(len(L)) for i in L: print(i, end=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN LIST IF VAR NUMBER ASSIGN VAR NUMBER LIST NUMBER RETURN VAR NUMBER IF VAR VAR RETURN VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER LIST BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER RETURN VAR VAR FUNC_DEF IF BIN_OP NUMBER BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP VAR LIST BIN_OP NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
n, x = list(map(int, input().split())) k, b = 1 << n, [] if x >= k: print(k - 1) b = list(range(1, k)) else: print(k - 2 >> 1) _b, b = set(range(1, k)), set() for bi in _b: b.add(bi) if x ^ bi in b: b.remove(x ^ bi) if x in b: b.remove(x) if b: b = list(b) a = [b[0]] + [(b[i] ^ b[i + 1]) for i in range(len(b) - 1)] print(*a)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP NUMBER VAR LIST IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
n, x = map(int, input().split()) nn = 2**n if x >= nn: x = 0 ans = [] for i in range(n): oks = [True] * nn oks[x] = False cur = 0 for j in ans[::-1]: cur ^= j oks[cur] = False oks[cur ^ x] = False try: a = next(j for j, ok in enumerate(oks[1:], 1) if ok) except StopIteration: break ans = [*ans, a, *ans] print(len(ans)) if ans: print(" ".join(map(str, ans)))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR ASSIGN VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
l = input().split() n = int(l[0]) x = int(l[1]) hashi = dict() for i in range(1, 2**n): hashi[i] = 1 pref = [0] for i in range(1, 2**n): if i in hashi and i != x: pref.append(i) curr = x ^ i if curr in hashi: del hashi[curr] if pref == [0]: print(0) else: fina = [] for i in range(1, len(pref)): fina.append(pref[i] ^ pref[i - 1]) print(len(fina)) for i in fina: print(i, end=" ") print()
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR IF VAR LIST NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
n, x = [int(x) for x in input().split()] ans = [] vis = [0] * (2**18 + 1) lmt = 2**n xor = 0 vis[0], vis[x] = 1, 1 for i in range(1, lmt): if vis[i]: continue ans.append(xor ^ i) xor = i vis[i] = 1 vis[i ^ x] = 1 print(len(ans)) print(*ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
n, x = map(int, input().split()) r = [] d = set() for a in range(1, 2**n): tmp = x ^ a if tmp not in d and a not in d and a not in (0, x): r.append(a) d.add(a) if not r: print(0) else: res = [r[0]] for i in range(1, len(r)): res.append(r[i - 1] ^ r[i]) print(len(res)) print(" ".join(map(str, res)))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. -----Input----- The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$). -----Output----- The first line should contain the length of the array $l$. If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$)Β β€” the elements of the array $a$. If there are multiple solutions, print any of them. -----Examples----- Input 3 5 Output 3 6 1 3 Input 2 4 Output 3 1 3 1 Input 1 1 Output 0 -----Note----- In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.
n, x = map(int, input().split()) a = [(True) for i in range(pow(2, n))] check = [] if x < pow(2, n): a[x] = False for i in range(1, pow(2, n)): if a[i] == True: check.append(i) if x ^ i < pow(2, n): a[x ^ i] = False print(len(check)) if len(check) == 1: print(check[0]) elif len(check) > 1: print(check[0], end=" ") for i in range(1, len(check)): print(check[i - 1] ^ check[i], end=" ")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST IF VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR STRING
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
I = input k, s, t = int(I()), I(), I() answer = [""] * k res = ord(s[-1]) + ord(t[-1]) - 194 for j in range(k - 2, -1, -1): res += 26 * (ord(s[j]) + ord(t[j]) - 194) answer[j + 1] = chr(res // 2 % 26 + 97) res //= 26 answer[0] = chr(res // 2 % 26 + 97) print("".join(answer))
ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
n = int(input()) s = input() t = input() suma = [(ord(s[i]) + ord(t[i]) - 194) for i in range(n)] for i in range(n - 1): j = n - 1 - i if suma[j] > 25: suma[j] -= 26 suma[j - 1] += 1 chuj = 0 if suma[0] == 26: chuj = 1 suma[0] = 0 print(chr(110), end="") for i in range(chuj == 1, n): print(chr(suma[i] // 2 + 97), end="") if suma[i] % 2 != 0 and i < n - 1: suma[i + 1] += 26
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER STRING IF BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
def add(a, b): c = [] z = 0 for i in range(k - 1, -1, -1): x = ord(a[i]) - ord("a") y = ord(b[i]) - ord("a") if x + y + z >= 26: c.append(x + y + z - 26) z = 1 else: c.append(x + y + z) z = 0 if z: c.append(z) return c[::-1] def div2(a): c = [] z = 0 for x in a: x += 26 * z c.append(chr(ord("a") + x // 2)) z = x % 2 return c k = int(input()) a = input() b = input() d = div2(add(a, b)) if len(d) > k: d = d[len(d) - k :] print("".join(d))
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR RETURN VAR NUMBER FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
n = int(input()) s = input() t = input() dic = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ] slis = [] tlis = [] for i in s: slis.append(dic.index(i)) for i in t: tlis.append(dic.index(i)) sumlis = [] cout = 0 for j in range(n - 1, -1, -1): res = slis[j] + tlis[j] + cout if j != 0: if res >= 26: res = res % 26 cout = 1 else: cout = 0 sumlis.append(res) total = sumlis[::-1] for i in range(n): if total[i] % 2 == 1: total[i] //= 2 total[i + 1] += 26 else: total[i] //= 2 result = [] for i in total: result.append(dic[i]) print("".join(result))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
k = int(input()) ALPHABET = "abcdefghijklmnopqrstuvwxyz" SIZE = len(ALPHABET) ALPHABET_TO_NUMBER = dict(zip(ALPHABET, range(len(ALPHABET)))) big_sum = [ (ALPHABET_TO_NUMBER[l] + ALPHABET_TO_NUMBER[u]) for l, u in zip(input(), input()) ] additional = 0 for index in range(k - 1, 0, -1): big_sum[index] += additional additional = big_sum[index] // SIZE if big_sum[index] >= SIZE: big_sum[index] %= SIZE big_sum[0] += additional for index in range(k): if big_sum[index] % 2 == 1: big_sum[index + 1] += 26 big_sum[index] //= 2 print("".join([ALPHABET[number] for number in big_sum]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
import sys class Main: def __init__(self): self.buff = None self.index = 0 def next(self): if self.buff is None or self.index == len(self.buff): self.buff = sys.stdin.readline().split() self.index = 0 val = self.buff[self.index] self.index += 1 return val def next_int(self): return int(self.next()) def solve(self): n = self.next_int() a = [(ord(x) - ord("a")) for x in self.next()] b = [(ord(x) - ord("a")) for x in self.next()] c = [(a[i] + b[i]) for i in range(0, n)] for i in range(n - 1, 0, -1): c[i - 1] += c[i] // 26 c[i] %= 26 for i in range(0, n): if c[i] % 2 == 1 and i < n - 1: c[i + 1] += 26 c[i] //= 2 print("".join(map(lambda x: chr(x + ord("a")), c))) Main().solve()
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR NONE ASSIGN VAR NUMBER FUNC_DEF IF VAR NONE VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL FUNC_CALL VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
BASE = 26 def str2num(s): return [(ord(x) - ord("a")) for x in reversed(s)] def num2str(number): return "".join(chr(x + ord("a")) for x in number) def add(x, y): k = len(x) result = [0] * (k + 1) memory = 0 for i in range(k): memory, result[i] = divmod(x[i] + y[i] + memory, BASE) result[-1] = memory return result def div(x): k = len(x) result = [0] * k carry = 0 for i in range(k - 1, -1, -1): current = x[i] + carry * BASE result[i], carry = divmod(current, 2) return result[::-1][1:] def main(): _ = int(input()) x = str2num(input()) y = str2num(input()) print(num2str(div(add(x, y)))) main()
ASSIGN VAR NUMBER FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
n = int(input()) ss = input() s = ss[::-1] t = input()[::-1] tt = [0] * n for i in range(n): c = ord(s[i]) - ord("a") tt[i] = ord(t[i]) - ord("a") tt[i] -= c for i in range(n - 1): if tt[i] < 0: tt[i] += 26 tt[i + 1] -= 1 tt = tt[::-1] rem = 0 for i in range(n): rem = rem * 26 + tt[i] tt[i] = rem // 2 rem = rem % 2 res = [x for x in ss] for i in range(n - 1, -1, -1): c = tt[i] + ord(res[i]) - ord("a") tt[i] = c % 26 if i > 0: tt[i - 1] += c // 26 res[i] = chr(tt[i] + ord("a")) print("".join(res))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
f = lambda s: [(ord(c) - ord("a")) for c in s] n = int(input()) a = f(input()) b = f(input()) c = [0] for i in range(n - 1, -1, -1): c[-1] += a[i] + b[i] m = c[-1] // 26 c[-1] %= 26 c.append(m) c.reverse() for i in range(n + 1): if c[i] & 1: c[i + 1] += 26 c[i] >>= 1 print("".join(chr(ord("a") + c[i]) for i in range(1, n + 1)))
ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
def plus(a, b): c = "" i = len(a) - 1 arg = 0 while i >= 0: k = (arg + ord(a[i]) + ord(b[i])) % 26 if arg + ord(a[i]) + ord(b[i]) < 26: arg = 0 else: arg = 1 i -= 1 c = chr(k) + c if arg: c = chr(1) + c return c def minus(a): c = "" i = 0 arg = 0 while i < len(a): c += chr((arg * 26 + ord(a[i])) // 2) arg = ord(a[i]) % 2 i += 1 if arg: c = c[: len(c) - 1] + chr(ord(c[len(c) - 1]) + 1) return c n = int(input()) a = input() b = input() ai = 0 bi = 0 a1 = "" b1 = "" i = 0 while i < n: a1 += chr(ord(a[i]) - ord("a")) b1 += chr(ord(b[i]) - ord("a")) i += 1 c = plus(a1, b1) c = minus(c) i = 0 c1 = "" while i < len(c): c1 += chr(ord(c[i]) + ord("a")) i += 1 print(c1[len(c1) - n :])
FUNC_DEF ASSIGN VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
BASE = 26 def convertToNum(s): n = len(s) ret = [-1] * n for i in range(n - 1, -1, -1): ret[i] = ord(s[i]) - ord("a") return ret def substract(a, b): n = len(a) ret = [-1] * n for i in range(n - 1, -1, -1): if b[i] > a[i]: a[i] += BASE a[i - 1] -= 1 ret[i] = a[i] - b[i] return ret def add(a, b): n = len(a) ret = [0] * n for i in range(n - 1, -1, -1): ret[i] += a[i] + b[i] if ret[i] > BASE - 1: ret[i] %= BASE ret[i - 1] = 1 return ret def divBy2(num): for i in range(len(num)): if num[i] & 1 == 1: num[i + 1] += BASE num[i] >>= 1 return num def convertToStr(num): return "".join([chr(c + ord("a")) for c in num]) n = int(input()) start = input() end = input() a, b = convertToNum(start), convertToNum(end) print(convertToStr(add(a, divBy2(substract(b, a)))))
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
n = int(input()) a = list(input()) b = list(input()) num_a = [(ord(i) - 97) for i in a] num_b = [(ord(i) - 97) for i in b] num = [(0) for i in range(n)] carry = 0 for i in range(n - 1, -1, -1): if i == 0: num[i] = num_a[i] + num_b[i] + carry continue add = num_a[i] + num_b[i] + carry carry = add // 26 num[i] = add % 26 carry = 0 for i in range(n): num[i] += carry carry = num[i] % 2 * 26 num[i] //= 2 print(chr(num[i] + 97), end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER STRING
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
n = int(input()) s, t = input(), input() a = [(ord(i) - ord("a")) for i in s] b = [(ord(i) - ord("a")) for i in t] a, b, c = a[::-1], b[::-1], [0] * (n + 1) for i in range(n): c[i] = c[i] + a[i] + b[i] c[i + 1] = c[i] // 26 c[i] = c[i] % 26 c = c[::-1] if c[0] == 0: c = c[1:] ans = [] ost = 0 for digit in c: ost = ost * 26 + digit t = ost // 2 ans.append(t) ost = digit % 2 if ans[0] == 0 and len(ans) > n: ans = ans[1:] ans = "".join([chr(i + ord("a")) for i in ans]) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING VAR VAR EXPR FUNC_CALL VAR VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
k = int(input()) s = input() t = input() num = [0] * k num2 = [0] * k alth = "abcdefghijklmnopqrstuvwxyz" for i in range(k): num[i] = alth.find(s[i]) num2[i] = alth.find(t[i]) num3 = [0] * k rem = 0 for i in range(k - 1, -1, -1): num3[i] = num2[i] - num[i] - rem if num3[i] < 0: num3[i] += 26 rem = 1 else: rem = 0 rem = 0 j = 0 while j < k: rem2 = (num3[j] + rem) % 2 num3[j] = (num3[j] + rem) // 2 rem = 26 * rem2 j += 1 rem = 0 for i in range(k - 1, -1, -1): num[i] += num3[i] + rem if num[i] > 25: num[i] -= 26 rem = 1 else: rem = 0 for i in num: print(alth[i], end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR BIN_OP VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
n = int(input()) a = [(ord(c) - 97) for c in input()] b = [(ord(c) - 97) for c in input()] ans = [] p = n - 1 bemp = b[p] + a[p] while p > 0: p -= 1 bemp += (b[p] + a[p]) * 26 ans.append(chr(int(bemp / 2) % 26 + 97)) bemp //= 26 ans.append(chr(int(bemp / 2) % 26 + 97)) p = n while p: p -= 1 print(ans[p], end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR WHILE VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
k = int(input()) A = list(input())[::-1] B = list(input())[::-1] C = [] pivot = (ord("z") - ord("a") + 1) // 2 for i in range(k): a, b = ord(A[i]), ord(B[i]) if (b - a) % 2 == 0: C += [chr((a + b) // 2)] elif ord(C[-1]) - ord("a") >= pivot: C[-1] = chr(ord(C[-1]) - pivot) C += [chr((a + b + 1) // 2)] else: C[-1] = chr(ord(C[-1]) + pivot) C += [chr((a + b - 1) // 2)] print("".join(C[::-1]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR LIST FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING VAR ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR LIST FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR LIST FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
letters = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ] k = int(input()) s = input() t = input() med = [(0) for i in range(k)] for i in range(k): tem = (letters.index(t[k - 1 - i]) + letters.index(s[k - 1 - i])) / 2 med[k - 1 - i] = med[k - 1 - i] + int(tem) if tem > int(tem): med[k - 1 - i + 1] = med[k - 1 - i + 1] + 13 if med[k - 1 - i + 1] > 25: med[k - 1 - i + 1] -= 26 med[k - 1 - i] += 1 if med[k - 1 - i] > 25: med[k - 1 - i] -= 26 med[k - 1 - i - 1] += 1 printout = "" for i in range(k): printout += letters[med[i]] print(printout)
ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER IF VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
k = int(input()) s = list(map(lambda x: ord(x) - ord("a"), input())) t = list(map(lambda x: ord(x) - ord("a"), input())) sum_ = [] old = 0 for i in reversed(range(k)): s_ = s[i] + t[i] + old new = s_ % 26 sum_.append(new) old = s_ // 26 sum_.append(old) sum_ = list(reversed(sum_)) for i in range(k + 1): r = sum_[i] % 2 sum_[i] //= 2 if i + 1 <= k: sum_[i + 1] += 26 * r print("".join(map(lambda x: chr(x + ord("a")), sum_[1:])))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING VAR NUMBER
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
n = int(input()) a = [(ord(c) - 97) for c in input()] b = [(ord(c) - 97) for c in input()] ans = [] for i in range(n): sum = a[i] + b[i] if i + 1 < n: a[i + 1] += sum % 2 * 26 sum //= 2 ans.append(sum) for i in range(n - 1, -1, -1): if i - 1 > -1: ans[i - 1] += ans[i] // 26 ans[i] %= 26 ans = [chr(x + 97) for x in ans] print("".join(ans))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
n = int(input()) a = list(input()) b = list(input()) dic = {} dic2 = {} ans = [(0) for _ in range(n)] for i in range(26): text = chr(97 + i) dic[text] = i dic2[str(i)] = text for i in range(n - 1, -1, -1): down = dic[a[i]] if ord(b[i]) < 97: up = 25 b[i - 1] = chr(ord(b[i - 1]) - 1) ans[i] = up - down else: up = dic.get(b[i]) if up >= down: ans[i] = up - down else: b[i - 1] = chr(ord(b[i - 1]) - 1) ans[i] = 26 + up - down left = 0 add = 0 for i in range(n): l = (left * 26 + ans[i]) % 2 ans[i] = (left * 26 + ans[i]) // 2 left = l for i in range(n - 1, -1, -1): num = dic.get(a[i]) + ans[i] + add if num > 25: num %= 26 add = 1 else: add = 0 a[i] = dic2.get(str(num)) print("".join(a))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
dic = {} dic2 = {} for i in range(97, 123): dic[chr(i)] = i dic2[i] = chr(i) k = int(input()) word1 = input() word2 = input() ords = [] carry = 0 for i in range(k): c = dic[word1[i]] + dic[word2[i]] + carry carry = 0 if c % 2 == 1: carry = 26 ords.append(c // 2) for i in range(k - 1, -1, -1): if ords[i] > 122: ords[i - 1] += 1 ords[i] = dic2[ords[i] - 26] else: ords[i] = dic2[ords[i]] p = "" for o in ords: p += o print(p)
ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR STRING FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
k = int(input()) def f(s): r = [0] * k for i, c in enumerate(s): r[i] = ord(c) - ord("a") return r s = input() t = input() sr = f(s) st = f(t) for i in range(k - 1, -1, -1): sr[i] += st[i] if i > 0: sr[i - 1] += sr[i] // 26 sr[i] %= 26 for i in range(k): r = sr[i] % 2 sr[i] = sr[i] // 2 if i < k - 1: sr[i + 1] += r * 26 for i in range(k): sr[i] = chr(ord("a") + sr[i]) print("".join(sr))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline N = int(input()) S = [(ord(c) - ord("a")) for c in input()[:-1]] T = [(ord(c) - ord("a")) for c in input()[:-1]] ans = [] p = N - 1 bemp = S[p] + T[p] while p > 0: p -= 1 bemp += (S[p] + T[p]) * 26 ans.append(chr(bemp // 2 % 26 + ord("a"))) bemp //= 26 ans.append(chr(bemp // 2 % 26 + ord("a"))) print("".join(map(str, reversed(ans))))
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR WHILE VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR FUNC_CALL VAR VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
def main(): n = int(input()) s = input() k = input() arr = [0] + [(ord(s[i]) + ord(k[i]) - 2 * ord("a")) for i in range(n)] for i in range(n, -1, -1): if arr[i] >= 26: arr[i] -= 26 arr[i - 1] += 1 for i in range(n, -1, -1): if arr[i] % 2: arr[i + 1] += 13 arr[i] //= 2 for i in range(n + 1): arr[i] = chr(arr[i] + ord("a")) print("".join(arr[1:])) return 0 main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
n = int(input()) s1 = input() s2 = input() m = ord("z") - ord("a") + 1 s1 = list(reversed(s1)) s2 = list(reversed(s2)) s3 = [] c = 0 for i in range(n): t = ord(s1[i]) + ord(s2[i]) - 2 * ord("a") + c s3.append(chr(t % m + ord("a"))) c = t // m if c != 0: s3.append(chr(c + ord("a"))) s3 = list(reversed(s3)) c = 0 ans = [] for i in s3: t = c * m + (ord(i) - ord("a")) c = t % 2 ans.append(chr(ord("a") + t // 2)) if len(ans) > n: ans = ans[len(ans) - n :] print("".join(ans))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
from sys import stdin def ip(): return [int(i) for i in stdin.readline().split()] def sp(): return [str(i) for i in stdin.readline().split()] def pp(A): for i in A: print(i) def solve(): n = int(input()) s = [0] + list(str(input())) t = [0] + list(str(input())) for i in range(1, n + 1): s[i] = ord(s[i]) - 97 t[i] = ord(t[i]) - 97 for i in range(len(s) - 1, -1, -1): s[i] += t[i] if i != 0: s[i - 1] += s[i] // 26 s[i] %= 26 for i in range(n + 1): r = s[i] % 2 s[i] /= 2 if i != n: s[i + 1] += r * 26 if i == 0: continue print(chr(int(s[i] + 97)), end="") return 0 solve()
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FOR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER STRING RETURN NUMBER EXPR FUNC_CALL VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
import sys input = sys.stdin.readline k = int(input()) s = input().rstrip() t = input().rstrip() ss = [(ord(s[i]) - ord("a")) for i in range(k)] tt = [(ord(t[i]) - ord("a")) for i in range(k)] z = [(ss[i] + tt[i]) for i in range(k)] for i in range(1, k)[::-1]: if z[i] // 26: z[i] %= 26 z[i - 1] += 1 ans = [] for i in range(k): if z[i] % 2: z[i + 1] += 26 z[i] -= 1 z[i] //= 2 ans.append(chr(z[i] + ord("a"))) print("".join(ans))
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
n = int(input()) s = input() t = input() c = ord("a") l = [(0) for i in range(n)] for i in range(n): l[-1 - i] += ord(s[i]) - c + 1 l[-1 - i] += ord(t[i]) - c + 1 for i in range(n - 1, -1, -1): if l[i] % 2 and i != 0: l[i - 1] += 26 l[i] = l[i] // 2 for i in range(0, n): if l[i] > 26: l[i] -= 26 l[i + 1] += 1 ans = "" for i in range(n - 1, -1, -1): ans += chr(ord("a") + l[i] - 1) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER VAR BIN_OP NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR STRING VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
def b26sub(a, b, n, c): for i in range(n - 1, -1, -1): if a[i] > b[i]: b[i] += 26 b[i - 1] -= 1 c[i] = b[i] - a[i] def b26add(a, b, n, c): car = 0 for i in range(n - 1, -1, -1): x = a[i] + b[i] + car car = x // 26 c[i] = x % 26 def b26div2(a, n, c): rem = 0 for i in range(n): cur = rem * 26 + a[i] c[i] = cur // 2 rem = cur % 2 n = int(input()) s = input() t = input() a = [] b = [] c = [] d = [] e = [] for i in range(n): c.append(0) d.append(0) e.append(0) a.append(ord(s[i]) - ord("a")) b.append(ord(t[i]) - ord("a")) b26sub(a, b, n, c) b26div2(c, n, d) b26add(a, d, n, e) l = "" for i in range(n): l += chr(e[i] + ord("a")) print(l)
FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
n = int(input("")) a = input("") b = input("") c = [(0) for _ in range(n + 1)] for i in range(n - 1, -1, -1): aa = ord(a[i]) - ord("a") bb = ord(b[i]) - ord("a") c[i + 1] += aa + bb if c[i + 1] >= 26: c[i] += c[i + 1] // 26 c[i + 1] %= 26 def show_str(l): out = "" for item in l: out += item print(out) carry_over = False for i in range(0, n + 1): if carry_over: c[i] += 26 carry_over = c[i] % 2 == 1 c[i] = c[i] // 2 c[i] = chr(ord("a") + c[i]) show_str(c[1:])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR BIN_OP VAR NUMBER BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR STRING FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
k = int(input()) s = input() t = input() val = [(0) for i in range(0, k)] nval = [(0) for i in range(0, k)] for i in range(0, k): val[i] = ord(s[i]) - ord("a") + ord(t[i]) - ord("a") ans = ["a" for i in range(0, k)] carry = 0 for i in range(0, k): ncarry = 0 t = val[i] // 2 + carry if val[i] % 2 == 1: ncarry += 13 nval[i] = t carry = ncarry for i in range(k - 1, -1, -1): if nval[i] >= 26: nval[i - 1] += nval[i] // 26 nval[i] %= 26 ans[i] = chr(ord("a") + nval[i]) print("".join(x for x in ans))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR STRING VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
def divide_2(a, m): r = 0 q = [] for x in a: cur = r * m + x q.append(cur // 2) r = cur % 2 return q def add(s, t, m): r = 0 a = [] for x, y in zip(s[::-1], t[::-1]): cur = r + x + y a.append(cur % m) r = cur // m if r != 0: a.append(r) return a[::-1] def to_num(s): a = [] for x in s: a.append(ord(x) - ord("a")) return a def to_char(s, k): a = [] for x in s[-k:]: a.append(chr(x + ord("a"))) return "".join(a) k = int(input()) x = to_num(input()) y = to_num(input()) print(to_char(divide_2(add(x, y, 26), 26), k))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR NUMBER FUNC_DEF ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING RETURN VAR FUNC_DEF ASSIGN VAR LIST FOR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING RETURN FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
from sys import stdin class base: def __init__(self, s, base): self.num, self.base = [0] + s, base def __add__(self, other): out = base([0] * (max(len(other.num), len(self.num)) - 1), self.base) carry = 0 for i in range(len(self.num) - 1, -1, -1): su = self.num[i] + other.num[i] + carry if su < self.base: out.num[i], carry = su, 0 else: out.num[i], carry = su % self.base, 1 return out def __truediv__(self, other): carry = 0 for i in range(len(self.num)): cur = self.num[i] + carry * self.base self.num[i], carry = divmod(cur, other) return self letters = "0123456789ABCDEFGHIJKLMNOP" rstr = lambda: [(ord(x) - 97) for x in stdin.readline().strip()] n, s1, t1 = int(input()), base(rstr(), 26), base(rstr(), 26) s1 += t1 s1 = s1 / 2 print("".join([chr(i + 97) for i in s1.num[1:]]))
CLASS_DEF FUNC_DEF ASSIGN VAR VAR BIN_OP LIST NUMBER VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
k = int(input()) a = reversed(input()) b = reversed(input()) aa = [0] * (k + 1) bb = [0] * (k + 1) for i, x in enumerate(a): aa[i] = ord(x) - 97 for i, x in enumerate(b): bb[i] = ord(x) - 97 carry = 0 cc = [0] * (k + 1) for i in range(k + 1): cc[i] = aa[i] + bb[i] + carry if cc[i] >= 26: carry = 1 cc[i] -= 26 else: carry = 0 carry = 0 for i in reversed(range(k + 1)): value = carry * 26 + cc[i] carry = value % 2 cc[i] = value // 2 answer = "" for x in reversed(cc[:-1]): answer += chr(x + 97) print(answer)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
dicti = {} for i in range(26): dicti[chr(97 + i)] = i + 1 k = int(input()) str1 = list(input()) str2 = list(input()) delta = [] for i in range(k): str1[i] = dicti[str1[i]] str2[i] = dicti[str2[i]] delta.append(str2[i] - str1[i]) for i in range(k - 1, 0, -1): if delta[i] < 0: delta[i - 1] -= 1 delta[i] += 26 divide = [] for i in range(k - 1): divide.append(delta[i]) if delta[i] % 2 != 0: divide[i] = delta[i] // 2 delta[i + 1] += 26 else: divide[i] = delta[i] // 2 divide.append(delta[-1] // 2) ans = [(0) for i in range(k)] for i in range(k - 1, -1, -1): sumi = str1[i] + divide[i] if sumi > 26: sumi -= 26 if i != 0: divide[i - 1] += 1 ans[i] = chr(96 + sumi) print(*ans, sep="")
ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR STRING
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
length = int(input()) start = input() slist = [(ord(char) - 97) for char in start] end = input() elist = [(ord(char) - 97) for char in end] result = [] weirdnumber = 0 for i in range(0, length, 1): dif = (elist[i] + slist[i]) / 2 + weirdnumber weirdnumber = 0 if int(dif) != dif: result.append(int(dif)) weirdnumber = 13 else: result.append(int(dif)) for i in range(length - 1, -1, -1): if result[i] >= 26: r = result[i] // 26 result[i] -= r * 26 result[i - 1] += r actualresult = "" for char in result: thing = chr(97 + char) if thing == "{": actualresult += "a" else: actualresult += chr(97 + char) print(actualresult)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR STRING VAR STRING VAR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
n = int(input()) s1 = [(ord(x) - 97) for x in input()] s2 = [(ord(x) - 97) for x in input()] s12s = s1[n - 1] + s2[n - 1] res = [] ni = n - 1 while ni > 0: ni -= 1 s12s += (s1[ni] + s2[ni]) * 26 res.append(chr(s12s // 2 % 26 + 97)) s12s = s12s // 26 res.append(chr(s12s // 2 % 26 + 97)) ni = n while ni > 0: ni -= 1 print(res[ni], end="") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
def to_cc26(s): result = [(ord(v) - ord("a")) for v in s] result.reverse() return result def to_number(a): result = 0 mult = 1 for v in a: result += v * mult mult *= 26 return result def minus(b, a): index = 0 result = [] additional = 0 while index < len(b): if b[index] >= a[index] + additional: result.append(b[index] - a[index] - additional) additional = 0 else: result.append(b[index] + 26 - a[index] - additional) additional = 1 index += 1 return result def plus(a, b): index = 0 result = [] additional = 0 while index < len(a): if b[index] + a[index] + additional < 26: result.append(b[index] + a[index] + additional) additional = 0 else: result.append(b[index] + a[index] + additional - 26) additional = 1 index += 1 return result def to_str(a): a.reverse() return "".join(chr(v + ord("a")) for v in a) def divide_2(a): a.reverse() result = [] index = 0 value = 0 while index < len(a): value = value * 26 + a[index] result.append(value // 2) value %= 2 index += 1 result.reverse() return result def solve(s, t): b = to_cc26(t) a = to_cc26(s) diff_26 = minus(b, a) half_diff = divide_2(diff_26) result_26 = plus(a, half_diff) return to_str(result_26) def main() -> None: n = int(input()) s = input() t = input() print(solve(s, t)) main()
FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR EXPR FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR RETURN FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING VAR VAR FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NONE EXPR FUNC_CALL VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
def main(): k = int(input()) s = list(reversed(input())) t = list(reversed(input())) st = [0] * (k + 1) carry = 0 for pos in range(0, k): s_pos = ord(s[pos]) - ord("a") t_pos = ord(t[pos]) - ord("a") total = s_pos + t_pos + carry carry = total // 26 total %= 26 st[pos] = total st[k] = carry st = list(reversed(st)) for pos in range(0, len(st)): rem = st[pos] % 2 st[pos] //= 2 if pos < len(st) - 1: st[pos + 1] += rem * 26 else: assert rem == 0 print("".join([chr(st[pos] + ord("a")) for pos in range(1, len(st))])) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
N = int(input()) s = input() t = input() def stoi(s): return ord(s) - 97 def itos(i): return chr(97 + i) def stoL(s): L = [] for ss in s: L.append(stoi(ss)) return L A = stoL(s) B = stoL(t) C = [(A[i] + B[i]) for i in range(N)] for i in range(1, N)[::-1]: if C[i] >= 26: C[i] -= 26 C[i - 1] += 1 t = 0 for i in range(N): if C[i] % 2: C[i] = (C[i] + t - 1) // 2 t = 26 else: C[i] = (C[i] + t) // 2 t = 0 u = "" for c in C: u += itos(c) print(u)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR BIN_OP NUMBER VAR FUNC_DEF ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
from itertools import accumulate n, s, t = int(input()), input(), input() a = [0] + [(ord(s[i]) + ord(t[i]) - (ord("a") << 1)) for i in range(n)] for i in range(n, -1, -1): if a[i] >= 26: a[i] -= 26 a[i - 1] += 1 for i in range(n, -1, -1): if a[i] & 1: a[i + 1] += 13 a[i] >>= 1 print("".join(map(lambda _: chr(ord("a") + _), a[1:])))
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR STRING NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR NUMBER
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
def array_of(f, *dim): return [array_of(f, *dim[1:]) for _ in range(dim[0])] if dim else f() def atoi(c): return ord(c) - ord("a") def itoa(i): return chr(i + ord("a")) n = int(input()) s, t = input(), input() s = list(map(atoi, reversed(s))) t = list(map(atoi, reversed(t))) ss = array_of(int, n + 1) for i in range(n): x = s[i] + t[i] if ss[i] + x >= 26: ss[i] += x - 26 ss[i + 1] += 1 else: ss[i] += x for i in range(n + 1 - 1, -1, -1): if ss[i] % 2 == 1: ss[i - 1] += 26 ss[i] //= 2 out = [] for i in range(n - 1, -1, -1): out.append(itoa(ss[i])) print("".join(out))
FUNC_DEF RETURN VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
n = int(input()) s = input() t = input() def f(x): return ord(x) - ord("a") def g(x): return chr(x + ord("a")) A = [] for i in range(n): A.append(f(s[i]) + f(t[i])) for i in range(n - 1, 0, -1): if A[i] // 26: A[i - 1] += 1 A[i] %= 26 for i in range(n): if A[i] % 2: A[i + 1] += 26 A[i] -= 1 A[i] //= 2 for i in A: print(g(i), end="") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
input() a = input() b = input() x = [] y = [] for c in a: x.append(ord(c) - 97) for c in b: y.append(ord(c) - 97) result = [(u + v) for u, v in zip(x, y)] for i in range(len(result) - 1, 0, -1): result[i - 1] += result[i] // 26 result[i] %= 26 for i, r in enumerate(result): if r % 2 == 1: result[i + 1] += 26 result[i] //= 2 r = "".join(chr(c + 97) for c in result) print(r)
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
def decto26(n): a = [] while n > 0: a.insert(0, n % 26) n //= 26 return a def f26todec(a): n = 0 l = len(a) - 1 for i in a: n += i * 26**l l -= 1 return n def sum26(a, b, n): q = 0 c = [] for i in range(n + 1): c.append(0) for i in range(n, 0, -1): c[i] = (a[i - 1] + b[i - 1] + q) % 26 q = (a[i - 1] + b[i - 1] + q) // 26 c[0] += q return c def del26(a): n = len(a) q = a[0] c = [] for i in range(n): c.append(0) for i in range(n - 1): c[i] += a[i] // 2 if a[i] % 2 == 1: a[i + 1] += 26 c[-1] = a[-1] // 2 if q <= 1: c.pop(0) return c abc = "abcdefghijklmnopqrstuvwxyz" k = int(input()) s = input() a = [] for i in s: a.append(abc.index(i)) sm = a t = input() a = [] for i in t: a.append(abc.index(i)) tm = a a = del26(sum26(sm, tm, k)) b = "" for i in a: b += abc[i] print(b)
FUNC_DEF ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR STRING FOR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not less than $s$ and not greater than $t$ (including $s$ and $t$) in lexicographical order. For example, for $k=2$, $s=$"az" and $t=$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"]. Your task is to print the median (the middle element) of this list. For the example above this will be "bc". It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Input----- The first line of the input contains one integer $k$ ($1 \le k \le 2 \cdot 10^5$) β€” the length of strings. The second line of the input contains one string $s$ consisting of exactly $k$ lowercase Latin letters. The third line of the input contains one string $t$ consisting of exactly $k$ lowercase Latin letters. It is guaranteed that $s$ is lexicographically less than $t$. It is guaranteed that there is an odd number of strings lexicographically not less than $s$ and not greater than $t$. -----Output----- Print one string consisting exactly of $k$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $k$ lexicographically not less than $s$ and not greater than $t$. -----Examples----- Input 2 az bf Output bc Input 5 afogk asdji Output alvuw Input 6 nijfvj tvqhwp Output qoztvz
orda = ord("a") ord0 = ord("z") - orda + 1 n = int(input()) s = input() t = input() sv = [(ord(si) - orda) for si in s] tv = [(ord(ti) - orda) for ti in t] medv = [(ord(si) - orda) for si in s] for i in range(n - 1, -1, -1): medv[i] += tv[i] if i > 0 and medv[i] >= ord0: medv[i] -= ord0 medv[i - 1] += 1 for i in range(n): if i < n - 1 and medv[i] % 2 == 1: medv[i + 1] += ord0 medv[i] //= 2 ans = "".join([chr(medvi + orda) for medvi in medv]) print(ans)
ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR