description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
n = int(input()) c = input() a = input() c = [int(x) for x in c] a = [int(x) for x in a] res = -1 nz = 0 na = 0 nc = 0 nb = 0 for is_c, is_a in zip(c, a): if is_c and is_a: nb += 1 elif is_c: nc += 1 elif is_a: na += 1 else: nz += 1 rnb1 = None rna1 = None rnc1 = None rnz1 = None for nb2 in range(nb + 1): nb1 = nb - nb2 mn = max(0, nb2 - nb1) mx = min(nc, na + nb2 - nb1) + 1 for nc1 in range(mn, mx): if nc1 + nb1 - nb2 < 0: continue na2 = nc1 + nb1 - nb2 if na2 > na: continue na1 = na - na2 nz1 = n // 2 - na1 - nc1 - nb1 if nz1 < 0 or nz1 > nz: continue rnb1 = nb1 rna1 = na1 rnc1 = nc1 rnz1 = nz1 break else: continue break if rnb1 is None: print(-1) else: t = [] for i, (is_c, is_a) in enumerate(zip(c, a)): if is_c and is_a and rnb1: t.append(i + 1) rnb1 -= 1 elif is_c and not is_a and rnc1: t.append(i + 1) rnc1 -= 1 elif not is_c and is_a and rna1: t.append(i + 1) rna1 -= 1 elif not is_c and not is_a and rnz1: t.append(i + 1) rnz1 -= 1 print(" ".join([str(x) for x in t]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NONE FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NONE EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
from sys import stdin n = int(stdin.readline().strip()) s = stdin.readline().strip() s1 = stdin.readline().strip() s2 = [] x00 = 0 x01 = 0 x10 = 0 x11 = 0 for i in range(n): if s[i] == "0" and s1[i] == "0": x00 += 1 elif s[i] == "0" and s1[i] == "1": x01 += 1 elif s[i] == "1" and s1[i] == "0": x10 += 1 else: x11 += 1 mid = n // 2 for y10 in range(x10 + 1): for y11 in range(x11 + 1): y01 = -y10 - y11 + x01 + x11 - y11 y00 = mid - y01 - y11 - y10 if y01 < 0 or y01 > x01 or y00 < 0 or y00 > x00 or y00 + y01 + y11 + y10 != mid: continue for i in range(n): if s[i] == "0" and s1[i] == "0" and y00: print(i + 1, end=" ") y00 -= 1 elif s[i] == "0" and s1[i] == "1" and y01: print(i + 1, end=" ") y01 -= 1 elif s[i] == "1" and s1[i] == "0" and y10: print(i + 1, end=" ") y10 -= 1 elif s[i] == "1" and s1[i] == "1" and y11: print(i + 1, end=" ") y11 -= 1 exit(0) print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
n = int(input()) c = input() a = input() c00 = c01 = c10 = c11 = 0 d00 = [] d01 = [] d10 = [] d11 = [] for i in range(n): if c[i] == "1" and a[i] == "1": c11 += 1 d11.append(i) elif c[i] == "0" and a[i] == "1": c01 += 1 d01.append(i) elif c[i] == "1" and a[i] == "0": c10 += 1 d10.append(i) elif c[i] == "0" and a[i] == "0": c00 += 1 d00.append(i) for cc in range(n): nc = n // 2 - cc for j in range(cc + 1): if j > c10 or cc - j > c11: continue lc10 = c10 - j lc11 = c11 - (cc - j) if lc11 > cc: continue if lc10 + lc11 > n // 2: continue la = n // 2 - lc10 - lc11 mn = lc11 + (la - min(la, c00)) mx = lc11 + min(la, c01) if cc >= mn and cc <= mx: neans = [] neans += d10[:lc10] neans += d11[:lc11] neans += d01[: cc - lc11] neans += d00[: n // 2 - len(neans)] ans = list(set(range(n)) - set(neans)) print(" ".join([str(i + 1) for i in ans])) exit() print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR IF BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR LIST VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
import sys n = int(input()) c = [int(x) for x in input()] a = [int(x) for x in input()] by_diff = {i: [] for i in range(3)} diff = [(c[i] + a[i]) for i in range(n)] for i in range(n): by_diff[c[i] + a[i]].append(i + 1) total_sum = sum(a) total_count = [len(by_diff[i]) for i in range(3)] for count2 in range(total_count[2] + 1): count1 = total_sum - 2 * count2 count0 = n // 2 - count2 - count1 if 0 <= count0 <= total_count[0] and 0 <= count1 <= total_count[1]: print( " ".join( map( str, by_diff[0][:count0] + by_diff[1][:count1] + by_diff[2][:count2] ) ) ) sys.exit(0) print(-1)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR IF NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
n = int(input()) c = input() a = input() clowns = [] acr = [] both = [] neither = [] for i in range(n): if c[i] == "1" and a[i] == "1": both.append(i + 1) elif c[i] == "1": clowns.append(i + 1) elif a[i] == "1": acr.append(i + 1) else: neither.append(i + 1) x = len(clowns) y = len(acr) z = len(both) mn = min(x, y) mx = max(x, y) if mn == x: smaller = clowns larger = acr v = 0 else: smaller = acr larger = clowns v = 1 if mn + z < mx and mx > n / 2 or mx == 0 and z % 2 == 1: print(-1) else: if mn + z < mx: smaller = smaller + both while mx > mn + z: smaller.append(larger[-1]) mx -= 1 del larger[-1] p = len(smaller) while p < n / 2: smaller.append(neither[0]) del neither[0] p += 1 larger = larger + neither else: while mn < mx: smaller.append(both[0]) mn += 1 del both[0] if both == []: break while len(both) > 1: smaller.append(both[0]) larger.append(both[1]) del both[0] del both[0] if both != []: smaller.append(larger[0]) del larger[0] larger.append(both[0]) larger.append(neither[0]) del neither[0] while neither != []: smaller.append(neither[0]) larger.append(neither[1]) del neither[0] del neither[0] if v == 0: for i in smaller: print(i, end=" ") else: for i in larger: print(i, end=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR LIST WHILE FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR LIST EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER WHILE VAR LIST EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
cnt = [0] * 4 ans = [0] * 4 n = int(input()) c = [int(i) for i in input()] an = [int(i) for i in input()] for i in range(n): cnt[(c[i] & 1) << 1 | an[i] & 1] += 1 fl = 1 for d in range(cnt[3] + 1): a = (n >> 1) + d - cnt[1] - cnt[3] if a >= 0 and a <= cnt[0]: bc = cnt[1] + cnt[3] - 2 * d if bc >= 0 and bc <= cnt[1] + cnt[2]: ans[0] = a ans[3] = d ans[1] = min(bc, cnt[1]) ans[2] = bc - ans[1] fl = 0 if fl == 1: exit(print(-1)) else: for i in range(n): tmp = (c[i] & 1) << 1 | an[i] & 1 if ans[tmp]: print(i + 1, end=" ") ans[tmp] -= 1
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP NUMBER VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR VAR NUMBER
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
import sys input = sys.stdin.readline n = int(input()) c = list(input().rstrip()) a = list(input().rstrip()) f = [[] for i in range(4)] for i in range(n): c[i] = int(c[i]) a[i] = int(a[i]) if c[i] == a[i] == 0: f[0].append(i) elif c[i] == 0 and a[i] == 1: f[1].append(i) elif c[i] == 1 and a[i] == 0: f[2].append(i) else: f[3].append(i) ans1, ans2 = [], [] for w1 in range(len(f[3]) + 1): w2 = len(f[3]) - w1 for y1 in range(len(f[1]) + 1): y2 = len(f[1]) - y1 z1 = y2 + w2 - w1 z2 = len(f[2]) - z1 if z1 >= 0 and z2 >= 0 and (len(f[0]) + z2 - y1) % 2 == 0: x1 = (len(f[0]) + z2 - y1) // 2 x2 = len(f[0]) - x1 if not (x1 >= 0 and x2 >= 0): continue for i in range(x1): ans1.append(f[0][i] + 1) for i in range(x1, len(f[0])): ans2.append(f[0][i] + 1) for i in range(y1): ans1.append(f[1][i] + 1) for i in range(y1, len(f[1])): ans2.append(f[1][i] + 1) for i in range(z1): ans1.append(f[2][i] + 1) for i in range(z1, len(f[2])): ans2.append(f[2][i] + 1) for i in range(w1): ans1.append(f[3][i] + 1) for i in range(w1, len(f[3])): ans2.append(f[3][i] + 1) if ans1: break if ans1: break if ans1: print(*ans1) else: print(-1)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR IF VAR NUMBER VAR NUMBER BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR IF VAR IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
n = int(input()) a = input() b = input() init = sum(int(c) for c in b) mp = [[] for i in range(3)] for i in range(n): c = int(a[i]) + int(b[i]) mp[c] += [i + 1] need = n // 2 for i in range(len(mp[1]) + 1): for j in range(len(mp[2]) + 1): if i + 2 * j == init and i + j <= need and i + j + len(mp[0]) >= need: print(*(mp[0][: need - i - j] + mp[1][:i] + mp[2][:j])) exit() print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR LIST BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
import sys input = sys.stdin.readline n = int(input()) x = input() y = input() a = [] b = [] c = [] d = [] for i in range(n): if x[i] == "0" and y[i] == "0": a.append(i + 1) elif x[i] == "0" and y[i] == "1": b.append(i + 1) elif x[i] == "1" and y[i] == "0": c.append(i + 1) elif x[i] == "1" and y[i] == "1": d.append(i + 1) n_a = len(a) n_b = len(b) n_c = len(c) n_d = len(d) state = True box = [] for i in range(n_a + 1): for j in range(n_d + 1): if i - j == n // 2 - n_b - n_d: if 0 <= n // 2 - i - j <= n_b + n_c: s = i v = j state = False break if state: print(-1) else: t = min(n_b, n // 2 - s - v) u = n // 2 - s - v - t for i in range(s): print(a.pop(), end=" ") for i in range(v): print(d.pop(), end=" ") for i in range(t): print(b.pop(), end=" ") for j in range(u): print(c.pop(), end=" ") print()
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR IF NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
n = int(input()) c = list(map(int, list(input()))) a = list(map(int, list(input()))) p = [0, 0, 0, 0] ind = [[], [], [], []] for i in range(n): if c[i] and a[i]: p[3] += 1 ind[3].append(i) elif c[i]: p[1] += 1 ind[1].append(i) elif a[i]: p[2] += 1 ind[2].append(i) else: p[0] += 1 ind[0].append(i) first = [0, p[1], 0, 0] second = [0, 0, p[2], 0] def trans(i, n): first[i] += n second[i] -= n if p[2] > p[1]: d = p[2] - p[1] first[2] += d second[2] -= d else: d = p[1] - p[2] first[1] -= d second[1] += d d = p[3] while d > 0: if first[1] + first[3] > second[2] + second[3]: second[3] += 1 d -= 1 else: first[3] += 1 d -= 1 dif = first[1] + first[3] - (second[2] + second[3]) if dif > 0: if first[2] > 0: trans(2, -1) elif first[1] > 0: trans(1, -1) elif first[3] > 0 and second[1] > 0: trans(3, -1) trans(1, 1) else: print(-1) quit() elif dif < 0: if second[1] > 0: trans(1, 1) elif second[2] > 0: trans(2, 2) elif second[3] > 0 and first[2] > 0: trans(3, 1) trans(2, -1) else: print(-1) quit() d = p[0] while d > 0: if sum(first) > sum(second): second[0] += 1 d -= 1 else: first[0] += 1 d -= 1 while sum(first) > sum(second): if first[1] > 0 and first[2] > 0 and second[3] > 0: trans(1, -1) trans(2, -1) trans(3, 1) elif first[2] > 1 and second[3] > 0: trans(2, -1) trans(2, -1) trans(3, 1) else: print(-1) quit() while sum(first) < sum(second): if second[1] > 0 and second[2] > 0 and first[3] > 0: trans(1, 1) trans(2, 1) trans(3, -1) elif second[1] > 1 and first[3] > 0: trans(1, 1) trans(1, 1) trans(3, -1) else: print(-1) quit() ans = [] for i in range(4): for j in range(first[i]): ans.append(ind[i][j]) print(" ".join([str(x + 1) for x in ans]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST LIST LIST LIST LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR NUMBER NUMBER FUNC_DEF VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER NUMBER VAR NUMBER VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER WHILE VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER NUMBER VAR NUMBER WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
n = int(input()) c = input() a = input() aCnt = 0 bCnt = 0 cCnt = 0 dCnt = 0 for i in range(n): if a[i] == "0" and c[i] == "0": aCnt += 1 if a[i] == "0" and c[i] == "1": cCnt += 1 if a[i] == "1" and c[i] == "0": bCnt += 1 if a[i] == "1" and c[i] == "1": dCnt += 1 isDone = False for j in range(n + 1): a1 = n // 2 - j d1 = bCnt + dCnt - j b1Plusc1 = j - d1 if ( a1 >= 0 and d1 >= 0 and b1Plusc1 >= 0 and b1Plusc1 <= bCnt + cCnt and a1 <= aCnt and d1 <= dCnt ): ans = [] for i in range(n): if a[i] == "0" and c[i] == "0" and a1 > 0: ans.append(str(i + 1)) a1 -= 1 if ( a[i] == "0" and c[i] == "1" or a[i] == "1" and c[i] == "0" ) and b1Plusc1 > 0: ans.append(str(i + 1)) b1Plusc1 -= 1 if a[i] == "1" and c[i] == "1" and d1 > 0: ans.append(str(i + 1)) d1 -= 1 isDone = True print(" ".join(ans)) break if not isDone: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR EXPR FUNC_CALL VAR NUMBER
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
n = int(input()) s1 = input() s2 = input() w, x, y, z = 0, 0, 0, 0 W, X, Y, Z = [], [], [], [] for i in range(n): s = s1[i] + s2[i] if s == "00": w += 1 W.append(i) elif s == "11": x += 1 X.append(i) elif s == "10": y += 1 Y.append(i) else: z += 1 Z.append(i) can = False res_count = [] for i in range(x + 1): for j in range(n // 2 + 1): req1, left1 = j - i, y - j + i if req1 < 0: continue if y < req1: continue req2 = j - (x - i) left2 = z - req2 if req2 < 0 or z < req2: continue if req2 + left1 + (x - i) > n // 2 or req1 + left2 + i > n // 2: continue w_req = n // 2 - i - req1 - left2 if w_req > w: continue res_count = [i, req1, left2] can = True break if can: break if not can: print(-1) exit(0) res = [] for i in range(res_count[0]): res.append(X[i] + 1) for i in range(res_count[1]): res.append(Y[i] + 1) for i in range(res_count[2]): res.append(Z[i] + 1) for i in range(n // 2 - len(res)): res.append(W[i] + 1) res.sort() print(" ".join(map(str, res)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR LIST LIST LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR LIST VAR VAR VAR ASSIGN VAR NUMBER IF VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
n = int(input()) c_s = input() a_s = input() clowns = [] acrobats = [] both = [] none = [] for i in range(n): if a_s[i] == "1" and c_s[i] == "1": both.append(i + 1) elif a_s[i] == "1": acrobats.append(i + 1) elif c_s[i] == "1": clowns.append(i + 1) else: none.append(i + 1) nc = len(clowns) nb = len(acrobats) nd = len(both) na = len(none) found = False for b in range(0, nb + 1): for c in range(0, nc + 1): d = nb + nd - c - b if d % 2 == 1: continue d = d // 2 a = n // 2 - d - c - b if d < 0 or d > nd or a > na or a < 0: continue found = True break if found: break if not found: print(-1) else: ans = [] for i in range(a): ans.append(none[i]) for i in range(b): ans.append(acrobats[i]) for i in range(c): ans.append(clowns[i]) for i in range(d): ans.append(both[i]) print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR IF VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
from sys import stdin, stdout n = int(stdin.readline()) a = [int(x) for x in stdin.readline().strip()] c = [int(x) for x in stdin.readline().strip()] ind = [[], [], [], []] for i in range(len(a)): ind[2 * a[i] + c[i]].append(i + 1) cnt = [] r = [] for i in range(n // 2 + 1): for j in range(i + 1): if j > len(ind[2]): continue if i - j > len(ind[3]): continue cnt = [len(x) for x in ind] cnt[2] -= j cnt[3] += -i + j cnt1soll = i - cnt[3] cnt0soll = n // 2 - i - cnt[2] if ( cnt1soll >= 0 and cnt1soll <= cnt[1] and cnt0soll >= 0 and cnt0soll <= cnt[0] ): for x in range(j): r.append(ind[2][x]) for x in range(i - j): r.append(ind[3][x]) for x in range(cnt[1] - cnt1soll): r.append(ind[1][x]) for x in range(cnt[0] - cnt0soll): r.append(ind[0][x]) break else: continue break else: r = [-1] r = [str(x) for x in r] r.append("\n") stdout.write(" ".join(r))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST LIST LIST LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
n = int(input()) s = input() t = input() A = [] B = [] C = [] D = [] a, b, c, d = 0, 0, 0, 0 for i in range(n): f = s[i] + t[i] if f == "00": d += 1 D.append(i + 1) elif f == "01": a += 1 A.append(i + 1) elif f == "11": c += 1 C.append(i + 1) else: b += 1 B.append(i + 1) for x1 in range(a + 1): for x2 in range(b + 1): if (a + c - x1 - x2) % 2 == 0: x3 = (a + c - x1 - x2) // 2 x4 = n // 2 - x1 - x2 - x3 if 0 <= x3 <= c and 0 <= x4 <= d: ans = [] for i in range(x1): ans.append(A[i]) for i in range(x2): ans.append(B[i]) for i in range(x3): ans.append(C[i]) for i in range(x4): ans.append(D[i]) print(" ".join(list(map(str, ans)))) exit(0) print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR IF NUMBER VAR VAR NUMBER VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
n = int(input()) s1 = input() s2 = input() count1 = 0 count2 = 0 count3 = 0 count4 = 0 l1 = set() l2 = set() l3 = set() l4 = set() for i in range(n): if s1[i] == "1" and s2[i] == "0": count1 += 1 l1.add(i + 1) if s1[i] == "0" and s2[i] == "1": count2 += 1 l2.add(i + 1) if s1[i] == "0" and s2[i] == "0": count3 += 1 l3.add(i + 1) if s1[i] == "1" and s2[i] == "1": count4 += 1 l4.add(i + 1) ka = {} a, b, c, d = -1, -1, -1, -1 for i in range(count3 + 1): for j in range(count4 + 1): if j - i == count4 + count2 - n // 2: ka[i + j] = i, j for i in range(count1 + 1): flag = 1 for j in range(count2 + 1): if n // 2 - (i + j) in ka: x, y = ka[n // 2 - (i + j)] flag = 0 a, b, c, d = i, j, x, y break if not flag: break if a != -1 and b != -1 and c != -1 and d != -1: ans = [] l1 = list(l1) l2 = list(l2) l3 = list(l3) l4 = list(l4) for i in range(a): ans.append(l1[i]) for i in range(b): ans.append(l2[i]) for i in range(c): ans.append(l3[i]) for i in range(d): ans.append(l4[i]) print(*ans) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
import sys N = int(input()) c_ls = list(input()) a_ls = list(input()) total_both = 0 ls_both = [] total_Aonly = 0 ls_Aonly = [] total_Conly = 0 ls_Conly = [] total_none = 0 ls_none = [] for i in range(N): if c_ls[i] == "1" and a_ls[i] == "1": total_both += 1 ls_both.append(i) elif c_ls[i] == "1": total_Conly += 1 ls_Conly.append(i) elif a_ls[i] == "1": total_Aonly += 1 ls_Aonly.append(i) else: total_none += 1 ls_none.append(i) for first_both in range(total_both + 1): for first_Conly in range(total_Conly + 1): if first_both + first_Conly > N // 2: continue second_both = total_both - first_both second_Conly = total_Conly - first_Conly second_Aonly = first_both + first_Conly - second_both if second_Aonly < 0 or second_Aonly > total_Aonly: continue second_none = N // 2 - (second_both + second_Conly + second_Aonly) if second_none < 0 or second_none > total_none: continue ans_ls = [] for i in range(first_both): ans_ls.append(ls_both[i] + 1) for i in range(first_Conly): ans_ls.append(ls_Conly[i] + 1) first_Aonly = total_Aonly - second_Aonly for i in range(first_Aonly): ans_ls.append(ls_Aonly[i] + 1) first_none = total_none - second_none for i in range(first_none): ans_ls.append(ls_none[i] + 1) print(*ans_ls) sys.exit() print(-1)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
import sys n = int(input()) s = input() s1 = input() a = 0 b = 0 c = 0 d = 0 an = [] for i in range(n): if s[i] == "0" and s1[i] == "0": a += 1 elif s[i] == "1" and s1[i] == "0": b += 1 elif s[i] == "0" and s1[i] == "1": c += 1 else: d += 1 x = 0 y = 0 z = 0 w = 0 t = 0 for i in range(a + 1): for j in range(d + 1): if ( n // 2 - i - j == c + d - 2 * j and n // 2 - i - j >= 0 and n // 2 - i - j <= b + c ): x = i y = min(b, n // 2 - i - j) z = n // 2 - i - j - y w = j t = 1 break if t == 0: print(-1) sys.exit() for i in range(n): if s[i] == "0" and s1[i] == "0" and x > 0: an.append(i + 1) x -= 1 elif s[i] == "1" and s1[i] == "0" and y > 0: an.append(i + 1) y -= 1 elif s[i] == "0" and s1[i] == "1" and z > 0: an.append(i + 1) z -= 1 elif s[i] == "1" and s1[i] == "1" and w > 0: an.append(i + 1) w -= 1 print(*an, sep=" ")
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR STRING
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
k = lambda: map(int, input().split()) l = lambda: list(k()) n = int(input()) pairs = [None for _ in range(n)] cant = acros = clowns = both = 0 l1, l2 = input(), input() g1, g2 = [0, 0, 0, 0], [0, 0, 0, 0] ans = [0] * n for i in range(n): pairs[i] = int(l1[i]), int(l2[i]), i + 1 ans[i] = pairs[i][0] + pairs[i][1] * 2 if pairs[i][0]: if pairs[i][1]: both += 1 else: clowns += 1 elif pairs[i][1]: acros += 1 else: cant += 1 if (acros + clowns + both) % 2 == 1: if acros == clowns == 0: print(-1) raise SystemExit() if acros > clowns: acros -= 1 cant -= 1 g1[2] += 1 g2[0] += 1 else: clowns -= 1 cant -= 1 g2[1] += 1 g1[0] += 1 val = min(acros, clowns) g1[1] += val g2[2] += val acros -= val clowns -= val if clowns > 0: valb = min(clowns, both) g1[1] += valb g2[3] += valb both -= valb clowns -= valb elif acros > 0: valb = min(acros, both) g1[3] += valb g2[2] += valb acros -= valb both -= valb valb = both // 2 g1[3] += valb g2[3] += valb both -= valb * 2 if clowns > 0: valc = min(clowns, cant) g2[1] += valc g1[0] += valc clowns -= valc cant -= valc if acros > 0: valc = min(acros, cant) g2[0] += valc g1[2] += valc acros -= valc cant -= valc valc = cant // 2 g1[0] += valc g2[0] += valc cant -= valc * 2 if cant > 0 or clowns > 0 or acros > 0 or both > 0: print(-1) else: for i in range(n): if g1[ans[i]] > 0: g1[ans[i]] -= 1 print(i + 1, end=" ") print()
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 NONE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
import sys n = int(input()) a = input() b = input() pary = [] for i in range(n): pary.append([int(a[i]), int(b[i])]) jj = [] jz = [] zj = [] zz = [] for i in range(n): if pary[i] == [0, 0]: zz.append(i) if pary[i] == [1, 0]: jz.append(i) if pary[i] == [0, 1]: zj.append(i) if pary[i] == [1, 1]: jj.append(i) a = len(jj) b = len(jz) c = len(zj) d = len(zz) aa = -1 bb = 0 chuj = 0 for a1 in range(a + 1): if ( a - b <= 2 * a1 and 2 * a1 <= a + c and a + c - n // 2 <= a1 and a1 <= d + a + c - n // 2 ): aa = a1 break if aa == -1: print(-1) sys.exit(0) dd = aa - a - c + n // 2 bb = min(b, a + c - 2 * aa) cc = a + c - 2 * aa - bb for i in range(aa): print(jj[i] + 1, end=" ") for i in range(bb): print(jz[i] + 1, end=" ") for i in range(cc): print(zj[i] + 1, end=" ") for i in range(dd): print(zz[i] + 1, end=" ")
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER STRING
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
def calc(s, n, d): cnts = [len(v) for v in d.values()] half = n // 2 for a in range(0, cnts[0] + 1): for b in range(0, cnts[1] + 1): c = n - 2 * a - b - s d = a + s - half if ( 0 <= c <= cnts[2] and 0 <= d <= cnts[3] and a + b + c + d == half and b + c + 2 * d == s ): return True, a, b, c, d return (False,) def main(): n = int(input()) c_arr = list(map(int, list(input()))) a_arr = list(map(int, list(input()))) s = 0 kinds = [(0, 0), (0, 1), (1, 0), (1, 1)] d = {kind: [] for kind in kinds} for i in range(n): if a_arr[i] == 1: s += 1 d[c_arr[i], a_arr[i]].append(i) result, *params = calc(s, n, d) if not result: print(-1) else: ans = [] for i, kind in enumerate(kinds): for j in range(params[i]): ix = d[kind][j] ans.append(str(ix + 1)) print(" ".join(ans)) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR VAR RETURN NUMBER VAR VAR VAR VAR RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR LIST VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
n = int(input()) c = [int(i) for i in input()] a = [int(i) for i in input()] dzero_index = [] done_index = [] one_zero_index = [] aone_count = 0 find = False for i in range(n): if c[i] == a[i] == 0: dzero_index.append(i + 1) elif c[i] == a[i] == 1: done_index.append(i + 1) else: one_zero_index.append(i + 1) if a[i] == 1: aone_count += 1 for i in range(len(done_index) + 1): x = aone_count - 2 * i if ( x <= len(one_zero_index) and x >= 0 and n // 2 - i - x >= 0 and n // 2 - i - x <= len(dzero_index) ): a = x b = i c = n // 2 - i - x find = True break if find: result = ( " ".join(str(i) for i in one_zero_index[0:a]) + " " + " ".join(str(i) for i in done_index[0:b]) + " " + " ".join(str(i) for i in dzero_index[0:c]) ) print(result) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR NUMBER VAR STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR NUMBER VAR STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
n = int(input()) s = input() t = input() na, nb, nc, nd = 0, 0, 0, 0 for i in range(n): if s[i] == "0" and t[i] == "0": na += 1 if s[i] == "0" and t[i] == "1": nb += 1 if s[i] == "1" and t[i] == "0": nc += 1 if s[i] == "1" and t[i] == "1": nd += 1 ans = [] for b in range(nb + 1): for c in range(nc + 1): if (nb + nd - b - c) % 2 == 1: continue d = (nb + nd - b - c) // 2 if d < 0 or d > nd: continue a = n // 2 - b - c - d if a < 0 or a > na: continue else: for i in range(n): if s[i] == "0" and t[i] == "0" and a > 0: a -= 1 ans.append(i + 1) if s[i] == "0" and t[i] == "1" and b > 0: b -= 1 ans.append(i + 1) if s[i] == "1" and t[i] == "0" and c > 0: c -= 1 ans.append(i + 1) if s[i] == "1" and t[i] == "1" and d > 0: d -= 1 ans.append(i + 1) print(*ans) exit(0) print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR IF VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
n = int(input()) s1 = input() s2 = input() first = [] second = [] none = [] both = [] for i in range(n): if s1[i] == "1" and s2[i] == "0": first.append(i + 1) elif s1[i] == "0" and s2[i] == "1": second.append(i + 1) elif s1[i] == "1" and s2[i] == "1": both.append(i + 1) else: none.append(i + 1) fl = len(first) sl = len(second) bl = len(both) nl = len(none) ans = [] flag = 0 for a in range(fl + 1): for c in range(bl + 1): b = a + c - (bl - c) if b <= sl and b >= 0 and a + c + (sl - b) <= n // 2 and b + (bl - c) == a + c: ans = [a, sl - b, c, n // 2 - (a + c + (sl - b))] if ans[3] <= nl and ans[3] >= 0: flag = 1 break if flag == 1: break if flag == 1: print(*first[: ans[0]], *second[: ans[1]], *both[: ans[2]], *none[: ans[3]]) else: print("-1")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR LIST VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
n = int(input()) c = input() a = input() buff = [[] for i in range(4)] for i in range(n): if a[i] == c[i] == "0": buff[0].append(i) elif c[i] == "1" and a[i] == "0": buff[1].append(i) elif c[i] == "0" and a[i] == "1": buff[2].append(i) else: buff[3].append(i) ans = [0] * n while buff[1] and buff[2]: ans[buff[1].pop()] = 1 ans[buff[2].pop()] = 2 if buff[1] or buff[2]: k = 1 if len(buff[1]) != 0 else 2 while buff[k] and buff[3]: if k == 1: ans[buff[k].pop()] = 1 ans[buff[3].pop()] = 2 else: ans[buff[3].pop()] = 1 ans[buff[k].pop()] = 2 if len(buff[k]) > 0: while buff[k] and buff[0]: if k == 1: ans[buff[0].pop()] = 1 ans[buff[k].pop()] = 2 else: ans[buff[k].pop()] = 1 ans[buff[0].pop()] = 2 if buff[1] or buff[2]: ans = [] else: while len(buff[0]) > 1: ans[buff[0].pop()] = 1 ans[buff[0].pop()] = 2 while len(buff[3]) > 1: ans[buff[3].pop()] = 1 ans[buff[3].pop()] = 2 if buff[0] and buff[3]: i = 0 while i < n: if c[i] == "1" and a[i] == "0": ans[i] = 2 break i += 1 if i == n: ans = [] else: ans[buff[0].pop()] = 1 ans[buff[3].pop()] = 1 if len(ans) == 0: print(-1) else: for i in range(len(ans)): if ans[i] % 2: print("{0} ".format(i + 1), end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER NUMBER WHILE VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR LIST WHILE FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR NUMBER STRING
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
n = int(input()) n2 = n // 2 c = input() a = input() only_clown = sum([(1) for i in range(n) if c[i] == "1" and a[i] == "0"]) only_acrobat = sum([(1) for i in range(n) if c[i] == "0" and a[i] == "1"]) both = sum([(1) for i in range(n) if c[i] == "1" and a[i] == "1"]) neither = sum([(1) for i in range(n) if c[i] == "0" and a[i] == "0"]) answer = [] def choose_n(n, ai, ci): idx = 0 chosen = 0 while chosen < n: if a[idx] == ai and c[idx] == ci: answer.append(idx + 1) chosen += 1 idx += 1 for choose_clowns_left in range(n2 + 1): for choose_only_clowns_left in range(0, min(choose_clowns_left, only_clown) + 1): both_left = choose_clowns_left - choose_only_clowns_left clown_right = only_clown - choose_only_clowns_left if both_left > both: continue both_right = both - both_left acrobat_right = choose_clowns_left - both_right acrobat_left = only_acrobat - acrobat_right if acrobat_right < 0 or acrobat_left < 0: continue if choose_clowns_left + clown_right > n2: continue if acrobat_left + choose_clowns_left > n2: continue neither_left = n2 - (choose_only_clowns_left + both_left + acrobat_left) if neither_left > neither: continue choose_n(choose_only_clowns_left, ai="0", ci="1") choose_n(both_left, ai="1", ci="1") choose_n(acrobat_left, ai="1", ci="0") choose_n(neither_left, ai="0", ci="0") print(*answer) exit() print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR STRING VAR VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR STRING VAR VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR STRING VAR VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR STRING VAR VAR STRING ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR STRING STRING EXPR FUNC_CALL VAR VAR STRING STRING EXPR FUNC_CALL VAR VAR STRING STRING EXPR FUNC_CALL VAR VAR STRING STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
maxn = int(5010) a = [(0) for i in range(0, maxn)] b = [(0) for i in range(0, maxn)] n = int(input()) s1 = input() s2 = input() aa, bb, cc, dd = 0, 0, 0, 0 na, nb, nc, nd = 0, 0, 0, 0 for i in range(0, n): a[i] = int(s1[i]) b[i] = int(s2[i]) if a[i] == 0 and b[i] == 0: aa += 1 elif a[i] == 0 and b[i] == 1: bb += 1 elif a[i] == 1 and b[i] == 0: cc += 1 else: dd += 1 if bb > n // 2 or cc > n // 2: print("-1") else: flag = False for i in range(0, bb + 1): if flag == True: break for j in range(0, dd + 1): nc = dd - 2 * j + bb - i na = n // 2 - nc - i - j if na >= 0 and nc >= 0 and na <= aa and nc <= cc: flag = True nb = i nd = j break if flag: for i in range(0, n): if a[i] == 0 and b[i] == 0 and na != 0: na -= 1 print(i + 1, end=" ") if a[i] == 0 and b[i] == 1 and nb != 0: nb -= 1 print(i + 1, end=" ") if a[i] == 1 and b[i] == 0 and nc != 0: nc -= 1 print(i + 1, end=" ") if a[i] == 1 and b[i] == 1 and nd != 0: nd -= 1 print(i + 1, end=" ") else: print("-1")
ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
x = int(input()) s1 = input() s2 = input() a = [] b = [] c = [] d = [] for i in range(len(s1)): if s1[i] == "0" and s2[i] == "0": a.append(i + 1) elif s1[i] == "1" and s2[i] == "0": b.append(i + 1) elif s1[i] == "0" and s2[i] == "1": c.append(i + 1) else: d.append(i + 1) flag = 1 for i in range(len(a) + 1): for j in range(len(b) + 1): if flag == 0: continue a1 = i a2 = len(a) - i b1 = j b2 = len(b) - j c1 = a2 + b2 - a1 if c1 < 0: continue c2 = len(c) - c1 p = c2 - b1 q = len(d) if (p + q) % 2 != 0: continue if (p + q) // 2 >= 0: d1 = (p + q) // 2 d2 = q - d1 else: continue if min(a1, a2, b1, b2, c1, c2, d1, d2) < 0: continue else: flag = 0 if flag == 1: print(-1) else: ans = [] for i in range(a1): ans.append(a[i]) for i in range(b1): ans.append(b[i]) for i in range(c1): ans.append(c[i]) for i in range(d1): ans.append(d[i]) print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
import sys DBG = not True n = int(input()) cc = input() aa = input() c = [] a = [] for i in range(n): c.append(1 if cc[i] == "1" else 0) a.append(1 if aa[i] == "1" else 0) e = [0, 0, 0, 0] g = [[], [], [], []] if DBG: print(c) print(a) for i in range(n): if c[i] == 0 and a[i] == 0: e[0] += 1 g[0].append(i) elif c[i] == 0 and a[i] == 1: e[1] += 1 g[1].append(i) elif c[i] == 1 and a[i] == 0: e[2] += 1 g[2].append(i) elif c[i] == 1 and a[i] == 1: e[3] += 1 g[3].append(i) for x2 in range(min(e[2], n // 2) + 1): for x3 in range(min(e[3], n // 2 - x2) + 1): y3 = e[3] - x3 y1 = x2 + x3 - y3 x1 = e[1] - y1 x0 = n // 2 - x1 - x2 - x3 if 0 <= x1 and x1 <= min(e[1], n // 2) and 0 <= x0 and x0 <= min(e[0], n // 2): for i in range(x0): sys.stdout.write(str(g[0][i] + 1) + " ") for i in range(x1): sys.stdout.write(str(g[1][i] + 1) + " ") for i in range(x2): sys.stdout.write(str(g[2][i] + 1) + " ") for i in range(x3): sys.stdout.write(str(g[3][i] + 1) + " ") print("") sys.exit(0) print(-1)
IMPORT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR STRING NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST LIST LIST LIST LIST IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR IF NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
n = int(input()) c = input() a = input() counta = 0 for x in a: x = int(x) if x == 1: counta += 1 c0 = 0 c1 = 0 c2 = 0 for x, y in zip(c, a): x, y = int(x), int(y) if x == 1 and y == 1: c2 += 1 elif x == 1 or y == 1: c1 += 1 else: c0 += 1 p = 0 q = 0 r = 0 for k in range(c0 + 1): for l in range(c1 + 1): m = n // 2 - k - l if m < 0: break elif c2 < m: continue if l + m * 2 == counta: p, q, r = k, l, m break if p == 0 and q == 0 and r == 0: print(-1) exit() ans = [] for i in range(n): if a[i] == "0" and c[i] == "0" and p > 0: ans.append(i + 1) p -= 1 elif a[i] == "1" and c[i] == "1" and r > 0: ans.append(i + 1) r -= 1 elif (a[i] == "1" and c[i] == "0" or a[i] == "0" and c[i] == "1") and q > 0: ans.append(i + 1) q -= 1 print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER IF VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
n = int(input()) // 2 c = map(int, list(input())) a = map(int, list(input())) artists = zip(c, a) both, none, clowns, acrobats = [], [], [], [] for i, artist in enumerate(artists): if sum(artist) == 2: both.append(i + 1) elif sum(artist) == 0: none.append(i + 1) elif artist[0] == 1: clowns.append(i + 1) else: acrobats.append(i + 1) success = False for z1 in range(len(none) + 1): b1 = len(acrobats) + len(both) - n + z1 if not 0 <= b1 <= len(both): continue if success: break for a1 in range(len(acrobats) + 1): c1 = n - z1 - b1 - a1 if not 0 <= c1 <= len(clowns): continue if a1 + b1 + c1 + z1 == n: first = [] for i in range(z1): first.append(none[i]) for i in range(b1): first.append(both[i]) for i in range(a1): first.append(acrobats[i]) for i in range(c1): first.append(clowns[i]) success = True print(*first) break if not success: print(-1)
ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR LIST LIST LIST LIST FOR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR IF NUMBER VAR FUNC_CALL VAR VAR IF VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF NUMBER VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
n = int(input()) c = input() a = input() an = [(0) for i in range(n)] for i in range(n): if c[i] == "1" and a[i] == "1": an[i] = 3 elif a[i] == "1": an[i] = 1 elif c[i] == "1": an[i] = 2 a1 = [] a2 = [] a3 = [] a4 = [] for i in range(n): if an[i] == 1: a1.append(i) elif an[i] == 2: a2.append(i) elif an[i] == 3: a3.append(i) else: a4.append(i) l1, l2, l3, l4 = len(a1), len(a2), len(a3), len(a4) ans = [] su = 0 while l2 + l3 != l1 + su: if l1 > l2 + l3: if l1 == 0: print(-1) exit() ans.append(a1.pop()) l1 -= 1 elif l1 + su + 1 <= l2 + l3 - 1: if l3 == 0: if l2 != 0: a2.pop() l2 -= 1 else: print(-1) exit() else: a3.pop() l3 -= 1 su += 1 elif l2 != 0: a2.pop() l2 -= 1 else: print(-1) exit() ans.extend(a2) ans.extend(a3) l = len(ans) if l > n // 2: print(-1) exit() for i in range(n // 2 - l): if a4: ans.append(a4.pop()) else: print(-1) exit() for i in range(n // 2): ans[i] += 1 print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
n = int(input()) s1 = [int(i) for i in input()] s2 = [int(i) for i in input()] a = [[] for i in range(4)] for i in range(n): a[s2[i] * 2 + s1[i]].append(i + 1) def cal(a0, a2): nota0 = len(a[0]) - a0 nota2 = len(a[2]) - a2 nota1 = a0 + a2 - nota0 a1 = len(a[1]) - nota1 a3 = n // 2 - a0 - a1 - a2 nota3 = len(a[3]) - a3 if len(a[0]) < a0: return None if len(a[2]) < a2: return None if len(a[1]) < a1 or a1 < 0: return None if len(a[3]) < a3 or a3 < 0: return None if a1 + a3 != nota2 + nota3: return None return a0, a1, a2, a3 ans = None for i in range(n // 2 + 1): if ans != None: break for j in range(n // 2 + 1): ans = cal(i, j) if ans != None: break if ans == None: print(-1) else: res = [] a0, a1, a2, a3 = ans for i in range(a0): res.append(a[0][i]) for i in range(a1): res.append(a[1][i]) for i in range(a2): res.append(a[2][i]) for i in range(a3): res.append(a[3][i]) print(*res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR IF FUNC_CALL VAR VAR NUMBER VAR RETURN NONE IF FUNC_CALL VAR VAR NUMBER VAR RETURN NONE IF FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER RETURN NONE IF FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER RETURN NONE IF BIN_OP VAR VAR BIN_OP VAR VAR RETURN NONE RETURN VAR VAR VAR VAR ASSIGN VAR NONE FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NONE FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NONE IF VAR NONE EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
n = int(input()) y = list(map(int, list(input()))) a = list(map(int, list(input()))) x = [0, 0, 0, 0] for i in range(n): if y[i] == 0: if a[i] == 0: x[0] += 1 else: x[1] += 1 elif a[i] == 0: x[2] += 1 else: x[3] += 1 ok = False ans = [] for c in range(x[2] + 1): for d in range(x[3] + 1): b = x[1] + x[3] - c - 2 * d if 0 <= b + c + d <= n // 2 and 0 <= b <= x[1] and n // 2 - (b + c + d) <= x[0]: ok = True ans = [n // 2 - (b + c + d), b, c, d] if not ok: print(-1) exit() fin = [] for i in range(n): cur = -1 if y[i] == 0: if a[i] == 0: cur = 0 else: cur = 1 elif a[i] == 0: cur = 2 else: cur = 3 if ans[cur] > 0: ans[cur] -= 1 fin.append(i + 1) print(*fin)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR IF NUMBER BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performances in such a way that: * each artist plays in exactly one performance, * the number of artists in the two performances is equal (i.e. equal to n/2), * the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance. Input The first line contains a single integer n (2 ≀ n ≀ 5 000, n is even) β€” the number of artists in the troupe. The second line contains n digits c_1 c_2 … c_n, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise. The third line contains n digits a_1 a_2 … a_n, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise. Output Print n/2 distinct integers β€” the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer -1. Examples Input 4 0011 0101 Output 1 4 Input 6 000000 111111 Output -1 Input 4 0011 1100 Output 4 3 Input 8 00100101 01111100 Output 1 2 3 6 Note In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well. In the second example, the division is not possible. In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.
n = int(input()) clow = input() acro = input() a, b, c, d = 0, 0, 0, 0 for i in range(len(clow)): if clow[i] == "1" and acro[i] == "1": a += 1 elif clow[i] == "1": b += 1 elif acro[i] == "1": c += 1 else: d += 1 x, y, z, t = 0, 0, 0, 0 isAns = False for i in range(d + 1): x = a + c - int(n / 2) + i t = i if x < 0 or x > a: continue y = min(int(n / 2) - i - x, b) z = min(int(n / 2) - i - x - y, c) if y + z != int(n / 2) - i - x or y < 0 or z < 0: continue isAns = True break if not isAns: print(-1) else: for i in range(len(clow)): if clow[i] == "1" and acro[i] == "1": if x > 0: x -= 1 print(i + 1, end=" ") elif clow[i] == "1": if y > 0: y -= 1 print(i + 1, end=" ") elif acro[i] == "1": if z > 0: z -= 1 print(i + 1, end=" ") elif t > 0: t -= 1 print(i + 1, end=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF BIN_OP VAR VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c_{i} = b_{i} - a_{i}. About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≀ a_{i} ≀ r and l ≀ b_{i} ≀ r. About sequence c we know that all its elements are distinct. [Image] Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p_{i} equals to the number of integers which are less than or equal to c_{i} in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively. Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct. -----Input----- The first line contains three integers n, l, r (1 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ 10^9) β€” the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a_1, a_2, ..., a_{n} (l ≀ a_{i} ≀ r) β€” the elements of the sequence a. The next line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≀ p_{i} ≀ n) β€” the compressed sequence of the sequence c. -----Output----- If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers β€” the elements of any suitable sequence b. -----Examples----- Input 5 1 5 1 1 1 1 1 3 1 5 4 2 Output 3 1 5 4 2 Input 4 2 9 3 4 8 9 3 2 1 4 Output 2 2 2 9 Input 6 1 5 1 1 1 1 1 1 2 3 5 4 1 6 Output -1 -----Note----- Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that c_{i} = b_{i} - a_{i}) has compressed sequence equals to p = [3, 2, 1, 4].
n, l, r = list(map(int, input().split())) a = list(map(int, input().split())) p = list(map(int, input().split())) s = set() x = [] for i in range(len(a)): x.append([p[i], i]) x.sort() mx = -1000000000000 for i in range(n): p[x[i][1]] = max(l, mx + a[x[i][1]] + 1) if p[x[i][1]] > r: print("-1") return mx = p[x[i][1]] - a[x[i][1]] idx = 0 for i in p: if idx != 0: print("", i, end="") else: print(i, end="") idx = 1 print("")
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c_{i} = b_{i} - a_{i}. About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≀ a_{i} ≀ r and l ≀ b_{i} ≀ r. About sequence c we know that all its elements are distinct. [Image] Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p_{i} equals to the number of integers which are less than or equal to c_{i} in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively. Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct. -----Input----- The first line contains three integers n, l, r (1 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ 10^9) β€” the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a_1, a_2, ..., a_{n} (l ≀ a_{i} ≀ r) β€” the elements of the sequence a. The next line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≀ p_{i} ≀ n) β€” the compressed sequence of the sequence c. -----Output----- If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers β€” the elements of any suitable sequence b. -----Examples----- Input 5 1 5 1 1 1 1 1 3 1 5 4 2 Output 3 1 5 4 2 Input 4 2 9 3 4 8 9 3 2 1 4 Output 2 2 2 9 Input 6 1 5 1 1 1 1 1 1 2 3 5 4 1 6 Output -1 -----Note----- Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that c_{i} = b_{i} - a_{i}) has compressed sequence equals to p = [3, 2, 1, 4].
n, l, r = map(int, input().split()) A = [int(i) for i in input().split()] Cord = [int(i) for i in input().split()] Cinv = [(0) for _ in range(n)] for i in range(n): Cinv[Cord[i] - 1] = i pmin = -(10**18) B = [(0) for _ in range(n)] ans = True for i in range(n): ad = max(l, pmin + A[Cinv[i]] + 1) B[Cinv[i]] = ad pmin = B[Cinv[i]] - A[Cinv[i]] if ad > r: ans = False if ans: print(*B) else: print(-1)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c_{i} = b_{i} - a_{i}. About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≀ a_{i} ≀ r and l ≀ b_{i} ≀ r. About sequence c we know that all its elements are distinct. [Image] Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p_{i} equals to the number of integers which are less than or equal to c_{i} in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively. Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct. -----Input----- The first line contains three integers n, l, r (1 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ 10^9) β€” the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a_1, a_2, ..., a_{n} (l ≀ a_{i} ≀ r) β€” the elements of the sequence a. The next line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≀ p_{i} ≀ n) β€” the compressed sequence of the sequence c. -----Output----- If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers β€” the elements of any suitable sequence b. -----Examples----- Input 5 1 5 1 1 1 1 1 3 1 5 4 2 Output 3 1 5 4 2 Input 4 2 9 3 4 8 9 3 2 1 4 Output 2 2 2 9 Input 6 1 5 1 1 1 1 1 1 2 3 5 4 1 6 Output -1 -----Note----- Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that c_{i} = b_{i} - a_{i}) has compressed sequence equals to p = [3, 2, 1, 4].
n, l, r = map(int, input().split()) a = list(map(int, input().split())) p = list(map(int, input().split())) ans = [0] * n order = [0] * n for i in range(n): order[p[i] - 1] = i cur = -(10**19) for o in order: bi = max(l, cur + 1 + a[o]) if bi > r: print(-1) exit() ans[o] = bi cur = bi - a[o] print(*ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c_{i} = b_{i} - a_{i}. About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≀ a_{i} ≀ r and l ≀ b_{i} ≀ r. About sequence c we know that all its elements are distinct. [Image] Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p_{i} equals to the number of integers which are less than or equal to c_{i} in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively. Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct. -----Input----- The first line contains three integers n, l, r (1 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ 10^9) β€” the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a_1, a_2, ..., a_{n} (l ≀ a_{i} ≀ r) β€” the elements of the sequence a. The next line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≀ p_{i} ≀ n) β€” the compressed sequence of the sequence c. -----Output----- If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers β€” the elements of any suitable sequence b. -----Examples----- Input 5 1 5 1 1 1 1 1 3 1 5 4 2 Output 3 1 5 4 2 Input 4 2 9 3 4 8 9 3 2 1 4 Output 2 2 2 9 Input 6 1 5 1 1 1 1 1 1 2 3 5 4 1 6 Output -1 -----Note----- Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that c_{i} = b_{i} - a_{i}) has compressed sequence equals to p = [3, 2, 1, 4].
read = lambda: map(int, input().split()) n, l, r = read() mn = l A = [(-i) for i in list(read())] B = [0] * n C = list(enumerate(list(read()))) C.sort(key=lambda x: x[-1]) C = [i for i, j in C] for i in range(n): B[C[i]] = mn - A[C[i]] mn += 1 d = min(B) B = [(i - (d - l)) for i in B] if r - 1 + l >= n and max(B) <= r and min(B) >= l: print(*B) else: print(-1)
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c_{i} = b_{i} - a_{i}. About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≀ a_{i} ≀ r and l ≀ b_{i} ≀ r. About sequence c we know that all its elements are distinct. [Image] Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p_{i} equals to the number of integers which are less than or equal to c_{i} in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively. Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct. -----Input----- The first line contains three integers n, l, r (1 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ 10^9) β€” the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a_1, a_2, ..., a_{n} (l ≀ a_{i} ≀ r) β€” the elements of the sequence a. The next line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≀ p_{i} ≀ n) β€” the compressed sequence of the sequence c. -----Output----- If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers β€” the elements of any suitable sequence b. -----Examples----- Input 5 1 5 1 1 1 1 1 3 1 5 4 2 Output 3 1 5 4 2 Input 4 2 9 3 4 8 9 3 2 1 4 Output 2 2 2 9 Input 6 1 5 1 1 1 1 1 1 2 3 5 4 1 6 Output -1 -----Note----- Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that c_{i} = b_{i} - a_{i}) has compressed sequence equals to p = [3, 2, 1, 4].
n, l, r = map(int, input().split()) A = list(map(int, input().split())) P = list(map(int, input().split())) s = [0] * n per = 0 for j in range(n): s[P[j] - 1] = j b = [0] * n b[s[0]] = l for j in range(1, n): last = b[s[j - 1]] - A[s[j - 1]] nexs = last + 1 if r - A[s[j]] > last: b[s[j]] = max(nexs + A[s[j]], l) else: per = 1 break if per == 1: print(-1) else: print(" ".join(map(str, b)))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c_{i} = b_{i} - a_{i}. About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≀ a_{i} ≀ r and l ≀ b_{i} ≀ r. About sequence c we know that all its elements are distinct. [Image] Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p_{i} equals to the number of integers which are less than or equal to c_{i} in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively. Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct. -----Input----- The first line contains three integers n, l, r (1 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ 10^9) β€” the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a_1, a_2, ..., a_{n} (l ≀ a_{i} ≀ r) β€” the elements of the sequence a. The next line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≀ p_{i} ≀ n) β€” the compressed sequence of the sequence c. -----Output----- If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers β€” the elements of any suitable sequence b. -----Examples----- Input 5 1 5 1 1 1 1 1 3 1 5 4 2 Output 3 1 5 4 2 Input 4 2 9 3 4 8 9 3 2 1 4 Output 2 2 2 9 Input 6 1 5 1 1 1 1 1 1 2 3 5 4 1 6 Output -1 -----Note----- Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that c_{i} = b_{i} - a_{i}) has compressed sequence equals to p = [3, 2, 1, 4].
n, l, r = map(int, input().split(" ")) a = list(map(int, input().split(" "))) c = list(map(int, input().split(" "))) d = dict(zip(c, range(n))) b = [0] * n ckeys = sorted(d, reverse=True) curr = r curr_diff = r - a[d[ckeys[0]]] b[d[ckeys[0]]] = r for ck in ckeys[1:]: curr_diff -= 1 next_b = a[d[ck]] + curr_diff b[d[ck]] = next_b m = max(b) b = [(i - (m - r)) for i in b] possible = max(b) <= r and min(b) >= l print(-1 if not possible else " ".join(map(str, b)))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR FOR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c_{i} = b_{i} - a_{i}. About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≀ a_{i} ≀ r and l ≀ b_{i} ≀ r. About sequence c we know that all its elements are distinct. [Image] Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p_{i} equals to the number of integers which are less than or equal to c_{i} in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively. Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct. -----Input----- The first line contains three integers n, l, r (1 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ 10^9) β€” the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a_1, a_2, ..., a_{n} (l ≀ a_{i} ≀ r) β€” the elements of the sequence a. The next line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≀ p_{i} ≀ n) β€” the compressed sequence of the sequence c. -----Output----- If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers β€” the elements of any suitable sequence b. -----Examples----- Input 5 1 5 1 1 1 1 1 3 1 5 4 2 Output 3 1 5 4 2 Input 4 2 9 3 4 8 9 3 2 1 4 Output 2 2 2 9 Input 6 1 5 1 1 1 1 1 1 2 3 5 4 1 6 Output -1 -----Note----- Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that c_{i} = b_{i} - a_{i}) has compressed sequence equals to p = [3, 2, 1, 4].
import sys N, L, R = list(map(int, input().split())) a = list(map(int, input().split())) b = [0] * N c = list(map(int, input().split())) d = [i for i in range(N)] z = [list(t) for t in zip(c, a, b, d)] z = sorted(z) z[0][2] = L last = z[0][2] - z[0][1] for i in range(1, N): z[i][2] = max(last + 1 + z[i][1], L) if z[i][2] > R: print(-1) return last = z[i][2] - z[i][1] z = sorted(z, key=lambda t: t[3]) _, _, res, _ = list(zip(*z)) print(*res)
IMPORT ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c_{i} = b_{i} - a_{i}. About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≀ a_{i} ≀ r and l ≀ b_{i} ≀ r. About sequence c we know that all its elements are distinct. [Image] Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p_{i} equals to the number of integers which are less than or equal to c_{i} in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively. Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct. -----Input----- The first line contains three integers n, l, r (1 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ 10^9) β€” the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a_1, a_2, ..., a_{n} (l ≀ a_{i} ≀ r) β€” the elements of the sequence a. The next line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≀ p_{i} ≀ n) β€” the compressed sequence of the sequence c. -----Output----- If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers β€” the elements of any suitable sequence b. -----Examples----- Input 5 1 5 1 1 1 1 1 3 1 5 4 2 Output 3 1 5 4 2 Input 4 2 9 3 4 8 9 3 2 1 4 Output 2 2 2 9 Input 6 1 5 1 1 1 1 1 1 2 3 5 4 1 6 Output -1 -----Note----- Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that c_{i} = b_{i} - a_{i}) has compressed sequence equals to p = [3, 2, 1, 4].
n, l, r = map(int, input().split(" ")) a = list(map(int, input().split(" "))) compressed = list(map(int, input().split(" "))) b = [0] * n lastmod = -1 lol = list(zip(compressed, enumerate(a))) for i, (pos, val) in sorted(lol): if i == 1: b[pos] = l lastmod = pos if i > 1: b[pos] = max(b[lastmod] - a[lastmod] + val + 1, l) if b[pos] > r: print("-1") return lastmod = pos for i in b: print(i, end=" ")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c_{i} = b_{i} - a_{i}. About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≀ a_{i} ≀ r and l ≀ b_{i} ≀ r. About sequence c we know that all its elements are distinct. [Image] Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p_{i} equals to the number of integers which are less than or equal to c_{i} in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively. Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct. -----Input----- The first line contains three integers n, l, r (1 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ 10^9) β€” the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a_1, a_2, ..., a_{n} (l ≀ a_{i} ≀ r) β€” the elements of the sequence a. The next line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≀ p_{i} ≀ n) β€” the compressed sequence of the sequence c. -----Output----- If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers β€” the elements of any suitable sequence b. -----Examples----- Input 5 1 5 1 1 1 1 1 3 1 5 4 2 Output 3 1 5 4 2 Input 4 2 9 3 4 8 9 3 2 1 4 Output 2 2 2 9 Input 6 1 5 1 1 1 1 1 1 2 3 5 4 1 6 Output -1 -----Note----- Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that c_{i} = b_{i} - a_{i}) has compressed sequence equals to p = [3, 2, 1, 4].
def binary_search(l, r, k): while l <= r: mid = l + r >> 1 if mid < k: l = mid + 1 else: r = mid - 1 return l def main(): n, l, r = map(int, input().split()) a = list(map(int, input().split())) p = list(map(int, input().split())) x = [(p[i], i + 1, a[i]) for i in range(n)] x.sort() a = [x[i][2] for i in range(n)] p = [x[i][1] for i in range(n)] b = [0] * (n + 1) b[p[0] - 1] = l for i in range(1, n): idx_list = p[i - 1] - 1 b[p[i] - 1] = binary_search(l, r, b[idx_list] - a[i - 1] + a[i]) if b[idx_list] - a[i - 1] == b[p[i] - 1] - a[i]: b[p[i] - 1] += 1 if max(b) > r: print(-1) return for i in range(n): print(b[i], end=" ") main()
FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c_{i} = b_{i} - a_{i}. About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≀ a_{i} ≀ r and l ≀ b_{i} ≀ r. About sequence c we know that all its elements are distinct. [Image] Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p_{i} equals to the number of integers which are less than or equal to c_{i} in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively. Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct. -----Input----- The first line contains three integers n, l, r (1 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ 10^9) β€” the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a_1, a_2, ..., a_{n} (l ≀ a_{i} ≀ r) β€” the elements of the sequence a. The next line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≀ p_{i} ≀ n) β€” the compressed sequence of the sequence c. -----Output----- If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers β€” the elements of any suitable sequence b. -----Examples----- Input 5 1 5 1 1 1 1 1 3 1 5 4 2 Output 3 1 5 4 2 Input 4 2 9 3 4 8 9 3 2 1 4 Output 2 2 2 9 Input 6 1 5 1 1 1 1 1 1 2 3 5 4 1 6 Output -1 -----Note----- Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that c_{i} = b_{i} - a_{i}) has compressed sequence equals to p = [3, 2, 1, 4].
n, l, r = [int(i) for i in input().split()] a = [int(i) for i in input().split()] p = [int(i) for i in input().split()] pos = [] b = [0] * n for i in range(n): pos.append((p[i], i)) pos.sort() b[pos[0][1]] = l c = [0] * n c[pos[0][1]] = l - a[pos[0][1]] cur = c[pos[0][1]] for i in range(1, n): b[pos[i][1]] = cur + 1 + a[pos[i][1]] cur += 1 m = min(b) for i in range(n): b[i] += l - m if max(b) > r: print(-1) exit() print(*b)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c_{i} = b_{i} - a_{i}. About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≀ a_{i} ≀ r and l ≀ b_{i} ≀ r. About sequence c we know that all its elements are distinct. [Image] Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p_{i} equals to the number of integers which are less than or equal to c_{i} in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively. Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct. -----Input----- The first line contains three integers n, l, r (1 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ 10^9) β€” the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a_1, a_2, ..., a_{n} (l ≀ a_{i} ≀ r) β€” the elements of the sequence a. The next line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≀ p_{i} ≀ n) β€” the compressed sequence of the sequence c. -----Output----- If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers β€” the elements of any suitable sequence b. -----Examples----- Input 5 1 5 1 1 1 1 1 3 1 5 4 2 Output 3 1 5 4 2 Input 4 2 9 3 4 8 9 3 2 1 4 Output 2 2 2 9 Input 6 1 5 1 1 1 1 1 1 2 3 5 4 1 6 Output -1 -----Note----- Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that c_{i} = b_{i} - a_{i}) has compressed sequence equals to p = [3, 2, 1, 4].
from sys import stdin, stdout def ri(): return list(map(int, input().split())) n, l, r = ri() a = list(ri()) p = list(ri()) pi = [i for i in range(n)] pi.sort(key=lambda e: p[e]) b = [(0) for i in range(n)] i = pi[0] b[i] = l cp = b[i] - a[i] for ii in range(1, n): i = pi[ii] if a[i] + cp + 1 >= l: b[i] = a[i] + cp + 1 else: b[i] = l cp = b[i] - a[i] if b[i] > r: print(-1) return print(*b)
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c_{i} = b_{i} - a_{i}. About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≀ a_{i} ≀ r and l ≀ b_{i} ≀ r. About sequence c we know that all its elements are distinct. [Image] Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p_{i} equals to the number of integers which are less than or equal to c_{i} in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively. Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct. -----Input----- The first line contains three integers n, l, r (1 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ 10^9) β€” the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a_1, a_2, ..., a_{n} (l ≀ a_{i} ≀ r) β€” the elements of the sequence a. The next line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≀ p_{i} ≀ n) β€” the compressed sequence of the sequence c. -----Output----- If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers β€” the elements of any suitable sequence b. -----Examples----- Input 5 1 5 1 1 1 1 1 3 1 5 4 2 Output 3 1 5 4 2 Input 4 2 9 3 4 8 9 3 2 1 4 Output 2 2 2 9 Input 6 1 5 1 1 1 1 1 1 2 3 5 4 1 6 Output -1 -----Note----- Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that c_{i} = b_{i} - a_{i}) has compressed sequence equals to p = [3, 2, 1, 4].
n, L, R = map(int, input().split()) a = [*map(int, input().split())] p = sorted((e, i) for i, e in enumerate(map(int, input().split()))) prev = -float("inf") res = [0] * n for _, i in p: l = max(a[i] + prev, L - 1) + 1 if l > R: print(-1) exit() res[i] = l prev = l - a[i] print(*res)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c_{i} = b_{i} - a_{i}. About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≀ a_{i} ≀ r and l ≀ b_{i} ≀ r. About sequence c we know that all its elements are distinct. [Image] Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p_{i} equals to the number of integers which are less than or equal to c_{i} in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively. Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct. -----Input----- The first line contains three integers n, l, r (1 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ 10^9) β€” the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a_1, a_2, ..., a_{n} (l ≀ a_{i} ≀ r) β€” the elements of the sequence a. The next line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≀ p_{i} ≀ n) β€” the compressed sequence of the sequence c. -----Output----- If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers β€” the elements of any suitable sequence b. -----Examples----- Input 5 1 5 1 1 1 1 1 3 1 5 4 2 Output 3 1 5 4 2 Input 4 2 9 3 4 8 9 3 2 1 4 Output 2 2 2 9 Input 6 1 5 1 1 1 1 1 1 2 3 5 4 1 6 Output -1 -----Note----- Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that c_{i} = b_{i} - a_{i}) has compressed sequence equals to p = [3, 2, 1, 4].
n, l, f = map(int, input().split()) a = [int(x) for x in input().split()] c = [int(x) for x in input().split()] b = [] for i in range(n): b.append(a[i] + c[i]) m = max(b) if m > f: diff = m - f for i in range(n): b[i] -= diff else: diff = f - m for i in range(n): b[i] += diff if min(b) < l or max(b) > f: print(-1) exit(0) for i in range(n): if i == n - 1: print(b[i]) else: print(b[i], end=" ")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c_{i} = b_{i} - a_{i}. About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≀ a_{i} ≀ r and l ≀ b_{i} ≀ r. About sequence c we know that all its elements are distinct. [Image] Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p_{i} equals to the number of integers which are less than or equal to c_{i} in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively. Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct. -----Input----- The first line contains three integers n, l, r (1 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ 10^9) β€” the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a_1, a_2, ..., a_{n} (l ≀ a_{i} ≀ r) β€” the elements of the sequence a. The next line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≀ p_{i} ≀ n) β€” the compressed sequence of the sequence c. -----Output----- If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers β€” the elements of any suitable sequence b. -----Examples----- Input 5 1 5 1 1 1 1 1 3 1 5 4 2 Output 3 1 5 4 2 Input 4 2 9 3 4 8 9 3 2 1 4 Output 2 2 2 9 Input 6 1 5 1 1 1 1 1 1 2 3 5 4 1 6 Output -1 -----Note----- Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that c_{i} = b_{i} - a_{i}) has compressed sequence equals to p = [3, 2, 1, 4].
import sys n, l, r = map(int, input().split()) a = [int(i) for i in input().split()] p = [int(i) for i in input().split()] pp = [i for i in range(n)] pp.sort(key=lambda x: p[x] * -1) b = [0] * n b[pp[0]] = r c = [pp[0]] * n c[pp[0]] = b[pp[0]] - a[pp[0]] for j in range(1, n): i = pp[j] b[i] = a[i] + c[pp[j - 1]] - 1 if b[i] < l: print(-1) sys.exit(0) if b[i] > r: b[i] = r c[i] = b[i] - a[i] print(" ".join([str(i) for i in b]))
IMPORT ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR BIN_OP LIST VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c_{i} = b_{i} - a_{i}. About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≀ a_{i} ≀ r and l ≀ b_{i} ≀ r. About sequence c we know that all its elements are distinct. [Image] Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p_{i} equals to the number of integers which are less than or equal to c_{i} in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively. Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct. -----Input----- The first line contains three integers n, l, r (1 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ 10^9) β€” the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a_1, a_2, ..., a_{n} (l ≀ a_{i} ≀ r) β€” the elements of the sequence a. The next line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≀ p_{i} ≀ n) β€” the compressed sequence of the sequence c. -----Output----- If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers β€” the elements of any suitable sequence b. -----Examples----- Input 5 1 5 1 1 1 1 1 3 1 5 4 2 Output 3 1 5 4 2 Input 4 2 9 3 4 8 9 3 2 1 4 Output 2 2 2 9 Input 6 1 5 1 1 1 1 1 1 2 3 5 4 1 6 Output -1 -----Note----- Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that c_{i} = b_{i} - a_{i}) has compressed sequence equals to p = [3, 2, 1, 4].
n, l, r = map(int, input().split()) a = map(int, input().split()) p = map(int, input().split()) b = list(map(lambda x: sum(x), zip(a, p))) minb = min(b) maxb = max(b) if maxb - minb > r - l: print(-1) else: print(" ".join(str(i - minb + l) for i in b))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c_{i} = b_{i} - a_{i}. About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≀ a_{i} ≀ r and l ≀ b_{i} ≀ r. About sequence c we know that all its elements are distinct. [Image] Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p_{i} equals to the number of integers which are less than or equal to c_{i} in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively. Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct. -----Input----- The first line contains three integers n, l, r (1 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ 10^9) β€” the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a_1, a_2, ..., a_{n} (l ≀ a_{i} ≀ r) β€” the elements of the sequence a. The next line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≀ p_{i} ≀ n) β€” the compressed sequence of the sequence c. -----Output----- If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers β€” the elements of any suitable sequence b. -----Examples----- Input 5 1 5 1 1 1 1 1 3 1 5 4 2 Output 3 1 5 4 2 Input 4 2 9 3 4 8 9 3 2 1 4 Output 2 2 2 9 Input 6 1 5 1 1 1 1 1 1 2 3 5 4 1 6 Output -1 -----Note----- Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that c_{i} = b_{i} - a_{i}) has compressed sequence equals to p = [3, 2, 1, 4].
R = lambda: map(int, input().split()) n, l, r = R() a, d = list(R()), list(R()) b = [(av + cv) for av, cv in zip(a, d)] mi = min(b) if mi < l: b = [(bv + l - mi) for bv in b] mx = max(b) if mx > r: b = [(bv - (mx - r)) for bv in b] if l <= min(b) <= max(b) <= r: print(" ".join(map(str, b))) else: print(-1)
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c_{i} = b_{i} - a_{i}. About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≀ a_{i} ≀ r and l ≀ b_{i} ≀ r. About sequence c we know that all its elements are distinct. [Image] Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p_{i} equals to the number of integers which are less than or equal to c_{i} in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively. Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct. -----Input----- The first line contains three integers n, l, r (1 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ 10^9) β€” the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a_1, a_2, ..., a_{n} (l ≀ a_{i} ≀ r) β€” the elements of the sequence a. The next line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≀ p_{i} ≀ n) β€” the compressed sequence of the sequence c. -----Output----- If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers β€” the elements of any suitable sequence b. -----Examples----- Input 5 1 5 1 1 1 1 1 3 1 5 4 2 Output 3 1 5 4 2 Input 4 2 9 3 4 8 9 3 2 1 4 Output 2 2 2 9 Input 6 1 5 1 1 1 1 1 1 2 3 5 4 1 6 Output -1 -----Note----- Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that c_{i} = b_{i} - a_{i}) has compressed sequence equals to p = [3, 2, 1, 4].
n, l, r = input().split(" ") n = int(n) l = int(l) r = int(r) at = input().split(" ") pt = input().split(" ") a = [] b = [] p = [] indices = [] for i in range(n): a.append(int(at[i])) p.append(int(pt[i])) b.append(None) indices.append(None) for i in range(n): indices[p[i] - 1] = i flag = True i = 0 while i < n: ind = indices[i] if i == 0: b[ind] = str(l) last = l - a[ind] i += 1 continue exp = last + a[ind] + 1 if exp > r: flag = False break exp = max([l, exp]) last = exp - a[ind] b[ind] = str(exp) i += 1 if flag: print(" ".join(b)) else: print(-1)
ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NONE EXPR FUNC_CALL VAR NONE FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c_{i} = b_{i} - a_{i}. About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≀ a_{i} ≀ r and l ≀ b_{i} ≀ r. About sequence c we know that all its elements are distinct. [Image] Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p_{i} equals to the number of integers which are less than or equal to c_{i} in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively. Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct. -----Input----- The first line contains three integers n, l, r (1 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ 10^9) β€” the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a_1, a_2, ..., a_{n} (l ≀ a_{i} ≀ r) β€” the elements of the sequence a. The next line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≀ p_{i} ≀ n) β€” the compressed sequence of the sequence c. -----Output----- If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers β€” the elements of any suitable sequence b. -----Examples----- Input 5 1 5 1 1 1 1 1 3 1 5 4 2 Output 3 1 5 4 2 Input 4 2 9 3 4 8 9 3 2 1 4 Output 2 2 2 9 Input 6 1 5 1 1 1 1 1 1 2 3 5 4 1 6 Output -1 -----Note----- Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that c_{i} = b_{i} - a_{i}) has compressed sequence equals to p = [3, 2, 1, 4].
n, l, r = map(int, input().split()) a = list(map(int, input().split())) p = list(map(int, input().split())) c = [] for j in range(n): c.append([p[j], j]) c.sort() j = 0 b = [0] * n pre = -float("inf") f = 0 while j < n: i = c[j][1] if l - a[i] >= pre: b[i] = l pre = l - a[i] + 1 else: q = pre + a[i] if q <= r: b[i] = q pre = q - a[i] + 1 else: f = 1 break j += 1 if f == 1: print(-1) else: print(*b)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c_{i} = b_{i} - a_{i}. About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≀ a_{i} ≀ r and l ≀ b_{i} ≀ r. About sequence c we know that all its elements are distinct. [Image] Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p_{i} equals to the number of integers which are less than or equal to c_{i} in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively. Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct. -----Input----- The first line contains three integers n, l, r (1 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ 10^9) β€” the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a_1, a_2, ..., a_{n} (l ≀ a_{i} ≀ r) β€” the elements of the sequence a. The next line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≀ p_{i} ≀ n) β€” the compressed sequence of the sequence c. -----Output----- If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers β€” the elements of any suitable sequence b. -----Examples----- Input 5 1 5 1 1 1 1 1 3 1 5 4 2 Output 3 1 5 4 2 Input 4 2 9 3 4 8 9 3 2 1 4 Output 2 2 2 9 Input 6 1 5 1 1 1 1 1 1 2 3 5 4 1 6 Output -1 -----Note----- Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that c_{i} = b_{i} - a_{i}) has compressed sequence equals to p = [3, 2, 1, 4].
n, l, r = [int(el) for el in input().split()] a = [int(el) for el in input().split()] p = [int(el) for el in input().split()] b = [(a[i] + p[i]) for i in range(n)] mx = max(b) mn = min(b) if mx <= r: print(" ".join([str(el) for el in b])) else: diff = mx - r if mn - diff >= l: print(" ".join([str(el - diff) for el in b])) else: print(-1)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c_{i} = b_{i} - a_{i}. About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≀ a_{i} ≀ r and l ≀ b_{i} ≀ r. About sequence c we know that all its elements are distinct. [Image] Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p_{i} equals to the number of integers which are less than or equal to c_{i} in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively. Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct. -----Input----- The first line contains three integers n, l, r (1 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ 10^9) β€” the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a_1, a_2, ..., a_{n} (l ≀ a_{i} ≀ r) β€” the elements of the sequence a. The next line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≀ p_{i} ≀ n) β€” the compressed sequence of the sequence c. -----Output----- If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers β€” the elements of any suitable sequence b. -----Examples----- Input 5 1 5 1 1 1 1 1 3 1 5 4 2 Output 3 1 5 4 2 Input 4 2 9 3 4 8 9 3 2 1 4 Output 2 2 2 9 Input 6 1 5 1 1 1 1 1 1 2 3 5 4 1 6 Output -1 -----Note----- Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that c_{i} = b_{i} - a_{i}) has compressed sequence equals to p = [3, 2, 1, 4].
n, l, r = map(int, input().split()) a = list(map(int, input().split())) p = list(map(int, input().split())) seg = [0] * n for i in range(n): seg[i] = [l - a[i], r - a[i]] segments = [0] * n for i in range(n): segments[p[i] - 1] = seg[i] c = [0] * n can = True l = -(10**18) for i in range(n): if l >= segments[i][1]: can = False break if segments[i][0] > l: l = segments[i][0] else: l = l + 1 c[i] = l if not can: print(-1) else: for i in range(n): print(c[p[i] - 1] + a[i], end=" ")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR VAR STRING
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c_{i} = b_{i} - a_{i}. About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≀ a_{i} ≀ r and l ≀ b_{i} ≀ r. About sequence c we know that all its elements are distinct. [Image] Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p_{i} equals to the number of integers which are less than or equal to c_{i} in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively. Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct. -----Input----- The first line contains three integers n, l, r (1 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ 10^9) β€” the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a_1, a_2, ..., a_{n} (l ≀ a_{i} ≀ r) β€” the elements of the sequence a. The next line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≀ p_{i} ≀ n) β€” the compressed sequence of the sequence c. -----Output----- If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers β€” the elements of any suitable sequence b. -----Examples----- Input 5 1 5 1 1 1 1 1 3 1 5 4 2 Output 3 1 5 4 2 Input 4 2 9 3 4 8 9 3 2 1 4 Output 2 2 2 9 Input 6 1 5 1 1 1 1 1 1 2 3 5 4 1 6 Output -1 -----Note----- Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that c_{i} = b_{i} - a_{i}) has compressed sequence equals to p = [3, 2, 1, 4].
f = lambda: map(int, input().split()) n, l, r = f() b = [(x + y) for x, y in zip(f(), f())] u, v = l - min(b), r - max(b) print(-1 if u > v else " ".join(str(q + u) for q in b))
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR VAR VAR VAR
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c_{i} = b_{i} - a_{i}. About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≀ a_{i} ≀ r and l ≀ b_{i} ≀ r. About sequence c we know that all its elements are distinct. [Image] Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p_{i} equals to the number of integers which are less than or equal to c_{i} in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively. Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct. -----Input----- The first line contains three integers n, l, r (1 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ 10^9) β€” the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a_1, a_2, ..., a_{n} (l ≀ a_{i} ≀ r) β€” the elements of the sequence a. The next line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≀ p_{i} ≀ n) β€” the compressed sequence of the sequence c. -----Output----- If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers β€” the elements of any suitable sequence b. -----Examples----- Input 5 1 5 1 1 1 1 1 3 1 5 4 2 Output 3 1 5 4 2 Input 4 2 9 3 4 8 9 3 2 1 4 Output 2 2 2 9 Input 6 1 5 1 1 1 1 1 1 2 3 5 4 1 6 Output -1 -----Note----- Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that c_{i} = b_{i} - a_{i}) has compressed sequence equals to p = [3, 2, 1, 4].
n, l, r = map(int, input().split()) a = list(map(int, input().split())) out = [-1] * n p = list(map(int, input().split())) pp = [(p[i], i) for i in range(n)] pp.sort() curr = -(l + r) for v, i in pp: best = curr + 1 + a[i] if best < l: best = l out[i] = best curr = best - a[i] if max(out) > r: print(-1) else: print(" ".join(map(str, out)))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c_{i} = b_{i} - a_{i}. About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≀ a_{i} ≀ r and l ≀ b_{i} ≀ r. About sequence c we know that all its elements are distinct. [Image] Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p_{i} equals to the number of integers which are less than or equal to c_{i} in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively. Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct. -----Input----- The first line contains three integers n, l, r (1 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ 10^9) β€” the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a_1, a_2, ..., a_{n} (l ≀ a_{i} ≀ r) β€” the elements of the sequence a. The next line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≀ p_{i} ≀ n) β€” the compressed sequence of the sequence c. -----Output----- If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers β€” the elements of any suitable sequence b. -----Examples----- Input 5 1 5 1 1 1 1 1 3 1 5 4 2 Output 3 1 5 4 2 Input 4 2 9 3 4 8 9 3 2 1 4 Output 2 2 2 9 Input 6 1 5 1 1 1 1 1 1 2 3 5 4 1 6 Output -1 -----Note----- Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that c_{i} = b_{i} - a_{i}) has compressed sequence equals to p = [3, 2, 1, 4].
n, l, r = list(map(int, input().split())) a = list(map(int, input().split())) p = list(map(int, input().split())) order = dict() for i in range(len(p)): order[p[i]] = i curr = -100000000000 b = [-1] * n for i in range(1, n + 1): if i == 1: b[order[i]] = l curr = b[order[i]] - a[order[i]] continue b[order[i]] = max(l, curr + 1 + a[order[i]]) curr = b[order[i]] - a[order[i]] for i in b: if i > r: print(-1) return print(*b)
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c_{i} = b_{i} - a_{i}. About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≀ a_{i} ≀ r and l ≀ b_{i} ≀ r. About sequence c we know that all its elements are distinct. [Image] Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p_{i} equals to the number of integers which are less than or equal to c_{i} in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively. Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct. -----Input----- The first line contains three integers n, l, r (1 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ 10^9) β€” the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a_1, a_2, ..., a_{n} (l ≀ a_{i} ≀ r) β€” the elements of the sequence a. The next line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≀ p_{i} ≀ n) β€” the compressed sequence of the sequence c. -----Output----- If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers β€” the elements of any suitable sequence b. -----Examples----- Input 5 1 5 1 1 1 1 1 3 1 5 4 2 Output 3 1 5 4 2 Input 4 2 9 3 4 8 9 3 2 1 4 Output 2 2 2 9 Input 6 1 5 1 1 1 1 1 1 2 3 5 4 1 6 Output -1 -----Note----- Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that c_{i} = b_{i} - a_{i}) has compressed sequence equals to p = [3, 2, 1, 4].
from sys import stdin, stdout n, l, r = map(int, stdin.readline().split()) a = list(map(int, stdin.readline().split())) p = list(map(int, stdin.readline().split())) b = p[:] label = 1 diff = max(a) for i in range(n): b[i] += a[i] if min(b) < l: value = min(b) for i in range(n): b[i] += l - value if max(b) > r: value = max(b) for i in range(n): b[i] -= value - r if max(b) <= r and min(b) >= l: stdout.write(" ".join(list(map(str, b))) + "\n") else: stdout.write("-1")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c_{i} = b_{i} - a_{i}. About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≀ a_{i} ≀ r and l ≀ b_{i} ≀ r. About sequence c we know that all its elements are distinct. [Image] Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p_{i} equals to the number of integers which are less than or equal to c_{i} in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively. Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct. -----Input----- The first line contains three integers n, l, r (1 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ 10^9) β€” the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a_1, a_2, ..., a_{n} (l ≀ a_{i} ≀ r) β€” the elements of the sequence a. The next line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≀ p_{i} ≀ n) β€” the compressed sequence of the sequence c. -----Output----- If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers β€” the elements of any suitable sequence b. -----Examples----- Input 5 1 5 1 1 1 1 1 3 1 5 4 2 Output 3 1 5 4 2 Input 4 2 9 3 4 8 9 3 2 1 4 Output 2 2 2 9 Input 6 1 5 1 1 1 1 1 1 2 3 5 4 1 6 Output -1 -----Note----- Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that c_{i} = b_{i} - a_{i}) has compressed sequence equals to p = [3, 2, 1, 4].
n, l, r = map(int, input().split()) a = [int(i) for i in input().split()] p = [int(i) for i in input().split()] b = [(a[i] + p[i]) for i in range(n)] m1 = min(b) m2 = max(b) if r - l + 1 < m2 - m1 + 1: print(-1) exit() if l <= m1 <= m2 <= r: print(*b) exit() if l > m1 and r < m2: print(-1) exit() if l > m1: req = l - m1 b = [(i + req) for i in b] print(*b) exit() if r < m2: sub = m2 - r b = [(i - sub) for i in b] print(*b) exit() print(-1)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c_{i} = b_{i} - a_{i}. About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≀ a_{i} ≀ r and l ≀ b_{i} ≀ r. About sequence c we know that all its elements are distinct. [Image] Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p_{i} equals to the number of integers which are less than or equal to c_{i} in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively. Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct. -----Input----- The first line contains three integers n, l, r (1 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ 10^9) β€” the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a_1, a_2, ..., a_{n} (l ≀ a_{i} ≀ r) β€” the elements of the sequence a. The next line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≀ p_{i} ≀ n) β€” the compressed sequence of the sequence c. -----Output----- If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers β€” the elements of any suitable sequence b. -----Examples----- Input 5 1 5 1 1 1 1 1 3 1 5 4 2 Output 3 1 5 4 2 Input 4 2 9 3 4 8 9 3 2 1 4 Output 2 2 2 9 Input 6 1 5 1 1 1 1 1 1 2 3 5 4 1 6 Output -1 -----Note----- Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that c_{i} = b_{i} - a_{i}) has compressed sequence equals to p = [3, 2, 1, 4].
R = lambda: map(int, input().split()) n, l, r = R() a, d = list(R()), list(R()) b = [l for _ in range(n)] c = [(0) for _ in range(n)] for i in range(n): c[d[i] - 1] = i dif = l - a[c[0]] for x in c[1:]: if b[x] - a[x] <= dif: b[x] = a[x] + dif + 1 dif = b[x] - a[x] if b[x] > r: print("-1") exit() print(" ".join(map(str, b)))
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER FOR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c_{i} = b_{i} - a_{i}. About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≀ a_{i} ≀ r and l ≀ b_{i} ≀ r. About sequence c we know that all its elements are distinct. [Image] Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p_{i} equals to the number of integers which are less than or equal to c_{i} in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively. Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct. -----Input----- The first line contains three integers n, l, r (1 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ 10^9) β€” the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a_1, a_2, ..., a_{n} (l ≀ a_{i} ≀ r) β€” the elements of the sequence a. The next line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≀ p_{i} ≀ n) β€” the compressed sequence of the sequence c. -----Output----- If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers β€” the elements of any suitable sequence b. -----Examples----- Input 5 1 5 1 1 1 1 1 3 1 5 4 2 Output 3 1 5 4 2 Input 4 2 9 3 4 8 9 3 2 1 4 Output 2 2 2 9 Input 6 1 5 1 1 1 1 1 1 2 3 5 4 1 6 Output -1 -----Note----- Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that c_{i} = b_{i} - a_{i}) has compressed sequence equals to p = [3, 2, 1, 4].
n, l, r = map(int, input().split()) read = lambda: map(int, input().split()) a = list(read()) p = list(read()) d = [(a[i], p[i], i) for i in range(n)] d.sort(key=lambda x: x[1]) cur = l - d[0][0] b = [0] * n for i in range(n): ind = d[i][2] b[ind] = a[ind] + cur if b[ind] < l: cur = l - a[ind] b[ind] = l cur += 1 if max(b) > r: print(-1) exit() print(" ".join(map(str, b)))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR 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 VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
import sys input = sys.stdin.readline t = int(input()) for tests in range(t): n, m = map(int, input().split()) A = [list(map(int, input().split())) for i in range(n)] flag = 1 ANS = [] for i in range(n): if flag == 0 or len(ANS) > 0: break B = list(A[i]) C = list(A[i]) for j in range(1, m): C[j] = max(C[j - 1], C[j]) for j in range(m - 1, -1, -1): if B[j] < C[j]: for k in range(m): if B[k] > B[j]: A1 = [k, j] break x, y = A1 B[x], B[y] = B[y], B[x] if sorted(B) == B: ANS.append((x, y)) else: flag = 0 break if flag == 0: print(-1) continue if len(ANS) == 0: print(1, 1) continue x, y = ANS[0] for i in range(n): B = A[i] B[x], B[y] = B[y], B[x] if sorted(B) == B: True else: flag = 0 break if flag == 1: print(x + 1, y + 1) else: print(-1)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR LIST VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
t = int(input()) for _ in range(t): n, m = list(map(int, input().strip().split())) swap_pos = None impossible = False arr = [] for _ in range(n): row = list(map(int, input().strip().split())) sort_row = sorted(row) arr.append(row) pos = [] for i in range(m): if row[i] != sort_row[i]: pos.append(i) if len(pos) > 2: impossible = True elif len(pos) == 2: swap_pos = pos if impossible: print(-1) elif swap_pos is None: print("1 1") else: flag = False for i in range(n): arr[i][swap_pos[0]], arr[i][swap_pos[1]] = ( arr[i][swap_pos[1]], arr[i][swap_pos[0]], ) for j in range(m - 1): if arr[i][j] > arr[i][j + 1]: flag = True print(-1) break if flag: break if not flag: print(f"{swap_pos[0] + 1} {swap_pos[1] + 1}")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER IF VAR NONE EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER STRING BIN_OP VAR NUMBER NUMBER
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
t = int(input()) while t: n, m = map(int, input().split()) a = list() for i in range(n): a.append(list(map(int, input().split()))) x = list() i = 0 while i < n and not len(x): k = list(a[i]) k.sort() for j in range(m): if a[i][j] != k[j]: x.append(j) i += 1 if not len(x): print("1 1") t -= 1 continue elif len(x) != 2: print(-1) t -= 1 continue for i in a: i[x[0]], i[x[1]] = i[x[1]], i[x[0]] ok = True for i in a: j = 0 while j < m - 1: if i[j] > i[j + 1]: ok = False break j += 1 if not ok: break if ok: print(x[0] + 1, x[1] + 1) else: print(-1) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
t = int(input()) result = [] while t > 0: t -= 1 n, m = map(int, input().split()) a = [] b = [] for i in range(n): col1 = list(map(int, input().split())) col2 = col1.copy() col2.sort() a.append(col1) b.append(col2) s = set() for i in range(n): for j in range(m): if a[i][j] != b[i][j]: s.add(j) if len(s) > 2: print(-1) elif len(s) == 0: print(1, 1) else: x = 0 y = 0 for e in s: x = e s.remove(e) break for e in s: y = e s.remove(e) break for i in range(n): temp = a[i][y] a[i][y] = a[i][x] a[i][x] = temp flag = True for i in range(n): for j in range(m): if a[i][j] != b[i][j]: flag = False if flag: print(x + 1, y + 1) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
import sys input = sys.stdin.readline def solve(): N, M = list(map(int, input().split())) X = [] for i in range(M): X.append([]) for i in range(N): K = list(map(int, input().split())) for j in range(M): X[j].append(K[j]) flag = 0 ans = set() Y = X.copy() for i in range(N): if flag: break for j in range(1, M): if X[j - 1][i] > X[j][i]: X.sort(key=lambda x: x[i]) for l in range(M): if X[l][i] != Y[l][i]: ans.add(l + 1) continue for i in range(N): for j in range(1, M): if X[j - 1][i] > X[j][i]: print(-1) return if len(ans) == 0: print(1, 1) elif len(ans) >= 3: print(-1) else: print(*ans) for _ in range(int(input())): solve()
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
for inh in range(int(input())): n, m = map(int, input().split()) a, hehe = [], [] for i in range(n): k = list(map(int, input().split())) a.append(k) b = k.copy() b.sort() hehe.append(b) for i in range(n): k = 0 x, y = -1, -1 for j in range(m): if a[i][j] != hehe[i][j]: k += 1 if x == -1: x = j else: y = j if k > 0: break if x == -1: print(1, 1) elif k > 2: print(-1) else: for i in range(n): a[i][x], a[i][y] = a[i][y], a[i][x] ans = True for i in range(n): for j in range(m): if a[i][j] != hehe[i][j]: ans = False break if not ans: break if ans: print(x + 1, y + 1) else: print(-1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
def dif_col(l): new = l[:] new.sort() distinct = set() for i in range(len(l)): if l[i] != new[i]: distinct.add(i) return distinct def check_changed(l, swap): a, b = swap[0], swap[1] l[a], l[b] = l[b], l[a] for i in range(len(l) - 1): if l[i] > l[i + 1]: return False return True case = int(input()) for _ in range(case): q = input().split() n = int(q[0]) m = int(q[1]) board = [] for row in range(n): new = input().split() board.append([int(elem) for elem in new]) found = None for row in board: if found: break else: to_change = dif_col(row) if len(to_change) == 0: continue elif len(to_change) >= 3: found = 1, 1 break else: found = tuple(to_change) if found: wrong = False for i in range(n): if not check_changed(board[i], found): print(-1) wrong = True break if not wrong: print(found[0] + 1, found[1] + 1) else: print(1, 1)
FUNC_DEF ASSIGN VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NONE FOR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
def solve(arr): bad = [] for i in range(len(arr)): b = list(arr[i]) b.sort() for j in range(len(b)): if arr[i][j] != b[j]: bad.append(j) if len(bad) > 0: break if len(bad) == 0: print(1, 1) elif len(bad) > 2: print(-1) else: for i in range(n): arr[i][bad[0]], arr[i][bad[1]] = arr[i][bad[1]], arr[i][bad[0]] check = False for i in range(n): if arr[i] != sorted(arr[i]): check = True break if check: print(-1) else: print(bad[0] + 1, bad[1] + 1) for i in range(int(input())): n, m = map(int, input().split()) lis = [] for i in range(n): lis.append(list(map(int, input().split()))) solve(lis)
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
def check(grid, u, v): for irow in grid: sirow = list(irow) sirow[u], sirow[v] = sirow[v], sirow[u] for jc in range(1, len(sirow)): if sirow[jc - 1] > sirow[jc]: return False return True def solve(): n, m = map(int, input().split()) grid = [] for i in range(n): row = list(map(int, input().split())) grid.append(row) u, v = -1, -1 for row in grid: sorted_row = sorted(row) for j in range(m): if row[j] == sorted_row[j]: continue if v == -1: v = j elif u == -1: u = j else: v = u = -2 if v == -2: print("-1") return if v == -1: continue if check(grid, u, v): print(v + 1, u + 1) return print("-1") return print("1 1") t = int(input()) for _ in range(t): solve()
FUNC_DEF FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
for i in range(int(input())): n, m = map(int, input().split()) d = [] for j in range(n): A = [int(k) for k in input().split()] d.append(A) flag = 0 ans = [] for j in d: b = j.copy() b.sort() a = [] for h in range(m): if b[h] != j[h]: a.append(h) if len(a) > 2: flag = 1 break elif len(a) == 2: ans.append((a[0], a[1])) break if flag == 1: print(-1) else: f = -1 for r in ans: if r != (-1, -1): f = r break if f == -1: print(1, 1) else: l = f[0] r = f[1] a = 0 for j in range(n): d[j][l], d[j][r] = d[j][r], d[j][l] for j in range(n): for k in range(1, m): if d[j][k] < d[j][k - 1]: a = 1 break if a == 1: break if a == 1: print(-1) else: print(l + 1, r + 1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
t = int(input()) for i in range(t): n, m = map(int, input().split()) lst = [] for j in range(n): lst1 = list(map(int, input().split())) lst.append(lst1) lst1 = [] e = 0 ind = [] v = len(lst[0]) for j in lst: lst3 = j.copy() lst3.sort() a = [] for h in range(v): if lst3[h] != j[h]: a.append(h) if len(a) > 2: e += 1 break elif len(a) == 2: ind.append((a[0], a[1])) break if e > 0: print(-1) else: f = -1 for r in ind: if r != (-1, -1): f = r break if f == -1: print(1, 1) else: l = f[0] r = f[1] for q in lst: q[l], q[r] = q[r], q[l] a = 0 for q in lst: for w in range(1, v): if q[w] < q[w - 1]: a += 1 break if a > 0: break if a == 0: print(l + 1, r + 1) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
t = int(input()) for _ in range(t): n, m = map(int, input().split()) grid = [] for i in range(n): grid.append([int(x) for x in input().split()]) def solve(grid): x, y = -2, -2 for i in range(n): k = 0 for j in range(1, m): if grid[i][j] < grid[i][k]: if x == -2: x = k y = j if grid[i][j] > grid[i][j - 1]: k = j return [x, y] curr = solve(grid) a, b = curr[0], curr[1] def exec(a, b, grid): if a == -1 and b == -1: return [-1] if a == -2 and b == -2: return [1, 1] for i in range(n): grid[i][a], grid[i][b] = grid[i][b], grid[i][a] for j in range(1, m): if grid[i][j] < grid[i][j - 1]: return [-1] return [min(a, b) + 1, max(a, b) + 1] print(*exec(a, b, grid))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN LIST VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN LIST NUMBER IF VAR NUMBER VAR NUMBER RETURN LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN LIST NUMBER RETURN LIST BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
def sortcheck(ar): for i in range(0, len(ar) - 1): if ar[i] > ar[i + 1]: return False return True t = int(input()) for _ in range(t): n, m = map(int, input().split()) l = [] for _ in range(n): tl = list(map(int, input().split())) l.append(tl) u, v, issorted = -1, -1, 1 possible = 1 for i in range(0, n): tl = list(l[i]) tl.sort() inv = [] for p in range(0, m): if tl[p] != l[i][p]: inv.append(p) if len(inv) == 0: continue issorted = 0 if len(inv) > 2: possible = 0 break u, v = inv[0], inv[1] for k in range(0, n): l[k][u], l[k][v] = l[k][v], l[k][u] break fin = possible for x in l: fin &= sortcheck(x) if issorted: print(1, 1) elif fin: print(u + 1, v + 1) else: print(-1)
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR VAR VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
for _ in range(int(input())): n, m = map(int, input().split()) arr = [list(map(int, input().split())) for i in range(n)] swap = set() for row in arr: for i, a, b in zip(list(range(m)), row, sorted(row)): if a != b: swap.add(i + 1) if len(swap) > 2: print(-1) elif len(swap) == 2: swap = list(swap) y = 1 for i in range(n): arr[i][swap[0] - 1], arr[i][swap[1] - 1] = ( arr[i][swap[1] - 1], arr[i][swap[0] - 1], ) if sorted(arr[i]) != arr[i]: y = 0 if y: print(*swap) else: print(-1) else: print(1, 1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FOR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
test_cases = int(input()) def in_order(row): for i in range(1, len(row)): if row[i] < row[i - 1]: return False return True def diff_indices(a, b): indices = [] for i in range(len(a)): if a[i] != b[i]: indices.append(i) return indices for test in range(test_cases): nums = [int(num) for num in input().strip().split()] rows, cols = nums grid = [] for row in range(rows): line = [int(num) for num in input().strip().split()] grid.append(line) row_out_order = -1 for r, row in enumerate(grid): if not in_order(row): row_out_order = r break if row_out_order == -1: print(1, 1) else: sorted_row_out_order = sorted(grid[row_out_order]) diff_cols = diff_indices(grid[row_out_order], sorted_row_out_order) if len(diff_cols) != 2: print(-1) else: col1, col2 = diff_cols all_in_order = True for row in grid: row[col1], row[col2] = row[col2], row[col1] if not in_order(row): all_in_order = False break if all_in_order: print(col1 + 1, col2 + 1) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
def solve(arr): n = len(arr) m = len(arr[0]) sorted_arr = [] for row in arr: sorted_arr.append(sorted(row)) badIdx = [] for i in range(n): for j in range(m): if arr[i][j] != sorted_arr[i][j]: badIdx.append(j) if len(badIdx) >= 2: break if len(badIdx) == 0: print(1, 1) return if len(badIdx) != 2: print(-1) return for i in range(n): arr[i][badIdx[0]], arr[i][badIdx[1]] = arr[i][badIdx[1]], arr[i][badIdx[0]] for i in range(n): for j in range(m): if arr[i][j] != sorted_arr[i][j]: print(-1) return print(badIdx[0] + 1, badIdx[1] + 1) def get_input(): matrix_size = input() n = int(matrix_size.split()[0]) m = int(matrix_size.split()[1]) arr = [] for i in range(n): row = input() arr.append(list(map(int, row.split()))) return arr t = int(input()) for i in range(t): arr = get_input() solve(arr)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER RETURN IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
for case in range(int(input())): n, m = map(int, input().split()) arr = [list(map(int, input().split())) for _ in range(n)] if m == 1: print(1, 1) else: swap = set() not_possible = False for i in range(n): temp = sorted(arr[i]) for j in range(m): if temp[j] != arr[i][j]: swap.add(j) if not_possible: break swap = list(swap) if swap: for row in arr: temp_row = row temp_row[swap[0]], temp_row[swap[1]] = ( temp_row[swap[1]], temp_row[swap[0]], ) if temp_row != sorted(row): not_possible = True break for i in range(n): for j in range(1, m): if arr[i][j - 1] > arr[i][j]: not_possible = True break if not_possible: break if not_possible: print(-1) else: print(" ".join(str(n + 1) for n in swap) if swap else "1 1")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER IF VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR STRING
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
iT = int(input()) for _ in range(iT): answer = "" iN, iM = map(int, input().split()) lst_temp = [[] for _ in range(iN)] for idx in range(iN): lst_temp[idx] = list(map(int, input().split())) row = 0 idx1 = -1 for j in range(1, iM): for i in range(iN): if lst_temp[i][j] < lst_temp[i][j - 1] and idx1 == -1: idx1 = j row = i break if idx1 == -1: answer = "1 1" else: lst_temp_sot = sorted(lst_temp[row]) idx2 = -1 val = 0 for i in range(iM): if lst_temp_sot[i] != lst_temp[row][i]: idx2 = i val = lst_temp_sot[i] break for i in range(iM): if lst_temp[row][i] == val: idx1 = i for idx in range(iN): temp = lst_temp[idx][idx2] lst_temp[idx][idx2] = lst_temp[idx][idx1] lst_temp[idx][idx1] = temp T_F = True for j in range(1, iM): for i in range(iN): if lst_temp[i][j] < lst_temp[i][j - 1]: T_F = False break if T_F: answer = f"{idx2 + 1} {idx1 + 1}" else: answer = "-1" print(answer)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER STRING BIN_OP VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
def ss(g, m, n): l = [[0, 0] for _ in range(m)] for i in range(m): t = sorted(g[i]) c = 0 for j in range(n): if t[j] != g[i][j]: if c == 2: return -1 elif c == 0: c += 1 l[i][0] = j else: c += 1 l[i][1] = j t = [0, 0] for i in l: if i != [0, 0]: t = i break if t == [0, 0]: return t for i in range(m): g[i][t[0]], g[i][t[1]] = g[i][t[1]], g[i][t[0]] for j in range(1, n): if g[i][j] < g[i][j - 1]: return -1 return t for _ in range(int(input())): m, n = map(int, input().split()) g = [] for i in range(m): g.append(list(map(int, input().split()))) ans = ss(g, m, n) if ans == -1: print(-1) else: print(ans[0] + 1, ans[1] + 1)
FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR VAR IF VAR LIST NUMBER NUMBER ASSIGN VAR VAR IF VAR LIST NUMBER NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
for _ in range(int(input())): n, m = map(int, input().split()) a = [] for i in range(n): s = list(map(int, input().split())) a.append(s) res = [] for i in a: res.append(sorted(i)) x, y = -1, -1 ok = True for i in range(n): for j in range(m): if res[i][j] != a[i][j]: if x == -1: x = j elif y == -1: y = j if x >= 0 and y >= 0: break if x >= 0 and y >= 0: break for i in range(n): for j in range(m): if j == y and res[i][j] == a[i][j] and a[i][x] != a[i][y]: ok = False if a[i][j] != res[i][j] and j not in [x, y]: ok = False if not ok: print(-1) elif [x, y] == [-1, -1]: print(1, 1) else: print(x + 1, 1 + y)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR LIST VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER IF LIST VAR VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
t = int(input()) for _ in range(t): n, m = map(int, input().split()) arr = [] for i in range(n): l = list(map(int, input().split())) arr.append(l) flag = True indexs = [] for i in range(n): ol = arr[i].copy() sl = arr[i].copy() sl.sort() ti = [] li = 0 for j in range(m): if ol[j] != sl[j]: ti.append(j) li += 1 if li == 0: continue elif li == 2: indexs.append(tuple(ti)) else: flag = False break if flag: li = len(indexs) if li == 0: print("1 1") else: s = set(indexs) ls = len(s) if ls == 1: l = s.pop() p1, p2 = l[0], l[1] flag1 = True for i in range(n): if arr[i][p1] < arr[i][p2]: flag1 = False break if flag1: print(p1 + 1, p2 + 1) else: print(-1) else: print(-1) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
t = int(input()) for _ in range(t): n, m = map(int, input().split()) arr = [] arr_sorted = [] for i in range(n): arr.append(list(map(int, input().split()))) arr_sorted.append(sorted(arr[i])) for i in range(n): ind = 0 cnt = 0 flag = 0 for j in range(m): if arr[i][j] != arr_sorted[i][j]: if cnt == 0: start = j else: end = j cnt += 1 if cnt == 2: flag = 1 break if flag != 0: break if flag == 0: print(1, 1) else: for i in range(n): arr[i][start], arr[i][end] = arr[i][end], arr[i][start] for i in range(n): for j in range(m): if arr[i][j] != arr_sorted[i][j]: flag = 2 break if flag != 1: break if flag == 1: print(start + 1, end + 1) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
for u in range(int(input())): n, m = [int(x) for x in input().split()] l = [] for i in range(n): l.append([int(x) for x in input().split()]) temp = [] for i in range(n): temp.append(sorted(l[i])) for i in range(n): if l[i] != temp[i]: break q = [] for y in range(m): if l[i][y] != temp[i][y]: q.append(y) if len(q) > 2: print(-1) elif len(q) == 0: print(1, 1) else: for i in range(n): l[i][q[0]], l[i][q[1]] = l[i][q[1]], l[i][q[0]] flag = 0 for i in range(n): if l[i] != temp[i]: flag = 1 break if flag == 1: print(-1) else: print(q[0] + 1, q[1] + 1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
T = int(input()) for _ in range(T): N, M = map(int, input().split()) A = [[int(c) for c in input().split()] for _ in range(N)] swappos = [] for i in range(N): B = sorted(A[i]) for j in range(M): if B[j] != A[i][j]: swappos.append(j) if len(swappos) > 0: break if len(swappos) == 0: print("1 1") continue if len(swappos) > 2: print(-1) continue good = True for i in range(N): A[i][swappos[0]], A[i][swappos[1]] = A[i][swappos[1]], A[i][swappos[0]] for j in range(M - 1): if A[i][j] > A[i][j + 1]: good = False break if not good: break if good: print(f"{swappos[0] + 1} {swappos[1] + 1}") else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER STRING BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
t = int(input()) for _ in range(t): n, m = map(int, input().split()) rows = [list(map(int, input().split())) for i in range(n)] guess = None for r in range(n): row = rows[r] fixed = sorted(row) indexes = [i for i in range(m) if fixed[i] != row[i]] if len(indexes) > 2: break if len(indexes) == 2: if guess is None: guess = indexes elif guess != indexes: break else: if guess is None: print("1 1") continue else: for r in range(n): row = rows[r] if row[guess[0]] < row[guess[1]]: break else: print(guess[0] + 1, guess[1] + 1) continue print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR NONE ASSIGN VAR VAR IF VAR VAR IF VAR NONE EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
R = lambda: [*map(int, input().split())] for _ in [0] * R()[0]: n, m = R() a = [R() for _ in [0] * n] (*b,) = map(sorted, a) i = j = 0 for t in zip(a, b): i, j, *_ = [i for i, x, y in zip(range(m), *t) if x ^ y] or (i, j) for r in a: r[i], r[j] = r[j], r[i] print(*((i + 1, j + 1), [-1])[a > b])
ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR BIN_OP LIST NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER LIST NUMBER VAR VAR
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
T = int(input()) while T: T -= 1 n, m = map(int, input().split()) ex = [] a = [[0]] * n for i in range(n): a[i] = list(map(int, input().split())) for row in a: rc = row.copy() rc.sort() for i in range(m): if row[i] != rc[i]: ex.append(i) if len(ex): break if len(ex) == 0: print(1, 1) elif len(ex) == 2: c1, c2 = ex flag = True for row in a: row[c1], row[c2] = row[c2], row[c1] for i in range(1, m): if row[i] < row[i - 1]: flag = False break if not flag: break if flag: print(c1 + 1, c2 + 1) else: print(-1) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
T = int(input()) for case in range(T): n, m = map(int, input().split()) g = [tuple(map(int, input().split())) for r in range(n)] g = tuple(zip(*g)) r = tuple(sorted(g)) for i in range(1, m): for j in range(n): if r[i][j] < r[i - 1][j]: break else: continue print(-1) break else: d = [] for i in range(m): if g[i] != r[i]: d.append(i) if len(d) == 0: print(1, 1) elif len(d) == 2: print(d[0] + 1, d[1] + 1) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
for _ in range(int(input())): n, m = map(int, input().split()) l = [] w = 0 p, o = -1, -1 for i in range(n): t = list(map(int, input().split())) u = t.copy() u.sort() if t == u: w += 1 l.append(t) if w == n: print(1, 1) else: for i in range(len(l)): k = l[i] u = k.copy() u.sort() for i in range(len(k)): if u[i] != k[i]: if p == -1: p = i elif o == -1: o = i else: continue t = 0 for i in range(len(l)): k = l[i] u = k.copy() k.sort() u[p], u[o] = u[o], u[p] if u == k: continue else: t += 1 break if t > 0: print(-1) else: print(p + 1, o + 1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
cases = int(input()) for i in range(cases): good = True r, c = map(int, input().split()) gaps = [] mat = [] for j in range(r): row = list(map(int, input().split())) mat.append(row) for j in range(r): gaps = [] row = mat[j] sortedRow = sorted(row) for k in range(c): if row[k] != sortedRow[k]: gaps.append(k) if gaps: break if gaps: if len(gaps) != 2: print(-1) else: a, b = gaps for j in range(r): mat[j][a], mat[j][b] = mat[j][b], mat[j][a] for k in range(c - 1): if mat[j][k] > mat[j][k + 1]: good = False if good: print(a + 1, b + 1) else: print(-1) else: print(1, 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR IF VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
t = int(input()) while t != 0: r, c = list(map(int, input().split(" "))) arr = [] for i in range(r): r1 = list(map(int, input().split(" "))) arr.append(r1) bad = [] for i in range(0, r): if bad: break k = arr[i].copy() k.sort() for j in range(0, c): if arr[i][j] != k[j]: bad.append(j) flag = False if len(bad) == 0: print(1, 1) t -= 1 continue elif len(bad) > 2: print(-1) t -= 1 continue else: for i in range(0, r): arr[i][bad[0]], arr[i][bad[1]] = arr[i][bad[1]], arr[i][bad[0]] for i in range(0, r): for j in range(0, c - 1): if arr[i][j] > arr[i][j + 1]: print(-1) flag = True break if flag: break if not flag: print(bad[0] + 1, bad[1] + 1) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
t = int(input()) for i in range(t): a, b = input().split() n, m = int(a), int(b) c = [[] * m] * n e = [] flag = 0 ans = 0 tot = 0 for j in range(n): c[j] = input().split() for k in range(m): c[j][k] = int(c[j][k]) for j in range(n): if c[j] == sorted(c[j]): ans += 1 else: tot = j if ans == n: print("1 1") continue d = sorted(c[tot]) for j in range(m): if c[tot][j] != d[j]: e.append(j) if len(e) > 2: print("-1") continue for j in range(n): temp = c[j][e[0]] c[j][e[0]] = c[j][e[1]] c[j][e[1]] = temp if c[j] != sorted(c[j]): print("-1") flag = 1 break if flag == 0: print(e[0] + 1, e[1] + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST BIN_OP LIST VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR IF VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
for i in range(int(input())): n, m = list(map(int, input().split())) a = [0] * n b = [0] * n x = 0 y = 0 count = 0 for i in range(n): a[i] = list(map(int, input().split())) b[i] = a[i] b[i] = sorted(b[i]) for i in range(n): for j in range(m): if a[i][j] != b[i][j]: count += 1 if count == 1: x = j elif count == 2: y = j if count >= 2: break if count == 0: print(1, 1) else: for i in range(n): temp = a[i][x] a[i][x] = a[i][y] a[i][y] = temp if a == b: print(x + 1, y + 1) else: print(-1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
T = int(input()) for _ in range(T): n, m = map(int, input().split()) matrix = [None] * n for i in range(n): matrix[i] = list(map(int, input().split())) swap1 = -1 swap2 = -1 found = False for i in range(n): for j in range(m - 1): if matrix[i][j] > matrix[i][j + 1]: swap1 = j cur = int(matrix[i][j]) while swap1 >= 0 and matrix[i][swap1] == cur: swap1 -= 1 swap1 += 1 for k in range(j + 1, m - 1): if matrix[i][k] > matrix[i][k + 1]: swap2 = k + 1 break if swap2 == -1: for k in range(j + 1, m - 1): if matrix[i][k] < matrix[i][k + 1]: swap2 = k break if swap2 == -1: swap2 = m - 1 found = True break if found: break if not found: print("1 1") else: ans = True for i in range(n): temp = matrix[i][swap1] matrix[i][swap1] = matrix[i][swap2] matrix[i][swap2] = temp for i in range(n): for j in range(m - 1): if matrix[i][j] > matrix[i][j + 1]: ans = False break if not ans: break if not ans: print(-1) else: print(str(swap1 + 1) + " " + str(swap2 + 1))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR WHILE VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
class Solve: def __init__(self): self.n, self.m = map(int, input().strip().split()) self.table = [list(map(int, input().strip().split())) for _ in range(self.n)] def check_table(self): for i in range(self.n): for j in range(1, self.m): if self.table[i][j] < self.table[i][j - 1]: return i return None def solve(self): row = self.check_table() si = None sj = None if row is not None: sorted_row = sorted(self.table[row]) for i in range(self.m): if sorted_row[i] != self.table[row][i]: if si is None: si = i else: sj = i if si is None: si = sj = 0 for i in range(self.n): self.table[i][si], self.table[i][sj] = self.table[i][sj], self.table[i][si] if self.check_table() is not None: print(-1) else: print(si + 1, sj + 1) def main(): t = int(input().strip()) for i in range(t): Solve().solve() main()
CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR RETURN NONE FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR NONE IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR IF VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NONE ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR NONE EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
import sys input = sys.stdin.readline ints = lambda: list(map(int, input().split())) t = ints()[-1] for _ in range(t): n, m = ints() grid = [ints() for _ in range(n)] problem = set() for row in grid: temp = row[:] temp.sort() for i in range(m): if temp[i] != row[i]: problem.add(i) problem = list(problem) if len(problem) == 0: print(1, 1) elif len(problem) > 2: print(-1) else: is_possible = True for i in range(n): grid[i][problem[0]], grid[i][problem[1]] = ( grid[i][problem[1]], grid[i][problem[0]], ) for j in range(1, m): if grid[i][j] < grid[i][j - 1]: is_possible = False if not is_possible: print(-1) else: print(problem[0] + 1, problem[1] + 1)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
t = int(input()) while t > 0: t -= 1 n, m = map(int, input().split()) a = [] b = [] swap = [0] * m for i in range(n): a += [list(map(int, input().split()))] b += [sorted(a[i])] idx = -1 jdx = -1 k = 0 for i in range(n): for j in range(m): if a[i][j] != b[i][j]: if swap[j] != 1: k += 1 swap[j] = 1 if k == 0: print(1, 1) elif k == 2: idx = 0 while swap[idx] != 1: idx += 1 jdx = m - 1 while swap[jdx] != 1: jdx -= 1 ans = 0 for i in range(n): if a[i][idx] != b[i][jdx]: ans = -1 if ans == -1: print(ans) else: print(*sorted([idx + 1, jdx + 1])) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR LIST FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR LIST FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$. You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β€” the number of rows and columns respectively. Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) β€” the number written in the $j$-th cell of the $i$-th row. It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- If after the swap it is impossible to get a good grid, output $-1$. In the other case output $2$ integers β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. -----Examples----- Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Output 1 1 -1 1 2 1 3 1 1 -----Note----- In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
import sys input = sys.stdin.readline for _ in range(int(input())): n, m = list(map(int, input().split())) arr = [] for i in range(n): a = list(map(int, input().split())) arr.append(a) a = [] for i in range(n): b = sorted(arr[i]) for j in range(m): if arr[i][j] != b[j]: a.append(j) if a: break if len(a) > 2: print(-1) elif len(a) == 0: print(1, 1) else: for i in range(n): arr[i][a[0]], arr[i][a[1]] = arr[i][a[1]], arr[i][a[0]] found = False for i in range(n): for j in range(1, m): if arr[i][j] < arr[i][j - 1]: print(-1) found = True break if found: break else: a = [a[0] + 1, a[1] + 1] print(*a, sep=" ")
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR LIST BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING