description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Fox Ciel wants to write a task for a programming contest. The task is: "You are given a simple undirected graph with n vertexes. Each its edge has unit length. You should calculate the number of shortest paths between vertex 1 and vertex 2." Same with some writers, she wants to make an example with some certain output: for example, her birthday or the number of her boyfriend. Can you help her to make a test case with answer equal exactly to k? Input The first line contains a single integer k (1 ≤ k ≤ 109). Output You should output a graph G with n vertexes (2 ≤ n ≤ 1000). There must be exactly k shortest paths between vertex 1 and vertex 2 of the graph. The first line must contain an integer n. Then adjacency matrix G with n rows and n columns must follow. Each element of the matrix must be 'N' or 'Y'. If Gij is 'Y', then graph G has a edge connecting vertex i and vertex j. Consider the graph vertexes are numbered from 1 to n. The graph must be undirected and simple: Gii = 'N' and Gij = Gji must hold. And there must be at least one path between vertex 1 and vertex 2. It's guaranteed that the answer exists. If there multiple correct answers, you can output any of them. Examples Input 2 Output 4 NNYY NNYY YYNN YYNN Input 9 Output 8 NNYYYNNN NNNNNYYY YNNNNYYY YNNNNYYY YNNNNYYY NYYYYNNN NYYYYNNN NYYYYNNN Input 1 Output 2 NY YN Note In first example, there are 2 shortest paths: 1-3-2 and 1-4-2. In second example, there are 9 shortest paths: 1-3-6-2, 1-3-7-2, 1-3-8-2, 1-4-6-2, 1-4-7-2, 1-4-8-2, 1-5-6-2, 1-5-7-2, 1-5-8-2.
n, m, cnt = int(input()), 148, 0 ans = [(["N"] * m) for i in range(m)] def edge(i, j): ans[i][j] = ans[j][i] = "Y" def node(*adj): global cnt i = cnt cnt += 1 for j in adj: edge(i, j) return i start, end, choice = node(), node(), node() if n & 1: edge(choice, end) for i in range(1, 30): end, choice = node(node(end), node(end)), node(node(choice)) if n & 1 << i: edge(choice, end) edge(start, choice) print(m) for line in ans: print("".join(line))
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST STRING VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR STRING FUNC_DEF ASSIGN VAR VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Fox Ciel wants to write a task for a programming contest. The task is: "You are given a simple undirected graph with n vertexes. Each its edge has unit length. You should calculate the number of shortest paths between vertex 1 and vertex 2." Same with some writers, she wants to make an example with some certain output: for example, her birthday or the number of her boyfriend. Can you help her to make a test case with answer equal exactly to k? Input The first line contains a single integer k (1 ≤ k ≤ 109). Output You should output a graph G with n vertexes (2 ≤ n ≤ 1000). There must be exactly k shortest paths between vertex 1 and vertex 2 of the graph. The first line must contain an integer n. Then adjacency matrix G with n rows and n columns must follow. Each element of the matrix must be 'N' or 'Y'. If Gij is 'Y', then graph G has a edge connecting vertex i and vertex j. Consider the graph vertexes are numbered from 1 to n. The graph must be undirected and simple: Gii = 'N' and Gij = Gji must hold. And there must be at least one path between vertex 1 and vertex 2. It's guaranteed that the answer exists. If there multiple correct answers, you can output any of them. Examples Input 2 Output 4 NNYY NNYY YYNN YYNN Input 9 Output 8 NNYYYNNN NNNNNYYY YNNNNYYY YNNNNYYY YNNNNYYY NYYYYNNN NYYYYNNN NYYYYNNN Input 1 Output 2 NY YN Note In first example, there are 2 shortest paths: 1-3-2 and 1-4-2. In second example, there are 9 shortest paths: 1-3-6-2, 1-3-7-2, 1-3-8-2, 1-4-6-2, 1-4-7-2, 1-4-8-2, 1-5-6-2, 1-5-7-2, 1-5-8-2.
k = int(input()) edges = [["N" for i in range(1010)] for j in range(1010)] vertices = 2 def add_edge(a, b): global edges edges[a][b] = edges[b][a] = "Y" for i in range(1, 29 + 1): vertices += 3 add_edge(i * 3, i * 3 - 1) add_edge(i * 3, i * 3 + 2) add_edge(i * 3 + 1, i * 3 - 1) add_edge(i * 3 + 1, i * 3 + 2) for bit in range(30): if 1 << bit & k: lst = 1 for i in range((29 - bit) * 2): vertices += 1 add_edge(lst, vertices) lst = vertices add_edge(lst, 3 * bit + 2) print(vertices) if 0: for i in range(1, vertices + 1): print(i, ":", "\n\t", end="") for j in range(1, vertices + 1): if edges[i][j] == "Y": print(j, end=" ") print("") else: print( "\n".join(map(lambda x: "".join(x[1 : vertices + 1]), edges[1 : vertices + 1])) )
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER
Fox Ciel wants to write a task for a programming contest. The task is: "You are given a simple undirected graph with n vertexes. Each its edge has unit length. You should calculate the number of shortest paths between vertex 1 and vertex 2." Same with some writers, she wants to make an example with some certain output: for example, her birthday or the number of her boyfriend. Can you help her to make a test case with answer equal exactly to k? Input The first line contains a single integer k (1 ≤ k ≤ 109). Output You should output a graph G with n vertexes (2 ≤ n ≤ 1000). There must be exactly k shortest paths between vertex 1 and vertex 2 of the graph. The first line must contain an integer n. Then adjacency matrix G with n rows and n columns must follow. Each element of the matrix must be 'N' or 'Y'. If Gij is 'Y', then graph G has a edge connecting vertex i and vertex j. Consider the graph vertexes are numbered from 1 to n. The graph must be undirected and simple: Gii = 'N' and Gij = Gji must hold. And there must be at least one path between vertex 1 and vertex 2. It's guaranteed that the answer exists. If there multiple correct answers, you can output any of them. Examples Input 2 Output 4 NNYY NNYY YYNN YYNN Input 9 Output 8 NNYYYNNN NNNNNYYY YNNNNYYY YNNNNYYY YNNNNYYY NYYYYNNN NYYYYNNN NYYYYNNN Input 1 Output 2 NY YN Note In first example, there are 2 shortest paths: 1-3-2 and 1-4-2. In second example, there are 9 shortest paths: 1-3-6-2, 1-3-7-2, 1-3-8-2, 1-4-6-2, 1-4-7-2, 1-4-8-2, 1-5-6-2, 1-5-7-2, 1-5-8-2.
k = str(input()) l = len(k) paths = [] for i in range(l): paths.append([1] * i + [int(k[i])] + [10] * (l - i - 1)) lens = [sum(p) for p in paths] n = sum(lens) + 2 m = [""] * n m[0] = "N" * 2 for i in range(len(paths)): m[0] += "Y" * paths[i][0] + "N" * (lens[i] - paths[i][0]) m[1] = "N" for i in range(len(paths)): m[1] += "N" * (lens[i] - paths[i][-1]) + "Y" * paths[i][-1] ind = 2 for p in paths: for i in range(len(p) - 1): for j in range(p[i]): m[ind] = "N" * (p[i] - j) + "Y" * p[i + 1] + "N" * n ind += 1 for j in range(p[-1]): m[ind] = "N" * n ind += 1 m2 = [""] * n for i in range(n): m2[i] = "" for j in range(i): m2[i] += m2[j][i] m2[i] += m[i][: n - i] print(len(m2)) for s in m2: print(s)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP LIST NUMBER VAR LIST FUNC_CALL VAR VAR VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER BIN_OP STRING NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP BIN_OP STRING VAR VAR NUMBER BIN_OP STRING BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP BIN_OP STRING BIN_OP VAR VAR VAR VAR NUMBER BIN_OP STRING VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR VAR VAR BIN_OP STRING VAR BIN_OP VAR NUMBER BIN_OP STRING VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP STRING VAR VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
Fox Ciel wants to write a task for a programming contest. The task is: "You are given a simple undirected graph with n vertexes. Each its edge has unit length. You should calculate the number of shortest paths between vertex 1 and vertex 2." Same with some writers, she wants to make an example with some certain output: for example, her birthday or the number of her boyfriend. Can you help her to make a test case with answer equal exactly to k? Input The first line contains a single integer k (1 ≤ k ≤ 109). Output You should output a graph G with n vertexes (2 ≤ n ≤ 1000). There must be exactly k shortest paths between vertex 1 and vertex 2 of the graph. The first line must contain an integer n. Then adjacency matrix G with n rows and n columns must follow. Each element of the matrix must be 'N' or 'Y'. If Gij is 'Y', then graph G has a edge connecting vertex i and vertex j. Consider the graph vertexes are numbered from 1 to n. The graph must be undirected and simple: Gii = 'N' and Gij = Gji must hold. And there must be at least one path between vertex 1 and vertex 2. It's guaranteed that the answer exists. If there multiple correct answers, you can output any of them. Examples Input 2 Output 4 NNYY NNYY YYNN YYNN Input 9 Output 8 NNYYYNNN NNNNNYYY YNNNNYYY YNNNNYYY YNNNNYYY NYYYYNNN NYYYYNNN NYYYYNNN Input 1 Output 2 NY YN Note In first example, there are 2 shortest paths: 1-3-2 and 1-4-2. In second example, there are 9 shortest paths: 1-3-6-2, 1-3-7-2, 1-3-8-2, 1-4-6-2, 1-4-7-2, 1-4-8-2, 1-5-6-2, 1-5-7-2, 1-5-8-2.
n, m = 337, int(input()) p = [(["N"] * n) for i in range(n)] def f(i, j): p[i][j] = p[j][i] = "Y" k = 6 + 15 * 5 for j in range(2, 6): f(1, j) for i in range(6, k, 5): for j in range(i - 4, i): f(i, j) for j in range(i + 1, i + 5): f(i, j) q, d, s = 4**15, 0, k while q: if m >= q: t = m // q m -= t * q if d == 0: for j in range(k - t, k): f(0, j) else: f(0, s) for i in range(s, s + d): f(i, i + 1) s += d for j in range(k - t, k): f(s, j) s += 1 k -= 5 d += 2 q //= 4 print(s) for i in range(s): print("".join(p[i][:s]))
ASSIGN VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER NUMBER NUMBER VAR WHILE VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR
Fox Ciel wants to write a task for a programming contest. The task is: "You are given a simple undirected graph with n vertexes. Each its edge has unit length. You should calculate the number of shortest paths between vertex 1 and vertex 2." Same with some writers, she wants to make an example with some certain output: for example, her birthday or the number of her boyfriend. Can you help her to make a test case with answer equal exactly to k? Input The first line contains a single integer k (1 ≤ k ≤ 109). Output You should output a graph G with n vertexes (2 ≤ n ≤ 1000). There must be exactly k shortest paths between vertex 1 and vertex 2 of the graph. The first line must contain an integer n. Then adjacency matrix G with n rows and n columns must follow. Each element of the matrix must be 'N' or 'Y'. If Gij is 'Y', then graph G has a edge connecting vertex i and vertex j. Consider the graph vertexes are numbered from 1 to n. The graph must be undirected and simple: Gii = 'N' and Gij = Gji must hold. And there must be at least one path between vertex 1 and vertex 2. It's guaranteed that the answer exists. If there multiple correct answers, you can output any of them. Examples Input 2 Output 4 NNYY NNYY YYNN YYNN Input 9 Output 8 NNYYYNNN NNNNNYYY YNNNNYYY YNNNNYYY YNNNNYYY NYYYYNNN NYYYYNNN NYYYYNNN Input 1 Output 2 NY YN Note In first example, there are 2 shortest paths: 1-3-2 and 1-4-2. In second example, there are 9 shortest paths: 1-3-6-2, 1-3-7-2, 1-3-8-2, 1-4-6-2, 1-4-7-2, 1-4-8-2, 1-5-6-2, 1-5-7-2, 1-5-8-2.
class Node(object): cnt = 0 def __init__(_, adj=None): _.id = Node.cnt Node.cnt += 1 _.adj = adj if adj else [] _.seen = False n = int(input()) start = Node() end = Node() choose = Node() for i in range(30): if n & 1 << i: choose.adj.append(end) if i == 29: break end = Node([Node([end]), Node([end])]) choose = Node([Node([choose])]) start.adj.append(choose) ans = [(["N"] * Node.cnt) for i in range(Node.cnt)] def dfs(v): if v.seen: return v.seen = True for u in v.adj: ans[v.id][u.id] = ans[u.id][v.id] = "Y" dfs(u) dfs(start) print(Node.cnt) for line in ans: print("".join(line))
CLASS_DEF VAR ASSIGN VAR NUMBER FUNC_DEF NONE ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST FUNC_CALL VAR LIST VAR FUNC_CALL VAR LIST VAR ASSIGN VAR FUNC_CALL VAR LIST FUNC_CALL VAR LIST VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR RETURN ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Fox Ciel wants to write a task for a programming contest. The task is: "You are given a simple undirected graph with n vertexes. Each its edge has unit length. You should calculate the number of shortest paths between vertex 1 and vertex 2." Same with some writers, she wants to make an example with some certain output: for example, her birthday or the number of her boyfriend. Can you help her to make a test case with answer equal exactly to k? Input The first line contains a single integer k (1 ≤ k ≤ 109). Output You should output a graph G with n vertexes (2 ≤ n ≤ 1000). There must be exactly k shortest paths between vertex 1 and vertex 2 of the graph. The first line must contain an integer n. Then adjacency matrix G with n rows and n columns must follow. Each element of the matrix must be 'N' or 'Y'. If Gij is 'Y', then graph G has a edge connecting vertex i and vertex j. Consider the graph vertexes are numbered from 1 to n. The graph must be undirected and simple: Gii = 'N' and Gij = Gji must hold. And there must be at least one path between vertex 1 and vertex 2. It's guaranteed that the answer exists. If there multiple correct answers, you can output any of them. Examples Input 2 Output 4 NNYY NNYY YYNN YYNN Input 9 Output 8 NNYYYNNN NNNNNYYY YNNNNYYY YNNNNYYY YNNNNYYY NYYYYNNN NYYYYNNN NYYYYNNN Input 1 Output 2 NY YN Note In first example, there are 2 shortest paths: 1-3-2 and 1-4-2. In second example, there are 9 shortest paths: 1-3-6-2, 1-3-7-2, 1-3-8-2, 1-4-6-2, 1-4-7-2, 1-4-8-2, 1-5-6-2, 1-5-7-2, 1-5-8-2.
N = int(input()) b = bin(N)[2:][::-1] count = len(b) - 1 def print_matrix(m): print(len(m)) for i in range(len(m)): print("".join(m[i])) m = [["N" for i in range(2 * len(b) + count)] for j in range(2 * len(b) + count)] for i in range(count - 1): val = len(m) - count + i m[val][val + 1] = "Y" m[val + 1][val] = "Y" if count > 0: m[len(m) - 1][1] = "Y" m[1][len(m) - 1] = "Y" c = 0 c2 = len(m) - count for i in range(0, len(m) - count, 2): if i >= len(m) - 2 - count and i != 0: m[i][1] = "Y" m[i + 1][1] = "Y" m[1][i + 1] = "Y" m[1][i] = "Y" elif i < len(m) - 2 - count: m[i][i + 2] = "Y" m[i][i + 3] = "Y" m[i + 2][i] = "Y" m[i + 3][i] = "Y" if i != 0: m[i + 1][i + 2] = "Y" m[i + 1][i + 3] = "Y" m[i + 2][i + 1] = "Y" m[i + 3][i + 1] = "Y" if b[c] == "1": if i == len(m) - count - 2: c2 = 1 m[i][c2] = "Y" m[c2][i] = "Y" if i != 0: m[i + 1][c2] = "Y" m[c2][i + 1] = "Y" c2 += 1 c += 1 print(len(m)) for i in range(len(m)): print("".join(m[i]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER STRING ASSIGN VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER NUMBER STRING ASSIGN VAR NUMBER BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR STRING IF VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER VAR STRING ASSIGN VAR BIN_OP VAR NUMBER VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING IF VAR VAR STRING IF VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR STRING ASSIGN VAR VAR VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
t = int(input()) for _ in range(t): n = int(input()) x = list(map(int, input().split())) my_arr = list() my_list = list() res = 0 my_arr = [0] * 1000000 my_list = [0] * 1000000 arr2 = list(range(1000001)) my_arr[x[0]] = 0 my_list[x[0]] += 1 prev1 = 0 xr = 0 pos = 0 for i in range(1, n): xr = x[i] ^ xr prev2 = 0 pos = 0 pos = arr2[xr] prev2 = prev1 res += i * my_list[pos] - my_arr[pos] my_arr[prev2] += i my_list[prev2] += 1 prev1 = pos print(res)
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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
def prefix(lis): pre = [lis[0]] for i in range(1, len(lis)): pre.append(pre[i - 1] + lis[i]) sum = 0 for i in range(1, len(lis)): sum = sum + (i * lis[i] - pre[i - 1] - i) return sum t = int(input()) for q in range(t): n = int(input()) arr = list(map(int, input().split())) di = {} xor = 0 for i in range(n): xor = xor ^ arr[i] if di.__contains__(xor) == False: di[xor] = [i] else: lis = di[xor] lis.append(i) di[xor] = lis lis = [] res = list(di.values()) ans = 0 if di.__contains__(0): ans += sum(list(di[0])) for i in range(len(res)): ans += prefix(res[i]) print(ans)
FUNC_DEF 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR 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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR LIST VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
class C: def __init__(self, k): self.sum = k + 1 self.cnt = 1 self.res = 0 def nxt(self, k): self.res += k * self.cnt - self.sum self.sum += k + 1 self.cnt += 1 t = int(input()) for _ in range(t): n = int(input()) d = {} x = 0 for i, v in enumerate(map(int, input().split())): if x in d: d[x].nxt(i) else: d[x] = C(i) x ^= v if x in d: d[x].nxt(n) print(sum(x.res for x in d.values()))
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER 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 DICT ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
x = int(input()) for m in range(x): y = int(input()) l = list(map(int, input().split(" "))) count = 0 for i in range(y - 1): f = l[i] for j in range(i + 1, y): f = f ^ l[j] if f == 0: count += j - i print(count)
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 FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
t = int(input()) for _ in range(t): q = 0 n = int(input()) a = list(map(int, input().split())) x = [] x.append(0) for i in range(n): x.append(x[i] ^ a[i]) p = dict() for i in range(n + 1): p[x[i]] = [] for i in range(n + 1): p[x[i]].append(i) for k, v in p.items(): if len(v) != 1: for i in range(len(v) - 1, -1, -1): q += i * (v[i] - 1) - (len(v) - i - 1) * v[i] print(q)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) xor = [] xor.append(arr[0]) for i in range(1, n): xor.append(xor[i - 1] ^ arr[i]) di = {} for i in range(n): if xor[i] not in di: di[xor[i]] = [] di[xor[i]].append(i) cnt = 0 for i in di: arr = di[i] su = 0 if i == 0: su += sum(arr) if len(arr) == 2: su += arr[1] - arr[0] - 1 if len(arr) > 2: n1 = len(arr) j = n1 - 1 suo = 0 suo -= int(j * (j + 1) / 2) if n1 % 2 == 0: j = n1 + 1 for k in range(int(n1 / 2)): j -= 2 suo -= j * arr[k] for k in range(int(n1 / 2), n1): suo += j * arr[k] j += 2 else: for k in range(int(n1 / 2)): suo -= j * arr[k] j -= 2 j = 0 for k in range(int(n1 / 2), n1): suo += j * arr[k] j += 2 su += suo cnt += su print(cnt)
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 LIST EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
t = int(input()) for ankit in range(t): n = int(input()) arr = list(map(int, input().split())) ans = 0 m = 0 xorArr = [(0) for _ in range(n)] mp = dict() xorArr[0] = arr[0] for i in range(1, n): xorArr[i] = xorArr[i - 1] ^ arr[i] for i in range(n): tmp = m ^ xorArr[i] if tmp in mp.keys(): ans = ans + mp[tmp][0] * (i - mp[tmp][1]) - 1 + mp[tmp][2] if xorArr[i] == m: ans += i if mp.get(xorArr[i]) != None: mp[xorArr[i]] = [ mp[xorArr[i]][0] + 1, i, mp[xorArr[i]][2] + mp[tmp][0] * (i - mp[tmp][1]) - 1, ] else: mp[xorArr[i]] = [1, i, 0] print(ans)
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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER IF VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR NONE ASSIGN VAR VAR VAR LIST BIN_OP VAR VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR LIST NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
for i in range(int(input())): n = int(input()) l = list(map(int, input().split())) XOR = 0 d = {} res = 0 d[0] = [0, 1] for i in range(len(l)): XOR ^= l[i] if XOR in d: res += d[XOR][1] * i - d[XOR][0] d[XOR][0] += i + 1 d[XOR][1] += 1 else: d[XOR] = [i + 1, 1] print(res)
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 DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR VAR LIST BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
def tppp(ivvv): nmmm = 0 if 0 in ivvv.keys(): ivvv[0] += [-1] for key, indlll in ivvv.items(): indlll.sort(reverse=True) length = len(indlll) - 1 l = len(indlll) for i in indlll: nmmm += length * i length -= 2 nmmm = nmmm - int(l * (l - 1) / 2) return nmmm def rvv(mllll): map_of_values = {} for index, val in enumerate(mllll): if val not in map_of_values.keys(): map_of_values[val] = [index] else: map_of_values[val] += [index] return map_of_values try: tttt = int(input()) except: quit() while tttt != 0: number_of_integers = int(input()) illll = [int(x) for x in input().split()] for index, val in enumerate(illll): if index == 0: continue else: illll[index] = illll[index - 1] ^ val tmpppp = rvv(illll) anss = tppp(tmpppp) print(anss) tttt -= 1
FUNC_DEF ASSIGN VAR NUMBER IF NUMBER FUNC_CALL VAR VAR NUMBER LIST NUMBER FOR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR LIST VAR VAR VAR LIST VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
for _ in range(int(input())): n = int(input()) lst = list(map(int, input().split())) pr_xor = [0] * 10**6 pr_xor[0] = 1 last_index = [0] * 10**6 last_index[0] = -1 prev_xor_cnt = [0] * 10**6 prev_xor_cnt[0] = 1 prev_ans = [0] * 10**6 xor_val = 0 ans = 0 for idx, ele in enumerate(lst): xor_val ^= ele if pr_xor[xor_val]: ele_cnt = idx - last_index[xor_val] prev_ans[xor_val] = prev_ans[xor_val] + ele_cnt * prev_xor_cnt[xor_val] - 1 pr_xor[xor_val] = 1 prev_xor_cnt[xor_val] += 1 last_index[xor_val] = idx ans += prev_ans[xor_val] print(ans)
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 BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) c = 0 s = set() for i in range(0, n - 1): for k in range(1, n): x = 0 for y in a[i : k + 1]: x ^= y if x == 0: for j in range(i + 1, k + 1): if (i, j, k) not in s: s.add((i, j, k)) c += 1 print(c)
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 FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
for i in range(int(input())): a = int(input()) b = [x for x in map(int, input().split())] c = [0] * a c[0] = b[0] count = 0 for j in range(1, a): c[j] = c[j - 1] ^ b[j] dic = dict() for k in range(a): ans = 0 n = 0 if c[k] not in dic.keys(): dic[c[k]] = [k, 0, 1] elif dic[c[k]][1] == 0: ans = k - dic[c[k]][0] - 1 dic[c[k]] = [k, ans, 2] else: ans = dic[c[k]][1] + dic[c[k]][2] * (k - dic[c[k]][0]) - 1 n = dic[c[k]][2] + 1 dic[c[k]] = [k, ans, n] if c[k] == 0: count += k count += dic[c[k]][1] print(count)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR LIST VAR NUMBER NUMBER IF VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR LIST VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR LIST VAR VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
for t in range(int(input())): n = int(input()) l = [int(j) for j in input().split()] d = {(0): [1, 0]} v = 0 count = 0 for i in range(n): v = v ^ l[i] if v in d: count = count + i * d[v][0] - d[v][1] d[v][0] += 1 d[v][1] += i + 1 else: d[v] = [1, i + 1] print(count)
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 DICT NUMBER LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR LIST NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) ans = 0 prefix_xor = [] z = 0 prefix_xor.append(0) for i in range(n): z = z ^ a[i] prefix_xor.append(z) p_dict = dict() for i in range(n + 1): p_dict[prefix_xor[i]] = [] for i in range(n + 1): p_dict[prefix_xor[i]].append(i) for i, j in p_dict.items(): if len(j) != 1: l = len(j) for i in range(l - 1): ans += (j[i + 1] - j[i]) * (i + 1) * (l - i - 1) ans -= l - i - 1 print(ans)
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 LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
def xor(arr, n): result = 0 arrxor = [(0) for _ in range(n)] arrxor[0] = arr[0] i = 1 while i < n: arrxor[i] = arrxor[i - 1] ^ arr[i] i += 1 mydict = {} mydict[0] = [-1] for ind, elem in enumerate(arrxor): if elem in mydict: mydict[elem].append(ind) else: mydict.update({elem: [ind]}) for key, value in mydict.items(): if len(value) > 1: k = len(value) - 1 x = 0 i = k while i > 0: result += k * mydict[key][i] - k * mydict[key][x] x += 1 k -= 1 i -= 1 result -= int(len(value) * (len(value) - 1) / (2 * 1)) return result t = int(input()) while t > 0: t -= 1 n = int(input()) a = list(map(int, input().split())) print(xor(a, n))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER LIST NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR DICT VAR LIST VAR FOR VAR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER 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 VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
import itertools def findsubsets(s, n): return tuple(itertools.combinations(s, n)) def xorfunc(low, hi, a): xor1 = 0 for i in range(low, hi + 1): xor1 ^= a[i] if xor1 == 0: return hi - low else: return 0 t = int(input()) for i in range(t): n = int(input()) a = input() a = a.split() a = [int(it) for it in a] xor = 0 xorsum = [] for i in a: xor ^= i xorsum.append(xor) interlist = [i for i in range(n)] interlist2 = findsubsets(interlist, 2) interlist2 = [xorfunc(i, j, a) for i, j in interlist2] print(sum(interlist2))
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR NUMBER RETURN BIN_OP VAR VAR RETURN 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 ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
for _ in range(int(input())): n = int(input()) + 1 a = [0] + list(map(int, input().split())) for i in range(1, n): a[i] ^= a[i - 1] r = {} ans = 0 r[0] = 1, 0 for i in range(1, n): cnt, sm = r.get(a[i], (0, 0)) ans += cnt * (i - 1) - sm r[a[i]] = cnt + 1, sm + i print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
t = int(input()) while t: n = int(input()) arr = list(map(int, input().split())) pxor = [0] for i in range(n): pxor += [arr[i] ^ pxor[i]] d = dict() for i in range(n + 1): if pxor[i] in d.keys(): d[pxor[i]][2] = (i - d[pxor[i]][1]) * d[pxor[i]][0] + d[pxor[i]][2] d[pxor[i]][1] = i d[pxor[i]][3] += d[pxor[i]][2] - d[pxor[i]][0] d[pxor[i]][0] += 1 else: d[pxor[i]] = [1, i, 0, 0] sums = 0 for i in d.values(): sums += i[3] print(sums) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE 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 LIST NUMBER FOR VAR FUNC_CALL VAR VAR VAR LIST BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR LIST NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
t = int(input()) while t > 0: n = int(input()) inp = [int(i) for i in input().split()] t = t - 1 xorarr = [0] * n xorarr[0] = inp[0] mydict = dict() mydict[xorarr[0]] = 1 for i in range(1, n): xorarr[i] = xorarr[i - 1] ^ inp[i] if xorarr[i] not in mydict: mydict[xorarr[i]] = 1 else: mydict[xorarr[i]] = mydict[xorarr[i]] + 1 mydicts = dict() sums = 0 for i in range(n): if xorarr[i] == 0: sums = sums + i if xorarr[i] not in mydicts: val = 0 - i * (mydict[xorarr[i]] - 1) mydicts[xorarr[i]] = [1, val] else: val = (2 * mydicts[xorarr[i]][0] - mydict[xorarr[i]] + 1) * i mydicts[xorarr[i]][0] += 1 mydicts[xorarr[i]][1] += val for i in list(mydicts.keys()): sums = sums + mydicts[i][1] - mydict[i] * (mydict[i] - 1) / 2 print(int(sums))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR LIST NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
t = int(input()) for _ in range(t): n = int(input()) l = list(map(int, input().split())) ans = 0 m = [0] * n for i in range(n): if i == 0: m[i] = l[i] else: m[i] = m[i - 1] ^ l[i] d = {} c = 0 for i in l: c = c ^ i for i in range(n - 1, -1, -1): try: x = d[l[i] ^ c] ans += x[0] - x[1] * i except: pass try: d[m[i]] = [d[m[i]][0] + i, d[m[i]][1] + 1] except: d[m[i]] = [i, 1] c = c ^ l[i] print(ans)
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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR LIST BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR LIST VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
t = int(input()) for _ in range(t): n = int(input()) a = tuple(map(int, input().split())) prefix = [0] for item in a: temp = prefix[-1] ^ item prefix.append(temp) m = {} m[0] = 1, 0 ans = 0 for i in range(1, len(prefix)): try: ans += m[prefix[i]][0] * i - m[prefix[i]][1] - m[prefix[i]][0] m[prefix[i]] = m[prefix[i]][0] + 1, m[prefix[i]][1] + i except: m[prefix[i]] = 1, i print(ans)
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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER NUMBER BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
t = int(input()) for i in range(t): n = int(input()) lst = list(map(int, input().rstrip().split())) xlst = [(0) for j in range(n)] xlst[0] = lst[0] for j in range(1, n): xlst[j] = xlst[j - 1] ^ lst[j] xlst.insert(0, 0) di = {} for j in xlst: di[j] = [] for j in range(n + 1): tem = xlst[j] di[tem].append(j) num = 0 for ind in di: j = di[ind] te = len(j) if te < 2: continue su = sum(j) + te way = 0 sta = -1 for k in range(te - 1): f1 = j[k] - sta tem = f1 * (te - k) su = su - tem way += su - (te - k - 1) sta = j[k] num = num + way an = num print(an)
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 FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
def dictt(arr): Dict = {} Dict[0] = [-1] for i, val in enumerate(arr): if val not in Dict: Dict[val] = [i] else: Dict[val].append(i) count = 0 for keys in Dict: s = len(Dict[keys]) if s >= 2: k = s - 1 j = s - 1 while j >= 0: count += k * Dict[keys][j] k -= 2 j -= 1 count -= s * (s - 1) // 2 print(count) for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) prefix = [0] * n prefix[0] = arr[0] for i in range(1, n): prefix[i] = prefix[i - 1] ^ arr[i] dictt(prefix)
FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER LIST NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL 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 ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
from itertools import combinations t = int(input()) for c in range(t): n = int(input()) a = list(map(int, input().split())) l = [0] for i in range(n): l.append(a[i] ^ l[-1]) d = {} for j in range(n + 1): if l[j] in d: d[l[j]] += [j] else: d[l[j]] = [j] res = 0 for x in d.values(): le = len(x) for s in range(le): res += (2 * s + 1 - le) * x[s] res -= le * (le - 1) // 2 print(res)
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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR LIST VAR ASSIGN VAR VAR VAR LIST VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) d = [a[0]] c = 0 v, r = {}, {} v[d[0]] = 0 r[d[0]] = 0 for j in range(1, n): d.append(d[j - 1] ^ a[j]) v[d[j]] = 0 r[d[j]] = 0 for k in range(n): if v[d[k]] > 0: if d[k] == 0: c += k c += (k - 1) * v[d[k]] - r[d[k]] v[d[k]] += 1 r[d[k]] += k else: c += (k - 1) * v[d[k]] - r[d[k]] v[d[k]] += 1 r[d[k]] += k else: if d[k] == 0: c += k v[d[k]] += 1 r[d[k]] += k print(c)
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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR DICT DICT ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
def count_subarrays(l): res = 0 p = [] p.append(0) for i in range(1, len(l)): p.append(p[i - 1] + l[i - 1]) for i in range(1, len(l)): res += i * l[i] - p[i] - i return res def special_case(l): res = 0 for i in l: res += i return res def solve(): arr = [] pref = [] dic = {} counter = 0 n = int(input()) arr = [int(x) for x in input().split()] pref.append(arr[0]) dic.update({pref[0]: []}) dic[pref[0]].append(0) for i in range(1, n): pref.append(arr[i] ^ pref[i - 1]) if pref[i] not in dic.keys(): dic.update({pref[i]: []}) dic[pref[i]].append(i) for i in dic: if i == 0: counter += special_case(dic[i]) if len(dic[i]) > 1: counter += count_subarrays(dic[i]) print(counter) def main(): t = int(input()) while t: t -= 1 solve() main()
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR DICT VAR NUMBER LIST EXPR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR DICT VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
def find_coeffs(n): coeffs = [(0) for _ in range(n)] for i in range(1, n + 1): coeffs[i - 1] = i + (n - i) * i return coeffs def find_diff(indices): diff = [(0) for _ in range(len(indices) - 1)] for i in range(1, len(indices)): diff[i - 1] = int(indices[i] - indices[i - 1]) return diff test_cases = int(input()) for test in range(test_cases): n = int(input()) seq = list(map(int, input().split())) triplets = 0 res = [(0) for _ in range(n + 1)] for i in range(1, n + 1): res[i] = res[i - 1] ^ seq[i - 1] xors = {} for i in range(n + 1): if res[i] not in xors: xors[res[i]] = [i] else: xors[res[i]].append(i) for key in xors.keys(): if len(xors[key]) > 1: diff_array = find_diff(xors[key]) l = len(diff_array) coeffs = find_coeffs(l) triplets += sum([(diff_array[i] * coeffs[i]) for i in range(l)]) - int( l * (l + 1) / 2 ) print(triplets)
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR 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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
for _ in range(int(input())): N = int(input()) List = [int(x) for x in input().split()] Prefix = [] Temp = List[0] Prefix.append(List[0]) for i in range(1, N): Temp = List[i] ^ Temp Prefix.append(Temp) ans = 0 Dict = {(0): list()} Dict[0].append(0) Dict[0].append(0) for i in range(N): if Prefix[i] in Dict: count = len(Dict[Prefix[i]]) - 1 Dict[Prefix[i]].append(i + 1) ans += (i + 1) * count - count - Dict[Prefix[i]][0] Dict[Prefix[i]][0] += i + 1 else: Dict[Prefix[i]] = list() Dict[Prefix[i]].append(i + 1) Dict[Prefix[i]].append(i + 1) print(ans)
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 LIST ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
t = int(input()) for _ in range(t): size = int(input()) given = [0] [given.append(int(i)) for i in str(input()).split(" ")] s = 0 ans = 0 count = [0] * (10**6 + 1) sum = [0] * (10**6 + 1) for index, element in enumerate(given): s ^= element ans += count[s] * index - sum[s] count[s] += 1 sum[s] += index + 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
def rev_index(myList): V = {} for index, val in enumerate(myList): if val not in V.keys(): V[val] = [index] else: V[val] += [index] return V def No_tri(IV): num = 0 if 0 in IV.keys(): IV[0] += [-1] for key, IL in IV.items(): IL.sort(reverse=True) length = len(IL) - 1 l = len(IL) for i in IL: num += length * i length -= 2 num -= int(l * (l - 1) / 2) return num try: T = int(input()) except: quit() while T != 0: N = int(input()) L = [int(x) for x in input().split()] for index, val in enumerate(L): if index == 0: continue else: L[index] = L[index - 1] ^ val temp = rev_index(L) res = No_tri(temp) print(res) T -= 1
FUNC_DEF ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR LIST VAR VAR VAR LIST VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER IF NUMBER FUNC_CALL VAR VAR NUMBER LIST NUMBER FOR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
t = int(input()) for _ in range(t): n = int(input()) l = list(map(int, input().split())) x = [0] p = [[0, 0]] prev = 0 ans = 0 counter = 0 for i in range(1, n + 1): x.append(x[i - 1] ^ l[i - 1]) p.append([x[i], i]) p = sorted(p) for i in range(1, len(p)): if p[i][0] == p[i - 1][0]: counter += 1 else: counter = 0 prev = 0 continue prev = prev + (p[i][1] - p[i - 1][1] - 1) * counter + counter - 1 ans += prev print(ans)
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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) xor = [0] for i in range(n): last = xor[-1] xor.append(last ^ arr[i]) d = {} for i in range(len(xor)): if xor[i] not in d: d[xor[i]] = [i] else: d[xor[i]].append(i) ans = 0 for i in d: temp = d[i] temp1 = sum(temp) terms = len(temp) - 1 for j in range(len(temp)): cur = temp[j] temp1 = temp1 - cur ans += temp1 - terms * cur - terms terms -= 1 print(ans)
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 LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) xorsum = [] xor = 0 xorsum.append(xor) for i in range(len(a)): xor ^= a[i] xorsum.append(xor) xordict = dict() for i in range(len(xorsum)): if xorsum[i] in xordict: xordict[xorsum[i]].append(i) else: xordict[xorsum[i]] = [i] ans = 0 for key in xordict: for i in range(1, len(xordict[key])): x = i * xordict[key][i] - i - sum(xordict[key][:i]) ans += x print(ans)
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 LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
t = int(input()) while t: n = int(input()) z = input().split() for i in range(n): z[i] = int(z[i]) XOR = 0 prefix = [0] * n for i in range(n): XOR = XOR ^ z[i] prefix[i] = XOR dict1 = {} for i in range(n): dict1.setdefault(prefix[i], []).append(i) count = 0 for i, j in dict1.items(): if len(j) > 1: for k in range(len(j)): count += (2 * (k + 1) - len(j) - 1) * j[k] count -= len(j) * (len(j) - 1) / 2 if i == 0: for k in range(len(j)): count += j[k] t -= 1 print(int(count))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL FUNC_CALL VAR VAR VAR LIST VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
t = int(input()) while t: t -= 1 s = int(input()) lis = list(map(int, input().split(" "))) xor_lis = [(0) for i in range(len(lis) + 1)] i = 1 for v in lis: xor_lis[i] = xor_lis[i - 1] ^ v i += 1 dic = {} for i, val in enumerate(xor_lis): if val in dic.keys(): dic[val].append(i) else: dic[val] = [i] ans = 0 for key in dic.keys(): lis = dic[key] if len(lis) <= 1: continue length = len(lis) for i in range(length): ans += i * lis[i] - (length - 1 - i) * lis[i] ans -= length * (length - 1) / 2 print(int(ans))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) xor = [0] * n xor[0] = a[0] m = a[0] for i in range(1, n): xor[i] = xor[i - 1] ^ a[i] m = max(m, xor[i]) v = [] ans = 0 sum = [0] * (m + 1) for j in range(m + 2): v.append([]) for i in range(n): if xor[i] == 0: ans += i j = xor[i] size = len(v[j]) ans += size * i - sum[j] - size v[j].append(i) sum[j] += i print(ans)
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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
t = int(input()) for _ in range(t): n = int(input()) l = list(map(int, input().split())) xorArr = [(0) for _ in range(n)] xorArr[0] = l[0] for i in range(1, n): xorArr[i] = xorArr[i - 1] ^ l[i] vec = [] dic = {} count = 0 dic[0] = [-1] for i in range(n): if dic.get(xorArr[i]): dic.get(xorArr[i]).append(i) else: a = [] a.append(i) dic[xorArr[i]] = a for i in dic: l = dic[i] leng = len(l) for j in range(leng): count += j * l[j] - (leng - j - 1) * l[j] count -= leng * (leng - 1) // 2 print(count)
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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
t = int(input()) while t: t = t - 1 n = int(input()) arr = list(map(int, input().split())) mydict = {} x = [0] * (n + 1) y = 0 for i in range(len(arr)): x[i + 1] = y ^ arr[i] y = x[i + 1] for i in range(len(x)): if x[i] in mydict: mydict[x[i]].append(i) else: mydict[x[i]] = [i] ans = 0 for i in mydict: temp = mydict[i] temp1 = sum(temp) terms = len(temp) - 1 for j in range(len(temp)): cur = temp[j] temp1 = temp1 - cur ans += temp1 - terms * cur - terms terms -= 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
t = int(input()) for _ in range(t): n = int(input()) arr = list(map(int, input().strip().split())) prefix_xor = [arr[0]] for i in range(1, len(arr)): prefix_xor.append(prefix_xor[-1] ^ arr[i]) xor_map = {(0): [1, 0]} total_triplets = 0 for index, elem in enumerate(prefix_xor): if elem not in xor_map: xor_map[elem] = [1, index + 1] else: cnt, sum_all_pos = xor_map[elem][0], xor_map[elem][1] total_triplets += cnt * (index + 1) - cnt - sum_all_pos xor_map[elem][0] += 1 xor_map[elem][1] += index + 1 print(total_triplets)
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 FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR DICT NUMBER LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
t = int(input()) for _ in range(t): n = int(input()) b = list(map(int, input().split())) a = list() x1 = b[0] a.append(0) a.append(b[0]) for i in range(1, n): x1 ^= b[i] a.append(x1) c = {} for i in range(len(a)): c.setdefault(a[i], []).append(i) x, x3 = 0, 0 for i in c: x1 = 1 x2 = 1 if len(c[i]) > 1: for j in range(1, len(c[i])): x += (c[i][j] - 1 - c[i][0]) * x1 x1 += 1 for k in range(len(c[i]) - 2, 0, -1): x3 += (c[i][k] - c[i][0]) * x2 x2 += 1 print(x - x3)
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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL FUNC_CALL VAR VAR VAR LIST VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
for t in range(int(input())): n = int(input()) li = list(map(int, input().split())) sol = 0 p_s, c_s = li[0], 0 tmp = dict() tmp[p_s] = [0, 1] for i in range(1, n): c_s = p_s ^ li[i] if c_s == 0: sol += i if c_s in tmp.keys(): sol += tmp[c_s][1] * (i - 1) - tmp[c_s][0] tmp[c_s][0] += i tmp[c_s][1] += 1 else: tmp[c_s] = [i, 1] p_s = c_s print(sol)
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 VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR VAR IF VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR LIST VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
t = int(input()) while t: n = int(input()) arr = list(map(int, input().split())) prefix = [0] * n prefix[0] = arr[0] for i in range(1, n): prefix[i] = arr[i] ^ prefix[i - 1] pos = {(0): [0]} for i in range(n): if prefix[i] not in pos: pos[prefix[i]] = [i + 1] else: pos[prefix[i]].append(i + 1) result = 0 for key, value in pos.items(): size = len(value) cum = [0] * size cum[0] = value[0] temp = 0 for i in range(1, size): cum[i] = cum[i - 1] + value[i] temp += value[i] * i - cum[i - 1] temp -= size * (size - 1) // 2 result += temp print(result) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE 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 BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR DICT NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
def sumPairs(arr, n): sum = 0 for i in range(n - 1, -1, -1): sum += i * arr[i] - (n - 1 - i) * arr[i] return sum - n * (n - 1) // 2 R = lambda: map(int, input().split()) t = int(input()) for _ in range(t): n = int(input()) xs = list(map(int, input().split())) xor = 0 dict = {(0): [0]} count = 0 i = 0 for x in xs: xor = xor ^ x if xor not in dict: dict[xor] = [i + 1] else: dict[xor].append(i + 1) i += 1 ans = 0 for i in dict.values(): if len(i) == 1: continue else: ans += sumPairs(i, len(i)) print(ans)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR RETURN BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR 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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR LIST BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
T = int(input()) for _ in range(0, T): N = int(input()) arr = list(map(int, input().split())) prexor = [] cnt = 0 prexor.append(0) tp = 0 for i in range(N): tp ^= arr[i] prexor.append(tp) dict1 = dict() for i in range(0, len(prexor)): sm = prexor[i] if sm not in dict1.keys(): dict1[prexor[i]] = [i + 1] else: klis = dict1[prexor[i]] klis.append(i + 1) dict1[prexor[i]] = klis kys = list(dict1.keys()) for i in range(0, len(kys)): li = list(dict1[kys[i]]) l = len(li) if l > 1: for j in range(l - 1): cnt += (l - j - 1) * ((li[j + 1] - li[j]) * (j + 1) - 1) print(cnt)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER 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 LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR VAR LIST BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
def prefixXor(arr): output = [0] temp = 0 out = dict() out[0] = [1, 0] ans = 0 for item in range(len(arr)): temp ^= arr[item] output.append(temp) if not output[item + 1] in out.keys(): out[output[item + 1]] = [0, 0] count = out[output[item + 1]][0] su = out[output[item + 1]][1] ans += count * (item + 1) - count - su count += 1 out[output[item + 1]][0] = count out[output[item + 1]][1] += item + 1 return ans for _ in range(int(input())): N = int(input()) arr = list(map(int, input().split())) print(prefixXor(arr))
FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER LIST NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
for testcase in range(int(input())): n = int(input()) a = [0] + list(map(int, input().split())) sum = [0] * 2000020 cnt = [0] * 2000020 s = 0 ans = 0 cnt[0] = 1 sum[0] = 1 for i in range(1, len(a)): s ^= a[i] ans += i * cnt[s] - sum[s] cnt[s] += 1 sum[s] += i + 1 print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
final_result = [] def get_no_of_triplets(array): result = 0 aux_array = array length = len(array) hash_table = {} for i in range(1, length): aux_array[i] = aux_array[i] ^ aux_array[i - 1] for i in range(length): if aux_array[i] in hash_table: hash_table[aux_array[i]].append(i) else: hash_table[aux_array[i]] = [i] for key in list(hash_table.keys()): temp_array = hash_table[key] sum = 0 l = len(temp_array) if l > 1: for i in range(0, l): sum += temp_array[i] * (l - 1 - 2 * i) * -1 if key == 0: sum += temp_array[i] sum -= l * (l - 1) / 2 elif key == 0: sum += temp_array[0] result += sum return int(result) for _ in range(int(input())): input() ip = input().split(" ") final_result.append(get_no_of_triplets([int(i) for i in ip])) for i in range(len(final_result)): print(final_result[i])
ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR VAR NUMBER VAR VAR RETURN FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
def gudv(n, l): c = 0 b = 0 d = {} d[0] = [0, 1] for i in range(n): b = b ^ l[i] if b in d: c += d[b][1] * i - d[b][0] d[b][0] += i + 1 d[b][1] += 1 else: d[b] = [i + 1, 1] print(c) for i in range(int(input())): n = int(input()) l = list(map(int, input().split())) gudv(n, l)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR VAR LIST BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL 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 VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
t = int(input()) for i in range(t): n = int(input()) l = list(map(int, input().split())) l1 = [] fin = 0 for j in range(n): l1.append(0) d1 = {} d2 = {} d3 = {} d4 = {} d5 = {} d6 = {} l1[0] = l[0] for j in range(1, n): l1[j] = l1[j - 1] ^ l[j] d1[0] = [0] d2[0] = d3[0] = d4[0] = 0 d5[0] = [] for j in range(n): temp = 0 ^ l1[j] if l1[j] in d1.keys(): d1[l1[j]].append(j + 1 - d2[l1[j]]) else: d1[l1[j]] = [0] d2[l1[j]] = j + 1 if l1[j] not in d5.keys(): d5[l1[j]] = [] d3[l1[j]] = 0 d4[l1[j]] = 0 else: d5[l1[j]].append(d1[l1[j]][-1] - d1[l1[j]][-2]) d3[l1[j]] += 1 d4[l1[j]] += d5[l1[j]][-1] * d3[l1[j]] if temp in d6.keys(): if l1[j] == 0: fin += d4[l1[j]] - d6[temp] - d5[l1[j]][-1] else: fin += d4[l1[j]] - d6[temp] if l1[j] == 0: fin += d5[l1[j]][-1] - 1 d6[l1[j]] = d6.get(l1[j], 0) + 1 print(fin)
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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER LIST NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR VAR IF VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR LIST NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR LIST ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR IF VAR FUNC_CALL VAR IF VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) s = 0 c = {(0): [0]} for i, x in enumerate(a): s ^= x c.setdefault(s, []).append(i + 1) s = 0 for k, v in c.items(): l = len(v) - 1 if not l: continue x = sum((v[i] - v[i - 1] - 1) * i * (l + 1 - i) for i in range(1, l + 1)) y = sum(i * (l - i) for i in range(1, l)) s += x + y print(s)
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 DICT NUMBER LIST NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL FUNC_CALL VAR VAR LIST BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
t = int(input()) for _ in range(t): n = int(input()) l = list(map(int, input().split())) px = [0] x = 0 d = {(0): [0]} for i in range(n): x = x ^ l[i] px.append(x) if x not in d: d[x] = [i + 1] else: d[x].append(i + 1) gsum = 0 for i in d: if len(d[i]) > 1: summ = d[i][0] for j in range(1, len(d[i])): gsum += d[i][j] * j - summ - j summ += d[i][j] print(gsum)
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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR LIST BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split(" "))) pair = {} pair[0] = [-1] pair[a[0]] = [0] for i in range(1, n): a[i] = a[i - 1] ^ a[i] if a[i] in pair: pair[a[i]].append(i) else: pair[a[i]] = [i] ans = 0 for lst in pair.values(): x = [] for i in range(1, len(lst)): x.append(lst[i] - lst[i - 1]) m = len(x) l = m k = 1 while k <= l: ans += m * k * x[k - 1] k += 1 m -= 1 ans -= l * (l + 1) // 2 print(ans)
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 STRING ASSIGN VAR DICT ASSIGN VAR NUMBER LIST NUMBER ASSIGN VAR VAR NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL 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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
def maker_dictttt(a): ind = {} for i in range(len(a)): try: if ind[a[i]]: ind[a[i]].append(i) except KeyError: ind[a[i]] = [i] return ind def nC2(n): return int(n * (n - 1) / 2) def ardderr(arr): rest = 0 n = len(arr) prefix = -(n - 1) for i in arr: rest = rest + prefix * i prefix = prefix + 2 return int(rest - nC2(n)) for t in range(int(input())): n = int(input()) x = list(map(int, input().split())) a = [] xor = 0 for i in x: xor ^= i a.append(xor) ans = 0 rest = maker_dictttt(a) for j in rest.keys(): if j == 0: ans = ans + ardderr(rest[j]) ans = ans + sum(rest[j]) else: ans = ans + ardderr(rest[j]) print(ans)
FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR FUNC_CALL 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 ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
t = int(input()) while t: n = int(input()) arr = list(map(int, input().split())) pxor = [0] for i in range(n): pxor += [arr[i] ^ pxor[i]] m = max(pxor) count = [0] * (m + 1) ind = [-1] * (m + 1) val = [0] * (m + 1) res = [0] * (m + 1) for i in range(n + 1): val[pxor[i]] += (i - ind[pxor[i]]) * count[pxor[i]] if val[pxor[i]]: res[pxor[i]] += val[pxor[i]] - count[pxor[i]] ind[pxor[i]] = i count[pxor[i]] += 1 sums = 0 for i in res: sums += i print(sums) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE 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 LIST NUMBER FOR VAR FUNC_CALL VAR VAR VAR LIST BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
def passwr(length, guddu): password = 0 values = {} compute = guddu[0] values[compute] = [1, 1] j = 1 while j != length: compute = compute ^ guddu[j] try: if not compute: password += j password += values[compute][1] * j - values[compute][0] values[compute] = [values[compute][0] + (j + 1), values[compute][1] + 1] except: values[compute] = [j + 1, 1] j += 1 return password test = int(input()) for i in range(test): length = int(input()) guddu = [int(k) for k in input().split()] print(passwr(length, guddu))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR NUMBER ASSIGN VAR VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR LIST BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR LIST BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN VAR 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
t = int(input()) while t > 0: t = t - 1 n = int(input()) l = [] l = [int(x) for x in input().split()] prefix = [] prefix.append(l[0]) xor_vals = {} i_s = {} ans = 0 for i in range(1, n): prefix.append(prefix[i - 1] ^ l[i]) for i in range(0, n): if prefix[i] == 0: ans += i if prefix[i] not in xor_vals: xor_vals[prefix[i]] = 1 i_s[prefix[i]] = i + 1 else: ans += i * xor_vals[prefix[i]] - i_s[prefix[i]] xor_vals[prefix[i]] += 1 i_s[prefix[i]] += i + 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
def xorContest(seq): ans = 0 count = {} bad_count = {} pre_xor = [None] * (len(seq) + 1) pre_xor[0] = 0 for i in range(1, len(seq) + 1): pre_xor[i] = pre_xor[i - 1] ^ seq[i - 1] for i in range(len(pre_xor)): xor = pre_xor[i] ans = ( ans + i * (count[xor] if xor in count else 0) - (bad_count[xor] if xor in bad_count else 0) ) if xor in count: count[xor] = count[xor] + 1 bad_count[xor] = bad_count[xor] + (i + 1) else: count[xor] = 1 bad_count[xor] = i + 1 return ans X = [None] * 100000 R = [None] * 100000 T = int(input()) for t in range(T): N = int(input()) A = [int(x) for x in input().split()] print(xorContest(A))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NONE BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP LIST NONE NUMBER ASSIGN VAR BIN_OP LIST NONE 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
test_cases = int(input()) for test in range(test_cases): n = int(input()) seq = list(map(int, input().split())) triplets = 0 res = [(0) for _ in range(n + 1)] for i in range(1, n + 1): res[i] = res[i - 1] ^ seq[i - 1] xors = {} for i in range(n + 1): if res[i] not in xors: xors[res[i]] = [i] else: xors[res[i]].append(i) for key in xors.keys(): if len(xors[key]) > 1: for i in range(len(xors[key]) - 1): for j in range(i + 1, len(xors[key])): triplets += int(xors[key][j] - xors[key][i] - 1) print(triplets)
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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, so he had to leave that last problem to you. Can you solve it on his behalf? For a given sequence of positive integers $A_1, A_2, \ldots, A_N$, you are supposed to find the number of triples $(i, j, k)$ such that $1 \le i < j \le k \le N$ and Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,Ai⊕Ai+1⊕…⊕Aj−1=Aj⊕Aj+1⊕…⊕Ak,A_i \oplus A_{i+1} \oplus \ldots \oplus A_{j-1} = A_j \oplus A_{j+1} \oplus \ldots \oplus A_k \,, where $\oplus$ denotes bitwise XOR. -----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 $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of triples. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^6$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): - $1 \le T \le 5$ - $1 \le N \le 100$ Subtask #2 (30 points): - $1 \le T \le 5$ - $1 \le N \le 1,000$ Subtask #3 (50 points): original constraints -----Example Input----- 1 3 5 2 7 -----Example Output----- 2 -----Explanation----- Example case 1: The triples are $(1, 3, 3)$, since $5 \oplus 2 = 7$, and $(1, 2, 3)$, since $5 = 2 \oplus 7$.
t = int(input()) while t: n = int(input()) ans = 0 li = list(map(int, input().split())) li = [0] + li xor = [0] for i in range(1, n + 1): xor.append(xor[i - 1] ^ li[i]) di = dict() for i in range(0, n + 1): if xor[i] in di: di[xor[i]].append(i) else: di[xor[i]] = [i] for val in di.values(): l = len(val) if l >= 2: ans -= l * (l - 1) // 2 const = -(l - 1) for i in val: ans += const * i const += 2 print(ans) t = t - 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE 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 ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR FOR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
s = input() chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_" counts = [ 729, 243, 243, 81, 243, 81, 81, 27, 243, 81, 81, 27, 81, 27, 27, 9, 243, 81, 81, 27, 81, 27, 27, 9, 81, 27, 27, 9, 27, 9, 9, 3, 243, 81, 81, 27, 81, 27, 27, 9, 81, 27, 27, 9, 27, 9, 9, 3, 81, 27, 27, 9, 27, 9, 9, 3, 27, 9, 9, 3, 9, 3, 3, 1, ] s_counts = [None] * 64 for i in range(64): s_counts[i] = s.count(chars[i]) result = 1 for i in range(64): result *= counts[i] ** s_counts[i] print(result % (10**9 + 7))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NONE NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
import sys def convert(x): if x >= "A" and x <= "Z": return ord(x) - ord("A") + 10 if x >= "a" and x <= "z": return ord(x) - ord("a") + 36 if x >= "0" and x <= "9": return ord(x) - ord("0") if x == "-": return 62 return 63 def ones(n): r = 0 while n != 0: n &= n - 1 r += 1 return r def zeros(x): return 6 - ones(x) def pow(a, b, mod=10**9 + 7): res = 1 while b > 0: if b & 1 == 0: a = a * a % mod b = b >> 1 else: res = res * a % mod b -= 1 return res def main(): x = sys.stdin.readline().rstrip() t = 0 for s in x: v = convert(s) z = zeros(v) t += z print(pow(3, t)) main()
IMPORT FUNC_DEF IF VAR STRING VAR STRING RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER IF VAR STRING VAR STRING RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER IF VAR STRING VAR STRING RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING IF VAR STRING RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF RETURN BIN_OP NUMBER FUNC_CALL VAR VAR FUNC_DEF BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
import sys def minp(): return sys.stdin.readline().strip() alpha = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_" V = dict() for i in range(len(alpha)): for j in range(len(alpha)): k = i & j V[k] = V.get(k, 0) + 1 s = minp() r = 1 for i in range(len(s)): k = alpha.find(s[i]) r = r * V[k] % 1000000007 print(r)
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
def noof0(strin): s = 0 l = len(strin) for item in strin: if item == str(0): s += 1 return s + 6 - l string = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_" array = [] for item in string: array.append(item) def g(a, n, m): if n == 0: return 1 elif n % 2 == 0: return g(a, n // 2, m) ** 2 % m else: return g(a, n // 2, m) ** 2 * a % m def value(s): for i in range(64): if array[i] == s: return i inp = input() s = 0 for item in inp: s += noof0(str(bin(value(item)))[2:]) print(g(3, s, 1000000007))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR FUNC_CALL VAR NUMBER VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR STRING ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR RETURN BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
from sys import stdin result = 1 MD = 10**9 + 7 def charToInt(c): assert len(c) == 1 val = -1 if c in "0123456789": val = int(c) elif c in "ABCDEFGHIJKLMNOPQRSTUVWXYZ": val = ord(c) - 55 elif c in "abcdefghijklmnopqrstuvwxyz": val = ord(c) - 61 elif c == "-": val = 62 elif c == "_": val = 63 return val def solve(string): global result, MD for c in string: val = charToInt(c) binstring = bin(val)[2:] cnt = 0 for c2 in binstring: if c2 == "1": cnt += 1 num2 = 6 - cnt for x in range(num2): result = result * 3 % MD def parse(): global result line = input() solve(line) print(result) result = 1 parse()
ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER RETURN VAR FUNC_DEF FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
string = input() def entre(i, a, b): return ord(i) >= ord(a) and ord(i) <= ord(b) resp = 1 for char in string: if entre(char, "0", "9"): i = ord(char) - ord("0") elif entre(char, "A", "Z"): i = ord(char) - ord("A") + 10 elif entre(char, "a", "z"): i = ord(char) - ord("a") + 36 elif char == "-": i = 62 else: i = 63 for j in range(6): if i >> j & 1 == 0: resp = resp * 3 % 1000000007 print(resp)
ASSIGN VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR STRING STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR STRING STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER IF FUNC_CALL VAR VAR STRING STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
conversaoBase64 = {"-": 62, "_": 63} for j in range(0, 10): conversaoBase64[str(j)] = j j = 10 for i in range(ord("A"), ord("Z") + 1): conversaoBase64[chr(i)] = j j += 1 j = 36 for i in range(ord("a"), ord("z") + 1): conversaoBase64[chr(i)] = j j += 1 palavra = list(input()) cont = 0 for letra in palavra: letraBase64 = conversaoBase64[letra] for i in range(6): if letraBase64 >> i & 1 == 0: cont += 1 c = 1000000007 print(3**cont % c)
ASSIGN VAR DICT STRING STRING NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
mod = pow(10, 9) + 7 ans = 1 d = {} string = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_" for i in range(64): for j in range(64): if i & j in d: d[i & j] += 1 else: d[i & j] = 1 s = input() for i in s: x = string.index(i) ans = ans % mod * (d[x] % mod) % mod print(ans)
ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
s = input() bit, mp, ID, res, MOD = {}, {}, 0, 1, int(1000000000.0 + 7) for i in range(10): bit[chr(i + ord("0"))] = ID ID += 1 for i in range(26): bit[chr(i + ord("A"))] = ID ID += 1 for i in range(26): bit[chr(i + ord("a"))] = ID ID += 1 bit["-"] = ID bit["_"] = ID + 1 for i in range(64): for j in range(64): mp[i & j] = mp.get(i & j, 0) + 1 for i in s: res = res * mp[bit[i]] % MOD print(res)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR DICT DICT NUMBER NUMBER FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING VAR VAR NUMBER ASSIGN VAR STRING VAR ASSIGN VAR STRING BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
A = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_" Z = [0] * 64 for i in range(64): r = 0 for j in range(64): for k in range(64): if i == j & k: r += 1 Z[i] = r r = 1 for c in input(): r = r * Z[A.index(c)] % 1000000007 print(r)
ASSIGN VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
def main(): s = input() number = "" ans = 1 for c in s: if c >= "0" and c <= "9": number = bin(int(c))[2:] elif c >= "A" and c <= "Z": number = bin(ord(c) - 55)[2:] elif c >= "a" and c <= "z": number = bin(ord(c) - 61)[2:] elif c == "-": number = bin(62)[2:] else: number = bin(63)[2:] if len(number) < 6: diff = 6 - len(number) for i in range(diff): number += "0" for digit in number: if digit == "0": ans = ans * 3 % 1000000007 print(ans) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR STRING FOR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
def count(num): string = bin(num)[2:] return string.count("0") + 6 - len(string) key = [(3 ** count(x)) for x in range(64)] dic = {} for i in range(10): dic[chr(ord("0") + i)] = key[i] for i in range(26): dic[chr(ord("A") + i)] = key[i + 10] for i in range(26): dic[chr(ord("a") + i)] = key[i + 36] dic["-"] = key[62] dic["_"] = key[63] mod = int(1000000000.0) + 7 string = input() ans = 1 for x in string: ans = ans * dic[x] % mod print(ans)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER RETURN BIN_OP BIN_OP FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR BIN_OP VAR NUMBER ASSIGN VAR STRING VAR NUMBER ASSIGN VAR STRING VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
def Bina(n): s = "" while n != 0: s += str(n % 2) n = n // 2 return s def Zeros(b): ones = 0 for i in range(b.__len__()): if "1" == b[i]: ones += 1 return 6 - ones total = 1 alphabet = list("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-") dic = {} num = 0 for i in alphabet: dic[i] = Zeros(Bina(alphabet.index(i))) M = int(1000000000.0 + 7) for i in input(): if i == "_": continue num = dic[i] total = total * 3**num % M print(total)
FUNC_DEF ASSIGN VAR STRING WHILE VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR IF STRING VAR VAR VAR NUMBER RETURN BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR IF VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
print( 3 ** sum( 6 - bin( {"-": 62, "_": 63}.get(c, ord(c) - 7 * (c > "9") - 6 * (c > "Z") - 48) ).count("1") for c in input() ) % 1000000007 )
EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL FUNC_CALL VAR FUNC_CALL DICT STRING STRING NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER VAR STRING BIN_OP NUMBER VAR STRING NUMBER STRING VAR FUNC_CALL VAR NUMBER
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
z = input() l = [] for x in z: if ord(x) >= ord("0") and ord(x) <= ord("9"): l.append(ord(x) - ord("0")) elif ord(x) >= ord("A") and ord(x) <= ord("Z"): l.append(ord(x) - ord("A") + 10) elif ord(x) >= ord("a") and ord(x) <= ord("z"): l.append(ord(x) - ord("a") + 36) elif ord(x) == ord("-"): l.append(62) else: l.append(63) ans = 1 for i in l: unset = 6 - bin(i).count("1") for x in range(unset): ans *= 3 while ans >= 1000000007: ans -= 1000000007 print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR VAR VAR NUMBER WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
word = input() count = 0 for s in word: count = count - 2 if s == "0": count += 8 elif s == "1": count += 7 elif s == "2": count += 7 elif s == "3": count += 6 elif s == "4": count += 7 elif s == "5": count += 6 elif s == "6": count += 6 elif s == "7": count += 5 elif s == "8": count += 7 elif s == "9": count += 6 elif s == "A": count += 6 elif s == "B": count += 5 elif s == "C": count += 6 elif s == "D": count += 5 elif s == "E": count += 5 elif s == "F": count += 4 elif s == "G": count += 7 elif s == "H": count += 6 elif s == "I": count += 6 elif s == "J": count += 5 elif s == "K": count += 6 elif s == "L": count += 5 elif s == "M": count += 5 elif s == "N": count += 4 elif s == "O": count += 6 elif s == "P": count += 5 elif s == "Q": count += 5 elif s == "R": count += 4 elif s == "S": count += 5 elif s == "T": count += 4 elif s == "U": count += 4 elif s == "V": count += 3 elif s == "W": count += 7 elif s == "X": count += 6 elif s == "Y": count += 6 elif s == "Z": count += 5 elif s == "a": count += 6 elif s == "b": count += 5 elif s == "c": count += 5 elif s == "d": count += 4 elif s == "e": count += 6 elif s == "f": count += 5 elif s == "g": count += 5 elif s == "h": count += 4 elif s == "i": count += 5 elif s == "j": count += 4 elif s == "k": count += 4 elif s == "l": count += 3 elif s == "m": count += 6 elif s == "n": count += 5 elif s == "o": count += 5 elif s == "p": count += 4 elif s == "q": count += 5 elif s == "r": count += 4 elif s == "s": count += 4 elif s == "t": count += 3 elif s == "u": count += 5 elif s == "v": count += 4 elif s == "w": count += 4 elif s == "x": count += 3 elif s == "y": count += 4 elif s == "z": count += 3 elif s == "-": count += 3 elif s == "_": count += 2 print(3**count % 1000000007)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
s = input() ans = 1 for x in s: if 48 <= ord(x) <= 57: now = int(x) elif 65 <= ord(x) <= 90: now = ord(x) - 55 elif 97 <= ord(x) <= 122: now = ord(x) - 61 elif x == "-": now = 62 else: now = 63 for i in range(6): if now & 2**i == 0: ans = ans * 3 % (10**9 + 7) print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
s = input().strip() m = {} for i in range(10): m[str(i)] = i for i in range(ord("Z") - ord("A") + 1): m[chr(ord("A") + i)] = 10 + i for i in range(ord("z") - ord("a") + 1): m[chr(ord("a") + i)] = 36 + i m["-"] = 62 m["_"] = 63 zero_bits = 0 for c in s: n = m[c] for i in range(6): zero_bits += int(not n & 1) n >>= 1 res = 1 for z in range(zero_bits): res = res * 3 % 1000000007 print(res)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR BIN_OP NUMBER VAR ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
mod = 10**9 + 7 resp = 1 s = input() def between(n, a, b): return n >= a and n <= b for i in s: if between(i, "0", "9"): i = ord(i) - ord("0") elif between(i, "A", "Z"): i = ord(i) - ord("A") + 10 elif between(i, "a", "z"): i = ord(i) - ord("a") + 36 elif i == "-": i = 62 else: i = 63 for j in range(6): if i >> j & 1 == 0: resp = 3 * resp % mod print(resp)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_DEF RETURN VAR VAR VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR STRING STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR STRING STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER IF FUNC_CALL VAR VAR STRING STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_" mp = {} for i in range(len(chars)): mp[chars[i]] = i zero = 0 s = input() for i in range(len(s)): zero += sum([(i == "0") for i in format(mp[s[i]], "06b")]) print(str(pow(3, zero, int(1000000000.0 + 7))))
ASSIGN VAR STRING ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
def get(s): try: return int(s) except: if s == "-": return 62 elif s == "_": return 63 elif s.isupper(): return ord(s) - 55 else: return ord(s) - 61 arr = [ 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2, 5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, 5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, 4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0, ] st = input() count = 0 for i in range(len(st)): x = get(st[i]) count += arr[x] print(3**count % (10**9 + 7))
FUNC_DEF RETURN FUNC_CALL VAR VAR IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER IF FUNC_CALL VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
f = lambda x: 7 - len(bin(x)) + bin(x).count("0") d = {str(i): f(i) for i in range(10)} for i in range(65, 91): d[chr(i)] = f(i - 55) for i in range(97, 123): d[chr(i)] = f(i - 61) d["_"], d["-"], s, m = 0, 1, 1, 10**9 + 7 for i in input(): s *= 3 ** d[i] s %= m print(s)
ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR STRING VAR STRING VAR VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
s = input() ans = [(0) for i in range(64)] for i in range(len(ans)): temp = bin(i) ans[i] = temp.count("0") - 1 + (6 - (len(temp) - 2)) pri = 10**9 + 7 count = 1 for i in range(len(s)): if s[i].isdigit(): r = bin(int(s[i])) r = r[2:] count = count * pow(3, ans[int(s[i])], pri) count %= pri elif s[i] == "-": count = count * pow(3, ans[62], pri) count %= pri elif s[i] == "_": count = count * pow(3, ans[63], pri) count %= pri elif 65 <= ord(s[i]) <= 91: count = count * pow(3, ans[ord(s[i]) - 65 + 10], pri) count %= pri elif 97 <= ord(s[i]) <= 122: count = count * pow(3, ans[ord(s[i]) - 97 + 36], pri) count %= pri print(count % pri)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR STRING NUMBER BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR IF NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR VAR VAR IF NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_" d = {} cnt = 0 for i in chars: d[i] = cnt cnt += 1 s = input() ans = 1 mod = 10**9 + 7 for i in s: x = bin(d[i]) x = x.split("b") x = x[1] p = 0 for j in x: if j == "0": ans = ans * 3 % mod p += 1 ans = ans * 3 ** (6 - p) % mod print(ans)
ASSIGN VAR STRING ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
d = {} def init(): l = [] for item in range(10): l.append(str(item)) for item in range(ord("A"), ord("Z") + 1): l.append(chr(item)) for item in range(ord("a"), ord("z") + 1): l.append(chr(item)) l.append("-") l.append("_") for i, item in enumerate(l): d[item] = "{0:06b}".format(i).count("0") init() ret = 0 for item in input(): ret += d[item] print(3**ret % (10**9 + 7))
ASSIGN VAR DICT FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL STRING VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
def toi(c): if c >= "0" and c <= "9": return ord(c) - ord("0") if c >= "A" and c <= "Z": return ord(c) - ord("A") + 10 if c >= "a" and c <= "z": return ord(c) - ord("a") + 36 if c == "-": return 62 if c == "_": return 63 s = input() q = [0] * 64 for i in range(64): for j in range(64): q[i & j] += 1 r = 1 for c in s: r *= q[toi(c)] r %= 1000000007 print(r)
FUNC_DEF IF VAR STRING VAR STRING RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING IF VAR STRING VAR STRING RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER IF VAR STRING VAR STRING RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
ls = [0] * 100010 for i in range(64): for j in range(64): ls[i & j] += 1 s = input() ss = 1 for i in s: if ord(i) >= ord("a") and ord(i) <= ord("z"): ss *= ls[ord(i) - ord("a") + 36] elif ord(i) >= ord("A") and ord(i) <= ord("Z"): ss *= ls[ord(i) - ord("A") + 10] elif ord(i) >= ord("0") and ord(i) <= ord("9"): ss *= ls[ord(i) - ord("0")] elif i == "-": ss *= ls[62] elif i == "_": ss *= ls[63] ss %= 10**9 + 7 print(ss)
ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING IF VAR STRING VAR VAR NUMBER IF VAR STRING VAR VAR NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
x = 10**9 + 7 y = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_" s = input() count = 0 for i in s: b = bin(int(y.find(i)))[2:] count += b.zfill(6).count("0") print(3**count % x)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
def main(): l = [0] * 123 for i, c in enumerate( "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_" ): l[ord(c)] = "{:0>6b}".format(i).count("0") print(pow(3, sum(l[ord(c)] for c in input()), 1000000007)) main()
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL STRING VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
d = [0] * 64 for i in range(64): for j in range(64): d[i & j] += 1 s = input() ans = 1 for i in s: if "0" <= i <= "9": ans *= d[int(i)] elif "A" <= i <= "Z": ans *= d[ord(i) - ord("A") + 10] elif "a" <= i <= "z": ans *= d[ord(i) - ord("a") + 10 + 26] elif i == "-": ans *= d[62] elif i == "_": ans *= d[63] ans %= 10**9 + 7 print(ans)
ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF STRING VAR STRING VAR VAR FUNC_CALL VAR VAR IF STRING VAR STRING VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER IF STRING VAR STRING VAR VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER NUMBER IF VAR STRING VAR VAR NUMBER IF VAR STRING VAR VAR NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
all = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_" s = input() ans = 1 for c in s: pos = all.find(c) cnt = int(0) cnt += (pos + 1) % 2 pos //= 2 cnt += (pos + 1) % 2 pos //= 2 cnt += (pos + 1) % 2 pos //= 2 cnt += (pos + 1) % 2 pos //= 2 cnt += (pos + 1) % 2 pos //= 2 cnt += (pos + 1) % 2 pos //= 2 for i in range(0, cnt): ans *= 3 ans %= 1000000007 print(ans)
ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
s = input() m = dict() a = dict() m["-"] = 62 m["_"] = 63 for i in range(10): m[str(i)] = i for i in range(26): m[chr(65 + i)] = 10 + i for i in range(26): m[chr(97 + i)] = 36 + i for x in range(64): for j in range(64): a[x & j] = a.get(x & j, 0) + 1 ans = 1 for c in s: ans = ans * a.get(m[c], 0) % 1000000007 print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
word = input() mod = 1000000007 res = 1 for i in word: if ord(i) >= 48 and ord(i) <= 57: i = ord(i) - 48 elif ord(i) >= 65 and ord(i) <= 90: i = ord(i) - 55 elif ord(i) >= 97 and ord(i) <= 122: i = ord(i) - 61 elif ord(i) == 45: i = 62 else: i = 63 for j in range(6): if i >> j & 1 == 0: res = res * 3 % mod print(res)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
num = list(range(10)) bword = list(range(10, 36)) sword = list(range(36, 62)) bigconst = 65 smallconst = 97 ans = 1 s = input() for i in range(len(s)): if s[i] >= "0" and s[i] <= "9": k = int(s[i]) elif s[i] >= "A" and s[i] <= "Z": k = bword[ord(s[i]) - bigconst] elif s[i] >= "a" and s[i] <= "z": k = sword[ord(s[i]) - smallconst] elif s[i] == "-": k = 62 else: k = 63 k = bin(k) ans = ans * 3 ** (k.count("0") - 1 + (6 - (len(k) - 2))) % (10**9 + 7) % (10**9 + 7) print(ans % (10**9 + 7))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR STRING NUMBER BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 10^9 + 7. To represent the string as a number in numeral system with base 64 Vanya uses the following rules: digits from '0' to '9' correspond to integers from 0 to 9; letters from 'A' to 'Z' correspond to integers from 10 to 35; letters from 'a' to 'z' correspond to integers from 36 to 61; letter '-' correspond to integer 62; letter '_' correspond to integer 63. -----Input----- The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. -----Output----- Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 10^9 + 7. -----Examples----- Input z Output 3 Input V_V Output 9 Input Codeforces Output 130653412 -----Note----- For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: z&_ = 61&63 = 61 = z _&z = 63&61 = 61 = z z&z = 61&61 = 61 = z
def conv(d): if "0" <= d <= "9": return int(d) if "A" <= d <= "Z": return 10 + ord(d) - ord("A") if "a" <= d <= "z": return 36 + ord(d) - ord("a") if d == "-": return 62 return 63 cnt = [0] * 64 for a in range(64): for b in range(64): cnt[a & b] += 1 ans = 1 for d in input(): ans = ans * cnt[conv(d)] % (10**9 + 7) print(ans)
FUNC_DEF IF STRING VAR STRING RETURN FUNC_CALL VAR VAR IF STRING VAR STRING RETURN BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR STRING IF STRING VAR STRING RETURN BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR STRING IF VAR STRING RETURN NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR