Problem:

Lexicographical Comparison

 

  Compare given two sequence $A = \{a_0, a_1, ..., a_{n-1}\}$ and $B = \{b_0, b_1, ..., b_{m-1}$ lexicographically.

Input

  The input is given in the following format.

$n$
$a_0 \; a_1, ..., \; a_{n-1}$
$m$
$b_0 \; b_1, ..., \; b_{m-1}$

  The number of elements in $A$ and its elements $a_i$ are given in the first and second lines respectively.
  The number of elements in $B$ and its elements $b_i$ are given in the third and fourth lines respectively. All input are given in integers.

Output

  Print 1 $B$ is greater than $A$, otherwise 0.

Constraints

  
$1 \leq n, m \leq 1,000$

  
$0 \leq a_i, b_i \leq 1,000$

Sample Input 1

3
1 2 3
2
2 4

Sample Output 1

1

Sample Input 2

4
5 4 7 0
5
1 2 3 4 5

Sample Output 2

0

Sample Input 3

3
1 1 2
4
1 1 2 2

Sample Output 3

1



Sample input:
3
1 2 3
2
2 4


Sample output:
1

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split(' ')))
m = int(input())
b = list(map(int, input().split(' ')))

loop_num = n if n <= m else m
for i in range(loop_num):
    if a[i] < b[i]:
        print(1)
        break
    elif a[i] > b[i]:
        print(0)
        break

if len(a) < len(b):
    print(1)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
m = int(input())
t = input()

if s < t:
    print(1)
else:
    print(2)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))

la = len(a)
lb = len(b)
l = min(la, lb)

for i in range(l):
    if a[i] < b[i]:
        print(1)
        break
    elif a[i] > b[i]:
        print(2)
        break
else:
    if la < lb:
        print(1)
    else:
        print(2)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))

la = len(a)
lb = len(b)
l = min(la, lb)

for i in range(l):
    if a[i] < b[i]:
        print(0)
        break
    elif a[i] > b[i]:
        print(1)
        break
else:
    if la < lb:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))

la = len(a)
lb = len(b)
l = min(la, lb)

for i in range(l):
    if a[i] > b[i]:
        print(0)
        break
    elif a[i] < b[i]:
        print(1)
        break
else:
    if la < lb:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))

la = len(a)
lb = len(b)
l = min(la, lb)

for i in range(l):
    if a[i] > b[i]:
        print(0)
        break
    elif a[i] < b[i]:
        print(1)
        break
else:
    if la > lb:
        print(0)
    else:
        print(1)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split(' ')))
m = int(input())
b = list(map(int, input().split(' ')))

rst = None

loop_num = n if n <= m else m
for i in range(loop_num):
    if a[i] < b[i]:
        rst = 1
    elif a[i] > b[i]:
        rst = 0
    if rst != None: break

if rst == None:
    if len(a) < len(b):
        rst = 1
    else:
        rst = 0

print(rst)

Submission status: Accepted

Solution code:

from collections import UserList


class LexicalOrderedList(UserList):
    def __eq__(self, other):
        len_a = len(self)
        len_b = len(other)
        if len_a != len_b:
            return False
        i = 0
        while self.data[i] == other.data[i]:
            i += 1

        return i == len_a

    def __gt__(self, other):
        len_a = len(self)
        len_b = len(other)

        i = 0
        while (i < len_a and i < len_b
               and self.data[i] == other.data[i]):
            i += 1

        if i == len_a and i == len_b:
            return False
        elif i == len_a and i < len_b:
            return False
        elif i < len_a and i == len_b:
            return True
        else:
            return self.data[i] > other.data[i]

    def __ge__(self, other):
        return self == other or self > other


def run():
    n = int(input())
    a = LexicalOrderedList()
    for c in input().split():
        a.append(int(c))
    assert len(a) == n

    m = int(input())
    b = LexicalOrderedList()
    for c in input().split():
        b.append(int(c))
    assert len(b) == m

    if b > a:
        print(1)
    else:
        print(0)


if __name__ == '__main__':
    run()

Submission status: Accepted

Solution code:
# coding=utf-8

N = int(input())
A = list(map(int, input().split()))
M = int(input())
B = list(map(int, input().split()))

if A < B:
    print("1")
else:
    print("0")

Submission status: Accepted

Solution code:
# AOJ ITP2_3_D: Lexicographical Comparison
# Python3 2018.6.24 bal4u

n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
k = min(n, m)
f = 2
for i in range(k):
	if a[i] < b[i]:
		f = 1
		break
	if a[i] > b[i]:
		f = 0
		break
if f == 2: f = 1 if n < m else 0
print(f)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))

la = len(a)
lb = len(b)
l = min(la, lb)

for i in range(l):
    if a[i] > b[i]:
        print(0)
        break
    elif a[i] < b[i]:
        print(1)
        break
else:
    if la >= lb:
        print(0)
    else:
        print(1)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
m = int(input())
B = list(map(int, input().split()))
cnt = min(len(A), len(B))
flag = 0
for i in range(cnt):
    if A[i] > B[i]:
        flag = 1
        break
    elif A[i] < B[i]:
        flag = 2
        break
if (flag == 0 and len(A) < len(B)) or flag ==2:
    print(1)
else:
    print(0)

Submission status: Accepted

Solution code:
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy

BIG_NUM = 2000000000
HUGE_NUM = 999999999999999
MOD = 1000000007
EPS = 0.00000000001
sys.setrecursionlimit(10000)

len_A = int(input())
A = list(map(int, input().split()))

len_B = int(input())
B = list(map(int, input().split()))

B_Bigger = False

for i in range(min(len_A, len_B)):
    if A[i] != B[i]:
        B_Bigger = B[i] > A[i]
        break

    if i == len_A - 1 and i != len_B - 1:
        B_Bigger = True

if B_Bigger == True:
    print('1')
else:
    print('0')

Submission status: Accepted

Solution code:
def resolve():
    import sys
    from collections import deque
    input = sys.stdin.readline
    input()
    A = [int(i) for i in input().split()]
    input()
    B = [int(i) for i in input().split()]

    A = deque(A)
    B = deque(B)
    while len(A) > 0 and len(B) > 0:
        a = A.popleft()
        b = B.popleft()
        if a == b:
            continue
        elif a < b:
            print(1)
            return
        else:
            print(0)
            return
    if len(B) > 0:
        print(1)
    else:
        print(0)


resolve()

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
m = int(input())
B = list(map(int, input().split()))

l = min(n, m)

if A == B:
    print(0)
else:
    if n < m:
        A.append(-1)
    else:
        B.append(-1)

    for i in range(l+1):
        if A[i] == B[i]:
            pass
        elif A[i] < B[i]:
            print(1)
            break
        else:
            print(0)
            break

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))

for i in range(max(n, m)) :
    if a[i] > b[i] :
        print(0)
        break
    elif a[i] < b[i] :
        print(1)
        break
    elif i + 1 == m :
        print(0)
        break
    elif i + 1 == n :
        print(1)
        break

Submission status: Accepted

Solution code:
n = int(input())
A = input().replace(" ","")
m = int(input())
B = input().replace(" ","")
if n > m:
  for i in range(n - m):
    B += " "
elif m > n :
  for i in range(m - n):
    A += " "

if A >= B :
  print(0)
else:
  print(1)

Submission status: Accepted

Solution code:
input()
a = input().split()
input()
b = input().split()

A = ""
B = ""

for i in a:
    A += i
for i in b:
    B += i

if A < B:
    print(1)
else:
    print(0)

Submission status: Accepted

Solution code:
input()
a=input()
input()
print(+(a<input()))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
m = int(input())
b = list(map(int,input().split()))
ans = 0
for i in range(min(n,m)):
    if a[i] < b[i]:
        ans = 1
        break
    elif a[i] > b[i]:
        break
else:
    if n < m:
        ans = 1

print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int,input().split()))
    m = int(input())
    b = list(map(int,input().split()))
    if a<b:print (1)
    else  :print (0)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
if a < b:
    print(1)
else:
    print(0)

Submission status: Accepted

Solution code:
n=input()
l1=list(map(int,input().split()))
n=input()
l2=list(map(int,input().split()))

if l1<l2:
    print(1)
else:
    print(0)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
m = int(input())
B = list(map(int, input().split()))

if B <= A:
    print(0)
elif A < B:
    print(1)

Submission status: Accepted

Solution code:
n = int(input())
A = input().replace(' ', '')
m = int(input())
B = input().replace(' ', '')
if A < B:
    print(1)
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))

M = int(input())
B = list(map(int,input().split()))

print(1 if A<B else 0)

Submission status: Accepted

Solution code:
input()
a=input().replace(' ','')
input()
b=input().replace(' ','')
print(1 if a < b else 0)

Submission status: Accepted

Solution code:
def main():
    is_big = 0

    n = int(input())
    set_a = [int(a) for a in input().split(" ")]

    n = int(input())
    set_b = [int(a) for a in input().split(" ")]

    for i in range(len(set_b)):
        if i > len(set_a) - 1 or i > len(set_b) - 1:
            if len(set_a) >= len(set_b):
                is_big = 0
                break
            else:
                is_big = 1
                break
        else:
            if set_b[i] > set_a[i]:
                is_big = 1
                break
            elif set_b[i] < set_a[i]:
                is_big = 0
                break

    print(is_big)
main()

Submission status: Accepted

Solution code:
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


len_A = int(input())
A = list(map(int,input().split()))

len_B = int(input())
B = list(map(int,input().split()))

B_Bigger = False
for i in range(min(len_A,len_B)):
    if A[i] != B[i]:
        B_Bigger = B[i] > A[i]
        break
    if i == len_A-1 and i != len_B-1:
        B_Bigger = True

if B_Bigger == True:
    print("1")
else:
    print("0")

Submission status: Accepted

Solution code:
n=input()
A=str("".join(input().split()))
n=input()
B=str("".join(input().split()))
li=sorted([A]+[B])
if li[0]==A and A!=B:
        print(1)
else:
    print(0)

Submission status: Accepted

Solution code:
n = int(input())
a = list(input().split())
m = int(input())
b = list(input().split())
# for i in range(max(len(a),len(b))):
#     if a[i] == b[i]:
#         if i+1 >= len(a) and len(b) > i+1 :
#             print('1')
#             break
#         elif i+1 >= len(b):
#             print('0')
#             break
#         pass    
#     elif a[i] < b[i]:
#         print('1')
#         break
#     else:
#         print('0')
#         break
print(+(a < b))

Submission status: Accepted

Solution code:
#
input()
a = list(map(int, input().split()))
input()
b = list(map(int, input().split()))

for i in range( min(len(a), len(b) ) ):
    if a[i] < b[i]:
        print(1)
        exit(0)
    if a[i] > b[i]:
        print(0)
        exit(0)

if len(a) >= len(b):
    print(0)
else:
    print(1)

Submission status: Accepted

Solution code:
def solve():
    from sys import stdin
    f_i = stdin
    n = f_i.readline()
    A = tuple(map(int, f_i.readline().split()))
    m = f_i.readline()
    B = tuple(map(int, f_i.readline().split()))
    if A < B:
        print(1)
    else:
        print(0)

solve()

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    num_n = int(input())
    n = list(map(lambda x: int(x), input().split()))

    num_m = int(input())
    m = list(map(lambda x: int(x), input().split()))

    for idx in range(min(num_n, num_m)):
        if (n[idx] == m[idx]):
            continue
        elif (m[idx] < n[idx]):
            print(0)
            exit(0)
        elif (n[idx] < m[idx]):
            print(1)
            exit(0)

    if (num_n < num_m):
        print(1)
    else:
        print(0)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split( )))
a.append(-1)
m=int(input())
b=list(map(int,input().split( )))
b.append(-1)
i=0
while True:
    if a[i]<b[i]:
        print(1)
        break
    elif a[i]>b[i]:
        print(0)
        break
    elif a[i] == -1 and b[i] == -1:
        print(0)
        break
    i+=1

Submission status: Accepted

Solution code:
n = int(input())
A = [int(x) for x in input().split()]
m = int(input())
B = [int(x) for x in input().split()]
 
ans = 0
 
for i in range(min(len(A), len(B))):
    if A[i] < B[i]:
        ans = 1
        break
    elif A[i] > B[i]:
        break
else:
    if len(A) < len(B):
        ans = 1
 
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Basic Operations - Lexicographical Comparison
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_3_D&lang=jp

"""
from itertools import zip_longest

_ = input()
A = [int(a) for a in input().split()]
_ = input()
B = [int(b) for b in input().split()]

ans = 0
for a, b in zip_longest(A, B, fillvalue=-1):
    if a > b:
       break
    elif b > a:
        ans = 1
        break
print(ans)

Submission status: Accepted

Solution code:
from itertools import zip_longest

if __name__ == '__main__':

	int(input())
	A = list(map(int,input().split()))
	int(input())
	B = list(map(int,input().split()))

	win = 0
	for a,b in zip_longest(A,B,fillvalue=-1):
		if a < b:
			win = 1
			break
		elif a > b:
			win = 0
			break

	print(win)

Submission status: Accepted

Solution code:
n = int(input())

A = list(map(int, input().split()))

m = int(input())

B = list(map(int, input().split()))


if B > A:
    print(1)
else:
    print(0)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
cnt = 0
for i, j in zip(a,b):
    if i > j:
        print(0)
        break
    if i < j:
        print(1)
        break
    cnt += 1
if cnt == len(b):
    print(0)
elif cnt == len(a):
    print(1)

Submission status: Accepted

Solution code:
import sys

sys.stdin.readline()
a = ''.join(sys.stdin.readline().split())

sys.stdin.readline()
b = ''.join(sys.stdin.readline().split())

print(1 if a<b else 0)

Submission status: Accepted

Solution code:
input()
a = list(map(int, input().split(' ')))
input()
b = list(map(int, input().split(' ')))
print(1 if a<b else 0)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
k = min(n, m)
f = 2
for i in range(k):
    if a[i] < b[i]:
        f = 1
        break
    if a[i] > b[i]:
        f = 0
        break
if f == 2:
    f = 0
    if n<m:
        f = 1
    
print(f)

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
m=int(input())
B=list(map(int,input().split()))

if B>A:
    print(1)
else:
    print(0)

Submission status: Accepted

Solution code:
n = int(input())
A = [int(x) for x in input().split()]
m = int(input())
B = [int(x) for x in input().split()]

ans = 0

for i in range(min(len(A), len(B))):
    if A[i] < B[i]:
        ans = 1
        break
    elif A[i] > B[i]:
        break
else:
    if len(A) < len(B):
        ans = 1

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=input()
q=int(input())
b=input()
if a>=b:print(0)
else:print(1)

Submission status: Accepted

Solution code:
n1 = int(input())
txt1 = input().split()
n2 = int(input())
txt2 = input().split()

for i in range(min(n1, n2)):
    c1, c2 = txt1[i], txt2[i]
    if c1 != c2:
        print([0, 1][c1 < c2])
        break
else:
    print([0, 1][n1 < n2])

Submission status: Accepted

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_3_D&lang=jp
# Lexicographical Comparison

from functools import reduce
from collections import deque
import sys
input = sys.stdin.readline


def main():
    n1 = int(input())
    l1  = "".join(map(str,input().split()))
    n2 = int(input())
    l2  = "".join(map(str,input().split()))
    if (l1 >= l2):
        print (0)
    else:
        print(1)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
alist = list(map(int, input().split()))

m = int(input())
blist = list(map(int, input().split()))

for a, b in zip(alist, blist):
    if a > b:
        print(0)
        exit()
    elif a < b:
        print(1)
        exit()

if len(alist) < len(blist):
    print(1)
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
*A, = map(int, input().split())
M = int(input())
*B, = map(int, input().split())
print(+(A < B))

Submission status: Accepted

Solution code:
input(); A = input().split()
input(); B = input().split()
print(1 if A < B else 0)

Submission status: Accepted

Solution code:
n=input()
a=list(map(int,input().split()))
m=input()
b=list(map(int,input().split()))
print(int(a<b))

Submission status: Accepted

Solution code:
n = int(input())
a = input().replace(" ", "")
m = int(input())
b = input().replace(" ", "")
if a<b:
  print(1)
else:
  print(0)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split())
m = int(input())
b = list(map(int, input()))

la = len(a)
lb = len(b)
l = min(la, lb)

for i in range(l):
    if a[i] < b[i]:
        print(1)
        break
    elif a[i] > b[i]:
        print(2)
        break
else:
    if la < lb:
        print(1)
    else:
        print(2)