description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) l = [int(e.strip()) for e in input().strip().split()] ans = [] a = {} for pp in l: if pp in a: a[pp] += 1 else: a[pp] = 1 mx = 0 id = 0 for i, j in a.items(): if j > mx: mx = j id = i for i in range(len(l)): if l[i] == id: id = i break for i in range(id + 1, len(l)): if l[i] > l[id]: ans.append((2, i, i - 1)) elif l[i] < l[id]: ans.append((1, i, i - 1)) for i in range(id - 1, -1, -1): if l[i] > l[id]: ans.append((2, i, i + 1)) elif l[i] < l[id]: ans.append((1, i, i + 1)) print(len(ans)) for pp in ans: print(pp[0], pp[1] + 1, pp[2] + 1)
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 ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
from sys import stdin def mostFrequent(arr, n): Hash = dict() for i in range(n): if arr[i] in Hash.keys(): Hash[arr[i]] += 1 else: Hash[arr[i]] = 1 max_count = 0 res = -1 for i in Hash: if max_count < Hash[i]: res = i max_count = Hash[i] return res input = stdin.readline n = int(input()) l = list(map(int, input().split())) s = set(l) x = mostFrequent(l, n) a = [] ind = l.index(x) for i in range(0, ind): if l[ind - i - 1] < x: a.append([1, ind - i, ind - i + 1]) elif l[ind - i - 1] > x: a.append([2, ind - i, ind - i + 1]) for i in range(ind + 1, n): if l[i] < x: a.append([1, i + 1, i]) elif l[i] > x: a.append([2, i + 1, i]) print(len(a)) for i in a: print(*i)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR RETURN VAR ASSIGN 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 VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) a = list(map(int, input().split())) ints = [0] * (2 * 10**5 + 1) max_ = 0 argmax = 0 for i in a: ints[i] += 1 if ints[i] > max_: max_ = ints[i] argmax = i print(n - ints[argmax]) flag = True for i, value in enumerate(a): if value == argmax and flag: flag = False j = i - 1 while j >= 0 and a[j] != argmax: if a[j] < argmax: print(1, j + 1, j + 2) else: print(2, j + 1, j + 2) j -= 1 if not flag: if value != argmax: if a[i] < argmax: print(1, i + 1, i) else: print(2, i + 1, i)
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 BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR IF VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) arr = list(map(int, input().split())) el = -1 max0 = 0 cnt = [0] * 1000000 for el in arr: cnt[el] += 1 for i in range(1000000): if cnt[i] > max0: el = i max0 = cnt[i] for i in range(n): if arr[i] == el: pos = i break print(n - cnt[el]) for i in range(pos, n - 1): if arr[i + 1] != el: if arr[i + 1] > el: print(2, i + 1 + 1, i + 1) else: print(1, i + 1 + 1, i + 1) for i in range(pos, 0, -1): if arr[i - 1] != el: if arr[i - 1] > el: print(2, i - 1 + 1, i + 1) else: print(1, i - 1 + 1, i + 1)
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 BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) a = list(map(int, input().split())) cnt = [0] * (2 * 10**5 + 1) ind = [0] * (2 * 10**5 + 1) for i in range(n): cnt[a[i]] += 1 ind[a[i]] = i m = max(cnt) i_m = ind[cnt.index(m)] distinct = n - m print(distinct) i = i_m for j in range(i_m + 1, n): if a[j] != a[i]: if a[j] > a[i]: print(2, j + 1, j) a[j] = a[i] else: print(1, j + 1, j) a[j] = a[i] for j in range(i_m - 1, -1, -1): if a[j] != a[i]: if a[j] > a[i]: print(2, j + 1, j + 2) a[j] = a[i] else: print(1, j + 1, j + 2) a[j] = a[i]
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 BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
def solve(a): d = {} for i in a: if i in d: d[i] += 1 else: d[i] = 1 m = 0 elem = 0 for i in d: if d[i] > m: m = d[i] elem = i print(len(a) - m) start = -1 for i in range(len(a)): if a[i] == elem: start = i break for i in range(start - 1, -1, -1): if a[i] < elem: print("1 " + str(i + 1) + " " + str(i + 2)) else: print("2 " + str(i + 1) + " " + str(i + 2)) for i in range(start + 1, len(a)): if a[i] != elem: if a[i] < elem: print("1 " + str(i + 1) + " " + str(i)) else: print("2 " + str(i + 1) + " " + str(i)) n = int(input()) x = input().split() a = [] for i in x: a.append(int(i)) solve(a)
FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) a = list(map(int, input().split())) d = {} for i in a: if d.get(i) is not None: d[i] += 1 else: d[i] = 1 max_k = -1 max_v = -1 for k in d: if d[k] > max_v: max_v = d[k] max_k = k idx = -1 for id_, i in enumerate(a): if i == max_k: idx = id_ break ops = [] id_ = idx while id_ > 0: if a[id_] == a[id_ - 1]: id_ -= 1 continue ops.append(" ".join(["1" if a[id_] > a[id_ - 1] else "2", str(id_), str(id_ + 1)])) a[id_ - 1] = a[id_] id_ -= 1 id_ = idx while id_ < n - 1: if a[id_] == a[id_ + 1]: id_ += 1 continue ops.append( " ".join(["1" if a[id_] > a[id_ + 1] else "2", str(id_ + 2), str(id_ + 1)]) ) a[id_ + 1] = a[id_] id_ += 1 print(len(ops)) for i in ops: print(i)
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 FOR VAR VAR IF FUNC_CALL VAR VAR NONE VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR WHILE VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING LIST VAR VAR VAR BIN_OP VAR NUMBER STRING STRING FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING LIST VAR VAR VAR BIN_OP VAR NUMBER STRING STRING FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
def check(line): lst = sorted(line, key=lambda s: int(s)) for i in range(2, len(lst)): if lst[i] == lst[i - 2]: return False return lst def main(): n_row = input() line = input() num = line.strip(" ").split(" ") num = [int(i) for i in num] dic = {} for i in num: if i in dic.keys(): dic[i] += 1 else: dic[i] = 1 key, cnt = 0, 0 for i, j in dic.items(): if j > cnt: key, cnt = i, j idx = 0 for i, j in enumerate(num): if j == key: idx = i break i = idx - 1 answer = [] while i >= 0: if num[i] != key: if num[i] < key: answer.append((1, i + 1, i + 2)) elif num[i] > key: answer.append((2, i + 1, i + 2)) i -= 1 i = idx + 1 while i < len(num): if num[i] < key: answer.append((1, i + 1, i)) elif num[i] > key: answer.append((2, i + 1, i)) i += 1 print(len(answer)) for item in answer: print(item[0], item[1], item[2]) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER IF VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
N = int(input()) a = list(map(int, input().split())) ma = {} for n in a: if n in ma: ma[n] += 1 else: ma[n] = 1 le = -1 lo = 0 for k in ma: if ma[k] >= lo: le = k lo = ma[k] df = N - lo if df == 0: print(df) exit(0) moves = [] print(df) for i in range(N): if a[i] < le: moves.append((i + 1, 1)) elif a[i] > le: moves.append((i + 1, 2)) else: for m in reversed(moves): print(m[1], m[0], m[0] + 1) moves.clear() for m in moves: print(m[1], m[0], m[0] - 1)
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 FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) num = [int(x) for x in input().split(" ")] help = dict() used = set() for i in range(n): if num[i] not in used: help[num[i]] = 1 used.add(num[i]) else: help[num[i]] += 1 w = 0 for i in range(n): c = help[num[i]] if c > w: w = c ans = num[i] h = i ans = num[h] print(n - w) for i in range(h, -1, -1): if num[i] > ans: print(2, i + 1, i + 2) elif num[i] < ans: print(1, i + 1, i + 2) for i in range(h, n, 1): if num[i] > ans: print(2, i + 1, i) elif num[i] < ans: print(1, i + 1, i)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = input() a = input().split() a = [int(i) for i in a] counter = dict() for i in a: if i in counter: counter[i] = counter[i] + 1 else: counter[i] = 1 _max = -1 target = 0 for key, value in counter.items(): if value > _max: target = key _max = value position = [] for i, value in enumerate(a): if value == target: position.append(i) k = len(a) - _max print(k) if k > 0: for i in range(position[0] - 1, -1, -1): if a[i] > target: print("2 {} {}".format(i + 1, i + 2)) else: print("1 {} {}".format(i + 1, i + 2)) for i in range(position[0], position[-1]): if a[i] == target: continue elif a[i] > target: print("2 {} {}".format(i + 1, i)) else: print("1 {} {}".format(i + 1, i)) for i in range(position[-1] + 1, len(a)): if a[i] > target: print("2 {} {}".format(i + 1, i)) else: print("1 {} {}".format(i + 1, i))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR NUMBER VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) arr = [int(x) for x in input().split()] cnt = {} for x in arr: if x in cnt: cnt[x] += 1 else: cnt[x] = 1 mx_num, mx_cnt = max(cnt.items(), key=lambda x: x[1]) first_index = 0 for i, x in enumerate(arr): if mx_num == x: first_index = i break print(n - mx_cnt) for i in range(first_index - 1, -1, -1): j = i + 1 if mx_num == arr[i]: continue if mx_num > arr[i]: t = 1 else: t = 2 print(t, i + 1, j + 1) for i in range(first_index + 1, n): j = i - 1 if mx_num == arr[i]: continue if mx_num > arr[i]: t = 1 else: t = 2 print(t, i + 1, j + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
def counter(l, n): maxi, first_index, num = 0, 0, 0 d = {} for i in range(n): try: d[l[i]][0] += 1 except: d[l[i]] = [1, i + 1] if d[l[i]][0] > maxi: maxi = d[l[i]][0] num = l[i] first_index = d[l[i]][1] return [maxi, first_index, num] n = int(input()) l = list(map(int, input().split())) maxi, first_index, num = counter(l, n) print(n - maxi) for i in range(first_index - 1, 0, -1): if l[i - 1] < num: print("1", i, i + 1) elif l[i - 1] > num: print("2", i, i + 1) for i in range(first_index, n): if l[i] < num: print("1", i + 1, i) elif l[i] > num: print("2", i + 1, i)
FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR LIST NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER RETURN LIST VAR 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 VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING BIN_OP VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING BIN_OP VAR NUMBER VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
import sys input = sys.stdin.readline N = int(input()) a = list(map(int, input().split())) cnt = [0] * 200005 M = 0 key = 0 for i in a: cnt[i] += 1 if key < cnt[i]: M = i key = cnt[i] print(N - key) stack = [] idx = 0 for i in a: if i != M: stack.append(i) else: break idx += 1 save = idx while stack: print(2 if stack.pop() > M else 1, idx, idx + 1) idx -= 1 for i in range(save, N): if a[i] != M: print(2 if a[i] > M else 1, i + 1, i)
IMPORT ASSIGN 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) a = list(map(int, input().split())) pa = [0] * 200050 mx = -1 ele = -1 for i in a: pa[i] += 1 for i in range(len(pa)): if pa[i] > mx: mx = pa[i] ele = i t = len(a) - mx fi = a.index(ele) ite = fi - 1 print(t) while ite >= 0: if a[ite] > ele: print(2, ite + 1, ite + 2) else: print(1, ite + 1, ite + 2) ite -= 1 ite = fi while ite < len(a) - 1: if a[ite + 1] > ele: print(2, ite + 2, ite + 1) elif a[ite + 1] < ele: print(1, ite + 2, ite + 1) ite += 1
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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) a = [int(i) for i in input().split()] counts = {} max_cnt = 0 max_value = -1 indd = -1 for ij in range(n): i = a[ij] if i not in counts: counts[i] = 0 counts[i] += 1 if counts[i] > max_cnt: max_cnt = counts[i] max_value = i indd = ij print(n - max_cnt) for i in range(indd + 1, n): if a[i] != max_value: if a[i] < max_value: print(1, i + 1, i) else: print(2, i + 1, i) for i in range(indd - 1, -1, -1): if a[i] != max_value: if a[i] < max_value: print(1, i + 1, i + 2) else: print(2, i + 1, i + 2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) a = [int(s) for s in input().split()] cts = {} maxct = 1 maxn = a[0] for ai in a: cts[ai] = cts.get(ai, 0) + 1 if cts[ai] > maxct: maxct = cts[ai] maxn = ai print(n - maxct) def sweep(st, en, step): for i in range(st, en, step): if a[i + step] < a[i]: print(1, i + step + 1, i + 1) elif a[i + step] > a[i]: print(2, i + step + 1, i + 1) a[i + step] = a[i] sti = a.index(maxn) sweep(sti, 0, -1) sweep(sti, n - 1, 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) a = list(map(int, input().split())) cnt = [0] * 200001 for x in a: cnt[x] += 1 mx = max(cnt) val = -1 for x in a: if cnt[x] == mx: val = x index = -1 for i, x in enumerate(a): if x == val: index = i break answer = [] for i in reversed(range(index)): if a[i] > val: answer.append((2, i, i + 1)) elif a[i] < val: answer.append((1, i, i + 1)) for i in range(index + 1, n): if a[i] > val: answer.append((2, i, i - 1)) elif a[i] < val: answer.append((1, i, i - 1)) print(len(answer)) for a, b, c in answer: print(a, b + 1, c + 1)
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 NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) In = input().split() arr = [] dicr = {} for i in range(n): arr.append(int(In[i])) if dicr.get(int(In[i])): dicr[int(In[i])] += 1 else: dicr[int(In[i])] = 1 maxValue = max(dicr.keys(), key=lambda k: dicr[k]) print(n - dicr[maxValue]) for i in range(arr.index(maxValue), 0, -1): if maxValue != arr[i - 1]: if maxValue > arr[i - 1]: print(1, i, i + 1) else: print(2, i, i + 1) for i in range(arr.index(maxValue) - 1, n - 1): if maxValue != arr[i + 1]: if maxValue > arr[i + 1]: print(1, i + 2, i + 1) else: print(2, i + 2, i + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
d = {} n = int(input()) l = list(map(int, input().split())) ll = sorted(l) mid = n // 2 li = [] mx = -1 for i in l: d[i] = d.get(i, 0) + 1 for i in d: if d[i] > mx: mx = d[i] med = i for i in range(n): if l[i] == med: ind = i break for i in range(ind - 1, -1, -1): if l[i] > l[i + 1]: li.append((2, i + 1, i + 2)) elif l[i] < l[i + 1]: li.append((1, i + 1, i + 2)) l[i] = med for i in range(ind + 1, n): if l[i] > l[i - 1]: li.append((2, i + 1, i)) elif l[i] < l[i - 1]: li.append((1, i + 1, i)) l[i] = med print(len(li)) for i in li: print(*i)
ASSIGN VAR DICT 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 VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) arr = [int(x) for x in input().split()] cnt = list(sorted(arr)) same_val = cnt[0] same_num = 1 max_same_num = 1 for i in range(1, n): if cnt[i] == cnt[i - 1]: same_num += 1 else: same_num = 1 if same_num > max_same_num: max_same_num = same_num same_val = cnt[i] index = arr.index(same_val) print(n - max_same_num) for i in range(index - 1, -1, -1): if arr[i] == same_val: continue if arr[i] < same_val: print(1, i + 1, i + 2) if arr[i] > same_val: print(2, i + 1, i + 2) for i in range(index + 1, n): if arr[i] == same_val: continue if arr[i] < same_val: print(1, i + 1, i) if arr[i] > same_val: print(2, i + 1, i)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
a = int(input()) s = [int(x) for x in input().split()] d = {} n = 0 for i in range(a): d[s[i]] = 0 for i in s: d[i] += 1 x = 0 it = 0 for i in d: if d[i] > it: x = i it = d[i] c = s.index(x) for i in s: if i != x: n += 1 print(n) for i in range(c - 1, -1, -1): if s[i] < x: print(f"1 {i + 1} {i + 2}") elif s[i] > x: print(f"2 {i + 1} {i + 2}") for i in range(c + 1, a): if s[i] < x: print(f"1 {i + 1} {i}") elif s[i] > x: print(f"2 {i + 1} {i}")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR STRING BIN_OP VAR NUMBER STRING BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR STRING BIN_OP VAR NUMBER STRING BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING BIN_OP VAR NUMBER STRING VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING BIN_OP VAR NUMBER STRING VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
N = int(input()) A = [int(a) for a in input().split()] B = [0] * (2 * 10**5 + 10) for a in A: B[a] += 1 ma = 0 mai = 0 for i in range(len(B)): if B[i] > ma: ma = B[i] maa = i for i in range(N): if A[i] == maa: mai = i break print(N - ma) for i in range(mai)[::-1]: if A[i] < maa: print(1, i + 1, i + 2) elif A[i] > maa: print(2, i + 1, i + 2) for i in range(mai + 1, N): if A[i] < maa: print(1, i + 1, i) elif A[i] > maa: print(2, i + 1, i)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
import sys n = int(input()) arr = list(map(int, input().split())) noCounts = [0] * (2 * 10**5 + 1) for i in arr: noCounts[i] += 1 tmp = max(noCounts) print(n - tmp) x = noCounts.index(tmp) a = arr.index(x) for i in range(a, 0, -1): if arr[i] < arr[i - 1]: print(2, i, i + 1) arr[i - 1] = arr[i] else: print(1, i, i + 1) arr[i - 1] = arr[i] for i in range(a, n - 1): if arr[i] < arr[i + 1]: print(2, i + 2, i + 1) arr[i + 1] = arr[i] elif arr[i] == arr[i + 1]: continue else: print(1, i + 2, i + 1) arr[i + 1] = arr[i]
IMPORT 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 BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) a = list(map(int, input().split())) d = {} mx = 0 q = 0 ans = [] for i in a: if i not in d: d[i] = 1 else: d[i] += 1 if d[i] > q: q = d[i] mx = i for i in range(n): if a[i] == mx: ind = i break print(n - d[mx]) for i in range(ind - 1, -1, -1): if mx > a[i]: print(1, i + 1, i + 2) elif mx < a[i]: print(2, i + 1, i + 2) for i in range(ind + 1, n): if mx > a[i]: print(1, i + 1, i) elif mx < a[i]: print(2, i + 1, i)
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 ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) a = list(map(int, input().split())) g = {} for q in a: g[q] = g.get(q, 0) + 1 max_quantity = max(g, key=lambda x: g[x]) print(len(a) - g[max_quantity]) index_max = a.index(max_quantity) for q in range(index_max - 1, -1, -1): if a[q] > max_quantity: print(2, q + 1, q + 2) else: print(1, q + 1, q + 2) for q in range(index_max + 1, len(a)): if a[q] > max_quantity: print(2, q + 1, q) elif a[q] < max_quantity: print(1, q + 1, q)
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 FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
def main(): n = int(input()) arr = list(map(int, input().split())) dct = {} k = -1 m = 0 for i in range(n): try: dct[arr[i]] += 1 except: dct[arr[i]] = 1 if dct[arr[i]] > m: m = dct[arr[i]] k = arr[i] print(n - m) for i in range(n): if arr[i] == k: for j in range(i - 1, -1, -1): if arr[j] > k: print(2, j + 1, j + 2) else: print(1, j + 1, j + 2) break while i != n: if arr[i] > k: print(2, i + 1, i) if arr[i] < k: print(1, i + 1, i) i += 1 return 0 main()
FUNC_DEF 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) l = [*map(int, input().split())] cnt = [0] * 200001 for i in l: cnt[i] += 1 mx = num = -1 for i in range(200001): if mx < cnt[i]: mx = cnt[i] num = i idx = -1 for i in range(n): if num == l[i]: idx = i break res = [] for i in range(idx - 1, -1, -1): if l[i] < l[i + 1]: res.append([1, i, i + 1]) elif l[i] > l[i + 1]: res.append([2, i, i + 1]) l[i] = l[i + 1] for i in range(idx + 1, n): if l[i] < l[i - 1]: res.append([1, i, i - 1]) elif l[i] > l[i - 1]: res.append([2, i, i - 1]) l[i] = l[i - 1] print(len(res)) for i in res: print(i[0], i[1] + 1, i[2] + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) a = list(map(int, input().split())) count = {} for i in a: count[i] = count.get(i, 0) + 1 el = 0 ma = 0 for k in count: if count[k] > ma: ma = count[k] el = k ind = 0 for i in range(len(a)): if a[i] == el: ind = i break if len(count) == 1: print(0) else: print(len(a) - count[el]) j = ind for i in range(ind - 1, -1, -1): if a[i] != el: if a[i] < el: print(1, i + 1, j + 1) else: print(2, i + 1, j + 1) j = i j = ind for i in range(ind + 1, len(a)): if a[i] != el: if a[i] < el: print(1, i + 1, j + 1) else: print(2, i + 1, j + 1) j = i
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 FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) l = [int(i) for i in input().split(" ")] count = {} for i in l: if i in count: count[i] += 1 else: count[i] = 1 count_to_list = [(count[k], k) for k in count] count_to_list.sort(reverse=True) most_frequent_count, most_frequent = count_to_list[0] move_count = n - most_frequent_count print(move_count) first_most_freq = None for i, v in enumerate(l): if v == most_frequent: first_most_freq = i break for i in range(first_most_freq - 1, -1, -1): a = l[i] if a > most_frequent: op = 2 else: op = 1 print("%s %s %s" % (op, i + 1, i + 2)) for i in range(first_most_freq + 1, n): a = l[i] if a == most_frequent: continue if a > most_frequent: op = 2 else: op = 1 print("%s %s %s" % (op, i + 1, i))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NONE FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR BIN_OP VAR NUMBER VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) l = list(map(int, input().split())) dict = {} for i in l: try: dict[i] += 1 except: dict[i] = 1 maks = 0 eleman = 0 for i in dict: if dict[i] > maks: maks = dict[i] eleman = i indeks = [] for i in range(n): if l[i] == eleman: indeks.append(i) print(n - maks) k = indeks[0] while k - 1 > -1: if l[k - 1] < eleman: print(1, k, k + 1) elif l[k - 1] > eleman: print(2, k, k + 1) k -= 1 for i in range(1, maks): t = indeks[i] while t - 1 > indeks[i - 1]: if l[t - 1] < eleman: print(1, t, t + 1) elif l[t - 1] > eleman: print(2, t, t + 1) t -= 1 k = indeks[-1] while k + 1 < n: if l[k + 1] < eleman: print(1, k + 2, k + 1) elif l[k + 1] > eleman: print(2, k + 2, k + 1) k += 1
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 FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR WHILE BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER WHILE BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
def most_freq(a): s = {} for i in range(len(a)): s[a[i]] = 0 for i in range(len(a)): s[a[i]] += 1 l = 0 d = 0 for key in s: if s[key] > l: l = s[key] d = key return d n = int(input()) a = list(map(int, input().split())) s = most_freq(a) p = a.index(s) z = [] for i in range(p, len(a) - 1): if a[i + 1] > a[i]: a[i + 1] = s z.append([2, i + 2, i + 1]) elif a[i + 1] < a[i]: a[i + 1] = s z.append([1, i + 2, i + 1]) for i in range(p, 0, -1): if a[i] > a[i - 1]: a[i - 1] = s z.append([1, i, i + 1]) elif a[i] < a[i - 1]: a[i - 1] = s z.append([2, i, i + 1]) print(len(z)) for i in range(len(z)): print(*z[i])
FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR RETURN 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 VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR LIST NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR LIST NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
num = int(input().strip()) numbers = [int(i) for i in input().strip().split()] num_dict = dict() for i in numbers: if i not in num_dict: num_dict[i] = 1 else: num_dict[i] += 1 max_number = 0 max_index = 0 for i in num_dict: if num_dict[i] > max_number: max_index = i max_number = num_dict[i] for i in range(num): if numbers[i] == max_index: index = i break left = index - 1 right = index + 1 ans = [] while left >= 0 or right < num: if left >= 0: if numbers[left] != max_index: if numbers[left] < max_index: ans.append((1, left + 1, left + 1 + 1)) else: ans.append((2, left + 1, left + 1 + 1)) left -= 1 if right < num: if numbers[right] != max_index: if numbers[right] < max_index: ans.append((1, right + 1, right - 1 + 1)) else: ans.append((2, right + 1, right - 1 + 1)) right += 1 print(len(ans)) for i in ans: print(" ".join(str(j) for j in i))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER VAR VAR IF VAR NUMBER IF VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR IF VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) s = list(map(int, input().split())) cnt = dict() for x in s: if x not in cnt: cnt[x] = 1 else: cnt[x] += 1 mx = -1 x = -1 for k in cnt: if mx < cnt[k]: mx = cnt[k] x = k print(n - mx) for i in range(s.index(x) - 1, -1, -1): if s[i] > x: print(2, i + 1, i + 2) s[i] = x elif s[i] < x: print(1, i + 1, i + 2) s[i] = x for j in range(s.index(x) + 1, len(s)): if s[j] > x: print(2, j + 1, j) s[j] = x elif s[j] < x: print(1, j + 1, j) s[j] = x
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 FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) A = list(map(int, input().split())) A = [-1] + A vec = [[] for i in range(200005)] for i in range(1, n + 1): vec[A[i]].append(i) mx, num = 0, 0 for i in range(200005): mx = max(mx, len(vec[i])) if mx == len(vec[i]): num = i ans = [] for i in range(vec[num][0] - 1, 0, -1): if A[i] < A[i + 1]: ans.append([1, i, i + 1]) else: ans.append([2, i, i + 1]) A[i] = A[i + 1] for i in range(2, n + 1): if A[i] == A[i - 1]: continue elif A[i] < A[i - 1]: ans.append([1, i, i - 1]) else: ans.append([2, i, i - 1]) A[i] = A[i - 1] print(len(ans)) for i in ans: print(i[0], i[1], i[2])
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 LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) l = list(map(int, input().split())) hash = {} max = 0 ans = 0 for i in l: try: hash[i] except: hash[i] = 1 else: hash[i] += 1 if hash[i] > max: max = hash[i] ans = i posn = [] for i in range(n): if l[i] == ans: posn.append(i) z = posn[0] print(n - len(posn)) for i in range(z, n - 1): if l[i + 1] != ans: if l[i + 1] > ans: print(2, i + 2, i + 1) else: print(1, i + 2, i + 1) l[i + 1] = ans for i in range(z, 0, -1): if l[i - 1] != ans: if l[i - 1] > ans: print(2, i, i + 1) else: print(1, i, i + 1) l[i - 1] = ans
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 ASSIGN VAR NUMBER FOR VAR VAR EXPR VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
def _f(n, arr): number_count_map = {} for a in arr: if number_count_map.get(a, None) is None: number_count_map[a] = 1 else: number_count_map[a] += 1 max_number = list(number_count_map.keys())[0] for dict_key in list(number_count_map.keys()): if number_count_map[dict_key] > number_count_map[max_number]: max_number = dict_key result = [] empties = [] if arr[0] != max_number: empties.append([0, 0]) for i in range(1, len(arr)): if arr[i] == max_number and arr[i - 1] != max_number: empties[-1][1] = i - 1 elif arr[i] != max_number and arr[i - 1] != max_number: empties[-1][1] = i elif arr[i] != max_number and arr[i - 1] == max_number: empties.append([i, i]) for e in empties: try: arr.index(max_number, e[1]) for i in reversed(range(e[0], e[1] + 1)): if arr[i] > max_number: result.append((2, i + 1, i + 2)) elif arr[i] < max_number: result.append((1, i + 1, i + 2)) except: for i in range(e[0], e[1] + 1): if arr[i] > max_number: result.append((2, i + 1, i)) elif arr[i] < max_number: result.append((1, i + 1, i)) return result def f(n, arr): result = _f(n, arr) print(len(result)) for r in result: print("".join(str(e) + " " for e in r)) n = int(input()) arr = list(map(int, input().split())) f(n, arr)
FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF FUNC_CALL VAR VAR NONE NONE ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST IF VAR NUMBER VAR EXPR FUNC_CALL VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR LIST VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP FUNC_CALL VAR VAR STRING VAR 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
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
N = int(input()) arr = input() arr = [int(x) for x in arr.split(" ")] freq = {} max_f = 0 max_num = 0 for num in arr: if num not in freq: freq[num] = 1 else: freq[num] += 1 if freq[num] > max_f: max_num = num max_f = freq[num] target = max_num tar_idx = -1 equ = N - max_f for i in range(N): if arr[i] == target: tar_idx = i break print(equ) for i in range(tar_idx, N): if arr[i] < target: print("1", str(i + 1), str(i), sep=" ") if arr[i] > target: print("2", str(i + 1), str(i), sep=" ") for i in range(tar_idx - 1, -1, -1): if arr[i] < target: print("1", str(i + 1), str(i + 2), sep=" ") if arr[i] > target: print("2", str(i + 1), str(i + 2), sep=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR STRING IF VAR VAR VAR EXPR FUNC_CALL VAR STRING FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR STRING FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF VAR VAR VAR EXPR FUNC_CALL VAR STRING FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER STRING
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) arr = list(map(int, input().split())) cnts = [0] * 200001 best, best_cnt, idx = None, 0, None for i in range(n): cnts[arr[i]] += 1 if cnts[arr[i]] > best_cnt: best, best_cnt, idx = arr[i], cnts[arr[i]], i moves = [] for i in range(idx, 0, -1): if arr[i - 1] < best: moves.append((1, i, i + 1)) elif arr[i - 1] > best: moves.append((2, i, i + 1)) for i in range(idx, n - 1): if arr[i + 1] > best: moves.append((2, i + 2, i + 1)) elif arr[i + 1] < best: moves.append((1, i + 2, i + 1)) print(len(moves)) for move in moves: print(*move)
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 NUMBER ASSIGN VAR VAR VAR NONE NUMBER NONE FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) a = list(map(int, input().split())) d = {} for c in a: d[c] = d.get(c, 0) + 1 km = a[0] for c in d: if d[c] > d[km]: km = c pos = 0 for i in range(n): if a[i] == km: pos = i break print(n - d[km]) for i in range(pos + 1, n): if a[i] > km: print(2, i + 1, i) elif a[i] < km: print(1, i + 1, i) for i in range(pos - 1, -1, -1): if a[i] > km: print(2, i + 1, i + 2) elif a[i] < km: print(1, i + 1, i + 2)
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 FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) v = [int(x) for x in input().split()] hist = {} for x in v: hist.setdefault(x, 0) hist[x] += 1 target = max(hist, key=lambda x: hist[x]) print(len(v) - hist[target]) start = v.index(target) for i in range(start, len(v)): if v[i] == target: continue if v[i] < target: op = 1 else: op = 2 v[i] = target print("{} {} {}".format(op, i + 1, i)) for i in range(start, -1, -1): if v[i] == target: continue if v[i] < target: op = 1 else: op = 2 v[i] = target print("{} {} {}".format(op, i + 1, i + 2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) a = [int(x) for x in input().split()] d = {} for ai in a: d[ai] = d[ai] + 1 if d.get(ai) else 1 mai = max(d, key=d.get) mi = a.index(mai) s = [] x = 1 while True: f1 = False f2 = False if mi - x >= 0: f1 = True if a[mi - x] > mai: s.append(f"2 {mi - x + 1} {mi - x + 2}") else: s.append(f"1 {mi - x + 1} {mi - x + 2}") a[mi - x] = mai if mi + x < n: f2 = True if a[mi + x] > mai: s.append(f"2 {mi + x + 1} {mi + x}") elif a[mi + x] < mai: s.append(f"1 {mi + x + 1} {mi + x}") a[mi + x] = mai if not f1 and not f2: break else: x += 1 print(len(s)) for each in s: print(each)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING BIN_OP BIN_OP VAR VAR NUMBER STRING BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING BIN_OP BIN_OP VAR VAR NUMBER STRING BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING BIN_OP BIN_OP VAR VAR NUMBER STRING BIN_OP VAR VAR IF VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING BIN_OP BIN_OP VAR VAR NUMBER STRING BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
def mp(): return map(int, input().split()) n = int(input()) a = list(mp()) c = [0] * (2 * 10**5 + 1) for i in a: c[i] += 1 idx = 0 for i in range(2 * 10**5 + 1): if c[i] > c[idx]: idx = i for i in range(n): if a[i] == idx: idx = i break ans = [] for i in range(idx - 1, -1, -1): if a[i] == a[idx]: continue if a[i] > a[idx]: ans.append([2, i + 1, i + 2]) else: ans.append([1, i + 1, i + 2]) for i in range(idx + 1, n): if a[i] == a[idx]: continue if a[i] > a[idx]: ans.append([2, i + 1, i]) else: ans.append([1, i + 1, i]) print(len(ans)) for i in ans: print(*i)
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) a = [(-1) for i in range(n)] a[0:n] = map(int, input().split()) c = [(0) for i in range(200001)] maxc = 0 for number in a: c[number] += 1 maxc = max(maxc, c[number]) target = c.index(maxc) print(n - maxc) position = a.index(target) i = position - 1 while i >= 0: if a[i] > target: print(2, i + 1, i + 2) elif a[i] < target: print(1, i + 1, i + 2) i -= 1 j = position + 1 while j < n: if a[j] > target: print(2, j + 1, j) elif a[j] < target: print(1, j + 1, j) j += 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
IN = input rint = lambda: int(IN()) rlist = lambda: list(map(int, IN().split())) n = rint() a = rlist() f = [0] * 2 * 10**5 + [0] for c in a: f[c] += 1 j = a.index(f.index(max(f))) ans = [] def add(x, y, z): ans.append((x, y, z)) def check(x, y): if a[x] < a[y]: add(0, x, y) if a[x] > a[y]: add(1, x, y) a[x] = a[y] while j: check(j - 1, j) j -= 1 while j + 1 - n: check(j + 1, j) j += 1 print(len(ans)) for p in ans: for c in p: print(c + 1, end=" ") print()
ASSIGN 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 BIN_OP BIN_OP BIN_OP LIST NUMBER NUMBER BIN_OP NUMBER NUMBER LIST NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_DEF EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR WHILE VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER WHILE BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
N = int(input()) nums = [int(i) for i in input().split(" ")] count = dict() m = [0, 0] for n in nums: if count.get(n) is None: count[n] = 0 count[n] += 1 if count[n] > m[0]: m = [count[n], n] idx = [0] for i in range(N): if nums[i] == m[1]: idx.append(i) print(N - m[0]) for j in range(1, m[0] + 1): for i in range(idx[j] - 1, idx[j - 1] - 1, -1): if nums[i] < m[1]: print("1 %d %d" % (i + 1, i + 2)) elif nums[i] > m[1]: print("2 %d %d" % (i + 1, i + 2)) for i in range(idx[-1], N): if nums[i] < m[1]: print("1 %d %d" % (i + 1, i)) elif nums[i] > m[1]: print("2 %d %d" % (i + 1, i))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR LIST VAR VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR NUMBER VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR NUMBER VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) arr = list(map(int, input().split())) d = {} for i in arr: if i in d: d[i] += 1 else: d[i] = 1 mm = 0 xx = 0 for key, value in d.items(): if value > mm: xx = key mm = value if mm == 1: xx = min(arr) pos = [] for i in range(len(arr)): if arr[i] == xx: pos.append(i) ans = [] pre = -1 for i in pos: if pre == -1: for j in range(i, 0, -1): if arr[j] > arr[j - 1]: ans.append([1, j, j + 1]) arr[j - 1] = arr[j] elif arr[j - 1] > arr[j]: ans.append([2, j, j + 1]) arr[j - 1] = arr[j] else: for j in range(i, pre, -1): if arr[j] > arr[j - 1]: ans.append([1, j, j + 1]) arr[j - 1] = arr[j] elif arr[j - 1] > arr[j]: ans.append([2, j, j + 1]) arr[j - 1] = arr[j] pre = i for i in range(pre, len(arr) - 1, 1): if arr[i] < arr[i + 1]: ans.append([2, i + 2, i + 1]) arr[i + 1] = arr[i] elif arr[i + 1] < arr[i]: ans.append([1, i + 2, i + 1]) arr[i + 1] = arr[i] print(len(ans)) for i in range(len(ans)): print(ans[i][0], ans[i][1], ans[i][2])
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 FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR LIST NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR LIST NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) s = [int(x) for x in input().split()] L = sorted(s) c = 1 G = [] for i in range(1, len(L)): if L[i] == L[i - 1]: c = c + 1 else: G.append((c, L[i - 1])) c = 1 G.append((c, L[-1])) tg = -1 tgg = -1 for i in range(0, len(G)): if G[i][0] > tgg: tgg = G[i][0] tg = G[i][1] print(n - tgg) ptr = -1 for i in range(0, len(s)): if s[i] == tg: ptr = i break for i in range(ptr, len(s) - 1): if s[i + 1] != tg: if tg < s[i + 1]: print(2, i + 2, i + 1) else: print(1, i + 2, i + 1) for i in range(ptr, 0, -1): if s[i - 1] != tg: if tg < s[i - 1]: print(2, i, i + 1) else: print(1, i, i + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) A = list(map(int, input().split())) S = set(A) D = {} for i in A: if i in list(D.keys()): D[i] += 1 else: D[i] = 1 p = sorted(list(D.items()), key=lambda x: x[1]) max_number = p[-1][0] first_index = A.index(max_number) print(len(A) - p[-1][1]) for i in range(first_index - 1, -1, -1): if A[i] < max_number: x = 1 else: x = 2 print(x, i + 1, i + 2) for i in range(first_index + 1, n): if A[i] == max_number: continue if A[i] < max_number: x = 1 else: x = 2 print(x, i + 1, i)
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 VAR ASSIGN VAR DICT FOR VAR VAR IF VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) arr = list(map(int, input().split())) dict1 = {} for i in range(n): try: dict1[arr[i]] += 1 except: KeyError dict1[arr[i]] = 1 count = 0 maxval = -1 for i in dict1.keys(): if dict1[i] > count: maxval = i count = dict1[i] index1 = arr.index(maxval) i = index1 - 1 ansarr = [] while i >= 0: if arr[i] != maxval: if arr[i] > maxval: ansarr.append("2 " + str(i + 1) + " " + str(i + 2)) else: ansarr.append("1 " + str(i + 1) + " " + str(i + 2)) i -= 1 i = index1 + 1 while i < n: if arr[i] != maxval: if arr[i] > maxval: ansarr.append("2 " + str(i + 1) + " " + str(i)) else: ansarr.append("1 " + str(i + 1) + " " + str(i)) i += 1 print(len(ansarr)) if len(ansarr) != 0: print(*ansarr)
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 FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER IF VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) a = list(map(int, input().split())) d = dict() target = 0 count_max = 0 for i in range(n): l = d.get(a[i]) if l: l.append(i) else: l = [i] d[a[i]] = l if count_max < len(l): count_max = len(l) target = a[i] pos_max = d[target] print(n - len(pos_max)) pos_max.append(n) first = pos_max[0] for i in range(first - 1, -1, -1): if a[i] > a[i + 1]: print(str(2) + " " + str(i + 1) + " " + str(i + 2)) elif a[i] < a[i + 1]: print(str(1) + " " + str(i + 1) + " " + str(i + 2)) a[i] = a[i + 1] for i in range(first + 1, n): if a[i] > a[i - 1]: print(str(2) + " " + str(i + 1) + " " + str(i)) elif a[i] < a[i - 1]: print(str(1) + " " + str(i + 1) + " " + str(i)) a[i] = a[i - 1]
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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) a = [int(i) for i in input().split()] maxi1 = a[0] d = dict((i, 0) for i in a) for i in range(n): d[a[i]] += 1 if d[a[i]] > d[maxi1]: maxi1 = a[i] for i in range(n): if a[i] == maxi1: maxi = i s = "" c = 0 for i in range(maxi - 1, -1, -1): if a[i] < a[maxi]: c += 1 s += "1 " + str(i + 1) + " " + str(i + 2) + "\n" elif a[i] > a[maxi]: c += 1 s += "2 " + str(i + 1) + " " + str(i + 2) + "\n" for i in range(maxi + 1, n): if a[i] < a[maxi]: c += 1 s += "1 " + str(i + 1) + " " + str(i) + "\n" elif a[i] > a[maxi]: c += 1 s += "2 " + str(i + 1) + " " + str(i) + "\n" print(c) print(s[:-1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR VAR STRING IF VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) a = [int(item) for item in input().split()] m = {key: (0) for key in a} for x in a: m[x] += 1 mx = -1 e = -1 for i in range(n): if m[a[i]] > mx: mx = m[a[i]] e = a[i] last = -1 ans = 0 ops = [] for i in range(n): if a[i] == e and i > last + 1: for k in range(i - 1, last, -1): op = [0, k + 1, k + 1 + 1] if a[k] > e: op[0] = 2 elif a[k] < e: op[0] = 1 else: raise ops.append(op) if a[i] == e: last = i for k in range(last + 1, n): op = [0, k + 1, k - 1 + 1] if a[k] > e: op[0] = 2 elif a[k] < e: op[0] = 1 else: raise ops.append(op) print(len(ops)) for op in ops: print(*op)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR LIST NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) l = list(map(int, input().split())) dct = {} for i in range(n): if l[i] in dct: dct[l[i]].append(i) else: dct[l[i]] = [i] a = n - len(dct[l[0]]) num = l[0] for i in dct: if n - len(dct[i]) < a: a = n - len(dct[i]) num = i prev = -1 print(a) for x in dct[num]: for p in range(x - 1, prev, -1): if l[p] < num: print(1, p + 1, p + 2) else: print(2, p + 1, p + 2) prev = x for p in range(prev + 1, n): if l[p] < num: print(1, p + 1, p) else: print(2, p + 1, p)
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 FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF BIN_OP VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) arr = [int(x) for x in input().split()] d = {} for i in arr: if i in d: d[i] += 1 else: d[i] = 1 maxi = 0 for i in d: if d[i] >= maxi: maxi = d[i] ele = i if True: mid = arr.index(ele) ans = [] for i in range(mid - 1, -1, -1): if arr[i] > arr[mid]: ans.append([2, i + 1, i + 2]) elif arr[i] < arr[mid]: ans.append([1, i + 1, i + 2]) for i in range(mid + 1, n): if arr[i] > arr[mid]: ans.append([2, i + 1, i]) elif arr[i] < arr[mid]: ans.append([1, i + 1, i]) print(len(ans)) for i in ans: print(i[0], i[1], i[2])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) numbers = list(map(int, input().split())) frequency = {} for i in numbers: if i in frequency: frequency[i] += 1 else: frequency[i] = 1 items = list(frequency.items()) items.sort(key=lambda x: x[1]) m = items[-1][0] index = numbers.index(m) res = [] for i in range(index, 0, -1): if numbers[i - 1] == numbers[i]: continue elif numbers[i - 1] < numbers[i]: res.append((1, i, i + 1)) numbers[i - 1] = numbers[i] elif numbers[i - 1] > numbers[i]: res.append((2, i, i + 1)) numbers[i - 1] = numbers[i] for i in range(index, n - 1): if numbers[i + 1] == numbers[i]: continue elif numbers[i + 1] < numbers[i]: res.append((1, i + 2, i + 1)) numbers[i + 1] = numbers[i] elif numbers[i + 1] > numbers[i]: res.append((2, i + 2, i + 1)) numbers[i + 1] = numbers[i] print(len(res)) for i in res: print(i[0], i[1], i[2])
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 FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) a = list(map(int, input().split())) d = {} mv = 0 for i in range(n): d[a[i]] = d.get(a[i], 0) + 1 if d[a[i]] > mv: mv = d[a[i]] mk = a[i] mi = i ans = [] for i in range(mi + 1, n): if a[i] == mk: continue if a[i] > mk: ans.append((2, i + 1, i)) else: ans.append((1, i + 1, i)) for i in range(mi - 1, -1, -1): if a[i] == mk: continue if a[i] > mk: ans.append((2, i + 1, i + 2)) else: ans.append((1, i + 1, i + 2)) print(len(ans)) for i, j, k in ans: print(i, j, k)
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 VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) n1 = list(map(int, input().split())) newdict = {} for i in n1: if i in newdict.keys(): newdict[i] += 1 else: newdict[i] = 1 greatest = 0 maxi = 0 for i in newdict.keys(): if newdict[i] > maxi: maxi = newdict[i] greatest = i if maxi == 1: greatest = max(n1) output = [] index = n1.index(greatest) temp_index = index if index > 0 and index < len(n1) - 1: while index > 0: item = "" if n1[index - 1] < greatest: item += "1 " + str(index) + " " + str(index + 1) output.append(item) index -= 1 elif n1[index - 1] > greatest: item += "2 " + str(index) + " " + str(index + 1) index -= 1 output.append(item) else: index -= 1 continue while temp_index < len(n1) - 1: item = "" if n1[temp_index + 1] < greatest: item += "1 " + str(temp_index + 2) + " " + str(temp_index + 1) output.append(item) temp_index += 1 elif n1[temp_index + 1] > greatest: item += "2 " + str(temp_index + 2) + " " + str(temp_index + 1) temp_index += 1 output.append(item) else: temp_index += 1 continue elif temp_index == 0: while temp_index < len(n1) - 1: item = "" if n1[temp_index + 1] < greatest: item += "1 " + str(temp_index + 2) + " " + str(temp_index + 1) output.append(item) temp_index += 1 elif n1[temp_index + 1] > greatest: item += "2 " + str(temp_index + 2) + " " + str(temp_index + 1) temp_index += 1 output.append(item) else: temp_index += 1 continue elif index == len(n1) - 1: while index > 0: item = "" if n1[index - 1] < greatest: item += "1 " + str(index) + " " + str(index + 1) output.append(item) index -= 1 elif n1[index - 1] > greatest: item += "2 " + str(index) + " " + str(index + 1) index -= 1 output.append(item) else: index -= 1 continue print(len(output)) for i in output: print(i)
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 FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER ASSIGN VAR STRING IF VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING IF VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING IF VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER ASSIGN VAR STRING IF VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) a = list(map(int, input().split())) dic = {} maxim = 0 val = 0 for i in a: if i not in dic: dic[i] = 1 else: dic[i] += 1 if dic[i] > maxim: maxim = dic[i] for i in dic: if dic[i] == maxim: val = i break pos = a.index(val) k = len(a) - maxim print(k) for i in range(pos + 1, n): if a[i] > a[i - 1]: print(2, i + 1, i) a[i] = a[i - 1] elif a[i] < a[i - 1]: print(1, i + 1, i) a[i] = a[i - 1] for i in range(pos - 1, -1, -1): if a[i] > a[i + 1]: print(2, i + 1, i + 2) a[i] = a[i + 1] elif a[i] < a[i + 1]: print(1, i + 1, i + 2) a[i] = a[i + 1]
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 ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) a = [int(_) for _ in input().split()] freq = {} for item in a: if item in freq: freq[item] += 1 else: freq[item] = 1 most_occ = max(freq, key=lambda x: freq[x]) index_center = a.index(most_occ) print(len(a) - a.count(most_occ)) for i in range(index_center, 0, -1): if a[i - 1] < most_occ: a[i - 1] = most_occ print(1, i, i + 1) elif a[i - 1] > most_occ: a[i - 1] = most_occ print(2, i, i + 1) for i in range(index_center, n - 1): if a[i + 1] > most_occ: a[i + 1] = most_occ print(2, i + 2, i + 1) elif a[i + 1] < most_occ: a[i + 1] = most_occ print(1, i + 2, i + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
TN = 1 def solution(): n = int(input()) a = list(map(int, input().split())) klv = {} keys = [] for i in a: try: x = klv[i] except: keys.append(i) klv[i] = 1 else: klv[i] += 1 lcur = 0 cur = 0 for i in keys: if lcur <= klv[i]: lcur = klv[i] cur = i ind = a.index(cur) k = n - klv[cur] print(k) for i in reversed(range(ind)): if a[i] > a[ind]: print(2, i + 1, i + 2) elif a[i] < a[ind]: print(1, i + 1, i + 2) for i in range(ind + 1, n): if a[i] > a[ind]: print(2, i + 1, i) elif a[i] < a[ind]: print(1, i + 1, i) while TN != 0: solution() TN -= 1
ASSIGN VAR NUMBER FUNC_DEF 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 LIST FOR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) a = list(map(int, input().split())) d = dict() target = 0 count_max = 0 for i in range(n): c = d.get(a[i], 0) c += 1 d[a[i]] = c if count_max < c: count_max = c target = a[i] first = 0 for i in range(n): if a[i] == target: first = i break print(n - count_max) for i in range(first - 1, -1, -1): if a[i] > target: print(str(2) + " " + str(i + 1) + " " + str(i + 2)) elif a[i] < target: print(str(1) + " " + str(i + 1) + " " + str(i + 2)) for i in range(first + 1, n): if a[i] > target: print(str(2) + " " + str(i + 1) + " " + str(i)) elif a[i] < target: print(str(1) + " " + str(i + 1) + " " + str(i))
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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) nums = list(map(int, input().split())) count = dict() for i in range(n): if nums[i] in count.keys(): count[nums[i]][0] += 1 count[nums[i]].append(i) else: count[nums[i]] = [1] count[nums[i]].append(i) currCount = 1 currElem = nums[0] currInd = [0] for key in count.keys(): if count[key][0] > currCount: currCount = count[key][0] currElem = key currInd = count[key][1:] currInd.sort() steps = n - len(currInd) print(steps) if currInd[0] != 0: for i in range(currInd[0] - 1, -1, -1): if nums[i] > currElem: print(2, i + 1, i + 2) elif nums[i] < currElem: print(1, i + 1, i + 2) for i in range(len(currInd)): if i == len(currInd) - 1: if currInd[i] < n - 1: for j in range(currInd[i] + 1, n): if nums[j] > currElem: print(2, j + 1, j) elif nums[j] < currElem: print(1, j + 1, j) else: left = currInd[i] right = currInd[i + 1] for j in range(left + 1, right): if nums[j] > currElem: print(2, j + 1, j) elif nums[j] < currElem: print(1, j + 1, j)
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 FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
amount = int(input()) array = [int(s) for s in input().split()] counter = [0] * (2 * 10**5 + 1) for i in range(len(array)): counter[array[i]] += 1 idx = -1 max_counter = -1 for i in range(len(counter)): if counter[i] > max_counter: max_counter = counter[i] idx = i indices = [] for i in range(len(array)): if array[i] == idx: indices.append(i) print(len(array) - len(indices)) if indices[0] != 0: indices.insert(0, 0) ans = "" for i in range(1, len(indices)): for j in range(indices[i], indices[i - 1], -1): if idx > array[j - 1]: ans += "1" + " " + str(j) + " " + str(j + 1) + "\n" elif idx < array[j - 1]: ans += "2" + " " + str(j) + " " + str(j + 1) + "\n" if indices[-1] != len(array) - 1: for j in range(indices[-1], len(array) - 1): if idx > array[j + 1]: ans += "1" + " " + str(j + 2) + " " + str(j + 1) + "\n" elif idx < array[j + 1]: ans += "2" + " " + str(j + 2) + " " + str(j + 1) + "\n" print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) a = list(map(int, input().rstrip().split())) p = dict() for i in a: if i in p: p[i] += 1 else: p[i] = 1 b = list(p.values()) flag = 0 value = 0 index = -1 freq = 0 for i in p: if p[i] > freq: freq = p[i] value = i if freq > 1: flag = 1 index = a.index(value) count = 0 result = [] if flag == 1: if index == 0: for i in range(1, len(a)): if a[i] < value: result.append((1, i, i - 1)) a[i] = value elif a[i] > value: result.append((2, i, i - 1)) a[i] = value elif index == n - 1: for i in range(n - 1, -1, -1): if a[i] < value: result.append((1, i, i + 1)) a[i] = value elif a[i] > value: result.append((2, i, i + 1)) a[i] = value else: for i in range(index - 1, -1, -1): if a[i] < value: result.append((1, i, i + 1)) a[i] = value elif a[i] > value: result.append((2, i, i + 1)) a[i] = value for i in range(index + 1, n): if a[i] < value: result.append((1, i, i - 1)) a[i] = value elif a[i] > value: result.append((2, i, i - 1)) a[i] = value if flag == 0: value = a[0] for i in range(1, n): if a[i] < value: result.append((1, i, i - 1)) a[i] = value elif a[i] > value: result.append((2, i, i - 1)) a[i] = value print(len(result)) for i in result: print(i[0], i[1] + 1, i[2] + 1)
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 FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST IF VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) m = list(map(int, input().split())) l = [0] * (2 * 10**5 + 3) l1 = [[] for i in range(2 * 10**5 + 1)] ma = 0 a = 0 ansm = [] ans = 0 for i in range(n): l[m[i]] += 1 l1[m[i]].append(i) if l[m[i]] > a: ma = m[i] a = l[m[i]] for j in range(l1[ma][0] - 1, -1, -1): ans += 1 if m[j] < m[j + 1]: m[j] += abs(m[j + 1] - m[j]) ansm.append([1, j + 1, j + 2]) else: m[j] -= abs(m[j + 1] - m[j]) ansm.append([2, j + 1, j + 2]) for i in range(a - 1): for j in range(l1[ma][i], l1[ma][i + 1] - 1): ans += 1 if m[j] > m[j + 1]: m[j + 1] += abs(m[j + 1] - m[j]) ansm.append([1, j + 2, j + 1]) else: m[j + 1] -= abs(m[j + 1] - m[j]) ansm.append([2, j + 2, j + 1]) ans += max(0, n - 1 - l1[ma][-1]) for j in range(l1[ma][-1], n - 1): if m[j] > m[j + 1]: m[j + 1] += abs(m[j + 1] - m[j]) ansm.append([1, j + 2, j + 1]) else: m[j + 1] -= abs(m[j + 1] - m[j]) ansm.append([2, j + 2, j + 1]) print(ans) for i in ansm: print(*i)
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 BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
import sys input = sys.stdin.readline def main(): n = int(input()) a = list(map(int, input().split())) if len(set(a)) == 1: print(0) return d = {} for i in range(n): if a[i] in d: d[a[i]].add(i) else: d[a[i]] = {i} max_el, length = 0, 0 for k in d: if len(d[k]) > length: max_el = k length = len(d[k]) cur = list(d[max_el]) cur.sort() cur_ind = cur[0] res = [] for i in range(cur[0] - 1, -1, -1): if a[i] > max_el: res.append((2, i + 1, cur_ind + 1)) else: res.append((1, i + 1, cur_ind + 1)) cur_ind -= 1 cur_ind = cur[0] + 1 for i in range(cur[0], n): if i in d[max_el]: cur_ind = i continue else: if a[i] > max_el: res.append((2, i + 1, cur_ind + 1)) else: res.append((1, i + 1, cur_ind + 1)) cur_ind += 1 print(len(res)) for k in res: print(*k) main()
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given an array $a$ consisting of $n$ integers. You can perform the following operations arbitrary number of times (possibly, zero): Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i + |a_i - a_j|$; Choose a pair of indices $(i, j)$ such that $|i-j|=1$ (indices $i$ and $j$ are adjacent) and set $a_i := a_i - |a_i - a_j|$. The value $|x|$ means the absolute value of $x$. For example, $|4| = 4$, $|-3| = 3$. Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it. It is guaranteed that you always can obtain the array of equal elements using such operations. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- In the first line print one integer $k$ — the minimum number of operations required to obtain the array of equal elements. In the next $k$ lines print operations itself. The $p$-th operation should be printed as a triple of integers $(t_p, i_p, j_p)$, where $t_p$ is either $1$ or $2$ ($1$ means that you perform the operation of the first type, and $2$ means that you perform the operation of the second type), and $i_p$ and $j_p$ are indices of adjacent elements of the array such that $1 \le i_p, j_p \le n$, $|i_p - j_p| = 1$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $10^{18}$ by absolute value. If there are many possible answers, you can print any. -----Examples----- Input 5 2 4 6 6 6 Output 2 1 2 3 1 1 2 Input 3 2 8 10 Output 2 2 2 1 2 3 2 Input 4 1 1 1 1 Output 0
n = int(input()) a = list(map(int, input().split())) maxi = 0 el = -1 d = dict() for i in a: if i in d: d[i] += 1 if d[i] > maxi: maxi = d[i] el = i else: d[i] = 1 if d[i] > maxi: maxi = d[i] el = i print(n - maxi) for i in range(a.index(el) - 1, -1, -1): print(1 + int(a[i] > el), i + 1, i + 2) for i in range(a.index(el) + 1, n): if a[i] == el: continue print(1 + int(a[i] > el), i + 1, i)
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 FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR
Nauuo is a girl who loves playing cards. One day she was playing cards but found that the cards were mixed with some empty ones. There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n cards in the pile are also given in the order from top to bottom. In one operation she can choose a card in her hands and play it — put it at the bottom of the pile, then draw the top card from the pile. Nauuo wants to make the n numbered cards piled up in increasing order (the i-th card in the pile from top to bottom is the card i) as quickly as possible. Can you tell her the minimum number of operations? Input The first line contains a single integer n (1≤ n≤ 2⋅ 10^5) — the number of numbered cards. The second line contains n integers a_1,a_2,…,a_n (0≤ a_i≤ n) — the initial cards in Nauuo's hands. 0 represents an empty card. The third line contains n integers b_1,b_2,…,b_n (0≤ b_i≤ n) — the initial cards in the pile, given in order from top to bottom. 0 represents an empty card. It is guaranteed that each number from 1 to n appears exactly once, either in a_{1..n} or b_{1..n}. Output The output contains a single integer — the minimum number of operations to make the n numbered cards piled up in increasing order. Examples Input 3 0 2 0 3 0 1 Output 2 Input 3 0 2 0 1 0 3 Output 4 Input 11 0 0 0 5 0 0 0 4 0 0 11 9 2 6 0 8 1 7 0 3 0 10 Output 18 Note Example 1 We can play the card 2 and draw the card 3 in the first operation. After that, we have [0,3,0] in hands and the cards in the pile are [0,1,2] from top to bottom. Then, we play the card 3 in the second operation. The cards in the pile are [1,2,3], in which the cards are piled up in increasing order. Example 2 Play an empty card and draw the card 1, then play 1, 2, 3 in order.
n = int(input("")) a = list(map(int, input().split())) b = list(map(int, input().split())) c = [0] * n for i in range(n): if a[i] == 0: a[i] = n * 20 else: c[a[i] - 1] = -1 if b[i] == 0: b[i] = n * 20 else: c[b[i] - 1] = i d = c.copy() l = b[-1] ll = l f = 0 for i in range(1, l + 1): if l == 20 * n: f = 1 break j = i * -1 if b[j] != ll: f = 1 break ll -= 1 if f == 0: j = 0 for i in range(l, n): if d[i] == -1: if b[j] <= n: d[b[j] - 1] = -1 j += 1 else: f = 1 break if f == 0: print(n - l) exit() m = min(b) ind = b.index(m) if m == 1: for i in range(ind + 1): if b[i] != 20 * n: c[b[i] - 1] = -1 j = 2 fe = -1 fi = -1 ans = -1 for i in range(ind + 1, n): if b[i] < j: fe = b[i] fi = j ans = max(fi - fe, ans) j += 1 if fe == -1: print(ind + n + 1) else: print(ind + 1 + n + ans) exit() else: j = 2 fe = -1 fi = -1 ans = -1 for i in range(n): if b[i] < j: fe = b[i] fi = j ans = max(fi - fe, ans) j += 1 if fe == -1: print(n) else: print(ans + n)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
Nauuo is a girl who loves playing cards. One day she was playing cards but found that the cards were mixed with some empty ones. There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n cards in the pile are also given in the order from top to bottom. In one operation she can choose a card in her hands and play it — put it at the bottom of the pile, then draw the top card from the pile. Nauuo wants to make the n numbered cards piled up in increasing order (the i-th card in the pile from top to bottom is the card i) as quickly as possible. Can you tell her the minimum number of operations? Input The first line contains a single integer n (1≤ n≤ 2⋅ 10^5) — the number of numbered cards. The second line contains n integers a_1,a_2,…,a_n (0≤ a_i≤ n) — the initial cards in Nauuo's hands. 0 represents an empty card. The third line contains n integers b_1,b_2,…,b_n (0≤ b_i≤ n) — the initial cards in the pile, given in order from top to bottom. 0 represents an empty card. It is guaranteed that each number from 1 to n appears exactly once, either in a_{1..n} or b_{1..n}. Output The output contains a single integer — the minimum number of operations to make the n numbered cards piled up in increasing order. Examples Input 3 0 2 0 3 0 1 Output 2 Input 3 0 2 0 1 0 3 Output 4 Input 11 0 0 0 5 0 0 0 4 0 0 11 9 2 6 0 8 1 7 0 3 0 10 Output 18 Note Example 1 We can play the card 2 and draw the card 3 in the first operation. After that, we have [0,3,0] in hands and the cards in the pile are [0,1,2] from top to bottom. Then, we play the card 3 in the second operation. The cards in the pile are [1,2,3], in which the cards are piled up in increasing order. Example 2 Play an empty card and draw the card 1, then play 1, 2, 3 in order.
n = int(input()) _ = input() d = list(map(int, input().split())) m = -n z = -1 for i, v in enumerate(d): if not v: z = -1 continue if z >= 0 and v != i - z + 1: z = -1 elif v == 1: z = i y = m m = max(m, i - v + 2) if z == 0: print(0) elif z > 0 and y <= -n + z: print(z) else: print(n + max(m, 0))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER
Nauuo is a girl who loves playing cards. One day she was playing cards but found that the cards were mixed with some empty ones. There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n cards in the pile are also given in the order from top to bottom. In one operation she can choose a card in her hands and play it — put it at the bottom of the pile, then draw the top card from the pile. Nauuo wants to make the n numbered cards piled up in increasing order (the i-th card in the pile from top to bottom is the card i) as quickly as possible. Can you tell her the minimum number of operations? Input The first line contains a single integer n (1≤ n≤ 2⋅ 10^5) — the number of numbered cards. The second line contains n integers a_1,a_2,…,a_n (0≤ a_i≤ n) — the initial cards in Nauuo's hands. 0 represents an empty card. The third line contains n integers b_1,b_2,…,b_n (0≤ b_i≤ n) — the initial cards in the pile, given in order from top to bottom. 0 represents an empty card. It is guaranteed that each number from 1 to n appears exactly once, either in a_{1..n} or b_{1..n}. Output The output contains a single integer — the minimum number of operations to make the n numbered cards piled up in increasing order. Examples Input 3 0 2 0 3 0 1 Output 2 Input 3 0 2 0 1 0 3 Output 4 Input 11 0 0 0 5 0 0 0 4 0 0 11 9 2 6 0 8 1 7 0 3 0 10 Output 18 Note Example 1 We can play the card 2 and draw the card 3 in the first operation. After that, we have [0,3,0] in hands and the cards in the pile are [0,1,2] from top to bottom. Then, we play the card 3 in the second operation. The cards in the pile are [1,2,3], in which the cards are piled up in increasing order. Example 2 Play an empty card and draw the card 1, then play 1, 2, 3 in order.
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) if n == 1: if a[0] == 0: print(0) exit() else: print(1) exit() yes = True pos = -1 for i in range(n - 2, -1, -1): if b[i] == 1: pos = i break elif b[i] + 1 == b[i + 1]: continue else: yes = False if b[-1] == 1: yes = True pos = n - 1 if yes: min_len = -10000000000000 for i in range(pos): if b[i] == 0: continue min_len = max(i - b[i] + 2, min_len) if min_len + (n - pos) <= 0: print(pos) exit() min_len = 0 for i in range(n): if b[i] == 0: continue min_len = max(i - b[i] + 2, min_len) res = n + min_len print(res)
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR IF BIN_OP VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Nauuo is a girl who loves playing cards. One day she was playing cards but found that the cards were mixed with some empty ones. There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n cards in the pile are also given in the order from top to bottom. In one operation she can choose a card in her hands and play it — put it at the bottom of the pile, then draw the top card from the pile. Nauuo wants to make the n numbered cards piled up in increasing order (the i-th card in the pile from top to bottom is the card i) as quickly as possible. Can you tell her the minimum number of operations? Input The first line contains a single integer n (1≤ n≤ 2⋅ 10^5) — the number of numbered cards. The second line contains n integers a_1,a_2,…,a_n (0≤ a_i≤ n) — the initial cards in Nauuo's hands. 0 represents an empty card. The third line contains n integers b_1,b_2,…,b_n (0≤ b_i≤ n) — the initial cards in the pile, given in order from top to bottom. 0 represents an empty card. It is guaranteed that each number from 1 to n appears exactly once, either in a_{1..n} or b_{1..n}. Output The output contains a single integer — the minimum number of operations to make the n numbered cards piled up in increasing order. Examples Input 3 0 2 0 3 0 1 Output 2 Input 3 0 2 0 1 0 3 Output 4 Input 11 0 0 0 5 0 0 0 4 0 0 11 9 2 6 0 8 1 7 0 3 0 10 Output 18 Note Example 1 We can play the card 2 and draw the card 3 in the first operation. After that, we have [0,3,0] in hands and the cards in the pile are [0,1,2] from top to bottom. Then, we play the card 3 in the second operation. The cards in the pile are [1,2,3], in which the cards are piled up in increasing order. Example 2 Play an empty card and draw the card 1, then play 1, 2, 3 in order.
def solve(): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) for i in range(n): if b[i] == 1: if b[i:] == [x for x in range(1, n - i + 1)]: for j in range(i): if b[j] == 0: continue if b[j] - n + i - 1 < j + 1: break else: return i if 1 in a: for j in range(n): if b[j] == 0: continue if b[j] < j + 2: break else: return n max_diff = -1 j = -1 k = -1 for i in range(n): if b[i] == 0: continue if i + 1 - b[i] > max_diff: max_diff = i + 1 - b[i] j = i + 1 k = b[i] return j + n - k + 1 print(solve())
FUNC_DEF 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER RETURN VAR IF NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR
Nauuo is a girl who loves playing cards. One day she was playing cards but found that the cards were mixed with some empty ones. There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n cards in the pile are also given in the order from top to bottom. In one operation she can choose a card in her hands and play it — put it at the bottom of the pile, then draw the top card from the pile. Nauuo wants to make the n numbered cards piled up in increasing order (the i-th card in the pile from top to bottom is the card i) as quickly as possible. Can you tell her the minimum number of operations? Input The first line contains a single integer n (1≤ n≤ 2⋅ 10^5) — the number of numbered cards. The second line contains n integers a_1,a_2,…,a_n (0≤ a_i≤ n) — the initial cards in Nauuo's hands. 0 represents an empty card. The third line contains n integers b_1,b_2,…,b_n (0≤ b_i≤ n) — the initial cards in the pile, given in order from top to bottom. 0 represents an empty card. It is guaranteed that each number from 1 to n appears exactly once, either in a_{1..n} or b_{1..n}. Output The output contains a single integer — the minimum number of operations to make the n numbered cards piled up in increasing order. Examples Input 3 0 2 0 3 0 1 Output 2 Input 3 0 2 0 1 0 3 Output 4 Input 11 0 0 0 5 0 0 0 4 0 0 11 9 2 6 0 8 1 7 0 3 0 10 Output 18 Note Example 1 We can play the card 2 and draw the card 3 in the first operation. After that, we have [0,3,0] in hands and the cards in the pile are [0,1,2] from top to bottom. Then, we play the card 3 in the second operation. The cards in the pile are [1,2,3], in which the cards are piled up in increasing order. Example 2 Play an empty card and draw the card 1, then play 1, 2, 3 in order.
n = int(input()) a = list(map(int, input().split())) c = list(map(int, input().split())) b = dict(zip(c, range(n))) pos_one = b[1] if 1 in b else -1 if 1 in b: is_sorted = True for i in range(pos_one + 1, n): if c[i] != c[i - 1] + 1: is_sorted = False break if is_sorted: num_next = c[-1] + 1 flag = True for i in range(n): if c[i] == 1: break if num_next in b and b[num_next] >= num_next - (c[-1] + 1): flag = False break num_next += 1 if flag: print(pos_one) exit(0) max_pos = pos_one + 1 if 1 in b else 0 for i in range(2, n + 1): if i in b and b[i] >= pos_one + i: max_pos = max(max_pos, b[i] - i + 2) print(max_pos + n)
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR VAR NUMBER NUMBER IF NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Nauuo is a girl who loves playing cards. One day she was playing cards but found that the cards were mixed with some empty ones. There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n cards in the pile are also given in the order from top to bottom. In one operation she can choose a card in her hands and play it — put it at the bottom of the pile, then draw the top card from the pile. Nauuo wants to make the n numbered cards piled up in increasing order (the i-th card in the pile from top to bottom is the card i) as quickly as possible. Can you tell her the minimum number of operations? Input The first line contains a single integer n (1≤ n≤ 2⋅ 10^5) — the number of numbered cards. The second line contains n integers a_1,a_2,…,a_n (0≤ a_i≤ n) — the initial cards in Nauuo's hands. 0 represents an empty card. The third line contains n integers b_1,b_2,…,b_n (0≤ b_i≤ n) — the initial cards in the pile, given in order from top to bottom. 0 represents an empty card. It is guaranteed that each number from 1 to n appears exactly once, either in a_{1..n} or b_{1..n}. Output The output contains a single integer — the minimum number of operations to make the n numbered cards piled up in increasing order. Examples Input 3 0 2 0 3 0 1 Output 2 Input 3 0 2 0 1 0 3 Output 4 Input 11 0 0 0 5 0 0 0 4 0 0 11 9 2 6 0 8 1 7 0 3 0 10 Output 18 Note Example 1 We can play the card 2 and draw the card 3 in the first operation. After that, we have [0,3,0] in hands and the cards in the pile are [0,1,2] from top to bottom. Then, we play the card 3 in the second operation. The cards in the pile are [1,2,3], in which the cards are piled up in increasing order. Example 2 Play an empty card and draw the card 1, then play 1, 2, 3 in order.
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) l = -1 r = n moment = [0] * (n + 1) max_post = 1 while b[(-max_post - 1) % n] != 0 and b[(-max_post - 1) % n] + 1 == b[-max_post]: max_post += 1 if b[-max_post] != 1: max_post = 0 for i in range(n): moment[b[i]] = i + 1 m = -1 for i in range(max_post + 1, n + 1): m = max(m, moment[i] - i + max_post) m += 1 if m > 0: m = -2 for i in range(1, n + 1): m = max(m, moment[i] - i) m += 1 print(m + n) else: print(max(0, m + n - max_post))
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR
Nauuo is a girl who loves playing cards. One day she was playing cards but found that the cards were mixed with some empty ones. There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n cards in the pile are also given in the order from top to bottom. In one operation she can choose a card in her hands and play it — put it at the bottom of the pile, then draw the top card from the pile. Nauuo wants to make the n numbered cards piled up in increasing order (the i-th card in the pile from top to bottom is the card i) as quickly as possible. Can you tell her the minimum number of operations? Input The first line contains a single integer n (1≤ n≤ 2⋅ 10^5) — the number of numbered cards. The second line contains n integers a_1,a_2,…,a_n (0≤ a_i≤ n) — the initial cards in Nauuo's hands. 0 represents an empty card. The third line contains n integers b_1,b_2,…,b_n (0≤ b_i≤ n) — the initial cards in the pile, given in order from top to bottom. 0 represents an empty card. It is guaranteed that each number from 1 to n appears exactly once, either in a_{1..n} or b_{1..n}. Output The output contains a single integer — the minimum number of operations to make the n numbered cards piled up in increasing order. Examples Input 3 0 2 0 3 0 1 Output 2 Input 3 0 2 0 1 0 3 Output 4 Input 11 0 0 0 5 0 0 0 4 0 0 11 9 2 6 0 8 1 7 0 3 0 10 Output 18 Note Example 1 We can play the card 2 and draw the card 3 in the first operation. After that, we have [0,3,0] in hands and the cards in the pile are [0,1,2] from top to bottom. Then, we play the card 3 in the second operation. The cards in the pile are [1,2,3], in which the cards are piled up in increasing order. Example 2 Play an empty card and draw the card 1, then play 1, 2, 3 in order.
import sys input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) tmp = B[-1] ok = True if tmp != 0: for i in reversed(range(N)): b = B[i] if tmp - (N - 1 - i) > 0: if b != tmp - (N - 1 - i): ok = False for i in range(N - tmp): b = B[i] if b > 0 and b <= tmp + i + 1: ok = False else: ok = False if ok: ans = N - tmp else: ans = N for i, b in enumerate(B): if b != 0: ans = max(N - b + 2 + i, ans) print(ans)
IMPORT ASSIGN 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Nauuo is a girl who loves playing cards. One day she was playing cards but found that the cards were mixed with some empty ones. There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n cards in the pile are also given in the order from top to bottom. In one operation she can choose a card in her hands and play it — put it at the bottom of the pile, then draw the top card from the pile. Nauuo wants to make the n numbered cards piled up in increasing order (the i-th card in the pile from top to bottom is the card i) as quickly as possible. Can you tell her the minimum number of operations? Input The first line contains a single integer n (1≤ n≤ 2⋅ 10^5) — the number of numbered cards. The second line contains n integers a_1,a_2,…,a_n (0≤ a_i≤ n) — the initial cards in Nauuo's hands. 0 represents an empty card. The third line contains n integers b_1,b_2,…,b_n (0≤ b_i≤ n) — the initial cards in the pile, given in order from top to bottom. 0 represents an empty card. It is guaranteed that each number from 1 to n appears exactly once, either in a_{1..n} or b_{1..n}. Output The output contains a single integer — the minimum number of operations to make the n numbered cards piled up in increasing order. Examples Input 3 0 2 0 3 0 1 Output 2 Input 3 0 2 0 1 0 3 Output 4 Input 11 0 0 0 5 0 0 0 4 0 0 11 9 2 6 0 8 1 7 0 3 0 10 Output 18 Note Example 1 We can play the card 2 and draw the card 3 in the first operation. After that, we have [0,3,0] in hands and the cards in the pile are [0,1,2] from top to bottom. Then, we play the card 3 in the second operation. The cards in the pile are [1,2,3], in which the cards are piled up in increasing order. Example 2 Play an empty card and draw the card 1, then play 1, 2, 3 in order.
def get_int_list(): return list(map(int, input().split())) def get_max_repeats(l): if len(l) == 0: return 0 repeats = 1 max_repeats = 1 last_element = l[0] for i in range(1, len(l)): if l[i] == last_element: repeats += 1 else: if repeats > max_repeats: max_repeats = repeats repeats = 1 last_element = l[i] if repeats > max_repeats: max_repeats = repeats return max_repeats def order(pile): if pile[-1] == 1: return 1 if len(pile) == 1: return 0 for i in range(len(pile) - 2, -1, -1): if pile[i] == 1 and pile[i + 1] == 2: return len(pile) - i elif pile[i] == pile[i + 1] - 1: continue else: return 0 n = int(input()) hand = get_int_list() pile = get_int_list() places = {} for i in range(n): if hand[i] > 0: places[hand[i]] = 0 if pile[i] > 0: places[pile[i]] = i + 1 offset = order(pile) if offset > 0: in_order = True for i in range(offset + 1, n + 1): if places[i] == 0: continue distance = places[i] - (i - 1) + offset if distance > 0: in_order = False break if in_order: print(str(n - offset)) else: one_to_hand = places[1] max_distance = 0 for i in range(2, n + 1): if places[i] == 0: continue distance = places[i] - (i - 1) - one_to_hand if distance > max_distance: max_distance = distance moves = one_to_hand + max_distance + n print(str(moves)) else: one_to_hand = places[1] max_distance = 0 for i in range(2, n + 1): if places[i] == 0: continue distance = places[i] - (i - 1) - one_to_hand if distance > max_distance: max_distance = distance moves = one_to_hand + max_distance + n print(str(moves))
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Nauuo is a girl who loves playing cards. One day she was playing cards but found that the cards were mixed with some empty ones. There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n cards in the pile are also given in the order from top to bottom. In one operation she can choose a card in her hands and play it — put it at the bottom of the pile, then draw the top card from the pile. Nauuo wants to make the n numbered cards piled up in increasing order (the i-th card in the pile from top to bottom is the card i) as quickly as possible. Can you tell her the minimum number of operations? Input The first line contains a single integer n (1≤ n≤ 2⋅ 10^5) — the number of numbered cards. The second line contains n integers a_1,a_2,…,a_n (0≤ a_i≤ n) — the initial cards in Nauuo's hands. 0 represents an empty card. The third line contains n integers b_1,b_2,…,b_n (0≤ b_i≤ n) — the initial cards in the pile, given in order from top to bottom. 0 represents an empty card. It is guaranteed that each number from 1 to n appears exactly once, either in a_{1..n} or b_{1..n}. Output The output contains a single integer — the minimum number of operations to make the n numbered cards piled up in increasing order. Examples Input 3 0 2 0 3 0 1 Output 2 Input 3 0 2 0 1 0 3 Output 4 Input 11 0 0 0 5 0 0 0 4 0 0 11 9 2 6 0 8 1 7 0 3 0 10 Output 18 Note Example 1 We can play the card 2 and draw the card 3 in the first operation. After that, we have [0,3,0] in hands and the cards in the pile are [0,1,2] from top to bottom. Then, we play the card 3 in the second operation. The cards in the pile are [1,2,3], in which the cards are piled up in increasing order. Example 2 Play an empty card and draw the card 1, then play 1, 2, 3 in order.
N = int(input()) a_list = list(map(int, input().split())) b_list = list(map(int, input().split())) getting = [0] * (N + 1) flg = False for i in range(N): b = b_list[i] getting[b] = i + 1 if flg and b_list[i - 1] != b - 1: flg = False if b == 1: flg = True if flg: start = b_list[-1] + 1 step = 0 for i in range(start, N + 1): if getting[i] > step: flg = False break step += 1 if flg: print(N - start + 1) exit() ans = 0 for i in range(1, N + 1): if getting[i] > i - 1 and ans < getting[i] - (i - 1): ans = getting[i] - (i - 1) print(N + ans)
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Nauuo is a girl who loves playing cards. One day she was playing cards but found that the cards were mixed with some empty ones. There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n cards in the pile are also given in the order from top to bottom. In one operation she can choose a card in her hands and play it — put it at the bottom of the pile, then draw the top card from the pile. Nauuo wants to make the n numbered cards piled up in increasing order (the i-th card in the pile from top to bottom is the card i) as quickly as possible. Can you tell her the minimum number of operations? Input The first line contains a single integer n (1≤ n≤ 2⋅ 10^5) — the number of numbered cards. The second line contains n integers a_1,a_2,…,a_n (0≤ a_i≤ n) — the initial cards in Nauuo's hands. 0 represents an empty card. The third line contains n integers b_1,b_2,…,b_n (0≤ b_i≤ n) — the initial cards in the pile, given in order from top to bottom. 0 represents an empty card. It is guaranteed that each number from 1 to n appears exactly once, either in a_{1..n} or b_{1..n}. Output The output contains a single integer — the minimum number of operations to make the n numbered cards piled up in increasing order. Examples Input 3 0 2 0 3 0 1 Output 2 Input 3 0 2 0 1 0 3 Output 4 Input 11 0 0 0 5 0 0 0 4 0 0 11 9 2 6 0 8 1 7 0 3 0 10 Output 18 Note Example 1 We can play the card 2 and draw the card 3 in the first operation. After that, we have [0,3,0] in hands and the cards in the pile are [0,1,2] from top to bottom. Then, we play the card 3 in the second operation. The cards in the pile are [1,2,3], in which the cards are piled up in increasing order. Example 2 Play an empty card and draw the card 1, then play 1, 2, 3 in order.
n = int(input()) (*hand,) = map(int, input().split()) (*pile,) = map(int, input().split()) dist = [0] * (n + 1) for index, card in enumerate(pile): if card != 0: dist[card] = index + 1 def is_valid(): if dist[1] == 0: numbers_placed = 0 else: base = dist[1] for i in range(2, n - dist[1] + 2): if dist[i] != dist[1] + i - 1: numbers_placed = 0 break else: numbers_placed = n - dist[1] + 1 if numbers_placed != 0: for i in range(numbers_placed + 1, n + 1): if dist[i] >= i - numbers_placed: ans = dist[1] + n break else: ans = n - numbers_placed return ans else: delay = 0 for i in range(1, n + 1): delay += max(dist[i] - (i - 1 + delay), 0) return delay + n print(is_valid())
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER RETURN BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
Nauuo is a girl who loves playing cards. One day she was playing cards but found that the cards were mixed with some empty ones. There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n cards in the pile are also given in the order from top to bottom. In one operation she can choose a card in her hands and play it — put it at the bottom of the pile, then draw the top card from the pile. Nauuo wants to make the n numbered cards piled up in increasing order (the i-th card in the pile from top to bottom is the card i) as quickly as possible. Can you tell her the minimum number of operations? Input The first line contains a single integer n (1≤ n≤ 2⋅ 10^5) — the number of numbered cards. The second line contains n integers a_1,a_2,…,a_n (0≤ a_i≤ n) — the initial cards in Nauuo's hands. 0 represents an empty card. The third line contains n integers b_1,b_2,…,b_n (0≤ b_i≤ n) — the initial cards in the pile, given in order from top to bottom. 0 represents an empty card. It is guaranteed that each number from 1 to n appears exactly once, either in a_{1..n} or b_{1..n}. Output The output contains a single integer — the minimum number of operations to make the n numbered cards piled up in increasing order. Examples Input 3 0 2 0 3 0 1 Output 2 Input 3 0 2 0 1 0 3 Output 4 Input 11 0 0 0 5 0 0 0 4 0 0 11 9 2 6 0 8 1 7 0 3 0 10 Output 18 Note Example 1 We can play the card 2 and draw the card 3 in the first operation. After that, we have [0,3,0] in hands and the cards in the pile are [0,1,2] from top to bottom. Then, we play the card 3 in the second operation. The cards in the pile are [1,2,3], in which the cards are piled up in increasing order. Example 2 Play an empty card and draw the card 1, then play 1, 2, 3 in order.
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) f = True if 1 in b: j = b.index(1) for i in range(n - j): d = i + 1 - b[j + i] if d != 0: break else: s = -2 for k in range(j): if b[k] != 0 and b[k] - k <= n - (j - 1): break else: print(j) f = False if f: s = -2 for k in range(n): if b[k] != 0: s = max(s, k - b[k]) print(s + n + 2)
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
Nauuo is a girl who loves playing cards. One day she was playing cards but found that the cards were mixed with some empty ones. There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n cards in the pile are also given in the order from top to bottom. In one operation she can choose a card in her hands and play it — put it at the bottom of the pile, then draw the top card from the pile. Nauuo wants to make the n numbered cards piled up in increasing order (the i-th card in the pile from top to bottom is the card i) as quickly as possible. Can you tell her the minimum number of operations? Input The first line contains a single integer n (1≤ n≤ 2⋅ 10^5) — the number of numbered cards. The second line contains n integers a_1,a_2,…,a_n (0≤ a_i≤ n) — the initial cards in Nauuo's hands. 0 represents an empty card. The third line contains n integers b_1,b_2,…,b_n (0≤ b_i≤ n) — the initial cards in the pile, given in order from top to bottom. 0 represents an empty card. It is guaranteed that each number from 1 to n appears exactly once, either in a_{1..n} or b_{1..n}. Output The output contains a single integer — the minimum number of operations to make the n numbered cards piled up in increasing order. Examples Input 3 0 2 0 3 0 1 Output 2 Input 3 0 2 0 1 0 3 Output 4 Input 11 0 0 0 5 0 0 0 4 0 0 11 9 2 6 0 8 1 7 0 3 0 10 Output 18 Note Example 1 We can play the card 2 and draw the card 3 in the first operation. After that, we have [0,3,0] in hands and the cards in the pile are [0,1,2] from top to bottom. Then, we play the card 3 in the second operation. The cards in the pile are [1,2,3], in which the cards are piled up in increasing order. Example 2 Play an empty card and draw the card 1, then play 1, 2, 3 in order.
import sys input = sys.stdin.readline N = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) table = [0] * (N + 1) for i in range(N): if b[i]: table[b[i]] = i + 1 last = N - table[1] + 1 islast = 1 if table[1] == 0: last = 0 islast = 0 for i in range(1, last + 1): if table[i] != N - last + i: islast = 0 break if islast: for i in range(N - last): x = last + i + 1 if table[x] > i: islast = 0 break if islast: print(N - last) exit(0) x = 0 for i in range(1, N + 1): x = max(table[i], x) + 1 print(x)
IMPORT ASSIGN 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Nauuo is a girl who loves playing cards. One day she was playing cards but found that the cards were mixed with some empty ones. There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n cards in the pile are also given in the order from top to bottom. In one operation she can choose a card in her hands and play it — put it at the bottom of the pile, then draw the top card from the pile. Nauuo wants to make the n numbered cards piled up in increasing order (the i-th card in the pile from top to bottom is the card i) as quickly as possible. Can you tell her the minimum number of operations? Input The first line contains a single integer n (1≤ n≤ 2⋅ 10^5) — the number of numbered cards. The second line contains n integers a_1,a_2,…,a_n (0≤ a_i≤ n) — the initial cards in Nauuo's hands. 0 represents an empty card. The third line contains n integers b_1,b_2,…,b_n (0≤ b_i≤ n) — the initial cards in the pile, given in order from top to bottom. 0 represents an empty card. It is guaranteed that each number from 1 to n appears exactly once, either in a_{1..n} or b_{1..n}. Output The output contains a single integer — the minimum number of operations to make the n numbered cards piled up in increasing order. Examples Input 3 0 2 0 3 0 1 Output 2 Input 3 0 2 0 1 0 3 Output 4 Input 11 0 0 0 5 0 0 0 4 0 0 11 9 2 6 0 8 1 7 0 3 0 10 Output 18 Note Example 1 We can play the card 2 and draw the card 3 in the first operation. After that, we have [0,3,0] in hands and the cards in the pile are [0,1,2] from top to bottom. Then, we play the card 3 in the second operation. The cards in the pile are [1,2,3], in which the cards are piled up in increasing order. Example 2 Play an empty card and draw the card 1, then play 1, 2, 3 in order.
import sys n = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) if max(B) == 0: print(n) sys.exit() if 1 in B: x = B.index(1) y = n - x + 1 for i in range(x, n): if B[i] != i - x + 1: break else: for i in range(x): if B[i] > 0 and B[i] - y - i <= 0: break else: print(x) sys.exit() ANS = -2 for i in range(n): if B[i] != 0: ANS = max(ANS, i - B[i]) print(ANS + n + 2)
IMPORT 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
Nauuo is a girl who loves playing cards. One day she was playing cards but found that the cards were mixed with some empty ones. There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n cards in the pile are also given in the order from top to bottom. In one operation she can choose a card in her hands and play it — put it at the bottom of the pile, then draw the top card from the pile. Nauuo wants to make the n numbered cards piled up in increasing order (the i-th card in the pile from top to bottom is the card i) as quickly as possible. Can you tell her the minimum number of operations? Input The first line contains a single integer n (1≤ n≤ 2⋅ 10^5) — the number of numbered cards. The second line contains n integers a_1,a_2,…,a_n (0≤ a_i≤ n) — the initial cards in Nauuo's hands. 0 represents an empty card. The third line contains n integers b_1,b_2,…,b_n (0≤ b_i≤ n) — the initial cards in the pile, given in order from top to bottom. 0 represents an empty card. It is guaranteed that each number from 1 to n appears exactly once, either in a_{1..n} or b_{1..n}. Output The output contains a single integer — the minimum number of operations to make the n numbered cards piled up in increasing order. Examples Input 3 0 2 0 3 0 1 Output 2 Input 3 0 2 0 1 0 3 Output 4 Input 11 0 0 0 5 0 0 0 4 0 0 11 9 2 6 0 8 1 7 0 3 0 10 Output 18 Note Example 1 We can play the card 2 and draw the card 3 in the first operation. After that, we have [0,3,0] in hands and the cards in the pile are [0,1,2] from top to bottom. Then, we play the card 3 in the second operation. The cards in the pile are [1,2,3], in which the cards are piled up in increasing order. Example 2 Play an empty card and draw the card 1, then play 1, 2, 3 in order.
n = int(input()) a = [int(v) for v in input().split()] b = [int(v) for v in input().split()] c = 0 d = {} f = 0 for j in range(n): d[a[j]] = 1 j = n - 1 while j > 0: if b[j] == b[j - 1] + 1 and b[j] != 1: j = j - 1 else: break if b[j] == 1 and j > 0: p = b[-1] + 1 f = 1 elif b[j] == 1 and j == 0: f = 2 else: p = 1 if f == 0: w = 0 for j in range(n): if p not in d: w = w + 1 else: p = p + 1 d[b[j]] = 1 ans = w + n print(ans) elif f == 2: print(0) else: w = 0 m = j - 1 j = 0 while j <= m: if p in d and f == 1: w = w + 1 p = p + 1 elif f == 0 and p not in d: w = w + 1 elif f == 0 and p in d: p = p + 1 else: f = 0 w = w + 1 p = 1 m = n - 1 d[b[j]] = 1 j = j + 1 if f == 1: print(w) else: print(w + n)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
Nauuo is a girl who loves playing cards. One day she was playing cards but found that the cards were mixed with some empty ones. There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n cards in the pile are also given in the order from top to bottom. In one operation she can choose a card in her hands and play it — put it at the bottom of the pile, then draw the top card from the pile. Nauuo wants to make the n numbered cards piled up in increasing order (the i-th card in the pile from top to bottom is the card i) as quickly as possible. Can you tell her the minimum number of operations? Input The first line contains a single integer n (1≤ n≤ 2⋅ 10^5) — the number of numbered cards. The second line contains n integers a_1,a_2,…,a_n (0≤ a_i≤ n) — the initial cards in Nauuo's hands. 0 represents an empty card. The third line contains n integers b_1,b_2,…,b_n (0≤ b_i≤ n) — the initial cards in the pile, given in order from top to bottom. 0 represents an empty card. It is guaranteed that each number from 1 to n appears exactly once, either in a_{1..n} or b_{1..n}. Output The output contains a single integer — the minimum number of operations to make the n numbered cards piled up in increasing order. Examples Input 3 0 2 0 3 0 1 Output 2 Input 3 0 2 0 1 0 3 Output 4 Input 11 0 0 0 5 0 0 0 4 0 0 11 9 2 6 0 8 1 7 0 3 0 10 Output 18 Note Example 1 We can play the card 2 and draw the card 3 in the first operation. After that, we have [0,3,0] in hands and the cards in the pile are [0,1,2] from top to bottom. Then, we play the card 3 in the second operation. The cards in the pile are [1,2,3], in which the cards are piled up in increasing order. Example 2 Play an empty card and draw the card 1, then play 1, 2, 3 in order.
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) f = False if list(range(1, b[-1] + 1)) == b[-b[-1] :]: f = True s = set(a) for i in range(n - b[-1]): if b[-1] + i + 1 in s: s.add(b[i]) else: f = False break if f: print(n - b[-1]) if not f: print(max([-2] + [(i - b[i]) for i in range(n) if b[i]]) + 2 + n)
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP LIST NUMBER BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR
Nauuo is a girl who loves playing cards. One day she was playing cards but found that the cards were mixed with some empty ones. There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n cards in the pile are also given in the order from top to bottom. In one operation she can choose a card in her hands and play it — put it at the bottom of the pile, then draw the top card from the pile. Nauuo wants to make the n numbered cards piled up in increasing order (the i-th card in the pile from top to bottom is the card i) as quickly as possible. Can you tell her the minimum number of operations? Input The first line contains a single integer n (1≤ n≤ 2⋅ 10^5) — the number of numbered cards. The second line contains n integers a_1,a_2,…,a_n (0≤ a_i≤ n) — the initial cards in Nauuo's hands. 0 represents an empty card. The third line contains n integers b_1,b_2,…,b_n (0≤ b_i≤ n) — the initial cards in the pile, given in order from top to bottom. 0 represents an empty card. It is guaranteed that each number from 1 to n appears exactly once, either in a_{1..n} or b_{1..n}. Output The output contains a single integer — the minimum number of operations to make the n numbered cards piled up in increasing order. Examples Input 3 0 2 0 3 0 1 Output 2 Input 3 0 2 0 1 0 3 Output 4 Input 11 0 0 0 5 0 0 0 4 0 0 11 9 2 6 0 8 1 7 0 3 0 10 Output 18 Note Example 1 We can play the card 2 and draw the card 3 in the first operation. After that, we have [0,3,0] in hands and the cards in the pile are [0,1,2] from top to bottom. Then, we play the card 3 in the second operation. The cards in the pile are [1,2,3], in which the cards are piled up in increasing order. Example 2 Play an empty card and draw the card 1, then play 1, 2, 3 in order.
n = int(input()) arr1 = list(map(int, input().split())) arr2 = list(map(int, input().split())) arr3 = [0] mini = n + 1 for i in range(0, len(arr2)): if arr2[i] < mini and arr2[i] != 0: mini = arr2[i] if mini == n + 1: print(len(arr1)) exit() q = n + 1 a = 0 b = 0 m = 0 for i in range(0, len(arr2)): if mini == arr2[i]: q = int(i) if arr2[i] != 0: m = max(i + 1 - arr2[i] + 1, m) c = 1 count = 0 if arr2[q] == 1: for i in range(q + 1, len(arr2)): c += 1 if arr2[i] == c: count += 1 else: break a1 = 0 b1 = 0 if count == len(arr2) - q - 1: for j in range(0, q): if arr2[j] != 0: if arr2[j] <= arr2[count + q] + 1 + j: print(m + n) exit() print(q) exit() print(m + n)
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
Nauuo is a girl who loves playing cards. One day she was playing cards but found that the cards were mixed with some empty ones. There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n cards in the pile are also given in the order from top to bottom. In one operation she can choose a card in her hands and play it — put it at the bottom of the pile, then draw the top card from the pile. Nauuo wants to make the n numbered cards piled up in increasing order (the i-th card in the pile from top to bottom is the card i) as quickly as possible. Can you tell her the minimum number of operations? Input The first line contains a single integer n (1≤ n≤ 2⋅ 10^5) — the number of numbered cards. The second line contains n integers a_1,a_2,…,a_n (0≤ a_i≤ n) — the initial cards in Nauuo's hands. 0 represents an empty card. The third line contains n integers b_1,b_2,…,b_n (0≤ b_i≤ n) — the initial cards in the pile, given in order from top to bottom. 0 represents an empty card. It is guaranteed that each number from 1 to n appears exactly once, either in a_{1..n} or b_{1..n}. Output The output contains a single integer — the minimum number of operations to make the n numbered cards piled up in increasing order. Examples Input 3 0 2 0 3 0 1 Output 2 Input 3 0 2 0 1 0 3 Output 4 Input 11 0 0 0 5 0 0 0 4 0 0 11 9 2 6 0 8 1 7 0 3 0 10 Output 18 Note Example 1 We can play the card 2 and draw the card 3 in the first operation. After that, we have [0,3,0] in hands and the cards in the pile are [0,1,2] from top to bottom. Then, we play the card 3 in the second operation. The cards in the pile are [1,2,3], in which the cards are piled up in increasing order. Example 2 Play an empty card and draw the card 1, then play 1, 2, 3 in order.
n = int(input()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] r = 0 for ai in a: if ai != 0: r = max(r, n - ai + 1) b1 = [0] * (n + 1) b2 = [0] * (n + 1) bset = set() for i in range(n): if b[i] != 0: b2[b[i]] = i + 1 + n - b[i] + 1 b1[b[i]] = i + 1 - b[i] if b1[b[i]] < 0 or b1[b[i]] < r: b1[b[i]] = b2[b[i]] bset.add(b1[b[i]]) if len(bset) == 0: r = n else: mxbset = max(bset) bset2 = set() for i in range(1, n + 1): if b2[i] != 0: if b2[i] <= mxbset: bset2.add(mxbset) else: bset2.add(b1[i]) if len(bset2) == 1 and max(bset2) >= r: r = max(bset2) else: r = max(r, max(b2)) print(r)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Nauuo is a girl who loves playing cards. One day she was playing cards but found that the cards were mixed with some empty ones. There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n cards in the pile are also given in the order from top to bottom. In one operation she can choose a card in her hands and play it — put it at the bottom of the pile, then draw the top card from the pile. Nauuo wants to make the n numbered cards piled up in increasing order (the i-th card in the pile from top to bottom is the card i) as quickly as possible. Can you tell her the minimum number of operations? Input The first line contains a single integer n (1≤ n≤ 2⋅ 10^5) — the number of numbered cards. The second line contains n integers a_1,a_2,…,a_n (0≤ a_i≤ n) — the initial cards in Nauuo's hands. 0 represents an empty card. The third line contains n integers b_1,b_2,…,b_n (0≤ b_i≤ n) — the initial cards in the pile, given in order from top to bottom. 0 represents an empty card. It is guaranteed that each number from 1 to n appears exactly once, either in a_{1..n} or b_{1..n}. Output The output contains a single integer — the minimum number of operations to make the n numbered cards piled up in increasing order. Examples Input 3 0 2 0 3 0 1 Output 2 Input 3 0 2 0 1 0 3 Output 4 Input 11 0 0 0 5 0 0 0 4 0 0 11 9 2 6 0 8 1 7 0 3 0 10 Output 18 Note Example 1 We can play the card 2 and draw the card 3 in the first operation. After that, we have [0,3,0] in hands and the cards in the pile are [0,1,2] from top to bottom. Then, we play the card 3 in the second operation. The cards in the pile are [1,2,3], in which the cards are piled up in increasing order. Example 2 Play an empty card and draw the card 1, then play 1, 2, 3 in order.
n = int(input()) a = [(0 if i == 0 else n - i + 1) for i in map(int, input().split())] b = list(map(int, input().split())) t = True s = 0 if 1 in b: i = 0 while b[i] != 1: b[i] = 0 if b[i] == 0 else i + n - b[i] + 2 i += 1 s = i while i < n - 1: if b[i + 1] == b[i] + 1: i += 1 else: break if i == n - 1: if s == 0: print(0) elif max(max(a), max(b[:s])) > s: t = False else: print(s) else: t = False if not t: for i in range(s, n): b[i] = 0 if b[i] == 0 else i + n - b[i] + 2 print(max(max(a), max(b))) else: for i in range(n): b[i] = 0 if b[i] == 0 else i + n - b[i] + 2 print(max(max(a), max(b)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
Nauuo is a girl who loves playing cards. One day she was playing cards but found that the cards were mixed with some empty ones. There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n cards in the pile are also given in the order from top to bottom. In one operation she can choose a card in her hands and play it — put it at the bottom of the pile, then draw the top card from the pile. Nauuo wants to make the n numbered cards piled up in increasing order (the i-th card in the pile from top to bottom is the card i) as quickly as possible. Can you tell her the minimum number of operations? Input The first line contains a single integer n (1≤ n≤ 2⋅ 10^5) — the number of numbered cards. The second line contains n integers a_1,a_2,…,a_n (0≤ a_i≤ n) — the initial cards in Nauuo's hands. 0 represents an empty card. The third line contains n integers b_1,b_2,…,b_n (0≤ b_i≤ n) — the initial cards in the pile, given in order from top to bottom. 0 represents an empty card. It is guaranteed that each number from 1 to n appears exactly once, either in a_{1..n} or b_{1..n}. Output The output contains a single integer — the minimum number of operations to make the n numbered cards piled up in increasing order. Examples Input 3 0 2 0 3 0 1 Output 2 Input 3 0 2 0 1 0 3 Output 4 Input 11 0 0 0 5 0 0 0 4 0 0 11 9 2 6 0 8 1 7 0 3 0 10 Output 18 Note Example 1 We can play the card 2 and draw the card 3 in the first operation. After that, we have [0,3,0] in hands and the cards in the pile are [0,1,2] from top to bottom. Then, we play the card 3 in the second operation. The cards in the pile are [1,2,3], in which the cards are piled up in increasing order. Example 2 Play an empty card and draw the card 1, then play 1, 2, 3 in order.
from sys import exit N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) def checkran(X): m = X[-1] if m == 0: return 0 t = m for x in X[::-1]: if x != t: return 0 t -= 1 if t == 0: return m def check(X, k): for i, x in enumerate(X[: N - k]): if x == 0: continue if k + 1 + i >= x: return False return True k = checkran(B) if k: if check(B, k): print(N - k) exit() m = 0 for i, b in enumerate(B, 1): if b == 1: m = i break C = B[m:] C = [(i - c) for i, c in enumerate(C, 2) if c != 0] + [0] print(m + N + max(C))
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR FOR VAR VAR NUMBER IF VAR VAR RETURN NUMBER VAR NUMBER IF VAR NUMBER RETURN VAR FUNC_DEF FOR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER LIST NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR
Nauuo is a girl who loves playing cards. One day she was playing cards but found that the cards were mixed with some empty ones. There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n cards in the pile are also given in the order from top to bottom. In one operation she can choose a card in her hands and play it — put it at the bottom of the pile, then draw the top card from the pile. Nauuo wants to make the n numbered cards piled up in increasing order (the i-th card in the pile from top to bottom is the card i) as quickly as possible. Can you tell her the minimum number of operations? Input The first line contains a single integer n (1≤ n≤ 2⋅ 10^5) — the number of numbered cards. The second line contains n integers a_1,a_2,…,a_n (0≤ a_i≤ n) — the initial cards in Nauuo's hands. 0 represents an empty card. The third line contains n integers b_1,b_2,…,b_n (0≤ b_i≤ n) — the initial cards in the pile, given in order from top to bottom. 0 represents an empty card. It is guaranteed that each number from 1 to n appears exactly once, either in a_{1..n} or b_{1..n}. Output The output contains a single integer — the minimum number of operations to make the n numbered cards piled up in increasing order. Examples Input 3 0 2 0 3 0 1 Output 2 Input 3 0 2 0 1 0 3 Output 4 Input 11 0 0 0 5 0 0 0 4 0 0 11 9 2 6 0 8 1 7 0 3 0 10 Output 18 Note Example 1 We can play the card 2 and draw the card 3 in the first operation. After that, we have [0,3,0] in hands and the cards in the pile are [0,1,2] from top to bottom. Then, we play the card 3 in the second operation. The cards in the pile are [1,2,3], in which the cards are piled up in increasing order. Example 2 Play an empty card and draw the card 1, then play 1, 2, 3 in order.
import sys input = sys.stdin.readline sys.setrecursionlimit(10000) n = int(input()) a_list = list(map(int, input().split())) b_list = list(map(int, input().split())) def get_min(start_idx, l): min_value = -1 min_index = start_idx for i in range(start_idx, n): v = l[i] if v != 0 and (min_value > v or min_value == -1): min_index = i min_value = v if min_value == -1: return n, 0 return min_index, min_value min_index, min_value = get_min(0, b_list) if min_value == 1: flag = False for i in range(min_index + 1, n): v = b_list[i] if v - 1 != i - min_index: flag = True break ls = n - min_index fl = [(0) for _ in range(n + 1)] for i, v in enumerate(a_list): fl[v] = 1 for i in range(min_index): if fl[ls + i + 1] != 1: flag = True fl[b_list[i]] = 1 if not flag: print(min_index) sys.exit() pos = [(0) for i in range(n + 1)] for i, v in enumerate(b_list): pos[v] = i + 1 answer = -1 for i in range(1, n + 1): answer = max(answer, n + 1 - i + pos[i]) print(answer)
IMPORT ASSIGN VAR VAR EXPR FUNC_CALL 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER RETURN VAR NUMBER RETURN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
Nauuo is a girl who loves playing cards. One day she was playing cards but found that the cards were mixed with some empty ones. There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n cards in the pile are also given in the order from top to bottom. In one operation she can choose a card in her hands and play it — put it at the bottom of the pile, then draw the top card from the pile. Nauuo wants to make the n numbered cards piled up in increasing order (the i-th card in the pile from top to bottom is the card i) as quickly as possible. Can you tell her the minimum number of operations? Input The first line contains a single integer n (1≤ n≤ 2⋅ 10^5) — the number of numbered cards. The second line contains n integers a_1,a_2,…,a_n (0≤ a_i≤ n) — the initial cards in Nauuo's hands. 0 represents an empty card. The third line contains n integers b_1,b_2,…,b_n (0≤ b_i≤ n) — the initial cards in the pile, given in order from top to bottom. 0 represents an empty card. It is guaranteed that each number from 1 to n appears exactly once, either in a_{1..n} or b_{1..n}. Output The output contains a single integer — the minimum number of operations to make the n numbered cards piled up in increasing order. Examples Input 3 0 2 0 3 0 1 Output 2 Input 3 0 2 0 1 0 3 Output 4 Input 11 0 0 0 5 0 0 0 4 0 0 11 9 2 6 0 8 1 7 0 3 0 10 Output 18 Note Example 1 We can play the card 2 and draw the card 3 in the first operation. After that, we have [0,3,0] in hands and the cards in the pile are [0,1,2] from top to bottom. Then, we play the card 3 in the second operation. The cards in the pile are [1,2,3], in which the cards are piled up in increasing order. Example 2 Play an empty card and draw the card 1, then play 1, 2, 3 in order.
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) inhand = [(0) for i in range(2 * n + 2)] if 1 in b: loc1 = b.index(1) asc = 1 for i in range(loc1, n): if b[i] > asc: asc = 1 break if b[i] == asc: asc += 1 moves = 0 if asc > 1: for i in range(n): inhand[a[i]] = 1 for i in range(2 * n): if asc > n: break if inhand[asc]: asc += 1 inhand[b[moves % n]] = 1 moves += 1 if moves <= loc1: print(moves) exit() asc = 1 inhand = [(0) for i in range(n + 1)] for i in range(n): inhand[a[i]] = 1 moves = 0 for i in range(2 * n + 2): if asc > n: break if inhand[asc]: asc += 1 inhand[b[moves % n]] = 1 moves += 1 print(moves)
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Nauuo is a girl who loves playing cards. One day she was playing cards but found that the cards were mixed with some empty ones. There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n cards in the pile are also given in the order from top to bottom. In one operation she can choose a card in her hands and play it — put it at the bottom of the pile, then draw the top card from the pile. Nauuo wants to make the n numbered cards piled up in increasing order (the i-th card in the pile from top to bottom is the card i) as quickly as possible. Can you tell her the minimum number of operations? Input The first line contains a single integer n (1≤ n≤ 2⋅ 10^5) — the number of numbered cards. The second line contains n integers a_1,a_2,…,a_n (0≤ a_i≤ n) — the initial cards in Nauuo's hands. 0 represents an empty card. The third line contains n integers b_1,b_2,…,b_n (0≤ b_i≤ n) — the initial cards in the pile, given in order from top to bottom. 0 represents an empty card. It is guaranteed that each number from 1 to n appears exactly once, either in a_{1..n} or b_{1..n}. Output The output contains a single integer — the minimum number of operations to make the n numbered cards piled up in increasing order. Examples Input 3 0 2 0 3 0 1 Output 2 Input 3 0 2 0 1 0 3 Output 4 Input 11 0 0 0 5 0 0 0 4 0 0 11 9 2 6 0 8 1 7 0 3 0 10 Output 18 Note Example 1 We can play the card 2 and draw the card 3 in the first operation. After that, we have [0,3,0] in hands and the cards in the pile are [0,1,2] from top to bottom. Then, we play the card 3 in the second operation. The cards in the pile are [1,2,3], in which the cards are piled up in increasing order. Example 2 Play an empty card and draw the card 1, then play 1, 2, 3 in order.
def ain(): return map(int, input().split()) def lin(): return list(ain()) def plist(l): for x in l: print(x, end=" ") print() def indexof(l, v, l3): return l3[v] n = int(input()) l1 = lin() l2 = lin() l3 = [-1] * (n + 1) l4 = [0] * (n + 1) for i in range(n): x = l2[i] if x != 0: l3[x] = i ui = 0 if n == 1: if l2[0] == 1: print(0) else: print(1) ui = 1 if indexof(l2, 1, l3) >= 0 and indexof(l2, 1, l3) != n - 1 and ui == 0: i = indexof(l2, 1, l3) j = 1 fk = 0 while i < n: if l2[i] != j: fk = 1 i += 1 j += 1 if fk == 0: x = l2[n - 1] fm = 0 for i in range(1, n - l2[n - 1] + 1): if indexof(l2, x + i, l3) >= i - 1: fm = 1 break if fm == 0: print(indexof(l2, 1, l3)) ui = 1 if l2[n - 1] != 1 and ui == 0: if indexof(l2, 1, l3) == -1: w = 0 for j in range(n): if l2[j] != 0: w = max(w, j - l2[j] + 2) else: i1 = indexof(l2, 1, l3) w = i1 + 1 for j in range(i1 + 1, n): if l2[j] != 0: w = max(w, j - l2[j] + 2) print(w + n) elif ui == 0: fl = 0 for i in range(n - 1): if l2[i] - i < 3 and l2[i] != 0: fl = 1 break if 2 not in l1: fl = 1 if fl == 0: print(n - 1) else: print(2 * n)
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FUNC_DEF RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR
Nauuo is a girl who loves playing cards. One day she was playing cards but found that the cards were mixed with some empty ones. There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n cards in the pile are also given in the order from top to bottom. In one operation she can choose a card in her hands and play it — put it at the bottom of the pile, then draw the top card from the pile. Nauuo wants to make the n numbered cards piled up in increasing order (the i-th card in the pile from top to bottom is the card i) as quickly as possible. Can you tell her the minimum number of operations? Input The first line contains a single integer n (1≤ n≤ 2⋅ 10^5) — the number of numbered cards. The second line contains n integers a_1,a_2,…,a_n (0≤ a_i≤ n) — the initial cards in Nauuo's hands. 0 represents an empty card. The third line contains n integers b_1,b_2,…,b_n (0≤ b_i≤ n) — the initial cards in the pile, given in order from top to bottom. 0 represents an empty card. It is guaranteed that each number from 1 to n appears exactly once, either in a_{1..n} or b_{1..n}. Output The output contains a single integer — the minimum number of operations to make the n numbered cards piled up in increasing order. Examples Input 3 0 2 0 3 0 1 Output 2 Input 3 0 2 0 1 0 3 Output 4 Input 11 0 0 0 5 0 0 0 4 0 0 11 9 2 6 0 8 1 7 0 3 0 10 Output 18 Note Example 1 We can play the card 2 and draw the card 3 in the first operation. After that, we have [0,3,0] in hands and the cards in the pile are [0,1,2] from top to bottom. Then, we play the card 3 in the second operation. The cards in the pile are [1,2,3], in which the cards are piled up in increasing order. Example 2 Play an empty card and draw the card 1, then play 1, 2, 3 in order.
for _ in range(1): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) k = b[n - 1] for i in range(k): if b[n - i - 1] != k - i: k = 0 ma = 0 for i in range(n - k): if b[i] == 0: continue if b[i] - k - 1 <= i: ma = max(ma, i - b[i] + k + 2) if ma == 0: print(n - k) elif k == 0: print(n + ma) else: k = 0 ma = 0 for i in range(n - k): if b[i] == 0: continue if b[i] - k - 1 <= i: ma = max(ma, i - b[i] + k + 2) print(n + ma)
FOR VAR FUNC_CALL 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't. You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not. You managed to steal the general's notes, with n - k + 1 strings s_1, s_2, ..., s_{n} - k + 1, each either "YES" or "NO". The string s_1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise). The string s_2 describes a group of soldiers 2 through k + 1. And so on, till the string s_{n} - k + 1 that describes a group of soldiers n - k + 1 through n. Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example. Find and print any solution. It can be proved that there always exists at least one solution. -----Input----- The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively. The second line contains n - k + 1 strings s_1, s_2, ..., s_{n} - k + 1. The string s_{i} is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise. -----Output----- Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them. -----Examples----- Input 8 3 NO NO YES YES YES NO Output Adam Bob Bob Cpqepqwer Limak Adam Bob Adam Input 9 8 YES NO Output R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc Input 3 2 NO NO Output Na Na Na -----Note----- In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output: First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s_1 is "NO". Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s_2 is "NO". Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s_3 is "YES". ..., Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s_6 is "NO".
n, k = list(map(int, input().split())) a = input().split() names = [chr(ord("A") + i) for i in range(26)] + [ (chr(ord("A") + i) + chr(ord("a") + i)) for i in range(26) ] ans = [names[i] for i in range(n)] for i in range(k - 1, n): if a[i - k + 1] == "NO": ans[i] = ans[i - k + 1] print(*ans)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER STRING ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't. You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not. You managed to steal the general's notes, with n - k + 1 strings s_1, s_2, ..., s_{n} - k + 1, each either "YES" or "NO". The string s_1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise). The string s_2 describes a group of soldiers 2 through k + 1. And so on, till the string s_{n} - k + 1 that describes a group of soldiers n - k + 1 through n. Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example. Find and print any solution. It can be proved that there always exists at least one solution. -----Input----- The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively. The second line contains n - k + 1 strings s_1, s_2, ..., s_{n} - k + 1. The string s_{i} is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise. -----Output----- Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them. -----Examples----- Input 8 3 NO NO YES YES YES NO Output Adam Bob Bob Cpqepqwer Limak Adam Bob Adam Input 9 8 YES NO Output R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc Input 3 2 NO NO Output Na Na Na -----Note----- In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output: First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s_1 is "NO". Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s_2 is "NO". Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s_3 is "YES". ..., Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s_6 is "NO".
def name(n): return chr(ord("A") + n % 26) + chr(ord("a") + n // 26) def main(): n, k = map(int, input().split()) arr = list(map(str, input().split())) if arr.count("YES") == 0: for i in range(n): print("Max ", end="") return ans = ["" for i in range(n)] x = arr.index("YES") for i in range(k): ans[x + i] = name(i + x) for i in range(x + 1, n - k + 1): if arr[i] == "YES": ans[i + k - 1] = name(i + k - 1) else: ans[i + k - 1] = ans[i] for i in range(x - 1, -1, -1): if arr[i] == "YES": ans[i] = name(i) else: ans[i] = ans[i + k - 1] print(*ans) main()
FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING RETURN ASSIGN VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't. You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not. You managed to steal the general's notes, with n - k + 1 strings s_1, s_2, ..., s_{n} - k + 1, each either "YES" or "NO". The string s_1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise). The string s_2 describes a group of soldiers 2 through k + 1. And so on, till the string s_{n} - k + 1 that describes a group of soldiers n - k + 1 through n. Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example. Find and print any solution. It can be proved that there always exists at least one solution. -----Input----- The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively. The second line contains n - k + 1 strings s_1, s_2, ..., s_{n} - k + 1. The string s_{i} is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise. -----Output----- Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them. -----Examples----- Input 8 3 NO NO YES YES YES NO Output Adam Bob Bob Cpqepqwer Limak Adam Bob Adam Input 9 8 YES NO Output R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc Input 3 2 NO NO Output Na Na Na -----Note----- In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output: First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s_1 is "NO". Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s_2 is "NO". Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s_3 is "YES". ..., Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s_6 is "NO".
def get(x): return chr(ord("A") + x // 26) + chr(ord("a") + x % 26) read = lambda: map(int, input().split()) n, k = read() a = input().split() ans = [0] * n num = 1 for i in range(k - 1): ans[i] = num num += 1 for i in range(k - 1, n): cur = a[i - k + 1] if cur == "YES": num += 1 ans[i] = num else: ans[i] = ans[i - k + 1] res = " ".join(map(str, [get(i) for i in ans])) print(res)
FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR STRING VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't. You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not. You managed to steal the general's notes, with n - k + 1 strings s_1, s_2, ..., s_{n} - k + 1, each either "YES" or "NO". The string s_1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise). The string s_2 describes a group of soldiers 2 through k + 1. And so on, till the string s_{n} - k + 1 that describes a group of soldiers n - k + 1 through n. Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example. Find and print any solution. It can be proved that there always exists at least one solution. -----Input----- The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively. The second line contains n - k + 1 strings s_1, s_2, ..., s_{n} - k + 1. The string s_{i} is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise. -----Output----- Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them. -----Examples----- Input 8 3 NO NO YES YES YES NO Output Adam Bob Bob Cpqepqwer Limak Adam Bob Adam Input 9 8 YES NO Output R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc Input 3 2 NO NO Output Na Na Na -----Note----- In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output: First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s_1 is "NO". Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s_2 is "NO". Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s_3 is "YES". ..., Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s_6 is "NO".
n, k = map(int, input().split()) a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" names = [] for x in a: names.append(x) names.append(x + x.lower()) names = names[:n] s = input().split() for i in range(n - k + 1): if s[i] == "NO": names[i + k - 1] = names[i] print(" ".join(names))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't. You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not. You managed to steal the general's notes, with n - k + 1 strings s_1, s_2, ..., s_{n} - k + 1, each either "YES" or "NO". The string s_1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise). The string s_2 describes a group of soldiers 2 through k + 1. And so on, till the string s_{n} - k + 1 that describes a group of soldiers n - k + 1 through n. Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example. Find and print any solution. It can be proved that there always exists at least one solution. -----Input----- The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively. The second line contains n - k + 1 strings s_1, s_2, ..., s_{n} - k + 1. The string s_{i} is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise. -----Output----- Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them. -----Examples----- Input 8 3 NO NO YES YES YES NO Output Adam Bob Bob Cpqepqwer Limak Adam Bob Adam Input 9 8 YES NO Output R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc Input 3 2 NO NO Output Na Na Na -----Note----- In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output: First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s_1 is "NO". Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s_2 is "NO". Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s_3 is "YES". ..., Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s_6 is "NO".
names = [(chr(i + 65) + chr(j + 97)) for i in range(26) for j in range(26)] n, m = map(int, input().split()) ans = names[: m - 1] j = m - 1 k = 0 for i in input().split(): if i == "YES": ans.append(names[j]) j += 1 else: ans.append(ans[k]) k += 1 print(" ".join(ans))
ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't. You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not. You managed to steal the general's notes, with n - k + 1 strings s_1, s_2, ..., s_{n} - k + 1, each either "YES" or "NO". The string s_1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise). The string s_2 describes a group of soldiers 2 through k + 1. And so on, till the string s_{n} - k + 1 that describes a group of soldiers n - k + 1 through n. Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example. Find and print any solution. It can be proved that there always exists at least one solution. -----Input----- The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively. The second line contains n - k + 1 strings s_1, s_2, ..., s_{n} - k + 1. The string s_{i} is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise. -----Output----- Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them. -----Examples----- Input 8 3 NO NO YES YES YES NO Output Adam Bob Bob Cpqepqwer Limak Adam Bob Adam Input 9 8 YES NO Output R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc Input 3 2 NO NO Output Na Na Na -----Note----- In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output: First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s_1 is "NO". Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s_2 is "NO". Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s_3 is "YES". ..., Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s_6 is "NO".
l = [ "Aa", "Ab", "Ac", "Ad", "Ae", "Af", "Ag", "Ah", "Ai", "Aj", "Ak", "Al", "Am", "An", "Ao", "Ap", "Aq", "Ar", "As", "At", "Au", "Av", "Aw", "Ax", "Ay", "Az", "Aaa", "Abb", "Acc", "Add", "Aee", "Aff", "Agg", "Ahh", "Aii", "Ajj", "Akk", "All", "Amm", "Ann", "Aoo", "App", "Aqq", "Arr", "Ass", "Att", "Auu", "Avv", "Aww", "Axx", "Ayy", ] n, k = map(int, input().split()) li = list(map(str, input().split())) lc = l[:n] for i in range(len(li)): if li[i] == "NO": lc[i + k - 1] = lc[i] for i in lc: print(i, end=" ")
ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't. You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not. You managed to steal the general's notes, with n - k + 1 strings s_1, s_2, ..., s_{n} - k + 1, each either "YES" or "NO". The string s_1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise). The string s_2 describes a group of soldiers 2 through k + 1. And so on, till the string s_{n} - k + 1 that describes a group of soldiers n - k + 1 through n. Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example. Find and print any solution. It can be proved that there always exists at least one solution. -----Input----- The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively. The second line contains n - k + 1 strings s_1, s_2, ..., s_{n} - k + 1. The string s_{i} is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise. -----Output----- Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them. -----Examples----- Input 8 3 NO NO YES YES YES NO Output Adam Bob Bob Cpqepqwer Limak Adam Bob Adam Input 9 8 YES NO Output R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc Input 3 2 NO NO Output Na Na Na -----Note----- In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output: First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s_1 is "NO". Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s_2 is "NO". Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s_3 is "YES". ..., Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s_6 is "NO".
n, k = map(int, input().split()) l_o = input().split() a_n = ["A"] for i in range(1, n): diff = i - 25 if i >= 25 else 0 a_n += [ chr(ord("A") + i - (26 if diff != 0 else 0)) + ("" if diff == 0 else chr(ord("a") + diff)) ] for i in range(n - k + 1): if l_o[i] == "NO": a_n[i + k - 1] = a_n[i] print(" ".join(a_n))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR LIST BIN_OP FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR STRING VAR VAR NUMBER NUMBER NUMBER VAR NUMBER STRING FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't. You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not. You managed to steal the general's notes, with n - k + 1 strings s_1, s_2, ..., s_{n} - k + 1, each either "YES" or "NO". The string s_1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise). The string s_2 describes a group of soldiers 2 through k + 1. And so on, till the string s_{n} - k + 1 that describes a group of soldiers n - k + 1 through n. Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example. Find and print any solution. It can be proved that there always exists at least one solution. -----Input----- The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively. The second line contains n - k + 1 strings s_1, s_2, ..., s_{n} - k + 1. The string s_{i} is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise. -----Output----- Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them. -----Examples----- Input 8 3 NO NO YES YES YES NO Output Adam Bob Bob Cpqepqwer Limak Adam Bob Adam Input 9 8 YES NO Output R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc Input 3 2 NO NO Output Na Na Na -----Note----- In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output: First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s_1 is "NO". Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s_2 is "NO". Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s_3 is "YES". ..., Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s_6 is "NO".
n, k = map(int, input().split()) words = [] for i in range(ord("A"), ord("Z") + 1): for j in range(ord("a"), ord("z") + 1): words.append(chr(i) + chr(j)) our = input().split() res = [i for i in range(n)] for j in range(50): for i in range(len(our)): if our[i] == "NO": res[i] = res[i + k - 1] for elem in res: print(words[elem], end=" ")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't. You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not. You managed to steal the general's notes, with n - k + 1 strings s_1, s_2, ..., s_{n} - k + 1, each either "YES" or "NO". The string s_1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise). The string s_2 describes a group of soldiers 2 through k + 1. And so on, till the string s_{n} - k + 1 that describes a group of soldiers n - k + 1 through n. Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example. Find and print any solution. It can be proved that there always exists at least one solution. -----Input----- The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively. The second line contains n - k + 1 strings s_1, s_2, ..., s_{n} - k + 1. The string s_{i} is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise. -----Output----- Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them. -----Examples----- Input 8 3 NO NO YES YES YES NO Output Adam Bob Bob Cpqepqwer Limak Adam Bob Adam Input 9 8 YES NO Output R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc Input 3 2 NO NO Output Na Na Na -----Note----- In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output: First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s_1 is "NO". Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s_2 is "NO". Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s_3 is "YES". ..., Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s_6 is "NO".
n, k = map(int, input().split()) names = [] for i in range(ord("a"), ord("z") + 1): names.append("A" + chr(i)) for i in range(ord("a"), ord("z") + 1): names.append("B" + chr(i)) pos = 0 a = input().split() ans = [] for i in range(k - 1): ans.append(names[pos]) pos += 1 for i in range(n - k + 1): if a[i] == "YES": ans.append(names[pos]) pos += 1 else: ans.append(ans[i]) print(" ".join(ans))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR