Mandarin chinese
, Russian and Vietnamese as well.
Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$).
The difficulty of a problem can be calculated as follows:
- Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and the number of contestants who solved it by $NS_k$.
- Consider the subtasks sorted in the order of increasing score.
- Calculate the number $n$ of valid indices $k$ such that $NS_k > NS_{k + 1}$.
- For problem $i$, the difficulty is a pair of integers $(n, i)$.
You should sort the problems in the increasing order of difficulty levels. Since difficulty level is a pair, problem $a$ is more difficult than problem $b$ if the number $n$ is greater for problem $a$ than for problem $b$, or if $a > b$ and $n$ is the same for problems $a$ and $b$.

-----Input-----
- The first line of the input contains two space-separated integers $P$ and $S$ denoting the number of problems and the number of subtasks in each problem.
- $2P$ lines follow. For each valid $i$, the $2i-1$-th of these lines contains $S$ space-separated integers $SC_1, SC_2, \dots, SC_S$ denoting the scores of the $i$-th problem's subtasks, and the $2i$-th of these lines contains $S$ space-separated integers $NS_1, NS_2, \dots, NS_S$ denoting the number of contestants who solved the $i$-th problem's subtasks.

-----Output-----
Print $P$ lines containing one integer each — the indices of the problems in the increasing order of difficulty.

-----Constraints-----
- $1 \le P \le 100,000$
- $2 \le S \le 30$
- $1 \le SC_i \le 100$ for each valid $i$
- $1 \le NS_i \le 1,000$ for each valid $i$
- in each problem, the scores of all subtasks are unique

-----Subtasks-----
Subtask #1 (25 points): $S = 2$
Subtask #2 (75 points): original constraints

-----Example Input-----
3 3
16 24 60
498 861 589
14 24 62
72 557 819
16 15 69
435 779 232

-----Example Output-----
2
1
3

Starter code:

Solutions:
p,s = [int(i) for i in input().split()]
scores = {}

for j in range(1, p + 1):
 sc = [int(i) for i in input().split()]
 ns = [int(i) for i in input().split()]
 nsc = dict(list(zip(sc,ns)))
 ssc = sorted(sc)
 score = 0
 for a,b in zip(ssc[:-1], ssc[1:]):
  if nsc[a] > nsc[b]:
   score += 1
 if score in list(scores.keys()) :
  scores[score].append(j)
 else :
  scores[score] = [j]

total_scores = sorted(list(scores.keys()))
final_list = []
for val in total_scores :
 final_list += sorted(scores[val])

for val in final_list :
 print(val)


p,s = [int(i) for i in input().split()]
scores = {}

for j in range(1, p + 1):
 sc = [int(i) for i in input().split()]
 ns = [int(i) for i in input().split()]
 nsc = dict(list(zip(sc,ns)))
 ssc = sorted(sc)
 score = 0
 for a,b in zip(ssc[:-1], ssc[1:]):
  if nsc[a] > nsc[b]:
   score += 1
 if score in list(scores.keys()) :
  scores[score].append(j)
 else :
  scores[score] = [j]

total_scores = sorted(list(scores.keys()))
final_list = []
for val in total_scores :
 final_list += sorted(scores[val])

for val in final_list :
 print(val)


# cook your dish here
p,s = [int(i) for i in input().split()]
scores = {}

for j in range(1, p + 1):
 sc = [int(i) for i in input().split()]
 ns = [int(i) for i in input().split()]
 nsc = dict(zip(sc,ns))
 ssc = sorted(sc)
 score = 0
 for a,b in zip(ssc[:-1], ssc[1:]):
  if nsc[a] > nsc[b]:
   score += 1
 if score in scores.keys() :
  scores[score].append(j)
 else :
  scores[score] = [j]

total_scores = sorted(list(scores.keys()))
final_list = []
for val in total_scores :
 final_list += sorted(scores[val])

for val in final_list :
 print(val)

# cook your dish here

p , s = list(map(int,input().split()))

nvalues = []

for i in range(p) :
 
 difficult = [0,0]
 
 n = 0
 
 sc = list(map(int,input().split()))
 
 
 ns = list(map(int,input().split()))
 
 a = list(zip(sc,ns))
 
 a.sort()
 
 for j in range(s-1) :
  
  if(a[j][1] > a[j+1][1]) :
   
   n = n + 1 
   
 difficult[0] = n 
 
 difficult[1] = i 
 
 nvalues.append(difficult)
 
nvalues.sort(key = lambda x: x[0])
 
for j in range(p) :
 
 print(nvalues[j][1] + 1)


 
 
   
 
 


# cook your dish here
p,s=[int(i) for i in input().split()]
l=[]
for j in range(p):
 l1=[int(i) for i in input().split()]
 l2=[int(i) for i in input().split()]
 l3=[[l1[i],l2[i]] for i in range(s)]
 l3.sort()
 count=0
 for i in range(s-1):
  if(l3[i][1]>l3[i+1][1]):
   count+=1 
 l.append([count,j+1])
l.sort()
for i in l:
 print(i[1])
 


from collections import defaultdict
x,y=list(map(int,input().split()))
m=[]
p=defaultdict(list)
for __ in range(x):
 a=list(map(int,input().split()))
 b=list(map(int,input().split()))
 c=defaultdict()
 for i in range(y):
  c[a[i]]=b[i]
 a.sort()
 d=[]
 for i in range(y):
  d.append(c[a[i]])
 n=0
 for i in range(1,y):
  if d[i]<d[i-1]:
   n+=1
 m.append(n)
 p[n].append(__ + 1)
m.sort()
m=list(set(m))
for i in m:
 if len(p[i])>1:
  p[i].sort()
  for j in p[i]:
   print(j)
 else:    
  print(*p[i])


p,s = map(int,input().split())
l = []
for i in range(p):
 ns = list(map(int,input().split()))
 n = list(map(int,input().split()))
 a = list(zip(ns,n))
 a.sort()
 count = 0
 for j in range(len(a) - 1):
  if(a[j][1] > a[j + 1][1]):
   count += 1
 l.append((i,count))
l.sort(key=lambda x:x[1])
for i in range(p):
 print(l[i][0] + 1)

from collections import defaultdict
from operator import itemgetter

p, s = list(map(int, input().split()))

diff = []
for _ in range(p):
 sc = list(map(int, input().split()))
 nk = list(map(int, input().split()))

 arr = list(zip(sc, nk))

 arr_sort = sorted(arr, key = itemgetter(0))
 # print(arr)
 temp = 0
 for i in range(s-1):
  if arr_sort[i][1] > arr_sort[i+1][1]:
   temp += 1
 a = (temp, _+1)
 diff.append(a)

temp = diff[:]
temp.sort(key=lambda x: x[0])


for i in temp:
 print(i[1])


from collections import defaultdict
from operator import itemgetter

p, s = map(int, input().split())

diff = []
for _ in range(p):
 sc = list(map(int, input().split()))
 nk = list(map(int, input().split()))

 arr_sort = list(zip(sc, nk))

 arr_sort.sort(key=lambda x: x[0])
 
 temp = 0
 for i in range(s-1):
  if arr_sort[i][1] > arr_sort[i+1][1]:
   temp += 1
 a = [temp, _+1]
 diff.append(a)

diff = sorted(diff, key = lambda x: x[0])

for i in diff:
 print(i[1])

from collections import defaultdict
from operator import itemgetter

p, s = map(int, input().split())

diff = []
for _ in range(p):
 sc = list(map(int, input().split()))
 nk = list(map(int, input().split()))

 arr = list(zip(sc, nk))

 arr_sort = sorted(arr, key = lambda x: x[0])
 
 temp = 0
 for i in range(s-1):
  if arr_sort[i][1] > arr_sort[i+1][1]:
   temp += 1
 a = [temp, _+1]
 diff.append(a)
temp = diff[:]

# temp = [(1, 2),(1, 1),(2, 1),(2, 3)]
temp.sort(key=lambda x: (x[0], x[1]))

diff = sorted(diff, key = lambda x: x[0])

for i in diff:
 print(i[1])

from collections import defaultdict
from operator import itemgetter

p, s = list(map(int, input().split()))

diff = []
for _ in range(p):
 sc = list(map(int, input().split()))
 nk = list(map(int, input().split()))

 arr = list(zip(sc, nk))

 arr_sort = sorted(arr, key = itemgetter(0))
 # print(arr)
 temp = 0
 for i in range(s-1):
  if arr_sort[i][1] > arr_sort[i+1][1]:
   temp += 1
 a = [temp, _+1]
 diff.append(a)
temp = diff[:]

# temp = [(1, 2),(1, 1),(2, 1),(2, 3)]
temp.sort(key=lambda x: (x[0], x[1]))

# print(temp)
'''
t = 1
d = defaultdict
for i in temp:
    d[i] = t
    t += 1
'''
diff = sorted(diff, key = lambda x: x[0])

for i in diff:
 print(i[1])
'''
v1=sorted(diff,key = itemgetter(0))
for i in v1:
    print(i[1])
    '''


from collections import defaultdict
from operator import itemgetter

p, s = map(int, input().split())

diff = []
for _ in range(p):
 sc = list(map(int, input().split()))
 nk = list(map(int, input().split()))

 arr = zip(sc, nk)

 arr_sort = sorted(arr, key = itemgetter(0))
 # print(arr)
 temp = 0
 for i in range(s-1):
  if arr_sort[i][1] > arr_sort[i+1][1]:
   temp += 1
 a = [temp, _+1]
 diff.append(a)
'''
temp = diff[:]

# temp = [(1, 2),(1, 1),(2, 1),(2, 3)]
temp.sort(key=lambda x: (x[0], x[1]))

# print(temp)

t = 1
d = defaultdict(int)
for i in temp:
    d[i] = t
    t += 1

for i in diff:
    print(d[i])
'''
v1=sorted(diff,key = itemgetter(0))
for i in v1:
 print(i[1])

import copy

def compute_problem_difficulty(problem,S):

 difficulty=0

 for i in range(S-1):

  if problem[i][1]>problem[i+1][1]:
   difficulty+=1
 
 return difficulty


P,S=list(map(int,input().split()))
problem_difficulty=[[] for _ in range(30)]
i=0

while i<P:
 subtasks_scores=list(map(int,input().split()))
 subtasks_num_of_contestants=list(map(int,input().split()))
 problem=[]

 for j in range(S):
  problem.append([subtasks_scores[j],subtasks_num_of_contestants[j]])
 
 problem.sort()
 difficulty=compute_problem_difficulty(problem,S)
 problem_difficulty[difficulty].append(i+1)
 i+=1

for i in range(30):

 j=0
 while j<len(problem_difficulty[i]):
  print(problem_difficulty[i][j])
  j+=1

from collections import *
P,S=input().split()
P=int(P)
S=int(S)
list_of_dictionaries=[]
for _ in range(P):
 scores=input().split()
 number_of_contestants=input().split()
 scores=map(int,scores)
 number_of_contestants=map(int,number_of_contestants)
 dictionary=dict(zip(scores,number_of_contestants))
 dictionary = OrderedDict(sorted(dictionary.items()))
 list_of_dictionaries.append(dictionary)
list_of_difficulty_tuples=[]
for alpha in range(P):
 current_dictionary = list_of_dictionaries[alpha]
 old=-1
 n=0
 for v in current_dictionary.values():
  if(old==-1):
   old=v
  else:
   if(v<old):
    n=n+1
    old=v
   else:
    old=v
 list_of_difficulty_tuples.append((n,alpha+1))
list_of_difficulty_tuples = (sorted(list_of_difficulty_tuples))
for result in range(len(list_of_difficulty_tuples)):
 print(list_of_difficulty_tuples[result][1])

'''stdin=open('input.txt')
def input():
    return stdin.readline()[:-1]
'''
p,s=input().split()
p=int(p)
s=int(s)
n=[0 for i in range(p)]
for prob in range(p):
 points=list(map(int,input().split()))
 nop=list(map(int,input().split()))
 for i in range(s):
  nop[i]=[points[i],nop[i]]
 nop.sort()
 for i in range(s-1):
  if nop[i][1]>nop[i+1][1]:
   n[prob]+=1
 #print(nop)
#print(n)
for i in range(p):
 n[i]=[n[i],i]
n.sort()

for i in range(p):
 print(n[i][1]+1)


'''stdin=open('input.txt')
def input():
    return stdin.readline()[:-1]

'''
p,s=input().split()
p=int(p)
s=int(s)
n=[0 for i in range(p)]
for prob in range(p):
 points=list(map(int,input().split()))
 nop=list(map(int,input().split()))
 for i in range(s):
  nop[i]=[points[i],nop[i]]
 nop.sort()
 for i in range(s):
  nop[i]=nop[i][1]
 sorted_nop=sorted(nop)
 n[prob]=0
 for i in range(s):
  ind=sorted_nop.index(nop[i])
  n[prob]+=ind
  sorted_nop.pop(ind)

for i in range(p):
 n[i]=[n[i],i]
n.sort()

for i in range(p):
 print(n[i][1]+1)


 #!/usr/bin/env python
"""Python Version:3.7.1"""
#start
P, S = list(map(int, input().split()))
COUNT = [0] * 101010
A = []
B = []
for i in range(P):
 A = list(map(int, input().split()))
 B = list(map(int, input().split()))
 A, B = list(zip(*sorted(zip(A, B))))
 for X in range(S-1):
  if B[X] > B[X+1]:
   COUNT[i] += 1
for i in range(31):
 for j in range(P):
  if COUNT[j] == i:
   print(j+1)
#end


 #!/usr/bin/env python
"""Python Version:3.7.1"""
#start
P, S = list(map(int, input().split()))
COUNT = [0] * 101010
A = []
B = []
for i in range(P):
 A = list(map(int, input().split()))
 B = list(map(int, input().split()))
 A, B = list(zip(*sorted(zip(A, B))))
 for X in range(len(B)-1):
  if B[X] > B[X+1]:
   COUNT[i] += 1
for i in range(31):
 for j in range(P):
  if COUNT[j] == i:
   print(j+1)
#end


p,s=list(map(int,input().split()))
count=[0]*101010
a=[]
b=[]
for i in range(p):
 a=list(map(int,input().split()))
 b=list(map(int,input().split()))
 a,b=list(zip(*sorted(zip(a,b))))
 for x in range(len(b)-1):
  if(b[x]>b[x+1]):
   count[i]+=1
for i in range(31):
 for j in range(p):
  if(count[j]==i):
   print(j+1)


p, s = list(map(int, input().split()))
sub = []
pro = []
t = []
for i in range(p):
 sub.append(list(map(int, input().split())))
 pro.append(list(map(int, input().split())))
for i in range(p):
 t.append(list(zip(sub[i], pro[i])))
indices = []

for a in t:
 a.sort(key = lambda x: x[0])
 m = 0
 n = 0
 while m != s-1:
  if a[m][1] > a[m+1][1]:
   n += 1
  m += 1
 indices.append(n) 

pb = [i+1 for i in range(p)]
sol = list(zip(indices, pb))
sol.sort()
for a in sol:
 print(a[1])











P,S = list(map(int, input().split()))
ans = []
for index in range(P):
 SC = list(map(int, input().split()))
 NS = list(map(int, input().split()))
 mlist = []
 for i in zip(SC, NS):
  mlist.append(i)
 mlist = sorted(mlist, key = lambda z : (z[0], z[1]), reverse = False)
 
 counter = 0
 for i in range(1, len(mlist)):
  if mlist[i-1][1] > mlist[i][1]:
   counter += 1
 ans.append((counter, index + 1))

ans = sorted(ans, key = lambda v: v[0], reverse = False)
for i in ans:
 print(i[1])


p1,n1=list(map(int,input().split(" ")))
x1=list()
j="0"
for i in range(p1):
 a1=list(map(int,input().split(" ")))
 b1=list(map(int,input().split(" "))) 
 c=list()
 cx=0
 al=len(a1)
 for z in range(al):
  c.append((a1[z],b1[z]))
 c=sorted(c,key=lambda x:x[0])
 ab=len(c)
 for z in range(ab-1):
  if(c[z+1][1]<c[z][1]):
   cx=cx+1
 x1.append((i,cx)) 
x1=sorted(x1,key=lambda x:x[1])
for i in range(len(x1)):
 print(x1[i][0] + 1)

p,s=map(int,input().split())
diff=list()
for i in range(s):
 diff.append([])
for i in range(p):
 n=0
 c=list(map(int,input().split()))
 sc=list(map(int,input().split()))
 dictionary=dict(zip(c,sc))
 c.sort()
 for j in range(s-1):
  if dictionary[c[j]]>dictionary[c[j+1]]:
   n+=1
 diff[n].append(i+1)
for i in range(s):
 for j in range(len(diff[i])):
  print(diff[i][j])

p1,n1=list(map(int,input().split(" ")))
x1=list()
j="0"
for i in range(p1):
 a1=list(map(int,input().split(" ")))
 b1=list(map(int,input().split(" "))) 
 c=list()
 cx=0
 al=len(a1)
 for z in range(al):
  c.append((a1[z],b1[z]))
 c=sorted(c,key=lambda x:x[0])
 ab=len(c)
 for z in range(ab-1):
  if(c[z+1][1]<c[z][1]):
   cx=cx+1
 x1.append((i,cx)) 
x1=sorted(x1,key=lambda x:x[1])
for i in range(len(x1)):
 print(x1[i][0] + 1)

P,S=list(map(int,(input().split(" "))))
d=[]
for p in range (0,P):
 ST=list(map (int,input().split (" ")))
 N=list(map(int,input().split(" ")))
 c=0
 L=sorted(list(zip(ST, N)))
 for i in range (0,S-1):
  if(L[i][1]>L[i+1][1]):
   c=c+1
 dd=()
 dd=(c,p+1)
 d.append(dd)
d=sorted(d)
for i in range(0,P):
 print(d[i][1])