description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended. Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times. -----Input----- The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive. -----Output----- Print the sought minimum number of people -----Examples----- Input +-+-+ Output 1 Input --- Output 3
s = input() n = len(s) x, a, b = 0, 0, 0 for i in range(n): if s[i] == "-": x -= 1 else: x += 1 a = min(a, x) b = max(b, x) print(b - a)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended. Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times. -----Input----- The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive. -----Output----- Print the sought minimum number of people -----Examples----- Input +-+-+ Output 1 Input --- Output 3
def rainy(S): IN = 0 OUT = 0 for i in S: if i == "+": if OUT == 0: IN += 1 else: IN += 1 OUT -= 1 elif IN == 0: OUT += 1 else: OUT += 1 IN -= 1 return IN + OUT S = input() print(rainy(S))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended. Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times. -----Input----- The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive. -----Output----- Print the sought minimum number of people -----Examples----- Input +-+-+ Output 1 Input --- Output 3
s = input() plus = 0 minus = 0 seen = 0 for letter in s: if letter == "+": if minus == 0: plus += 1 seen += 1 else: plus += 1 minus -= 1 elif plus == 0: minus += 1 seen += 1 else: minus += 1 plus -= 1 print(seen)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended. Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times. -----Input----- The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive. -----Output----- Print the sought minimum number of people -----Examples----- Input +-+-+ Output 1 Input --- Output 3
def puts(s): print(s, end="") s = input() a = mi = ma = 0 for c in s: if c == "+": a = a + 1 ma = max(ma, a) else: a = a - 1 mi = min(mi, a) print(ma - mi)
FUNC_DEF EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER FOR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended. Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times. -----Input----- The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive. -----Output----- Print the sought minimum number of people -----Examples----- Input +-+-+ Output 1 Input --- Output 3
import sys def get_string(): return sys.stdin.readline().strip() inNOut = get_string() pluses = 0 minuses = 0 for i in range(len(inNOut)): if inNOut[i] == "+": pluses += 1 if minuses != 0: minuses -= 1 elif inNOut[i] == "-": minuses += 1 if pluses != 0: pluses -= 1 print(pluses + minuses)
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended. Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times. -----Input----- The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive. -----Output----- Print the sought minimum number of people -----Examples----- Input +-+-+ Output 1 Input --- Output 3
s = input() s = list(s) s1 = [0] * len(s) for i in range(len(s)): if s[i] == "-": s[i] = 1 s1[i] = -1 else: s[i] = -1 s1[i] = 1 def kadane(s): maxi = -1 curr = 0 for i in s: curr = max(curr + i, i) maxi = max(maxi, curr) return maxi print(max(kadane(s), kadane(s1)))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended. Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times. -----Input----- The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive. -----Output----- Print the sought minimum number of people -----Examples----- Input +-+-+ Output 1 Input --- Output 3
s = input() c = 1 n = len(s) inside = 0 outside = 0 for i in range(n): if s[i] == "+": inside += 1 if outside > 0: outside -= 1 else: outside += 1 if inside > 0: inside -= 1 c = max(c, inside, outside) print(c)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended. Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times. -----Input----- The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive. -----Output----- Print the sought minimum number of people -----Examples----- Input +-+-+ Output 1 Input --- Output 3
def N5(): seq = input() inside = outside = 0 for i in seq: if i == "+": inside += 1 if outside: outside -= 1 else: outside += 1 if inside: inside -= 1 suspects = abs(inside + outside) print(suspects) N5()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended. Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times. -----Input----- The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive. -----Output----- Print the sought minimum number of people -----Examples----- Input +-+-+ Output 1 Input --- Output 3
s = list(input()) ans = 0 while s.count("+") != 0 and s.count("-") != 0: flag = 0 ans += 1 if s.index("+") < s.index("-"): s[s.index("+")] = 0 for i in range(1, len(s)): if flag == 0 and s[i] == "-": flag = 1 s[i] = 0 elif flag == 1 and s[i] == "+": flag = 0 s[i] = 0 elif s.index("-") < s.index("+"): s[s.index("-")] = 0 for i in range(1, len(s)): if flag == 0 and s[i] == "+": flag = 1 s[i] = 0 elif flag == 1 and s[i] == "-": flag = 0 s[i] = 0 print(max(ans + s.count("+"), ans + s.count("-")))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER VAR NUMBER IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING BIN_OP VAR FUNC_CALL VAR STRING
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended. Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times. -----Input----- The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive. -----Output----- Print the sought minimum number of people -----Examples----- Input +-+-+ Output 1 Input --- Output 3
c, v1, v2 = 0, 0, 0 for ch in input(): c += 1 if ch == "+" else -1 v1, v2 = min(v1, c), max(v2, c) print(v2 - v1)
ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR STRING NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended. Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times. -----Input----- The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive. -----Output----- Print the sought minimum number of people -----Examples----- Input +-+-+ Output 1 Input --- Output 3
inside = outside = 0 for c in list(input()): if c == "+": if outside: outside -= 1 inside += 1 else: if inside: inside -= 1 outside += 1 print(inside + outside)
ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR STRING IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended. Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times. -----Input----- The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive. -----Output----- Print the sought minimum number of people -----Examples----- Input +-+-+ Output 1 Input --- Output 3
s = input() t = mx = 0 for i in s: if i == "-" and t > 0: t -= 1 elif i == "+": t += 1 mx = max(mx, t) else: mx += 1 print(mx)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER IF VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended. Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times. -----Input----- The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive. -----Output----- Print the sought minimum number of people -----Examples----- Input +-+-+ Output 1 Input --- Output 3
s = input() ans = a1 = a2 = 0 for i in s: if i == "+": ans += 1 else: ans -= 1 a1 = max(a1, ans) a2 = min(a2, ans) print(a1 + abs(a2))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended. Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times. -----Input----- The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive. -----Output----- Print the sought minimum number of people -----Examples----- Input +-+-+ Output 1 Input --- Output 3
l = list(input()) j = 0 c = 0 k = 0 l1 = 0 e = 0 p = 0 while j < len(l): if l[j] == "+": p += 1 k += 1 else: l1 += 1 if k >= e: c += k - e e = k k -= 1 if l1 > p: l1 -= 1 c += 1 j += 1 if k > e: c += k - e print(c)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended. Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times. -----Input----- The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive. -----Output----- Print the sought minimum number of people -----Examples----- Input +-+-+ Output 1 Input --- Output 3
string_name = input() plus = 0 minus = 0 max = 0 for i in range(0, len(string_name)): if string_name[i] == "+": plus = plus + 1 if minus >= 1: minus = minus - 1 elif string_name[i] == "-": minus = minus + 1 if plus >= 1: plus = plus - 1 if plus > minus and max < plus - minus: max = plus - minus elif plus < minus and max < minus - plus: max = minus - plus if max == 0: max = 1 print(max)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended. Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times. -----Input----- The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive. -----Output----- Print the sought minimum number of people -----Examples----- Input +-+-+ Output 1 Input --- Output 3
m, p, c = 0, 0, 0 s = input() for i in s: if i == "-": c -= 1 else: c += 1 m = min(m, c) p = max(p, c) print(p - m)
ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended. Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times. -----Input----- The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive. -----Output----- Print the sought minimum number of people -----Examples----- Input +-+-+ Output 1 Input --- Output 3
a = input() n = len(a) ans = [] cnt = 1 m = 1 mm = 0 ans.append(1) for i in range(1, n): if a[i] == a[0]: cnt += 1 else: cnt -= 1 ans.append(cnt) m = max(m, cnt) mm = min(mm, cnt) print(m + abs(mm))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended. Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times. -----Input----- The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive. -----Output----- Print the sought minimum number of people -----Examples----- Input +-+-+ Output 1 Input --- Output 3
S = input() ans = 0 p, n = 0, 0 for i in range(len(S)): if S[i] == "+": p += 1 n -= 1 else: n += 1 p -= 1 n = max(0, n) p = max(0, p) ans = max(ans, max(n, p)) print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended. Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times. -----Input----- The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive. -----Output----- Print the sought minimum number of people -----Examples----- Input +-+-+ Output 1 Input --- Output 3
def solve(s): n = len(s) if n == 1: return 1 else: start = 0 prev = s[0] ans = 0 f = 1 for i in range(1, n): f = 1 if s[i] == prev: continue else: f = 0 ans = max(ans, i - start) start = i prev = s[i] if f: ans = max(ans, n - start) start = i prev = s[i] return ans def solve1(s): st = [] ans = 0 maxx = 0 for i in s: if st: ans = 0 if i == "+": st.append("+") elif st: st.pop() else: ans += 1 maxx = max(maxx, ans) maxx = max(maxx, len(st)) maxx = max(maxx, len(st)) return maxx def solve2(s): st = [] ans = 0 maxx = 0 for i in s: if st: ans = 0 if i == "-": st.append("-") elif st: st.pop() else: ans += 1 maxx = max(maxx, ans) maxx = max(maxx, len(st)) maxx = max(maxx, len(st)) return maxx l = input() ans = solve(l) ans1 = solve1(l) ans2 = solve2(l) print(max(ans, ans1, ans2))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR ASSIGN VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR STRING IF VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR ASSIGN VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR STRING IF VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not. Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days. -----Input----- In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters. -----Output----- If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer l_{i} (1 ≀ l_{i} ≀ |s|), which is the length of the i-th subsequence, and then l_{i} indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k. -----Examples----- Input 0010100 Output 3 3 1 3 4 3 2 5 6 1 7 Input 111 Output -1
def read_data(): a = list(map(int, list(input().strip()))) return a def solve(): sol = [] pos = -1 try: for i in range(0, len(a)): if a[i] == 0: if pos > -1: sol[pos].append(i + 1) pos -= 1 else: sol.append([i + 1]) else: pos += 1 sol[pos].append(i + 1) except: return -1 if pos == -1: return sol else: return -1 def print_sol(sol): if sol == -1: print(sol) return 0 print(len(sol)) for list in sol: print(len(list), *list) a = read_data() sol = solve() print_sol(sol)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR RETURN NUMBER FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not. Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days. -----Input----- In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters. -----Output----- If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer l_{i} (1 ≀ l_{i} ≀ |s|), which is the length of the i-th subsequence, and then l_{i} indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k. -----Examples----- Input 0010100 Output 3 3 1 3 4 3 2 5 6 1 7 Input 111 Output -1
s = input() v = [] for x in range(200000): v.append([]) idx = 0 pos = 0 sz = 0 for x in s: if x == "0": v[idx].append(pos + 1) idx += 1 else: if idx == 0: print("-1") exit() idx -= 1 v[idx].append(pos + 1) pos += 1 sz = max(sz, idx) if sz != idx: print("-1") exit() print(idx) at = 0 while at < idx: print(len(v[at]), end=" ") att = 0 for x in v[at]: print(x, end=" ") at += 1 print("")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR NUMBER FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not. Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days. -----Input----- In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters. -----Output----- If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer l_{i} (1 ≀ l_{i} ≀ |s|), which is the length of the i-th subsequence, and then l_{i} indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k. -----Examples----- Input 0010100 Output 3 3 1 3 4 3 2 5 6 1 7 Input 111 Output -1
a = [int(x) for x in input().strip()] len0 = len([x for x in a if x == 0]) len1 = len(a) - len0 m = len0 - len1 if m <= 0: ans = -1 else: n, pt = 0, -1 ans = [] for i, x in enumerate(a): if x == 0: if n < m: ans.append([i + 1]) n += 1 else: if pt < 0 or pt >= n: ans = -1 break ans[pt].append(i + 1) pt -= 1 else: pt += 1 if pt >= n or pt < 0: ans = -1 break ans[pt].append(i + 1) if ans == -1: print(-1) else: print(n) out = [] for line in ans: out.append(" ".join([str(x) for x in [len(line)] + line])) print("\n".join(out))
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR BIN_OP LIST FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not. Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days. -----Input----- In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters. -----Output----- If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer l_{i} (1 ≀ l_{i} ≀ |s|), which is the length of the i-th subsequence, and then l_{i} indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k. -----Examples----- Input 0010100 Output 3 3 1 3 4 3 2 5 6 1 7 Input 111 Output -1
n = input() zeb = 0 azeb = 0 zebras = [] azebras = [] c = 0 for i in range(len(n)): if n[i] == "0": if len(azebras) != 0: t = azebras.pop() t.append(i) zebras.append(t) else: zeb += 1 zebras.append([i]) elif len(zebras) != 0: t = zebras.pop() t.append(i) azebras.append(t) else: print(-1) c = 1 break if c == 0: if len(azebras) == 0: print(len(zebras)) for i in zebras: print(len(i), end=" ") for j in i: print(j + 1, end=" ") print("") else: print(-1)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not. Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days. -----Input----- In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters. -----Output----- If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer l_{i} (1 ≀ l_{i} ≀ |s|), which is the length of the i-th subsequence, and then l_{i} indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k. -----Examples----- Input 0010100 Output 3 3 1 3 4 3 2 5 6 1 7 Input 111 Output -1
from sys import stdin, stdout readline = stdin.readline write = stdout.write s = input() M = [] U = [] for i, ch in enumerate(s): if ch == "0": if U: z = U.pop() z.append(i + 1) M.append(z) else: M.append([i + 1]) elif not M: print(-1) exit() else: z = M.pop() z.append(i + 1) U.append(z) if U: print(-1) exit() print(len(M)) for z in M: write(str(len(z)) + " " + " ".join(str(i) for i in z) + "\n")
ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR STRING
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not. Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days. -----Input----- In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters. -----Output----- If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer l_{i} (1 ≀ l_{i} ≀ |s|), which is the length of the i-th subsequence, and then l_{i} indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k. -----Examples----- Input 0010100 Output 3 3 1 3 4 3 2 5 6 1 7 Input 111 Output -1
zebra = input() zebra = "0" + zebra end0lists = [] end1lists = [] lists = [] now = [] cnt = 0 for i in range(1, len(zebra)): if zebra[i] == "0": if len(end1lists) == 0: now = [] now.append(i) lists.append(now) end0lists.append(cnt) cnt += 1 else: now_id = end1lists.pop() now = lists[now_id] now.append(i) end0lists.append(now_id) elif len(end0lists) == 0: print(-1) exit() else: now_id = end0lists.pop() now = lists[now_id] now.append(i) end1lists.append(now_id) if len(end1lists) > 0: print(-1) exit() cnt = len(lists) print(cnt) print( "\n".join( [(str(len(list_i)) + " " + " ".join(map(str, list_i))) for list_i in lists] ) )
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not. Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days. -----Input----- In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters. -----Output----- If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer l_{i} (1 ≀ l_{i} ≀ |s|), which is the length of the i-th subsequence, and then l_{i} indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k. -----Examples----- Input 0010100 Output 3 3 1 3 4 3 2 5 6 1 7 Input 111 Output -1
from sys import stdin, stdout def solution(): life = stdin.readline().strip() result = [[1]] zeros = [0] ones = [] if life[0] == "1": print("-1") return for i in range(1, len(life)): if life[i] == "0": if ones: index = ones.pop() result[index].append(i + 1) zeros.append(index) else: result.append([i + 1]) zeros.append(len(result) - 1) elif zeros: index = zeros.pop() result[index].append(i + 1) ones.append(index) else: print("-1") return if ones: print("-1") return print(len(result)) print("\n".join([(str(len(x)) + " " + " ".join(map(str, x))) for x in result])) solution()
FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST IF VAR NUMBER STRING EXPR FUNC_CALL VAR STRING RETURN FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING RETURN IF VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not. Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days. -----Input----- In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters. -----Output----- If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer l_{i} (1 ≀ l_{i} ≀ |s|), which is the length of the i-th subsequence, and then l_{i} indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k. -----Examples----- Input 0010100 Output 3 3 1 3 4 3 2 5 6 1 7 Input 111 Output -1
from sys import stdin, stdout def main(): life = stdin.readline() zeroes = [] ones = [] zebras = [] fail = False for i in range(1, len(life) + 1): day = life[i - 1] if day == "0": if len(ones) != 0: one = ones.pop() zebras[one].append(i) zeroes.append(one) else: zebras.append([i]) zeroes.append(len(zebras) - 1) elif day == "1": if len(zeroes) != 0: zero = zeroes.pop() zebras[zero].append(i) ones.append(zero) else: fail = True break if len(ones) != 0: fail = True if fail: stdout.write(str("-1\n")) else: stdout.write(str(len(zebras)) + "\n") for i in zebras: stdout.write(str(len(i)) + " " + " ".join([str(k) for k in i]) + "\n") main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not. Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days. -----Input----- In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters. -----Output----- If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer l_{i} (1 ≀ l_{i} ≀ |s|), which is the length of the i-th subsequence, and then l_{i} indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k. -----Examples----- Input 0010100 Output 3 3 1 3 4 3 2 5 6 1 7 Input 111 Output -1
temp = [int(x) for x in list(input())] b = [] cnt = -1 skip = False for i in range(len(temp)): if temp[i] == 0: if cnt == -1: b.append([i + 1]) else: b[cnt] += [i + 1] cnt -= 1 else: cnt += 1 if cnt == len(b): skip = True break else: b[cnt].append(i + 1) if skip or cnt != -1: print(-1) else: print(len(b)) for i in b: print(str(len(i)) + " " + " ".join([str(x) for x in i]))
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR VAR LIST BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not. Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days. -----Input----- In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters. -----Output----- If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer l_{i} (1 ≀ l_{i} ≀ |s|), which is the length of the i-th subsequence, and then l_{i} indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k. -----Examples----- Input 0010100 Output 3 3 1 3 4 3 2 5 6 1 7 Input 111 Output -1
life_log = input() result = list() def possible(): ones = 0 zeros = 0 for k in life_log: if k == "0": if ones > 0: ones -= 1 zeros += 1 else: zeros -= 1 ones += 1 if zeros < 0: return False if ones > 0: return False return True def compute(): ones = 0 for k in range(len(life_log)): char = life_log[k] if char == "0": if ones == 0: result.append([k + 1]) else: result[ones - 1].append(k + 1) ones -= 1 else: result[ones].append(k + 1) ones += 1 if possible(): compute() print(len(result)) print( "\n".join([(str(len(sub)) + " " + " ".join(map(str, sub))) for sub in result]) ) else: print(-1)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not. Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days. -----Input----- In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters. -----Output----- If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer l_{i} (1 ≀ l_{i} ≀ |s|), which is the length of the i-th subsequence, and then l_{i} indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k. -----Examples----- Input 0010100 Output 3 3 1 3 4 3 2 5 6 1 7 Input 111 Output -1
s = input() a = [] i = -1 p = True for j in range(len(s)): if s[j] == "1": i += 1 if i == len(a): p = False break else: a[i].append(j) if s[j] == "0": if i == -1: a.append([j]) else: a[i].append(j) i = i - 1 if not p or i != -1: print(-1) else: print(len(a)) for k in a: print(len(k), end=" ") for r in k: print(r + 1, end=" ") print()
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not. Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days. -----Input----- In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters. -----Output----- If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer l_{i} (1 ≀ l_{i} ≀ |s|), which is the length of the i-th subsequence, and then l_{i} indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k. -----Examples----- Input 0010100 Output 3 3 1 3 4 3 2 5 6 1 7 Input 111 Output -1
s = input() c0 = s.count("0") c1 = s.count("1") qs = c0 - c1 if qs <= 0: print(-1) exit() ans = [[] for i in range(qs)] n1 = [] n0 = [i for i in range(qs)] p0 = 0 p1 = 0 for i in range(len(s)): l = s[i] if l == "0": if len(n0) <= p0: print(-1) exit() f = n0[p0] p0 += 1 n1.append(f) ans[f].append(i + 1) else: if len(n1) <= p1: print(-1) exit() f = n1[p1] p1 += 1 n0.append(f) ans[f].append(i + 1) for q in ans: if len(q) % 2 != 1: print(-1) exit() print(qs) for q in ans: print(" ".join([str(len(q)), " ".join([str(i) for i in q])]))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR STRING IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING LIST FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not. Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days. -----Input----- In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters. -----Output----- If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer l_{i} (1 ≀ l_{i} ≀ |s|), which is the length of the i-th subsequence, and then l_{i} indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k. -----Examples----- Input 0010100 Output 3 3 1 3 4 3 2 5 6 1 7 Input 111 Output -1
import sys z = [] i = 1 p = -1 d = sys.stdin.read(1) while d == "0" or d == "1": if d == "0": if p == -1: z.append([i]) else: z[p].append(i) p -= 1 elif p == len(z) - 1: p = 0 break else: z[p + 1].append(i) p += 1 i += 1 d = sys.stdin.read(1) if p == -1: sys.stdout.write(str(len(z)) + "\n") for zz in z: sys.stdout.write(str(len(zz)) + " " + " ".join(map(str, zz)) + "\n") else: sys.stdout.write("-1\n")
IMPORT ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER WHILE VAR STRING VAR STRING IF VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not. Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days. -----Input----- In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters. -----Output----- If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer l_{i} (1 ≀ l_{i} ≀ |s|), which is the length of the i-th subsequence, and then l_{i} indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k. -----Examples----- Input 0010100 Output 3 3 1 3 4 3 2 5 6 1 7 Input 111 Output -1
import sys def solve(days): zebras = [] azebras = [] for i in range(len(days)): if days[i] == 1: if not zebras: return False, [] seq = zebras.pop() seq.append(i) azebras.append(seq) elif not azebras: zebras.append([i]) else: seq = azebras.pop() seq.append(i) zebras.append(seq) if azebras: return False, [] return True, zebras def main(): days = [int(i) for i in sys.stdin.readline().strip()] ok, seqs = solve(days) if not ok: print(-1) else: print(len(seqs)) for seq in seqs: print(len(seq), " ".join([str(i + 1) for i in seq])) main()
IMPORT FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR RETURN NUMBER LIST ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR LIST VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR RETURN NUMBER LIST RETURN NUMBER VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not. Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days. -----Input----- In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters. -----Output----- If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer l_{i} (1 ≀ l_{i} ≀ |s|), which is the length of the i-th subsequence, and then l_{i} indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k. -----Examples----- Input 0010100 Output 3 3 1 3 4 3 2 5 6 1 7 Input 111 Output -1
s = input() l = [] even = [] odd = [] f = 1 for i in range(len(s)): if s[i] == "0": if len(even) != 0: ind = even.pop() l[ind].append(i + 1) odd.append(ind) else: l.append([i + 1]) odd.append(len(l) - 1) elif len(odd): ind = odd.pop() l[ind].append(i + 1) even.append(ind) else: f = 0 break if f and len(even) == 0: print(len(l)) for x in l: print(len(x), *x) else: print(-1)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not. Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days. -----Input----- In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters. -----Output----- If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer l_{i} (1 ≀ l_{i} ≀ |s|), which is the length of the i-th subsequence, and then l_{i} indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k. -----Examples----- Input 0010100 Output 3 3 1 3 4 3 2 5 6 1 7 Input 111 Output -1
s = input() arr, zero, one = [], [], [] for i in range(len(s)): if s[i] == "0": if one: idx = one.pop() arr[idx].append(i + 1) zero.append(idx) else: zero.append(len(arr)) arr.append([i + 1]) else: if not zero: break idx = zero.pop() one.append(idx) arr[idx].append(i + 1) if arr and zero and not one: print(len(arr)) for x in zero: print(len(arr[x]), end=" ") print(*arr[x]) else: print(-1)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR LIST LIST LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not. Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days. -----Input----- In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters. -----Output----- If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer l_{i} (1 ≀ l_{i} ≀ |s|), which is the length of the i-th subsequence, and then l_{i} indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k. -----Examples----- Input 0010100 Output 3 3 1 3 4 3 2 5 6 1 7 Input 111 Output -1
import sys input = sys.stdin.readline s = input() cnt0 = s.count("0") cnt1 = s.count("1") k = cnt0 - cnt1 if k <= 0: print(-1) exit() set_ = [set() for _ in range(k)] set_0 = set() set_1 = set() set_none = set([i for i in range(k)]) for i, char in enumerate(s): if char == "1": if not set_0: print(-1) exit() v = set_0.pop() set_[v].add(i + 1) set_1.add(v) if char == "0": if set_none: v = set_none.pop() set_[v].add(i + 1) set_0.add(v) elif set_1: v = set_1.pop() set_[v].add(i + 1) set_0.add(v) else: print(-1) exit() print(k) for i in set_: print(len(i), *sorted(list(i)))
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR STRING IF VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not. Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days. -----Input----- In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters. -----Output----- If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer l_{i} (1 ≀ l_{i} ≀ |s|), which is the length of the i-th subsequence, and then l_{i} indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k. -----Examples----- Input 0010100 Output 3 3 1 3 4 3 2 5 6 1 7 Input 111 Output -1
s = input() seqs = [] zero = set() one = set() impossible = False for i in range(len(s)): day = i + 1 if s[i] == "0": if len(one) > 0: ends_with_one = one.pop() seqs[ends_with_one].append(day) zero.add(ends_with_one) else: seqs.append([day]) ends_with_zero = len(seqs) - 1 zero.add(ends_with_zero) elif len(zero) > 0: ends_with_zero = zero.pop() seqs[ends_with_zero].append(day) one.add(ends_with_zero) else: impossible = True break if impossible: break if len(one) > 0: impossible = True if impossible: print(-1) else: print(len(seqs)) for se in seqs: print(len(se), " ".join([str(e) for e in se]))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not. Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days. -----Input----- In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters. -----Output----- If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer l_{i} (1 ≀ l_{i} ≀ |s|), which is the length of the i-th subsequence, and then l_{i} indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k. -----Examples----- Input 0010100 Output 3 3 1 3 4 3 2 5 6 1 7 Input 111 Output -1
s, a, i, p = input(), [], -1, True for j in range(len(s)): if s[j] == "0": if i == -1: a.append([j]) else: a[i].append(j) i -= 1 else: i += 1 if i == len(a): p = False break else: a[i].append(j) if not p or i > -1: print(-1) else: print(len(a)) for k in a: print(len(k), *map(lambda x: x + 1, k))
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not. Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days. -----Input----- In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters. -----Output----- If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer l_{i} (1 ≀ l_{i} ≀ |s|), which is the length of the i-th subsequence, and then l_{i} indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k. -----Examples----- Input 0010100 Output 3 3 1 3 4 3 2 5 6 1 7 Input 111 Output -1
from sys import stdin n0 = set() n1 = set() res = [] i = 1 c = "-" while c != "": c = stdin.read(1) if c == "0": if len(n1) > 0: ind = n1.pop() else: ind = len(res) res.append([]) res[ind].append(i) n0.add(ind) elif c == "1": if len(n0) < 1: res = -1 break ind = n0.pop() n1.add(ind) res[ind].append(i) i += 1 if res == -1 or len(n1) > 0: print(-1) else: print(len(res)) for ar in res: print(len(ar), end=" ") for el in ar: print(el, end=" ") print()
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not. Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days. -----Input----- In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters. -----Output----- If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer l_{i} (1 ≀ l_{i} ≀ |s|), which is the length of the i-th subsequence, and then l_{i} indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k. -----Examples----- Input 0010100 Output 3 3 1 3 4 3 2 5 6 1 7 Input 111 Output -1
import sys input = sys.stdin.readline s = list(input().rstrip()) n = len(s) for i in range(n): s[i] = int(s[i]) end0 = [] end1 = [] for i in range(n): if s[i] == 1: if len(end0) == 0: print(-1) exit() else: arr = end0.pop() arr.extend([i + 1]) end1.append(arr) elif len(end1) > 0: arr = end1.pop() arr.extend([i + 1]) end0.append(arr) else: end0.append([i + 1]) if len(end1) > 0: print(-1) else: print(len(end0)) for x in end0: print(len(x), *x)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not. Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days. -----Input----- In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters. -----Output----- If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer l_{i} (1 ≀ l_{i} ≀ |s|), which is the length of the i-th subsequence, and then l_{i} indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k. -----Examples----- Input 0010100 Output 3 3 1 3 4 3 2 5 6 1 7 Input 111 Output -1
s = input() black = set() white = set() subs = [] possible = True for i in range(len(s)): if s[i] == "1": if not black: possible = False break k = black.pop() white.add(k) subs[k].append(i + 1) elif white: k = white.pop() black.add(k) subs[k].append(i + 1) else: black.add(len(subs)) subs.append([i + 1]) if possible and not white: print(len(subs)) print("\n".join([(str(len(sub)) + " " + " ".join(map(str, sub))) for sub in subs])) else: print(-1)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not. Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days. -----Input----- In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters. -----Output----- If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer l_{i} (1 ≀ l_{i} ≀ |s|), which is the length of the i-th subsequence, and then l_{i} indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k. -----Examples----- Input 0010100 Output 3 3 1 3 4 3 2 5 6 1 7 Input 111 Output -1
s = input() one = -1 ans = [] p = True for i in range(0, len(s)): if s[i] == "0": if one == -1: ans.append([i + 1]) else: ans[one].append(i + 1) one -= 1 else: one += 1 if one == len(ans): p = False break else: ans[one].append(i + 1) if p == False or one != -1: print("-1") else: print(len(ans)) print("\n".join([(str(len(sub)) + " " + " ".join(map(str, sub))) for sub in ans]))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not. Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days. -----Input----- In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters. -----Output----- If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer l_{i} (1 ≀ l_{i} ≀ |s|), which is the length of the i-th subsequence, and then l_{i} indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k. -----Examples----- Input 0010100 Output 3 3 1 3 4 3 2 5 6 1 7 Input 111 Output -1
from sys import stdin, stdout s = stdin.readline().strip() n = len(s) labels = [(-1) for i in range(n)] used = [(0) for i in range(n)] l0, l1 = 0, 0 for i in range(n): l0, l1 = max(l0, i), max(l1, i) if s[i] == "0": while l0 < n and (s[l0] == "0" or used[l0]): l0 += 1 if l0 != n: labels[i] = l0 used[l0] = 1 l0 += 1 else: while l1 < n and (s[l1] == "1" or used[l1]): l1 += 1 if l1 != n: labels[i] = l1 used[l1] = 1 l1 += 1 for i in range(n): if s[i] == "1" and (labels[i] == -1 or not used[i]): stdout.write("-1") break else: used = [(0) for i in range(n + 1)] g_ans = [] for i in range(n): if used[i]: continue ans = [i + 1] used[i] = 1 ind = labels[i] while ind != -1: used[ind] = 1 ans.append(ind + 1) ind = labels[ind] g_ans.append(ans) stdout.write(str(len(g_ans)) + "\n") for v in g_ans: stdout.write(str(len(v)) + " " + " ".join(list(map(str, v))) + "\n")
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING WHILE VAR VAR VAR VAR STRING VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR LIST BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR STRING FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not. Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days. -----Input----- In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters. -----Output----- If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer l_{i} (1 ≀ l_{i} ≀ |s|), which is the length of the i-th subsequence, and then l_{i} indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k. -----Examples----- Input 0010100 Output 3 3 1 3 4 3 2 5 6 1 7 Input 111 Output -1
s = input() res, p = [], -1 for i in range(len(s)): j = i + 1 if s[i] == "0": if p > -1: res[p].append(j) p -= 1 else: res.append([j]) else: p += 1 if p >= len(res): print(-1) exit() res[p].append(j) if p != -1: print(-1) exit() print(len(res)) for x in res: print(len(x), *x)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not. Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days. -----Input----- In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters. -----Output----- If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer l_{i} (1 ≀ l_{i} ≀ |s|), which is the length of the i-th subsequence, and then l_{i} indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k. -----Examples----- Input 0010100 Output 3 3 1 3 4 3 2 5 6 1 7 Input 111 Output -1
s, r, f, p = input(), [], 0, -1 try: for i in range(len(s)): j = i + 1 if s[i] == "0": if p > -1: r[p].append(j) p -= 1 else: r.append([j]) else: p += 1 r[p].append(j) except: f = 1 if f or p > -1: print(-1) else: print(len(r)) for x in r: print(len(x), *x)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not. Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days. -----Input----- In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters. -----Output----- If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer l_{i} (1 ≀ l_{i} ≀ |s|), which is the length of the i-th subsequence, and then l_{i} indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k. -----Examples----- Input 0010100 Output 3 3 1 3 4 3 2 5 6 1 7 Input 111 Output -1
def solve(s): lists = [[] for _ in range(len(s))] cid = 0 waitSet = set() doneSet = set() zeros = set() for i, c in enumerate(s): i += 1 if c == "1": if not doneSet and not zeros: print(-1) return elif doneSet: aid = doneSet.pop() lists[aid].append(i) waitSet.add(aid) else: aid, idx = zeros.pop() lists[aid].append(idx) lists[aid].append(i) waitSet.add(aid) elif waitSet: aid = waitSet.pop() lists[aid].append(i) doneSet.add(aid) else: zeros.add((cid, i)) cid += 1 if waitSet: print(-1) return k = len(doneSet) + len(zeros) print(k) for i in doneSet: zebra = lists[i] print("%d %s" % (len(zebra), " ".join(map(str, zebra)))) for aid, idx in zeros: print("1 %d" % idx) s = input() solve(s)
FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN IF VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL 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())) b = [] c = [] for i in range(200005): c.append(0) mc = -1 m = -1 for i in range(len(a)): c[a[i]] += 1 if c[a[i]] >= mc: mc = c[a[i]] m = a[i] ans = 1 u = 0 l = n - 1 if mc == n: ans = 0 print(ans) for i in range(n): if a[i] == m: u = i break ud = u ld = n - u - 1 if ans == 1: for i in range(u + 1, n): if a[i] == a[i - 1]: continue elif a[i] > a[i - 1]: b.append([2, i + 1, i]) a[i] = a[i - 1] else: b.append([1, i + 1, i]) a[i] = a[i - 1] for i in range(u - 1, -1, -1): if a[i] == a[i + 1]: continue elif a[i] > a[i + 1]: b.append([2, i + 1, i + 2]) a[i] = a[i + 1] else: b.append([1, i + 1, i + 2]) a[i] = a[i + 1] print(len(b)) for i in range(len(b)): for j in range(3): print(b[i][j], end=" ") print()
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 LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST 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 IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR 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()) A = [int(s) for s in input().split()] count = {} max_count = 1 most_common = A[0] def equalise(start_index, end_index, step): for i in range(start_index, end_index, 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] for value in A: count[value] = count.get(value, 0) + 1 if count[value] > max_count: max_count = count[value] most_common = value print(n - max_count) start = A.index(most_common) equalise(start, 0, -1) equalise(start, 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 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 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 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 = [int(x) for x in input().split()] cnt = [0] * 200005 arr = [] for i in a: cnt[i] += 1 moves = n - max(cnt) ele = cnt.index(max(cnt)) idx = a.index(ele) print(moves) if moves: c = 0 while c < n: if a[c] != ele and c < idx: arr.append([[1, 2][a[c] > ele], c + 1, c + 2]) elif a[c] == ele: idx = c elif a[c] != ele and c > idx: print([1, 2][a[c] > ele], c + 1, c) c += 1 arr = arr[::-1] for i in arr: print(*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 NUMBER ASSIGN VAR LIST FOR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST LIST NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER 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()) ai = list(map(int, input().split())) ai2 = sorted(ai) num = 1 num2 = ai2[0] ans = 1 for i in range(1, n): if ai2[i] != ai2[i - 1]: if num > ans: ans = num num2 = ai2[i - 1] num = 1 else: num += 1 if num > ans: ans = num num2 = ai2[-1] num3 = 0 for i in range(n): if ai[i] == num2: num3 = i break print(n - ans) for i in range(num3 - 1, -1, -1): if ai[i] > ai[i + 1]: print(2, i + 1, i + 2) else: print(1, i + 1, i + 2) ai[i] = num2 ai[i + 1] = num2 for i in range(num3 + 1, n): if ai[i] == ai[i - 1]: continue if ai[i] > ai[i - 1]: print(2, i + 1, i) else: print(1, i + 1, i) ai[i] = num2 ai[i - 1] = num2
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 NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER 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 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 ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF 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 EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR 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
n = int(input()) a = list(map(int, input().split())) b = dict() b[a[0]] = 0 maxim = a[0] for i in a: if i in b: b[i] += 1 if b[i] > b[maxim]: maxim = i else: b[i] = 1 maxindex = [0] j = 0 if a[0] != maxim: j = 1 for i in range(1, len(a)): if a[i] == maxim: maxindex.append(i) print(n - len(maxindex) + j) for i in range(len(maxindex) - 1): j1 = maxindex[i] j2 = maxindex[i + 1] while j2 != j1: if a[j2] - a[j2 - 1] > 0: print(1, j2 - 1 + 1, j2 + 1) a[j2 - 1] += abs(a[j2 - 1] - a[j2]) elif a[j2 - 1] - a[j2] > 0: print(2, j2 - 1 + 1, j2 + 1) a[j2 - 1] -= abs(a[j2 - 1] - a[j2]) j2 -= 1 j1 = maxindex[-1] for i in range(j1, len(a) - 1): if a[i] - a[i + 1] > 0: print(1, i + 2, i + 1) a[i + 1] += abs(a[i + 1] - a[i]) else: print(2, i + 2, i + 1) a[i + 1] -= abs(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 VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR 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 NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP 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
def calc(n, a): dic = {} for i in a: if i not in dic: dic[i] = 1 else: dic[i] += 1 val = 0 big = 0 for i in dic: if dic[i] > val: val = dic[i] big = i if val == n: print(0) return if val == 1: print(n - 1) for i in range(1, n): if a[i] > a[i - 1]: print(2, i + 1, i) a[i] = a[i - 1] else: print(1, i + 1, i) a[i] = a[i - 1] else: print(n - val) index = a.index(big) i = index + 1 while i < n: if a[i] < a[i - 1]: print(1, i + 1, i) a[i] = a[i - 1] elif a[i] > a[i - 1]: print(2, i + 1, i) a[i] = a[i - 1] i = i + 1 j = index - 1 while j >= 0: if a[j] > a[j + 1]: print(2, j + 1, j + 2) a[j] = a[j + 1] elif a[j] < a[j + 1]: print(1, j + 1, j + 2) a[j] = a[j + 1] j -= 1 n = int(input()) a = list(map(int, input().split())) calc(n, a)
FUNC_DEF ASSIGN VAR DICT 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 IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL 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 EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR 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 ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE 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 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 VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR 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 = [int(x) for x in input().split()] dic = {} maxim = 0 for item in a: if item not in dic: dic[item] = 1 else: dic[item] += 1 for item in dic: if dic[item] > maxim: maxim = dic[item] Item = item k = 0 flag = False answer = [] for item in a: if item == Item: for i in range(k - 1, -1, -1): if k != 0 and a[i] > a[i + 1]: flag = True answer.append([2, i + 1, i + 2]) a[i] = a[i + 1] elif k != 0 and a[i] < a[i + 1]: flag = True answer.append([1, i + 1, i + 2]) a[i] = a[i + 1] for i in range(k + 1, n): if a[i] > a[i - 1]: flag = True answer.append([2, i + 1, i]) a[i] = a[i - 1] elif a[i] < a[i - 1]: flag = True answer.append([1, i + 1, i]) a[i] = a[i - 1] break k += 1 if flag == False: print(0) else: print(len(answer)) for i in answer: print(*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 VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER 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 ASSIGN VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL 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()) s = list(map(int, input().split())) a = set(s) t = {i: (0) for i in a} for i in s: t[i] += 1 k = [i for i in t] def f(x): return t[x] a = max(k, key=f) print(n - t[a]) m = s.index(a) asd = list(range(m)) asd.reverse() for i in asd: if s[i] == a: continue else: print(str(int(s[i + 1] < s[i]) + 1) + " " + str(i + 1) + " " + str(i + 2)) s[i] = a for i in range(m, n): if s[i] == a: continue else: print(str(int(s[i - 1] < s[i]) + 1) + " " + str(i + 1) + " " + str(i)) s[i] = a
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 VAR NUMBER VAR VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_DEF RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR 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 = [int(x) for x in input().split()] f = set(a) max = 0 b = [0] * 200001 for i in a: b[i] += 1 if b[i] > max: max = b[i] maxr = i for i in range(n): if a[i] == maxr: startpos = i break print(n - max) if n - max > 0: for i in range(startpos - 1, -1, -1): if a[i] == maxr: continue elif a[i] < maxr: print(1, i + 1, i + 2) else: print(2, i + 1, i + 2) for i in range(startpos + 1, n): if a[i] == maxr: continue elif a[i] < maxr: print(1, i + 1, i) else: 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 VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR 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 IF BIN_OP VAR VAR NUMBER 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 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
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 = input().split() nums = list(map(int, nums)) count = {} for i in nums: count[i] = count.get(i, 0) + 1 max_ = 0 for i in count: if count[i] > max_: max_ = count[i] maxNum = i if max_ == n: print(0) else: print(n - max_) for i in range(n): if nums[i] == maxNum: break if i > 0: for j in range(i - 1, -1, -1): if nums[j] > maxNum: print("2 " + str(j + 1) + " " + str(j + 2)) if nums[j] < maxNum: print("1 " + str(j + 1) + " " + str(j + 2)) while i + 1 < n: i += 1 if nums[i] == maxNum: continue if nums[i] > maxNum: opt = "2" else: opt = "1" print(opt + " " + str(i + 1) + " " + str(i))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR NUMBER 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 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 WHILE BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR IF VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR 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()) Arr = list(map(int, input().split())) max_stat = 0 num = 0 idx = -1 Stat = [0] * (2 * 10**5 + 3) for i in range(n): Stat[Arr[i]] += 1 if Stat[Arr[i]] > max_stat: max_stat = Stat[Arr[i]] num = Arr[i] idx = i k = 0 for el in Arr: if el != num: k += 1 print(k) for i in range(idx, n - 1): if Arr[i + 1] < Arr[i]: print(1, i + 1 + 1, i + 1) elif Arr[i + 1] > Arr[i]: print(2, i + 1 + 1, i + 1) Arr[i + 1] = num for i in range(idx, 0, -1): if Arr[i - 1] < Arr[i]: print(1, i - 1 + 1, i + 1) elif Arr[i - 1] > Arr[i]: print(2, i - 1 + 1, i + 1) Arr[i - 1] = num
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER 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 VAR EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER 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
n = int(input()) a = list(map(int, input().split())) x = a[0] if a.count(x) == n: print(0) else: r = [[a[i], i] for i in range(n)] r.sort() f = {} mv = 0 ans = [] for i in a: if i in f: f[i] += 1 else: f[i] = 1 x = max(f.values()) ind = 0 for i in f.keys(): if f[i] == x: ind = i break i = a.index(ind) for j in range(i + 1, n): if a[j] > a[j - 1]: a[j] = a[j - 1] ans.append([2, j + 1, j]) mv += 1 elif a[j] < a[j - 1]: a[j] = a[j - 1] ans.append([1, j + 1, j]) mv += 1 for j in range(i - 1, -1, -1): if a[j] > a[j + 1]: a[j] = a[j + 1] ans.append([2, j + 1, j + 2]) mv += 1 elif a[j] < a[j + 1]: a[j] = a[j + 1] ans.append([1, j + 1, j + 2]) mv += 1 print(mv) for i in ans: 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 VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER 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
n = int(input()) num = [int(x) for x in input().split()] dic = {} target = -1 index = 0 for x in num: if x in dic: dic[x] += 1 if dic[x] > dic[target]: target = x else: dic[x] = 1 if target == -1: target = x steps = n - dic[target] for i in range(n): if num[i] == target: index = i print(steps) i = index - 1 while i >= 0: if num[i] < target: print(1, i + 1, i + 1 + 1) elif num[i] > target: print(2, i + 1, i + 1 + 1) i -= 1 i = index + 1 while i < n: if num[i] < target: print(1, i + 1, i) elif num[i] > target: print(2, i + 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 DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR EXPR 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 BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER 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
n = int(input()) a = list(map(int, input().split())) b = [0] * 200001 for v in a: b[v] += 1 commands = [] i = a.index(b.index(max(b))) j = i - 1 while j >= 0: if a[j] < a[j + 1]: commands.append((1, j + 1, j + 1 + 1)) else: commands.append((2, j + 1, j + 1 + 1)) a[j] = a[j + 1] j -= 1 j = i + 1 while j < n: if a[j] < a[j - 1]: commands.append((1, j + 1, j - 1 + 1)) elif a[j] > a[j - 1]: commands.append((2, j + 1, j - 1 + 1)) a[j] = a[j - 1] j += 1 print(len(commands)) print("\n".join([" ".join(list(map(str, commands[i]))) for i in range(len(commands))]))
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 LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER 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 ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR 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()) lis = list(map(int, input().split())) has = [0] * 200002 mx = 0 no = 0 ans = [] nu = 0 for j in range(n): i = lis[j] has[i] += 1 if has[i] > mx: mx = has[i] no = j nu = i i = no - 1 while i >= 0: if lis[i] != nu: if lis[i] < nu: ans.append([1, i + 1, i + 2]) else: ans.append([2, i + 1, i + 2]) i -= 1 i = no + 1 while i < n: if lis[i] != nu: if lis[i] < nu: ans.append([1, i + 1, i]) else: ans.append([2, i + 1, i]) i += 1 print(len(ans)) for i in ans: 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR IF 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 VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR VAR IF 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 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()) l = list(map(int, input().strip().split())) count = [(0) for i in range(2000001)] mx = 0 ind = 0 for i in range(n): count[l[i]] += 1 if count[l[i]] > mx: mx = count[l[i]] ind = i print(n - mx) c = l[ind] for j in range(ind, n): if l[j] > c: print(2, j + 1, j) elif l[j] < c: print(1, j + 1, j) for j in range(ind, -1, -1): if l[j] > c: print(2, j + 1, j + 2) elif l[j] < c: print(1, j + 1, j + 2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL 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 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
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())) freq = {} for a in A: r = freq.get(a, 0) freq[a] = r + 1 sfreq = sorted(freq.items(), key=lambda x: x[1], reverse=True) x = sfreq[0][0] res = [] for i in range(N): ai = A[i] if ai == x: for j in range(i - 1, -1, -1): aj = A[j] if A[j] < x: res.append((1, j, j + 1)) elif A[j] > x: res.append((2, j, j + 1)) for j in range(i + 1, N): aj = A[j] if A[j] < x: res.append((1, j, j - 1)) elif A[j] > x: res.append((2, j, j - 1)) break k = len(res) print(k) for t, i, j in res: print(t, i + 1, j + 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 ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR 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 ASSIGN VAR 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 ASSIGN VAR FUNC_CALL VAR VAR EXPR 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
R = lambda: map(int, input().split()) n = int(input()) L = list(R()) f = [0] * (max(L) + 1) for i in L: f[i] += 1 ma = max(f) ind = f.index(ma) A = [0] * n for i in range(n): if L[i] == ind: A[i] = 1 res = n - ma print(res) j = L.index(ind) while j >= 0: if A[j] == 0: A[j] = 1 if L[j] > ind: print(2, j + 1, j + 2) else: print(1, j + 1, j + 2) j -= 1 j = L.index(ind) while j < n: if A[j] == 0: A[j] = 1 if L[j] > ind: print(2, j + 1, j) else: print(1, j + 1, j) j += 1
ASSIGN VAR 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 FUNC_CALL VAR VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR 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 FUNC_CALL VAR VAR WHILE VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER 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
n = int(input()) a = list(map(int, input().split())) d = dict() for i in range(0, 200005): d[i] = 0 for i in range(n): d[a[i]] += 1 maxa = num = 0 for i in range(200005): if num < d[i]: maxa = i num = d[i] ans = n - num print(ans) if ans == 0: exit() for i in range(n - 1): if a[i] == maxa: continue if i == 0: if a[i + 1] == maxa: if a[i] < maxa: print(1, i + 1, i + 2) else: print(2, i + 1, i + 2) a[i] = maxa continue if a[i + 1] == maxa: if a[i] < maxa: print(1, i + 1, i + 2) else: print(2, i + 1, i + 2) a[i] = maxa continue if a[i - 1] == maxa: if a[i] < maxa: print(1, i + 1, i) else: print(2, i + 1, i) a[i] = maxa continue if a[n - 1] != maxa: if a[n - 1] < maxa: print(1, n, n - 1) else: print(2, n, n - 1) a[n - 1] = maxa for i in range(n - 1, -1, -1): if a[i] != maxa: if a[i] < maxa: 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR IF VAR NUMBER IF VAR BIN_OP VAR NUMBER 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 VAR IF VAR BIN_OP VAR NUMBER 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 VAR IF 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 ASSIGN VAR VAR VAR 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 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(i) for i in input().split()] c = [(0) for i in range(200005)] firsts = [n for i in range(200005)] m, x = 0, 0 for j in range(n): i = a[j] c[i] += 1 if c[i] > m: m = c[i] x = i if firsts[i] > j: firsts[i] = j print(n - m) for i in range(firsts[x], 0, -1): j = i - 1 l = a[j] r = a[i] if l > r: print(2, j + 1, i + 1) else: print(1, j + 1, i + 1) a[j] = x for i in range(firsts[x], n - 1): j = i + 1 l = a[i] r = a[j] if l == r: continue elif r > l: print(2, j + 1, i + 1) else: print(1, j + 1, i + 1) a[j] = x
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF 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 VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR IF 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 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()) d = dict() a = list(map(int, input().split())) mx = 0 for i in a: d[i] = 0 for i in range(n): d[a[i]] += 1 if d[a[i]] > d[a[mx]]: mx = i ans = [] for i in range(mx + 1, n): op = 0 if a[i] == a[i - 1]: continue if a[i] > a[i - 1]: op = 2 else: op = 1 ans.append([op, i + 1, i]) a[i] = a[i - 1] for i in range(mx - 1, -1, -1): op = 0 if a[i] == a[i + 1]: continue if a[i] > a[i + 1]: op = 2 else: op = 1 ans.append([op, i + 1, i + 2]) a[i] = a[i + 1] print(len(ans)) for i in ans: print(*i)
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 NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER 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
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()) all_nums = list(map(int, input().split())) def find_max(all_nums): nums_dict = {} for i in all_nums: if i in nums_dict: nums_dict[i] += 1 else: nums_dict[i] = 1 max_key = max(nums_dict.keys(), key=lambda x: nums_dict.get(x)) max_position = 0 for i in range(len(all_nums)): if all_nums[i] == max_key: max_position = i break return max_key, max_position def change_rest_elements(all_nums, max_key_max_position): max_key = max_key_max_position[0] max_position = max_key_max_position[1] output = [] for i in range(max_position + 1, len(all_nums), 1): if all_nums[i] < max_key: new_i = i + 1 j = i output_trio = 1, new_i, j output.append(output_trio) elif all_nums[i] > max_key: new_i = i + 1 j = i output_trio = 2, new_i, j output.append(output_trio) elif all_nums[i] == max_key: continue for i in range(max_position - 1, -1, -1): if all_nums[i] < max_key: new_i = i + 1 j = i + 2 output_trio = 1, new_i, j output.append(output_trio) elif all_nums[i] > max_key: new_i = i + 1 j = i + 2 output_trio = 2, new_i, j output.append(output_trio) elif all_nums[i] == max_key: continue return len(output), output def print_output(output_tuple): a = output_tuple[0] matrix = output_tuple[1] print(a) for i in matrix: new_i = str(i) new_i = new_i.replace(",", "") new_i = new_i.strip("(") new_i = new_i.strip(")") print(new_i) max_key_max_position = find_max(all_nums) output_tuple = change_rest_elements(all_nums, max_key_max_position) print_output(output_tuple)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR 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())) cnt = {} for i in A: if i not in cnt: cnt[i] = 0 cnt[i] += 1 mas = 0 z = 0 for u in cnt: if mas < cnt[u]: mas = cnt[u] z = u print(len(A) - cnt[z]) zind = A.index(z) for u in range(zind - 1, -1, -1): if A[u] < z: print(1, u + 1, u + 2) elif A[u] > z: print(2, 1 + u, u + 2) for i in range(zind, n): if A[i] < z: print(1, i + 1, i) elif A[i] > z: 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 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 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 IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL 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
n = int(input()) array = input() A = [int(x) for x in array.split()] newA = A[:] def convert(a, b): if a >= b: ans = 2 else: ans = 1 return ans if n == 1: print(0) else: newA.sort() maxi = 0 counter = 1 current = newA[0] repeated = newA[0] for i in range(1, n): if newA[i] == current: counter += 1 else: if maxi < counter: maxi = counter repeated = current counter = 1 current = newA[i] if maxi < counter: maxi = counter repeated = current print(n - maxi) found = False for i in range(n): if A[i] == repeated and not found: index = i found = True for i in range(index, n): if A[i] != repeated: operation = [convert(A[i], repeated), i + 1, i] print(" ".join([str(x) for x in operation])) for i in range(index): operation = [convert(A[index - i - 1], repeated), index - i, index - i + 1] print(" ".join([str(x) for x in operation]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_DEF IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER RETURN VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR LIST FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER 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()) nums = list(map(int, input().split())) sor = sorted(nums) max_num = 0 max_count = 0 ans = "" curr = sor[0] curr_c = 0 for num in sor: if num == curr: curr_c += 1 else: if curr_c > max_count: max_num = curr max_count = curr_c curr_c = 1 curr = num if curr_c > max_count: max_num = curr ind = nums.index(max_num) if ind > 0: for i in range(ind - 1, -1, -1): if nums[i] < max_num: ans += "1 " + str(i + 1) + " " + str(i + 2) + "\n" elif nums[i] > max_num: ans += "2 " + str(i + 1) + " " + str(i + 2) + "\n" for i in range(ind + 1, len(nums)): if nums[i] < max_num: ans += "1 " + str(i + 1) + " " + str(i) + "\n" elif nums[i] > max_num: ans += "2 " + str(i + 1) + " " + str(i) + "\n" print(ans.count("\n")) print(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 VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR 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 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 FUNC_CALL VAR VAR IF VAR VAR VAR 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 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 FUNC_CALL VAR 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()) l = list(map(int, input().split())) d = {} for i in l: if i not in d: d[i] = 1 else: d[i] += 1 m = 0 for i in d: if d[i] > m: x = i m = d[i] dp = [] for i in range(len(l)): if l[i] == x: dp.append(i) t = -1 ans = [] for i in range(len(dp)): t1 = dp[i] for h in range(t1 - 1, t, -1): if l[h] < x: ans.append([1, h + 1, h + 2]) else: ans.append([2, h + 1, h + 2]) t = t1 for c in range(dp[-1] + 1, len(l)): if l[c] < x: ans.append([1, c + 1, c]) else: ans.append([2, c + 1, c]) print(len(ans)) for i in ans: 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 VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR 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 NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF 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 ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR IF 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
def run(n, a): dic = {} co = 0 maxx = -1 index = -1 for i in range(n): dic[a[i]] = dic.get(a[i], 0) + 1 if dic[a[i]] > co: co = dic[a[i]] maxx = a[i] index = i temp = 0 for i in a: if i == maxx: temp += 1 print(n - temp) for i in range(index + 1, n): if maxx > a[i]: print("1 " + str(i + 1) + " " + str(i)) if a[i] > maxx: print("2 " + str(i + 1) + " " + str(i)) for i in range(index - 1, -1, -1): if maxx > a[i]: print("1 " + str(i + 1) + " " + str(i + 2)) if a[i] > maxx: print("2 " + str(i + 1) + " " + str(i + 2)) n = int(input()) a = list(map(int, input().split())) run(n, a)
FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER 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 NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER 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 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 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 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 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
def main(): n = int(input()) a = list(map(int, input().split())) d = {} for i in range(n): if d.get(a[i]) == None: d[a[i]] = 1 else: d[a[i]] += 1 mxCnt = 0 mx = 0 for x in d: if d[x] > mxCnt: mxCnt = d[x] mx = x index = -1 for i in range(n): if a[i] == mx: index = i break print(n - mxCnt) for i in range(index + 1, n): if a[i] < mx: print("1", i + 1, i) elif a[i] > mx: print("2", i + 1, i) for i in range(index - 1, -1, -1): if a[i] < mx: print("1", i + 1, i + 2) elif a[i] > mx: print("2", i + 1, i + 2) return return 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 FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NONE ASSIGN VAR VAR VAR NUMBER VAR 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 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 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 FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR STRING BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR STRING BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN RETURN 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
def most_frequent(arr): memo = {} most = 0 element = None for a in arr: if a not in memo: memo[a] = 0 memo[a] += 1 for k, v in memo.items(): if v > most: element = k most = v idx = arr.index(element) return idx def solution(arr, idx): cnt = 0 oprs = [] left = idx - 1 right = idx + 1 while left >= 0: if arr[left] > arr[idx]: cnt += 1 oprs.append([2, left + 1, left + 2]) elif arr[left] < arr[idx]: cnt += 1 oprs.append([1, left + 1, left + 2]) left -= 1 while right < len(arr): if arr[idx] > arr[right]: cnt += 1 oprs.append([1, right + 1, right]) elif arr[idx] < arr[right]: cnt += 1 oprs.append([2, right + 1, right]) right += 1 return [cnt, oprs] n = int(input()) arr = [int(i) for i in input().split()] idx = most_frequent(arr) cnt, oprs = solution(arr, idx) if not cnt: print(0) else: print(cnt) for o in oprs: print(*o)
FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER RETURN LIST VAR VAR 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 VAR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL 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
n = int(input("")) a = input("").split() count = [(0) for _ in range(200001)] max_count = -1 max_number = -1 max_index = -1 for i in range(n): a[i] = int(a[i]) count[a[i]] += 1 if count[a[i]] > max_count: max_count = count[a[i]] max_number = a[i] max_index = i tot = n - max_count print(tot) curr = max_index - 1 while curr >= 0: if a[curr] > max_number: print("2 " + str(curr + 1) + " " + str(curr + 2)) elif a[curr] < max_number: print("1 " + str(curr + 1) + " " + str(curr + 2)) curr -= 1 curr = max_index + 1 while curr < n: if a[curr] > max_number: print("2 " + str(curr + 1) + " " + str(curr)) elif a[curr] < max_number: print("1 " + str(curr + 1) + " " + str(curr)) curr += 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR 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 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 VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE 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 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 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
import sys n = int(input()) arr = list(map(int, input().split())) dictionary = dict() max = 0 maxnum = 0 for i in range(len(arr)): try: if dictionary[arr[i]]: pass except: dictionary[arr[i]] = [] dictionary[arr[i]].append(i) if max < len(dictionary[arr[i]]): max = len(dictionary[arr[i]]) maxnum = arr[i] if len(dictionary.keys()) == 1: print("0") sys.exit() indexes = dictionary[maxnum] print(len(arr) - max) indexes.sort() i = indexes[0] while i > 0: t = 1 if arr[i - 1] > maxnum: t = 2 print("{:d} {:d} {:d}".format(t, i, i + 1)) i -= 1 for i in range(len(indexes) - 1): for j in range(indexes[i] + 1, indexes[i + 1]): t = 1 if arr[j] > maxnum: t = 2 print("{:d} {:d} {:d}".format(t, j + 1, j)) for i in range(indexes[len(indexes) - 1] + 1, len(arr)): t = 1 if arr[i] > maxnum: t = 2 print("{:d} {:d} {:d}".format(t, i + 1, 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 FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL 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()) a = [int(x) for x in input().split()] m = {} for i in a: m[i] = 0 for i in a: m[i] += 1 mx = 0 mxn = 0 for i in m: if m[i] > mx: mx = m[i] mxn = i print(n - mx) cnt = 1 ans = [] for i in range(n): if a[i] != mxn: if a[i] > mxn: ans.append([2, i + 1]) else: ans.append([1, i + 1]) a[i] = mxn else: break ans.reverse() for i in ans: print(i[0], i[1], i[1] + 1) for i in range(n): if a[i] > mxn: print(2, i + 1, i) elif a[i] < mxn: 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 ASSIGN VAR DICT FOR VAR VAR ASSIGN 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 VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR 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
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(" "))) dicti = {} for i in Arr: if i in dicti: dicti[i] += 1 else: dicti[i] = 1 maxi = 0 maxchar = 0 for i in dicti: if dicti[i] > maxi: maxi = dicti[i] maxchar = i index = Arr.index(maxchar) print(n - maxi) tempInd = index for i in range(tempInd + 1, n): if Arr[i] == maxchar: continue elif Arr[i] > maxchar: print(2, i + 1, i) else: print(1, i + 1, i) for i in range(tempInd, -1, -1): if Arr[i] == maxchar: continue elif Arr[i] > maxchar: print(2, i + 1, i + 2) else: 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 STRING 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 ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN 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 VAR 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 = list(map(int, input().split())) b = [0] * 200001 c = [0] * 200001 for i in range(n): b[a[i]] += 1 c[a[i]] = i maxi = 0 for i in range(200001): if b[i] > maxi: maxi = b[i] x = i y = c[i] print(n - b[x]) for i in range(y + 1, n): if a[i] != x: if a[i] > x: print(2, i + 1, i) else: print(1, i + 1, i) d = y while d >= 0: if a[d] != x: if a[d] > x: print(2, d + 1, d + 2) if a[d] < x: print(1, d + 1, d + 2) d -= 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 BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR 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 IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR 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
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()) A = list(map(int, input().split())) B = [0] * (max(A) + 1) for i in range(a): B[A[i]] += 1 q = B.index(max(B)) c = B[q] b = A.index(q) print(a - c) i = b - 1 while i >= 0: if A[i] < q: print(1, i + 1, i + 2) else: print(2, i + 1, i + 2) i -= 1 while b < a - 1: if A[b + 1] < q: print(1, b + 2, b + 1) elif A[b + 1] > q: print(2, b + 2, b + 1) b += 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 BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP 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 EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER WHILE 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 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
import sys input = sys.stdin.readline n = int(input()) c = dict() b = list(map(int, input().split())) for j in b: if j in c.keys(): c[j] += 1 else: c[j] = 1 m = -1 for j in b: if m <= c[j]: m = c[j] p = j for j in range(n): if b[j] == p: r = j d = [] for j in range(r): if b[j] > p: d.append([2, j + 1, j + 2]) elif b[j] < p: d.append([1, j + 1, j + 2]) else: pass d.reverse() for j in range(r, n): if b[j] > p: d.append([2, j + 1, j]) elif b[j] < p: d.append([1, j + 1, j]) else: pass print(len(d)) for j in d: print(*j)
IMPORT ASSIGN VAR VAR 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 FOR VAR VAR IF VAR FUNC_CALL 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 FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR 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
input() arr = [int(x) for x in input().split()] arr2 = arr + [] arr2.sort() k = -1 count = 0 max_count = 0 arr2.append(-1) for i in range(0, len(arr2) - 1): count = count + 1 if arr2[i] != arr2[i + 1]: if count > max_count: max_count = count k = arr2[i] count = 0 i = len(arr) - 1 l = [] index = -1 j = 0 while i >= 0: if arr[i] != k: if i + 1 <= len(arr) - 1 and arr[i + 1] == k: index = i j = 1 break elif i - 1 >= 0 and arr[i - 1] == k: index = i break i -= 1 if index != -1: if j == 0: if arr[index] < k: l.append([1, index, index - 1]) else: l.append([2, index, index - 1]) elif arr[index] < k: l.append([1, index, index + 1]) else: l.append([2, index, index + 1]) i = len(arr) - 1 i1 = index + 1 i2 = index - 1 i = i1 while i < len(arr): if arr[i] != k: if k > arr[i]: l.append([1, i, i - 1]) else: l.append([2, i, i - 1]) arr[i] = k i += 1 i = i2 while i > -1: if arr[i] != k: if k > arr[i]: l.append([1, i, i + 1]) else: l.append([2, i, i + 1]) arr[i] = k i -= 1 print(len(l)) for ele in l: print(ele[0], ele[1] + 1, ele[2] + 1)
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR LIST EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR IF BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR LIST NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR LIST NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR VAR 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 VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF VAR VAR VAR IF VAR VAR VAR 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 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())) o = [] podsch = [(0) for i in range(2 * 10**5 + 1)] ist = [[] for i in range(2 * 10**5 + 1)] for i in range(n): podsch[a[i]] += 1 ist[a[i]].append(i) maxi = 0 for i in range(len(podsch)): if podsch[maxi] < podsch[i]: maxi = i beg = min(ist[maxi]) for i in range(beg, 0, -1): if a[i - 1] > a[i]: o.append([2, i, i + 1]) a[i - 1] = a[i] elif a[i - 1] != a[i]: o.append([1, i, i + 1]) a[i - 1] = a[i] for i in range(beg, n - 1): if a[i + 1] > a[i]: o.append([2, i + 2, i + 1]) a[i + 1] = a[i] elif a[i + 1] != a[i]: o.append([1, i + 2, i + 1]) a[i + 1] = a[i] print(len(o)) for i in o: 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 LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR 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 FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER 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 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 BIN_OP VAR NUMBER 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 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 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 = list(map(int, input().split())) counter = {} for a in arr: counter[a] = counter.get(a, 0) + 1 need = sorted(counter.items(), key=lambda d: d[1], reverse=True)[0][0] pre = -1 operations = [] i = 0 while i < n: if arr[i] == need: i += 1 continue elif i > 0: if arr[i] > need: operations.append((2, i + 1, i)) else: operations.append((1, i + 1, i)) i += 1 else: j = i + 1 while arr[j] != need: j += 1 i = j + 1 while j > 0: if arr[j - 1] > need: operations.append((2, j, j + 1)) else: operations.append((1, j, j + 1)) j -= 1 print(len(operations)) for i in range(len(operations)): print("%d %d %d" % operations[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 FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER 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 VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING 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())) curm = 0 maps = {} curv = 0 for l in L: if l not in maps: maps[l] = 1 else: maps[l] += 1 curm = max(curm, maps[l]) if curm == maps[l]: curv = l i = L.index(curv) print(N - curm) for k in range(i + 1, len(L)): if L[k] > curv: print(2, end=" ") print(k + 1, end=" ") print(k) if L[k] < curv: print(1, end=" ") print(k + 1, end=" ") print(k) for k in range(i - 1, -1, -1): if L[k] > curv: print(2, end=" ") print(k + 1, end=" ") print(k + 2) if L[k] < curv: print(1, end=" ") print(k + 1, end=" ") print(k + 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 NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR ASSIGN 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 FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL 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
def main(): n = int(input()) array = list(map(int, input().split())) counts = {} for i in array: if i not in counts.keys(): counts[i] = 1 else: counts[i] += 1 max_count = 0 num = 0 for i in counts: if counts[i] > max_count: max_count = counts[i] num = i ans = [] orders = [] order = [] for i in range(n): if array[i] != num: order.append(i) else: order.reverse() orders.append(order) order = [] if order: orders.append(order) ans = [] for order in orders: for i in order: if i > 0: if array[i - 1] == num: if array[i] > num: ans.append([2, i + 1, i]) else: ans.append([1, i + 1, i]) array[i] = num if i < n - 1: if array[i + 1] == num and array[i] != num: if array[i] > num: ans.append([2, i + 1, i + 2]) else: ans.append([1, i + 1, i + 2]) array[i] = num elif array[i + 1] == num: if array[i] > num: ans.append([2, i + 1, i + 2]) else: ans.append([1, i + 1, i + 2]) array[i] = num print(len(ans)) for i in ans: for j in i: print(j, end=" ") print() 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 FOR VAR VAR IF VAR FUNC_CALL 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 LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR FOR VAR VAR IF VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR IF 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 ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF 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 ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR IF 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 ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL 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
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) output = [] maxi = 0 start = -1 counts = {} for i in range(n): if a[i] not in counts.keys(): counts[a[i]] = 0 counts[a[i]] += 1 if counts[a[i]] > maxi: start = i maxi = counts[a[i]] for i in range(start, 0, -1): if a[i - 1] < a[i]: a[i - 1] = a[i] output.append("1 " + str(i) + " " + str(i + 1)) elif a[i - 1] > a[i]: a[i - 1] = a[i] output.append("2 " + str(i) + " " + str(i + 1)) for i in range(start, n - 1): if a[i + 1] < a[i]: a[i + 1] = a[i] output.append("1 " + str(i + 2) + " " + str(i + 1)) elif a[i + 1] > a[i]: a[i + 1] = a[i] output.append("2 " + str(i + 2) + " " + str(i + 1)) print(len(output)) for line in output: print(line)
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 LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER 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 IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER 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 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())) times = [0] * 200001 for i in l: times[i] += 1 maks = 0 k = 0 for i in range(200001): if times[i] > maks: k = i maks = times[i] start = 0 for i in range(200001): if l[i] == k: start = i break wyn = n - maks print(wyn) for i in range(start + 1, n): if l[i - 1] != l[i]: print((l[i] > l[i - 1]) + 1, end=" ") print(i + 1, end=" ") print(i) l[i] = l[i - 1] i = start while i > 0: if l[i - 1] != l[i]: print((l[i - 1] > l[i]) + 1, end=" ") print(i, end=" ") print(i + 1) l[i - 1] = l[i] 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 BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR 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(" "))) cnt = {} ans = 0 val = 0 for i in range(0, n): try: cnt[a[i]] += 1 if ans < cnt[a[i]]: ans = cnt[a[i]] pos = i val = a[i] except: cnt[a[i]] = 1 if ans < cnt[a[i]]: ans = cnt[a[i]] pos = i val = a[i] print(n - ans) for i in range(pos - 1, -1, -1): if a[i] < a[i + 1]: print("1 " + str(i + 1) + " " + str(i + 2)) a[i] = val elif a[i] > a[i + 1]: print("2 " + str(i + 1) + " " + str(i + 2)) a[i] = val for i in range(pos + 1, n): if a[i] < a[i - 1]: print("1 " + str(i + 1) + " " + str(i)) a[i] = val elif a[i] > a[i - 1]: print("2 " + str(i + 1) + " " + str(i)) a[i] = val
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR 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 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 ASSIGN VAR VAR VAR IF VAR VAR 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 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 BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR 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 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()) l = list(map(int, input().split())) l1 = [0] * 200005 for i in range(n): l1[l[i]] += 1 mx = l1.index(max(l1)) print(n - max(l1)) for i in range(n): if l[i] == mx: mxi = i break for i in range(mxi - 1, -1, -1): if l[i] > l[i + 1]: print(2, i + 1, i + 2) elif l[i] < l[i + 1]: print(1, i + 1, i + 2) l[i] = l[i + 1] for i in range(mxi + 1, n): if l[i] > l[i - 1]: print(2, i + 1, i) elif l[i] < l[i - 1]: print(1, i + 1, i) l[i] = l[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 BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL 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 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 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 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
m = int(input()) a = list(map(int, input().split())) c = [(0) for i in range(200000 + 1)] inc = [] dec = [] mark = [] l = 0 i = 0 l1 = 0 max = 0 check = 0 maxi = 0 mark1 = [] r = 0 while i < len(a): c[a[i]] += 1 i += 1 i = 0 while i < len(c): if c[i] > max: max = c[i] maxi = i i += 1 i = 0 while i < len(a): if check == 0: if a[i] < maxi: mark.append(str(1) + " " + str(i + 1) + " " + str(i + 2)) r += 1 elif a[i] > maxi: r += 1 mark.append(str(2) + " " + str(i + 1) + " " + str(i + 2)) elif a[i] == maxi or a[i + 1] == maxi: check = 1 elif a[i] > maxi: r += 1 mark1.append(str(2) + " " + str(i + 1) + " " + str(i)) elif a[i] < maxi: r += 1 mark1.append(str(1) + " " + str(i + 1) + " " + str(i)) i += 1 print(r) for i in range(len(mark) - 1, -1, -1): print(mark[i]) for i in range(len(mark1)): print(mark1[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 VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF 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 VAR NUMBER IF VAR VAR VAR 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 VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR VAR VAR 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 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 VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR 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
n = int(input()) a = list(map(int, input().split())) c = [0] * 200001 for i in range(n): c[a[i]] += 1 x = -1 ma = 0 for i in range(200001): if c[i] > ma: ma = c[i] x = i l = [] print(n - ma) for i in range(n): if a[i] == x: l.append(i) j = l[0] while j > 0: if a[j - 1] > a[j]: print(2, j, j + 1) else: print(1, j, j + 1) a[j - 1] = x j -= 1 for i in range(len(l) - 1): j = l[i] while j < l[i + 1] - 1: if a[j + 1] > a[j]: print(2, j + 2, j + 1) else: print(1, j + 2, j + 1) a[j + 1] = x j += 1 j = l[len(l) - 1] while j < n - 1: if a[j + 1] > a[j]: print(2, j + 2, j + 1) else: print(1, j + 2, j + 1) a[j + 1] = x j += 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 FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER WHILE VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR 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 VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER 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 BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER 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 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
MOD = 10**9 + 7 ii = lambda: int(input()) si = lambda: input() dgl = lambda: list(map(int, input())) f = lambda: map(int, input().split()) il = lambda: list(map(int, input().split())) ls = lambda: list(input()) n = ii() l = il() lnum = [0] * (2 * 10**5 + 10) for i in l: lnum[i] += 1 mx = 0 for i in range(2 * 10**5 + 5): if lnum[i] > mx: mx = lnum[i] num = i ind = l.index(num) print(n - mx) for i in range(ind - 1, -1, -1): if l[i] < l[i + 1]: l[i] = l[i + 1] print(1, i + 1, i + 2) elif l[i] > l[i + 1]: l[i] = l[i + 1] print(2, i + 1, i + 2) for i in range(ind + 1, n): if l[i - 1] < l[i]: print(2, i + 1, i) l[i] = l[i - 1] elif l[i - 1] > l[i]: l[i] = l[i - 1] print(1, i + 1, i)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN 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 ASSIGN VAR FUNC_CALL VAR ASSIGN 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 ASSIGN VAR VAR VAR ASSIGN 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 BIN_OP VAR NUMBER ASSIGN 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 ASSIGN VAR VAR VAR 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 VAR IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER 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()) l = list(map(int, input().split())) mask = [0] * 200001 for i in range(n): mask[l[i]] += 1 for i in range(200001): mask[i] = [mask[i], i] mask.sort(reverse=True) cur = mask[0][1] print(n - mask[0][0]) basis = l.index(cur) for i in range(basis - 1, -1, -1): if l[i] > cur: print(2, i + 1, i + 2) elif l[i] < cur: print(1, i + 1, i + 2) for i in range(basis + 1, n): if l[i] > cur: print(2, i + 1, i) elif l[i] < cur: print(1, 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 NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER 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 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())) h = [0] * 200001 max_a = 0 max_h = 0 ind = 0 for i in range(len(a)): h[a[i]] += 1 if h[a[i]] > max_h: max_h = h[a[i]] max_a = a[i] ind = i print(n - max_h) l = ind - 1 r = ind + 1 while l >= 0 or r <= n - 1: if l > -1: if a[l] > a[l + 1]: a[l] = a[l + 1] print(2, l + 1, l + 2) elif a[l] < a[l + 1]: a[l] = a[l + 1] print(1, l + 1, l + 2) l -= 1 if r < n: if a[r] > a[r - 1]: a[r] = a[r - 1] print(2, r + 1, r) elif a[r] < a[r - 1]: a[r] = a[r - 1] print(1, r + 1, r) r += 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN 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 ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN 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 ASSIGN VAR VAR VAR BIN_OP VAR NUMBER 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
n = int(input()) a = [int(j) for j in input().split()] li = [0] * (2 * 10**5 + 1) for x in a: li[x] += 1 ma = 0 for j in range(len(li)): if li[j] > ma: ma = li[j] val = j print(n - li[val]) for x in range(n): if a[x] == val: ind = x for x in range(ind + 1, n): if a[x] < val: print(1, x + 1, x) elif a[x] > val: print(2, x + 1, x) for x in range(ind - 1, -1, -1): if a[x] < val: print(1, x + 1, x + 2) elif a[x] > val: print(2, x + 1, x + 2)
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 FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR 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 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()) a = list(map(int, input().split())) b = [] for i in a: b.append(i) b.sort() b.append(-1) tem = b[0] ln = 1 ou = 0 i = 1 va = b[0] for i in range(1, n + 1): if b[i] == tem: ln += 1 else: if ou < ln: ou = ln va = b[i - 1] ln = 1 tem = b[i] print(n - ou) k = n - ou i = 0 st = [] while a[i] != va: if a[i] < va: st.append([1, i, i + 1]) i += 1 elif a[i] > va: st.append([2, i, i + 1]) i += 1 for j in range(len(st) - 1, -1, -1): print(str(st[j][0]), str(st[j][1] + 1), str(st[j][2] + 1)) for j in range(i + 1, n): if a[j] < va: print(str(1), str(j + 1), str(j)) elif a[j] > va: print(str(2), str(j + 1), str(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 LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR LIST NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR LIST NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER 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 = [int(t) for t in input().split(" ")] numbers = [0] * (max(a) + 1) for ai in a: numbers[ai] += 1 most = max(numbers) target = numbers.index(most) ops = n - most print(ops) left = 0 while ops: try: idx = a.index(target, left) for i in reversed(range(left, idx)): print(1 if a[i] < target else 2, i + 1, i + 2) ops -= 1 left = idx while left < len(a) and a[left] == target: left += 1 except ValueError: for i in range(left, n): print(1 if a[i] < target else 2, i + 1, i) ops -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER 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
n, l = int(input()), list(map(int, input().split())) d = {} mx, index = 0, 0 for i in l: if i in d: d[i] += 1 else: d[i] = 1 if d[i] > mx: mx = d[i] index = i print(n - mx) i = l.index(index) j = i while j >= 0: if l[j] > index: print(2, j + 1, j + 2) elif l[j] < index: print(1, j + 1, j + 2) j -= 1 while i < n: if l[i] > index: print(2, i + 1, i) elif l[i] < index: print(1, i + 1, i) i += 1
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR 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 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