Problem:


Reservation System

The supercomputer system L in the PCK Research Institute performs a variety of calculations upon request from external institutes, companies, universities and other entities. To use the L system, you have to reserve operation time by specifying the start and end time. No two reservation periods are allowed to overlap each other.

  Write a program to report if a new reservation overlaps with any of the existing reservations. Note that the coincidence of start and end times is not considered to constitute an overlap. All the temporal data is given as the elapsed time from the moment at which the L system starts operation.

Input

  The input is given in the following format.

a b
N
s_1 f_1
s_2 f_2
:
s_N f_N

The first line provides new reservation information, i.e., the start time a and end time b (0 ≤ a < b ≤ 1000) in integers. The second line specifies the number of existing reservations N (0 ≤ N ≤ 100). Subsequent N lines provide temporal information for the i-th reservation: start time s_i and end time f_i (0 ≤ s_i < f_i ≤ 1000) in integers. No two existing reservations overlap.

Output

  Output "1" if the new reservation temporally overlaps with any of the existing ones, or "0" otherwise.

Sample Input 1

5 7
3
1 4
4 5
7 10

Sample Output 1

0

Sample Input 2

3 7
3
7 10
1 4
4 5

Sample Output 2

1



Sample input:
5 7
3
1 4
4 5
7 10


Sample output:
0

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
N = int(input())
flag = 0
for _ in range(N):
    s, f = map(int, input().split())
    if a > s and f > b:
        flag = 1
    elif a < f < b:
        flag = 1
    elif a < s < b:
        flag = 1
    if flag:
        break
print(1 if flag else 0)

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
N = int(input())
flag = 0
for _ in range(N):
    s, f = map(int, input().split())
    if f > a or s < b:
        flag = 1
        break
print(1 if flag else 0)

Submission status: Wrong Answer

Solution code:
a,b = map(int,list(input().split(" ")))
n = int(input())
c = [0 for i in range(1002)]
ans = 0
c[a]+=1
c[b]-=1
for i in range(n):
      s,f = map(int,list(input().split(" ")))
      c[s]+=1
      c[f]-=1
for i in range(1,1001):
      c[i] += c[i-1]
      if(c[i]>1):
            ans = 1
print(ans)

Submission status: Wrong Answer

Solution code:
a, b = map(int,input().split())
t = []
for _ in range(int(input())):
    t += list(map(int, input().split()))
print(sum(i <= a for i in t) % 2 or sum(i >= b for i in t) % 2)

Submission status: Wrong Answer

Solution code:
a, b = map(int,input().split())
t = []
for _ in range(int(input())):
    t += list(map(int, input().split()))
print(1 if sum(i <= a for i in t) % 2 or sum(i >= b for i in t) % 2 or (a < i and i < b for i in t) else 0)

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
for i in range(int(input())):
    s, f = map(int, input().split())
    if s <= a and a < f\
    or s < b and b <= f:
        print("1")
        break
    else:
        print("0")

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
for i in range(int(input())):
    s, f = map(int, input().split())
    if s <= a and a < f\
    or s < b and b <= f:
        print("1")
        break
else:
    print("0")

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
N = int(input())
books = []
for i in range(N):
    books.append(list(map(int, input().split())))

is_booked = 0
for i in range(len(books)):
    if books[i][0] <= a < books[i][1]:
        is_booked = 1

print(is_booked)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
n = int(input())
l = sorted([list(map(int, input().split())) for _ in range(n)])
line = [0]*1010
line[a] += 1
line[b] -= 1
for a, b in l:
    line[a] += 1
    line[b] -= 1
for i in range(1006):
    line[i+1] += line[i]
if line.count(2):
    print(1)
else:
    print(0)

Submission status: Accepted

Solution code:
time=[0]*1001
a,b=list(map(int,input().split()))
n=int(input())
for i in range(n):
    s,f=list(map(int,input().split()))
    time[s:f]=[1]*(f-s)
if sum(time[a:b])==0:print("0")
else:print("1")

Submission status: Accepted

Solution code:
def main():
    a,b = map(int,input().split())

    n = int(input())
    s,f = [],[]
    for i in range(n):
        ss,ff = map(int,input().split())
        s.append(ss)
        f.append(ff)

    for i in range(n):
        if f[i] <= a or b <= s[i]:
            continue
        else:
            return 1
    return 0

if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
c=0
for i in range(int(input())):
    s,t=map(int,input().split())
    if not (t<=a or b<=s):
        c=1
print(c)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
N = int(input())
flag = 0
for _ in range(N):
    s, f = map(int, input().split())
    if not (f <= a or b <= s):
        flag = 1
        break
print(1 if flag else 0)

Submission status: Accepted

Solution code:
a,b = map(int,list(input().split(" ")))
n = int(input())
c = [0 for i in range(1002)]
ans = 0
c[a]+=1
c[b]-=1
for i in range(n):
      s,f = map(int,list(input().split(" ")))
      c[s]+=1
      c[f]-=1
for i in range(1001):
      c[i+1] += c[i]
      if(c[i]>1):
            ans = 1
print(ans)

Submission status: Accepted

Solution code:
def ans(res, L, N):
    for i in range(N):
        count = 0
        for new in res:
            for k in L[i]:
                if(new == k):
                    count += 1
        if(count >= 2):
            return 1
    return 0



a, b = map(int, input().split())
res  = []
for i in range(a,b+1, 1):
    res.append(i)
N = int(input())
L = []
for i in range(N):
    l = []
    s, f = map(int, input().split())
    for i in range(s,f + 1,1):
        l.append(i)
    L.append(l)
print(ans(res, L, N))

Submission status: Accepted

Solution code:
a, b = map(int,input().split())
t = []
for _ in range(int(input())):
    t += list(map(int, input().split()))
print(1 if sum(i <= a for i in t) % 2 or sum(i >= b for i in t) % 2 or sum(a < i and i < b for i in t) else 0)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
N = int(input())
books = []
for i in range(N):
    books.append(list(map(int, input().split())))

is_booked = 0
for i in range(len(books)):
    if books[i][0] <= a < books[i][1]:
        is_booked = 1
    elif a < books[i][0] < b:
        is_booked = 1

print(is_booked)

Submission status: Accepted

Solution code:
def check(a, b, lst):
  for s, f in lst:
    if not(b <= s or f <= a):
      return 1
  return 0

a, b = map(int, input().split())
n = int(input())
lst = [tuple(map(int, input().split())) for _ in range(n)]
print(check(a, b, lst))

Submission status: Accepted

Solution code:
A, B = map(int, input().split())
N = int(input())
SF = [[0, 0], [1000, 1000]]
for _ in range(N):
	SF.append(list(map(int, input().split())))
SF.sort()
R = 1
for i in range(N+1):
	if SF[i][1]<=A and B<=SF[i+1][0]:
		R = 0
		break
print(R)

Submission status: Accepted

Solution code:
# N = int(sys.stdin.readline())
# INF = float("inf")
import sys

# N,M = map(int,sys.stdin.readline().split())
# abx = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(M)) # multi line with multi param

# imos=[[0]*(N) for _ in range(N)]

# for a,b,x in abx:
#     imos[a-1][b-1] += 1
#     if a+x-1+1 < N and b+x-1+1 < N:
#         imos[a+x-1+1][b+x-1+1] -= 1
#         imos[a+x-1+1][b-1+1] -= 1
# print(imos)
# for r in range(N):
#     for c in range(N):
#         imos[r][c] += imos[r-1][c-1]#+imos[r][c-1]
# print(imos)

a,b = map(int,sys.stdin.readline().split())
N = int(sys.stdin.readline())
sf = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
M = 1000
imos = [0]*(M+1)
imos[a] += 1
imos[b] -= 1

for s,f in sf:
    imos[s] += 1
    imos[f] -= 1
for i in range(M):
    imos[i+1] += imos[i]
for i in range(a,b+1):
    if imos[i] > 1:
        print("1")
        exit()
print("0")

Submission status: Accepted

Solution code:
import itertools

a,b = map(int,input().split())

N = int(input())
reserved = [0]*1001
for _ in range(N):
    s, f = map(int,input().split())
    reserved[s] += 1
    reserved[f] -= 1

cumsum = list(itertools.accumulate(reserved))

#print(cumsum)

if sum(cumsum[a:b]):
    print(1)
else:
    print(0)

Submission status: Accepted

Solution code:
a,b = list(map(int, input().split()))
n = int(input())
sf = [list(map(int, input().split())) for _ in range(n)]

ans = 0
li = [True] * 1000
sf.sort()
for i in sf:
    for j in range(i[0], i[1]):
        li[j] = False
for i in range(a,b):
    if li[i] == False:
        ans = 1
        break


print(ans)

Submission status: Accepted

Solution code:
x, y = map(int, input().split())
n = int(input())

ans = 0
for _ in range(n):
    a, b = map(int, input().split())
    if x < b and a < y:
        ans = 1

print(ans)

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
n = int(input())
t = 0
for i in range(n):
    s,f=map(int,input().split())
    if s<b<=f or s<=a<f:
        t=1
    elif a<=s and b>=f:
        t=1
print(t)

Submission status: Accepted

Solution code:
def solve():
    from sys import stdin
    f_i = stdin
    
    a, b = map(int, f_i.readline().split())
    N = int(f_i.readline())
    for i in range(N):
        s, f = map(int, f_i.readline().split())
        if b <= s or f <= a:
            pass
        else:
            print(1)
            break
    else:
        print(0)

solve()

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
N = int(input())
n = 1009
reserve = [0]*n

#新しい予約
b = b-1
reserve[a] += 1
reserve[b+1] -= 1

#既存の予約
for i in range(N):
    s,f = map(int,input().split())
    f = f-1
    reserve[s] += 1
    reserve[f+1] -= 1

judge = 0
for i in range(n):
 if(i != 0): reserve[i] += reserve[i-1]
 if(reserve[i] >= 2): judge = 1

#print(reserve)
print(judge)

Submission status: Accepted

Solution code:
a, b =map(int,input().split())
n=int(input())
m=0
for i in range(n):
    c,d=map(int,input().split())
    if d<=a or c>=b:
        pass
    else:
        m=m+1
if m != 0:
    print(1)
else:
    print (0)

Submission status: Accepted

Solution code:
def overlap(a, b, c, d):
    if d <= a:  return False
    if b <= c:  return False
    return True
 
a,b = map(int, input().split())
res = 0
for i in range(int(input())):
    s, t = map(int, input().split())
    if overlap(a, b, s, t): res = 1
print(res)

Submission status: Accepted

Solution code:
a, b= map(int,input().split())
N = int(input())
 
for i in range(N):
  c, d = map(int,input().split())
  if d <= a or b <= c:continue
  else:
    print("1")
    exit()
print("0")

Submission status: Accepted

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

for i in range(N):
  c, d = map(int,input().split())
  if d <= a or b <= c:continue
  else:
    print("1")
    exit()
print("0")

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
N=int(input())
judge=0
for i in range(N):
    rs,re=map(int,input().split())
    if judge==0:
        if a<=rs and b>rs:
            judge=1
        elif a>rs and a<re:
            judge=1
print(judge)

Submission status: Accepted

Solution code:
def overlap(a, b, c, d):
    if d <= a:  return False
    if b <= c:  return False
    return True
 
a, b = map(int, input().split())
res = 0
for i in range(int(input())):
    s, t = map(int, input().split())
    if overlap(a, b, s, t): res = 1
print(res)

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
c=0
for i in range (int(input())):
  s,t=map(int,input().split())
  if not (t<=a or b<=s):
    c=1
print(c)

Submission status: Accepted

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

ans = 0

for i in range(n):
   A,B = map(int,input().split())

   if not (A >= b or B<= a):
       ans = 1
       
 
print(ans)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
N = int(input())
T = [0]*1001
ok = 0
for i in range(N):
    s, f = map(int, input().split())
    if s < b and a < f:
        ok = 1
print(ok)

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
c=0
for i in range(int(input())):
    s,t=map(int,input().split())
    if not (t<=a or b<=s):
        c=1
print(c)

Submission status: Accepted

Solution code:
time=[]
a,b=map(int,input().split())
N=int(input())
for i in range(N):
  s,f=map(int,input().split())
  for i in range(s,f):
    time.append(i)
#print(time)
for i in range(a,b):
  #print(i)
  if i in time:
    print(1)
    break
  elif i==b-1:
    print(0)

Submission status: Accepted

Solution code:
b,e = map(int,input().split())
r = [0]*1000
for _ in range(int(input())):
 b1,e2 =map(int,input().split())
 for x in range(b1,e2):
     r[x] = 1
def check():
 for x in range(b,e):
   if r[x] ==1:
     return 1
 return 0
print(check())

Submission status: Accepted

Solution code:
b,e = map(int,input().split())
r = [0]*1000
for _ in range(int(input())):
  b1,e2 =map(int,input().split())
  for x in range(b1,e2):
      r[x] = 1
def check():
  for x in range(b,e):
    if r[x] ==1:
      return 1
  return 0
print(check())

Submission status: Accepted

Solution code:
b,e = map(int, input().split())

r = [0] * 1000
for _ in range(int(input())):
    b1, e2 = map(int, input().split())
    for x in range(b1, e2):
        r[x] = 1

def check():
    for x in range(b, e):
        if r[x] == 1:
            return 1
    return 0

print(check())

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
n = int(input())
flag = True
for i in range(n):
  aa, bb = map(int, input().split())
  if bb <= a or aa >= b:
    pass
  else:
    flag = False
if(flag == True):
  print("0")
else:
  print("1")

Submission status: Accepted

Solution code:
a,b = [int(i) for i in input().split()]
N = int(input())

ans = 0

for l in range(N):
    s,f = [int(i) for i in input().split()]
#    if f <= a or b <= s:
    if a < f and s < b:
        ans = 1
        break

print(ans)

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
N=int(input())
s=[]
f=[]
h=0
for i in range(N):
    int_s,int_f=map(int,input().split())
    s.append(int_s)
    f.append(int_f)

for j in range(N):
    if s[j]<=a and b<=f[j]:
        h+=1
        break
    elif a<=s[j] and f[j]<=b:
        h+=1
        break
    elif s[j]<b<f[j]:
        h+=1
        break
    elif s[j]<a<f[j]:
        h+=1
        break
print(h)

Submission status: Accepted

Solution code:
def overlap(a, b, c, d):
    if d <= a:  return False
    if b <= c:  return False
    return True

a, b = map(int, input().split())
res = 0
for i in range(int(input())):
    s, t = map(int, input().split())
    if overlap(a, b, s, t): res = 1
print(res)

Submission status: Accepted

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

res = []
for _ in range(n):
    s, f = map(int, input().split())
    res.append([s, f])

for r in res:
    if r[1] > a and r[0] < b:
        print(1)
        break
else:
    print(0)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = int(input())
for i in range(a):
  a,b = map(int,input().split())
  if b <= n or m <= a:continue
  else:
    print("1")
    exit()
print("0")

Submission status: Accepted

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

booking = True
for i in range(n):
	s, f = map(int, input().split())
	if(f <= a or b <= s):
		continue
	else:
		booking = False
print(int(not(booking)))

Submission status: Runtime Error

Solution code:
import numpy
a, b = map(int, input().split())
n = int(input())
l = sorted([list(map(int, input().split())) for _ in range(n)])
line = [0]*(max(l)[1]+2)
line[a] += 1
line[b] -= 1
for a, b in l:
    line[a] += 1
    line[b] -= 1
if list(numpy.cumsum(line)).count(2):
    print(1)
else:
    print(0)

Submission status: Runtime Error

Solution code:
a, b = map(int, input().split())
n = int(input())
l = sorted([list(map(int, input().split())) for _ in range(n)])
line = [0]*(max(l)[1]+2)
line[a] += 1
line[b] -= 1
for a, b in l:
    line[a] += 1
    line[b] -= 1
for i in range(len(line)-1):
    line[i+1] += line[i]
if line.count(2):
    print(1)
else:
    print(0)

Submission status: Runtime Error

Solution code:
s = input()
print(s)

Submission status: Runtime Error

Solution code:
a,b = map(int,list(input().split(" ")))
n = int(input())
c = [0 for i in range(1002)]
ans = 0
c[a]+=1
c[b]-=1
for i in range(n):
      s,f = map(int,list(input().split(" ")))
      c[s]+=1
      c[f]-=1
for i in range(1002):
      c[i+1] += c[i]
      if(c[i]>1):
            ans = 1
print(ans)