Problem:


多角形の面積

１つの円に内接する２つの多角形の頂点情報を入力とし、それらの面積の大小関係を出力するプログラムを作成してください。

X 角形の各頂点には反時計回りに 1 から X まで番号が振ってあるものとします（図は、X = 4 の場合の例を示しています）。ただし、与えられる多角形は円の中心を内部に含むものとし、頂点 i の位置に関するデータは、頂点 i から頂点 i+1  まで反時計回りに計った中心角の角度 v (1 ≤ v < 180 の整数) で与えられます。また、出力する大小関係については、第１の多角形の面積が大きい場合は 1 (半角数字)、第２の多角形の面積が大きい場合は 2 (半角数字)、それぞれの面積が等しい場合は 0 (半角数字) と出力してください。

Input

複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。
各データセットは以下の形式で与えられます。

m
v1
v2
:
vm &minus;1
n
v1
v2
:
vn &minus; 1

１行目に第１の多角形の頂点の数 m (3 ≤ m ≤ 50)、続く m &minus; 1 行に第１の多角形の頂点 i の情報 vi (1 ≤ vi < 180) が与えられます。

続く行に第２の多角形の頂点の数 n (3 ≤ n ≤ 50)、続く n &minus; 1 行に第２の多角形の頂点 i の情報 vi (1 ≤ vi < 180) が与えられます。

データセットの数は 200 を超えません。

Output

データセットごとに大小関係（半角数字）を１行に出力します。

Sample Input

4
30
125
75
4
30
125
75
5
30
125
75
65
4
30
125
75
4
30
125
75
6
30
50
50
25
75
0

Output for the Sample Input

0
1
2



Sample input:
4
30
125
75
4
30
125
75
5
30
125
75
65
4
30
125
75
4
30
125
75
6
30
50
50
25
75
0


Sample output:
0
1
2

Submission status: Wrong Answer

Solution code:
import math
def f(n): return math.sin(n*math.pi/180)
def g(n):
  x = [int(raw_input()) for _ in [0]*n]
  x += [360-sum(x)]
  return sum(map(f, x))
  
while 1:
  n = input()
  if n==0: break
  s1 = g(n-1)
  s2 = g(input()-1)
  if s1>s2: print 1
  elif s1<s2: print 2
  else: print 0

Submission status: Wrong Answer

Solution code:
import math

while True:
    m = input()
    if m == 0: break
    ms = 0
    for i in range(m-1):
        ra = math.radians(input())
        ms += math.sin(ra)
    ns = 0
    for i in range(input()-1):
        ra = math.radians(input())
        ns += math.sin(ra)
    if ns < ms:
        print 1
    elif ms < ns:
        print 2
    else:
        print 0

Submission status: Wrong Answer

Solution code:
import math

def f(a):
    s = 0
    an = 360
    for i in range(a-1):
        th = input()
        ra = math.radians(th)
        s += math.sin(ra)
        an -= th
    else:
        ra = math.radians(an)
        s += math.sin(ra)
        return s

while True:
    m = input()
    if m == 0: break
    ms = f(m)
    ns = f(input())
    if ns < ms:
        print 1
    elif ms < ns:
        print 2
    else:
        print 0

Submission status: Wrong Answer

Solution code:
import math

def f(a, an):
    s = 0
    for i in range(a-1):
        th = input()
        ra = math.radians(th)
        s += math.sin(ra)
        an -= th
    else:
        ra = math.radians(an)
        s += math.sin(ra)
        return s

while True:
    m = input()
    if m == 0: break
    ms = f(m, 180*(m-2))
    n = input()
    ns = f(n, 180*(n-2))
    if ns < ms:
        print 1
    elif ms < ns:
        print 2
    else:
        print 0

Submission status: Wrong Answer

Solution code:
import math

def f(c, an):
    s = 0
    for i in range(c):
        th = input()
        ra = math.radians(th)
        s += math.sin(ra)
        an -= th
    else:
        ra = math.radians(an)
        s += math.sin(ra)
        return s

while True:
    m = input()
    if m == 0: break
    ms = f(m-1, 180*(m-2))
    n = input()
    ns = f(n-1, 180*(n-2))
    if ns < ms:
        print 1
    elif ms < ns:
        print 2
    else:
        print 0

Submission status: Wrong Answer

Solution code:
from decimal import Decimal
import math

def f(c, an):
    s = 0
    for i in range(c):
        th = input()
        ra = Decimal(math.radians(th))
        s += Decimal(math.sin(ra))
        an -= th
    else:
        ra = Decimal(math.radians(an))
        s += Decimal(math.sin(ra))
        return s

while True:
    m = input()
    if m == 0: break
    ms = f(m-1, 180*(m-2))
    n = input()
    ns = f(n-1, 180*(n-2))
    if ns < ms:
        print 1
    elif ms < ns:
        print 2
    else:
        print 0

Submission status: Wrong Answer

Solution code:
import math

def f(c, an):
    s = 0
    for i in range(c):
        th = input()
        ra = math.radians(th)
        s += math.sin(ra)
        an -= th
    else:
        ra = math.radians(an)
        s += math.sin(ra)
        return 10*s/2

while True:
    m = input()
    if m == 0: break
    ms = f(m-1, 180*(m-2))
    n = input()
    ns = f(n-1, 180*(n-2))
    if ns < ms:
        print 1
    elif ms < ns:
        print 2
    else:
        print 0

Submission status: Wrong Answer

Solution code:
import math

def f(c, an):
    s = 0
    for i in range(c):
        th = input()
        ra = math.radians(th)
        s += math.sin(ra)
        an -= th
    else:
        ra = math.radians(an)
        s += math.sin(ra)
        return (((math.sqrt(2))**2)/2)*s

while True:
    m = input()
    if m == 0: break
    ms = f(m-1, 180*(m-2))
    n = input()
    ns = f(n-1, 180*(n-2))
    if ns < ms:
        print 1
    elif ms < ns:
        print 2
    else:
        print 0

Submission status: Wrong Answer

Solution code:
import math

def f(c, an):
    s = 0
    for i in range(c):
        th = input()
        ra = math.radians(th)
        s += math.sin(ra)
        an -= th
    else:
        ra = math.radians(an)
        s += math.sin(ra)
        return (2.0/2)*s

while True:
    m = input()
    if m == 0: break
    ms = f(m-1, 180*(m-2))
    n = input()
    ns = f(n-1, 180*(n-2))
    if ns < ms:
        print 1
    elif ms < ns:
        print 2
    else:
        print 0

Submission status: Wrong Answer

Solution code:
import math

def f(c, an):
    s = 0
    for i in range(c):
        th = input()
        ra = math.radians(th)
        s += (2.0/2)*math.sin(ra)
        an -= th
    else:
        ra = math.radians(an)
        s += math.sin(ra)
        return s

while True:
    m = input()
    if m == 0: break
    ms = f(m-1, 180*(m-2))
    n = input()
    ns = f(n-1, 180*(n-2))
    if ns < ms:
        print 1
    elif ms < ns:
        print 2
    else:
        print 0

Submission status: Wrong Answer

Solution code:
from decimal import Decimal
import math

def f(c, an):
    s = 0
    for i in range(c):
        th = input()
        ra = Decimal(math.radians(th))
        s += Decimal((2.0/2)*math.sin(ra))
        an -= th
    else:
        ra = Decimal(math.radians(an))
        s += Decimal((2.0/2)*math.sin(ra))
        return s

while True:
    m = input()
    if m == 0: break
    ms = f(m-1, 180*(m-2))
    n = input()
    ns = f(n-1, 180*(n-2))
    if ns < ms:
        print 1
    elif ms < ns:
        print 2
    else:
        print 0

Submission status: Wrong Answer

Solution code:
import math

def f(c, an):
    s = 0
    for i in range(c):
        th = input()
        ra = math.radians(th)
        s += (1.0*math.sin(ra))
        an -= th
    else:
        ra = math.radians(an)
        s += (1.0*math.sin(ra))
        return s

while True:
    m = input()
    if m == 0: break
    ms = f(m-1, 360)
    n = input()
    ns = f(n-1, 360)
    if ns < ms:
        print 1
    elif ms < ns:
        print 2
    else:
        print 0

Submission status: Wrong Answer

Solution code:
from math import sin, radians

ONE_BIGGER_TWO = 1
TWO_BIGGER_ONE = 2
SAME = 0


def calculate_area(input_list):
    radian_list = [radians(item) for item in input_list]
    sin_list = [sin(item) for item in radian_list]
    area = sum(sin_list)
    return area


while True:
    input_count = int(input())

    if input_count == 0:
        break

    input_list1 = [int(input()) for _ in range(input_count - 1)]
    area1 = calculate_area(input_list1)

    input_count = int(input())
    input_list2 = [int(input()) for _ in range(input_count - 1)]
    area2 = calculate_area(input_list2)

    if area1 == area2:
        print(SAME)
    elif area1 > area2:
        print(ONE_BIGGER_TWO)
    else:
        print(TWO_BIGGER_ONE)

Submission status: Wrong Answer

Solution code:
from sys import float_info
from math import sin, radians

ONE_BIGGER_TWO = 1
TWO_BIGGER_ONE = 2
SAME = 0


def calculate_area(input_list):
    radian_list = [radians(item) for item in input_list]
    sin_list = [sin(item) for item in radian_list]
    area = sum(sin_list)

    return area


while True:
    input_count = int(input())

    if input_count == 0:
        break

    input_list1 = [int(input()) for _ in range(input_count - 1)]
    area1 = calculate_area(input_list1)

    input_count = int(input())
    input_list2 = [int(input()) for _ in range(input_count - 1)]
    area2 = calculate_area(input_list2)

    if area1 - area2 < float_info.epsilon:
        print(SAME)
    elif area1 > area2:
        print(ONE_BIGGER_TWO)
    else:
        print(TWO_BIGGER_ONE)

Submission status: Wrong Answer

Solution code:
import math

"""
import decimal
quantizeで1つずつ丸めていく?
"""

ONE_BIGGER_TWO = 1
TWO_BIGGER_ONE = 2
SAME = 0


def calculate_area(input_list):
    radian_list = [math.radians(item) for item in input_list]
    sin_list = [math.sin(item) for item in radian_list]
    area = math.fsum(sin_list)

    return area


while True:
    input_count = int(input())

    if input_count == 0:
        break

    input_list1 = [int(input()) for _ in range(input_count - 1)]
    area1 = calculate_area(input_list1)

    input_count = int(input())
    input_list2 = [int(input()) for _ in range(input_count - 1)]
    area2 = calculate_area(input_list2)

    if math.isclose(area1, area2):
        print(SAME)
    elif area1 > area2:
        print(ONE_BIGGER_TWO)
    else:
        print(TWO_BIGGER_ONE)

Submission status: Wrong Answer

Solution code:
import math

ONE_BIGGER_TWO = 1
TWO_BIGGER_ONE = 2
SAME = 0


def calculate_area(input_list):
    last = 360 - sum(input_list)
    input_list.append(last)

    radian_list = [math.radians(item) for item in input_list]
    sin_list = [math.sin(item) for item in radian_list]

    area = sum(sin_list)

    return area


while True:
    input_count = int(input())

    if input_count == 0:
        break

    input_list1 = [int(input()) for _ in range(input_count - 1)]
    area1 = calculate_area(input_list1)

    input_count = int(input())
    input_list2 = [int(input()) for _ in range(input_count - 1)]
    area2 = calculate_area(input_list2)

    if area1 == area2:
        print(SAME)
    elif area1 > area2:
        print(ONE_BIGGER_TWO)
    else:
        print(TWO_BIGGER_ONE)

Submission status: Wrong Answer

Solution code:
import math

def inputData(j):
    A=[]
    t=0
    for i in range(j-1):
        v=input()
        x=math.cos(math.pi*(v+t)/180)
        y=math.sin(math.pi*(v+t)/180)
        t+=v
        A.append((x,y))
    A.append(A[0])
    return A

def calcArea(A,j):
    return sum((A[i][0]-A[i+1][0])*(A[i][1]+A[i+1][1]) for i in range(j-1))/2

while True:
    m=input()
    if m==0:break
    A=inputData(m)
    n=input()
    B=inputData(n)
    S1,S2=calcArea(A,m),calcArea(B,n)
    if S1>S2:
        print 1
    elif S1<S2:
        print 2
    else:
        print 0

Submission status: Wrong Answer

Solution code:
# Area of Polygon

from math import sin
from math import radians

while True:
    m = int(raw_input())
    if m == 0:
        break

    a1 = 0
    sum = 0
    for i in range(m):
        if i < m - 1:
            v = int(raw_input())
            sum += v
        else:
            v = 360 - sum
        a1 += sin(radians(v))

    n = int(raw_input())
    a2 = 0
    sum = 0
    for i in range(n):
        if i < n - 1:
            v = int(raw_input())
            sum += v
        else:
            v = 360 - sum
        a2 += sin(radians(v))

    if a1 > a2:
        print 1
    elif a1 < a2:
        print 2
    else:
        print 0

Submission status: Wrong Answer

Solution code:
# Area of Polygon

from math import sin
from math import radians

while True:
    m = int(raw_input())
    if m == 0:
        break

    a1, v, sum = (0, 0, 0)
    for i in range(m):
        if i < m - 1:
            v = int(raw_input())
            sum += v
        else:
            v = 360 - sum
        a1 += sin(radians(v))

    n = int(raw_input())

    a2, v, sum = (0, 0, 0)
    for i in range(n):
        if i < n - 1:
            v = int(raw_input())
            sum += v
        else:
            v = 360 - sum
        a2 += sin(radians(v))

    if a1 > a2:
        print 1
    elif a1 < a2:
        print 2
    else:
        print 0

Submission status: Wrong Answer

Solution code:
# Area of Polygon

from math import sin
from math import radians

while True:
    m = int(raw_input())
    if m == 0:
        break

    a1, v, sum = (0.0, 0, 0)
    for i in range(m):
        if i < m - 1:
            v = int(raw_input())
            sum += v
        else:
            v = 360 - sum
        a1 += sin(radians(v)) / 2

    n = int(raw_input())

    a2, v, sum = (0.0, 0, 0)
    for i in range(n):
        if i < n - 1:
            v = int(raw_input())
            sum += v
        else:
            v = 360 - sum
        a2 += sin(radians(v)) / 2

    if a1 > a2:
        print 1
    elif a1 < a2:
        print 2
    else:
        print 0

Submission status: Wrong Answer

Solution code:
# Area of Polygon

from math import sin
from math import radians

while True:
    m = int(raw_input())
    if m == 0:
        break

    a1, v, sum = (0.0, 0, 0)
    for i in range(m):
        if i < m - 1:
            v = int(raw_input())
            sum += v
        else:
            v = 360 - sum
        a1 += sin(radians(v)) / 2.0

    n = int(raw_input())

    a2, v, sum = (0.0, 0, 0)
    for i in range(n):
        if i < n - 1:
            v = int(raw_input())
            sum += v
        else:
            v = 360 - sum
        a2 += sin(radians(v)) / 2.0

    if a1 > a2:
        print 1
    elif a1 < a2:
        print 2
    else:
        print 0

Submission status: Wrong Answer

Solution code:
# Area of Polygon

from math import sin
from math import radians

while True:
    m = int(raw_input())
    if m == 0:
        break

    a1, v, vv = (0.0, 0, 0)
    for i in range(m):
        if i < m - 1:
            v = int(raw_input())
            vv += v
        else:
            v = 360 - vv
        a1 += (sin(radians(v)) / 2)

    n = int(raw_input())

    a2, v, vv = (0.0, 0, 0)
    for i in range(n):
        if i < n - 1:
            v = int(raw_input())
            vv += v
        else:
            v = 360 - vv
        a2 += (sin(radians(v)) / 2)

    if a1 > a2:
        print 1
    elif a1 < a2:
        print 2
    else:
        print 0

Submission status: Wrong Answer

Solution code:
# Area of Polygon

from math import sin
from math import radians

while True:
    m = int(raw_input())
    if m == 0:
        break

    a1, v, vv = (0.0, 0, 0)
    for i in range(m):
        if i < m - 1:
            v = int(raw_input())
            vv += v
        else:
            v = 360 - vv
        a1 += sin(radians(v))

    n = int(raw_input())

    a2, v, vv = (0.0, 0, 0)
    for i in range(n):
        if i < n - 1:
            v = int(raw_input())
            vv += v
        else:
            v = 360 - vv
        a2 += sin(radians(v))

    if a1 > a2:
        print 1
    elif a1 < a2:
        print 2
    else:
        print 0

Submission status: Wrong Answer

Solution code:
from math import *

def S(p):
	return sum([sin(angle*pi/180)/2 for angle in p])

	
while 1:
	m=input()
	if m==0:break
	p1=[int(raw_input()) for i in range(m-1)]
	p1.append(360-sum(p1))
	n=input()
	p2=[int(raw_input()) for i in range(n-1)]
	p2.append(360-sum(p2))
	s1,s2=S(p1),S(p2)
	if    s1>s2: print 1
	elif  s1<s2: print 2
	else:print 0

Submission status: Wrong Answer

Solution code:
from math import *

def S(p):
	return sum([sin(a*pi/180)/2 for a in p])+sin((360-sum(p))*pi/180)

while 1:
	try:
		p1=[int(raw_input()) for i in range(input()-1)]
		p2=[int(raw_input()) for i in range(input()-1)]
		s1,s2=S(p1),S(p2)
		if    s1-s2>1e-10: print 1
		elif  s2-s1>1e-10: print 2
		else:print 0
	except:break

Submission status: Accepted

Solution code:
import math
def g(n):
  x = [int(raw_input()) for _ in [0]*n]
  x += [360-sum(x)]
  f = lambda x: math.sin(x*math.pi/180)
  return sum(map(f, x))
  
while 1:
  n = input()
  if n==0: break
  s1 = g(n-1)
  s2 = g(input()-1)
  if abs(s1-s2)<1e-6: print 0
  elif s1>s2: print 1
  elif s1<s2: print 2

Submission status: Accepted

Solution code:
import math
def g(n):
  x = [int(raw_input()) for _ in [0]*n]
  x += [360-sum(x)]
  return sum(map(lambda x: math.sin(x*math.pi/180), x))
  
while 1:
  n = input()
  if n==0: break
  s1 = g(n-1)
  s2 = g(input()-1)
  if abs(s1-s2)<1e-6: print 0
  elif s1>s2: print 1
  elif s1<s2: print 2

Submission status: Accepted

Solution code:
from decimal import Decimal
import math

def f(c, an):
    s = 0
    for i in range(c):
        th = input()
        ra = Decimal(math.radians(th))
        s += Decimal(math.sin(ra))
        an -= th
    else:
        ra = Decimal(math.radians(an))
        s += Decimal(math.sin(ra))
        return s

while True:
    m = input()
    if m == 0: break
    ms = f(m-1, 360)
    n = input()
    ns = f(n-1, 360)
    if ns < ms:
        print 1
    elif ms < ns:
        print 2
    else:
        print 0

Submission status: Accepted

Solution code:
from math import *
def area(x):
    ret=0.
    theta = 360.
    for i in range(x-1):
        tmp=float(input())
        theta-=tmp
        tmp=tmp*pi/180.
        ret+=(sin(tmp/2)*cos(tmp/2))
    theta=pi*theta/180.
    ret+=sin(theta/2)*cos(theta/2);
    return ret;
while 1:
    m=int(input())
    if m==0:break
    a=area(m)
    b=area(int(input()))
    print(0 if a==b else (1 if a>b else 2))

Submission status: Accepted

Solution code:
from math import sin, pi
def calc(n):
    s = a = 0
    V = []
    for i in range(n-1):
        v = int(input())
        s += v
        a += sin(v*pi/180)
        V.append(v)
    V.append(360-s)
    a += sin((360-s)*pi/180)
    return a, sorted(V)
while 1:
    m = int(input())
    if m == 0:
        break
    a1, V1 = calc(m)
    n = int(input())
    a2, V2 = calc(n)
    if V1 == V2 or a1 == a2:
        print(0)
    elif a1 < a2:
        print(2)
    else:
        print(1)

Submission status: Accepted

Solution code:
import math

ONE_BIGGER_TWO = 1
TWO_BIGGER_ONE = 2
SAME = 0


def calculate_area(input_list):
    last = 360 - sum(input_list)
    input_list.append(last)

    radian_list = [math.radians(item) for item in input_list]
    sin_list = [math.sin(item) for item in radian_list]

    area = math.fsum(sin_list)

    return area


while True:
    input_count = int(input())

    if input_count == 0:
        break

    input_list1 = [int(input()) for _ in range(input_count - 1)]
    area1 = calculate_area(input_list1)

    input_count = int(input())
    input_list2 = [int(input()) for _ in range(input_count - 1)]
    area2 = calculate_area(input_list2)

    if math.isclose(area1, area2):
        print(SAME)
    elif area1 > area2:
        print(ONE_BIGGER_TWO)
    else:
        print(TWO_BIGGER_ONE)

Submission status: Accepted

Solution code:
# AOJ 0166: Area of Polygon
# Python3 2018.6.18 bal4u

import math
M = 0.00872664625997164788461845384244
EPS = 1e-8

a = [0]*2
s = [0.0]*2
while True:
	eof = False
	for i in range(2):
		s[i] = a[i] = 0;
		n = int(input())
		if n == 0:
			eof = True
			break
		for j in range(1, n):
			v = int(input())
			a[i] += v
			s[i] += math.sin(M*v)*math.cos(M*v)
		v = 360-a[i]
		s[i] += math.sin(M*v)*math.cos(M*v)
	if eof: break
	if abs(s[1]-s[0]) <= EPS: print(0)
	elif s[1] >= s[0]: print(2)
	else: print(1);

Submission status: Accepted

Solution code:
import math

def area(n):
    S,r,t=0,10,0
    for i in range(n):
        if i==n-1:
            v=360-t
        else:
            v=input()
            t+=v
        S+=r*r*math.sin(math.pi*v/180)/2
    return S

while True:
    m=input()
    if m==0:break
    S1=area(m)
    n=input()
    S2=area(n)
    if S1>S2:
        print 1
    elif S1<S2:
        print 2
    else:
        print 0

Submission status: Accepted

Solution code:
# Area of Polygon

from math import sin
from math import radians

while True:
    m = int(raw_input())
    if m == 0:
        break

    a1, v, vv = (0.0, 0, 0)
    for i in range(m):
        if i < m - 1:
            v = int(raw_input())
            vv += v
        else:
            v = 360 - vv
        a1 += sin(radians(v)) * 100 / 2

    n = int(raw_input())

    a2, v, vv = (0.0, 0, 0)
    for i in range(n):
        if i < n - 1:
            v = int(raw_input())
            vv += v
        else:
            v = 360 - vv
        a2 += sin(radians(v)) * 100 / 2

    if a1 > a2:
        print 1
    elif a1 < a2:
        print 2
    else:
        print 0

Submission status: Accepted

Solution code:
# Area of Polygon

from math import sin
from math import radians

while True:
    m = int(raw_input())
    if m == 0:
        break

    a1, v, vv = (0.0, 0, 0)
    for i in range(m):
        if i < m - 1:
            v = int(raw_input())
            vv += v
        else:
            v = 360 - vv
        a1 += sin(radians(v)) * 10

    n = int(raw_input())

    a2, v, vv = (0.0, 0, 0)
    for i in range(n):
        if i < n - 1:
            v = int(raw_input())
            vv += v
        else:
            v = 360 - vv
        a2 += sin(radians(v)) * 10

    if a1 > a2:
        print 1
    elif a1 < a2:
        print 2
    else:
        print 0

Submission status: Accepted

Solution code:
from math import *

def S(p):
	return sum([sin(angle*pi/180)/2 for angle in p])

while 1:
	m=input()
	if m==0:break
	p1=[int(raw_input()) for i in range(m-1)]
	p1.append(360-sum(p1))
	n=input()
	p2=[int(raw_input()) for i in range(n-1)]
	p2.append(360-sum(p2))
	s1,s2=S(p1),S(p2)
	if    s1-s2>1e-10: print 1
	elif  s2-s1>1e-10: print 2
	else:print 0

Submission status: Accepted

Solution code:
from math import *

def S(p):
	return sum([sin(a*pi/180) for a in p])+sin((360-sum(p))*pi/180)

while 1:
	try:
		p1=[int(raw_input()) for i in range(input()-1)]
		p2=[int(raw_input()) for i in range(input()-1)]
		s1,s2=S(p1),S(p2)
		if    s1-s2>1e-10: print 1
		elif  s2-s1>1e-10: print 2
		else:print 0
	except:break

Submission status: Runtime Error

Solution code:
import math

def inputData(j):
    A=[]
    t=0
    for i in range(j-1):
        v=input()
        x=math.cos(math.pi*(v+t)/180)
        y=math.sin(math.pi*(v+t)/180)
        t+=v
        A.append((x,y))
    A.append(A[0])
    return A

def calcArea(A):
    return sum((A[i][0]-A[i+1][0])*(A[i][1]+A[i+1][1]) for i in range(m-1))/2

while True:
    m=input()
    if m==0:break
    A=inputData(m)
    n=input()
    B=inputData(n)
    S1,S2=calcArea(A),calcArea(B)
    if S1>S2:
        print 1
    elif S1<S2:
        print 2
    else:
        print 0