import sys
input = sys.stdin.readline
def solve():
n, = map(int, input().split())
c = list(map(int, input().split()))
cc = [c[0]]
for i in range(1, len(c)):
cc.append(cc[i-1] + c[i])
items = []
m = {}
def get_xy(i):
for j in range(n):
if i < cc[j]:
if i < cc[0]:
prev = 0
else:
prev = cc[j - 1]
return [j+1, i - prev + 1]
for i in range(n):
line = list(map(int, input().split()))
for j in range(len(line)):
items.append(line[j])
m[line[j]] = len(items) - 1
sorted_items = sorted(items)
r = []
for i in range(len(items)):
if items[i] != sorted_items[i]:
r.append([*get_xy(i), *get_xy(m[sorted_items[i]])])
items[i], items[m[sorted_items[i]]] = items[m[sorted_items[i]]], items[i]
m[items[m[sorted_items[i]]]] = m[items[i]]
print(len(r))
for i in r:
print(*i)
solve()
Count of integers | Differences of the permutations |
Doctor's Secret | Back to School |
I am Easy | Teddy and Tweety |
Partitioning binary strings | Special sets |
Smallest chosen word | Going to office |
Color the boxes | Missing numbers |
Maximum sum | 13 Reasons Why |
Friend's Relationship | Health of a person |
Divisibility | A. Movement |
Numbers in a matrix | Sequences |
Split houses | Divisible |
Three primes | Coprimes |
Cost of balloons | One String No Trouble |
Help Jarvis! | Lift queries |
Goki and his breakup | Ali and Helping innocent people |