CodeEff/ECCO huggingface dataset:
# Original solution
n = int(eval(input()))
ans_t, ans_a = list(map(int,input().split()))
for i in range(n-1):
    t, a = list(map(int,input().split()))
    now_t, now_a = t, a
    q = True
    while q:
        if ans_t <= now_t and ans_a <= now_a:
            q = False
            ans_t = now_t
            ans_a = now_a
        else:
            now_t += t
            now_a += a

print((ans_a + ans_t))

# Optimized solution
n = int(eval(input()))
ans_t, ans_a = list(map(int,input().split()))
for i in range(n-1):
    t, a = list(map(int,input().split()))

    if ans_t % t == 0:
        p = ans_t//t
    else:
        p = ans_t//t + 1
    if ans_a % a == 0:
        q = ans_a // a
    else:
        q = ans_a// a + 1

    r = max(p, q)
    ans_a = a * r
    ans_t = t * r


print((ans_a + ans_t))
# Original solution
N = int(eval(input()))
TA = [[int(x) for x in input().split()]for _ in range(N)]
t = 1
a = 1

for i in TA:
    j = 1
    while(t>i[0]*j or a>i[1]*j):
        j+=1
    t = i[0]*j
    a = i[1]*j

print((t+a))


# Optimized solution
N = int(eval(input()))
TA = [[int(x) for x in input().split()]for _ in range(N)]
t = 1
a = 1

for i in TA:
    j = max(t//i[0],a//i[1])
    if(t>i[0]*j or a>i[1]*j):
        j+=1
    t = i[0]*j
    a = i[1]*j

print((t+a))
# Original solution
import sys
readline = sys.stdin.readline

N = int(readline())
T, A = list(map(int,readline().split()))

import math
for i in range(N - 1):
  t,a = list(map(int,readline().split()))
  i = 1
  while True:
    if t * i >= T and a * i >= A:
      T,A = t * i,a * i
      break
    i += 1

print((T + A))

# Optimized solution
import sys
readline = sys.stdin.readline

N = int(readline())
T, A = list(map(int,readline().split()))

for i in range(N - 1):
  t,a = list(map(int,readline().split()))
  # newT % t == 0 , newA % a == 0である
  # newT >= T , newA >= Aである
  
  # T以上の、tの倍数の最小値 = T / tの切り上げ
  minT = ((T + t - 1) // t) * t
  minA = minT * a // t
  if minA >= A:
    T,A = minT,minA
    continue
  minA = ((A + a - 1) // a) * a
  minT = minA * t // a
  T,A = minT,minA
  
print((T + A))
# Original solution
def gcd(a, b): 
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

def lcm(a, b):
    return((a*b)//gcd(a,b))

def main():
    n=int(eval(input()))
    a=1
    b=1
    for _ in range(n):
        x,y = list(map(int,input().split()))
        x1=x
        y1=y
        while x1<a or y1<b:
            x1+=x
            y1+=y
        a=x1
        b=y1
    print((a+b))
        

if __name__ == "__main__":
    main()


# Optimized solution
def gcd(a, b): 
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

def lcm(a, b):
    return((a*b)//gcd(a,b))

def main():
    n=int(eval(input()))
    a=1
    b=1
    for _ in range(n):
        x,y = list(map(int,input().split()))
        n=a//x
        m=b//y
        if a%x!=0:
            n+=1
        if b%y!=0:
            m+=1
        a=max(n,m)*x
        b=max(n,m)*y
    print((a+b))
        

if __name__ == "__main__":
    main()
# Original solution
n=int(eval(input()))
from math import gcd
a,b=list(map(int,input().split()))
temp=a+b
for i in range(1,n):
    c,d=list(map(int,input().split()))
    i=c+d
    j=i
    c1=c
    d1=d
    while i<temp or c<a or d<b:

        i+=j
        c+=c1
        d+=d1
        
        
        
    temp=i
    a=c
    b=d
    
print(temp)

# Optimized solution
n=int(eval(input()))
from math import gcd
a,b=list(map(int,input().split()))
temp=a+b
for i in range(1,n):
    c,d=list(map(int,input().split()))
    j=c+d
    
    x=max(a-c,0)//c
    if max(a-c,0)%c!=0:
        x+=1
    y=max(b-d,0)//d
    if max(b-d,0)%d!=0:
        y+=1
    z=max(temp-j,0)//j
    if max(temp-j,0)%j!=0:
        z+=1
    l=[x,y,z]
    temp=max(l)*j+j
    a=max(l)*c+c
    b=max(l)*d+d
        
print(temp)
# Original solution
N=int(eval(input()))
T=[]
A=[]
for i in range(N):
    t,a=list(map(int,input().split()))
    T.append(t)
    A.append(a)

Tnow=T[0]
Anow=A[0]
ans=Tnow+Anow

for i in range(1,N):
    t=T[i]
    a=A[i]
    tempans=(t+a+ans-1)//(t+a)*(t+a)
    while True:
        tempT=tempans*t//(t+a)
        tempA=tempans*a//(t+a)
        if tempT>=Tnow and tempA>=Anow:
            ans=tempans
            Tnow=tempT
            Anow=tempA
            break
        else:
            tempans+=t+a
print(ans)



# Optimized solution
N=int(eval(input()))
T=[]
A=[]
for i in range(N):
    t,a=list(map(int,input().split()))
    T.append(t)
    A.append(a)

Tnow=T[0]
Anow=A[0]


for i in range(1,N):
    t=T[i]
    a=A[i]
    t1=(Tnow+t-1)//t*t
    a1=t1//t*a
    a2=(Anow+a-1)//a*a
    t2=a2//a*t
    if a1<Anow:
        Tnow=t2
        Anow=a2
    elif t2<Tnow:
        Tnow=t1
        Anow=a1
    elif t1+a1<=t2+a2:
        Tnow=t1
        Anow=a1
    else:
        Tnow=t2
        Anow=a2
print((Tnow+Anow))
# Original solution
#! /usr/bin/env python3

def f(a, b, c, d):
    n = 1
    while a > c * n or b > d * n : n += 1
    return c * n, d * n
    
def main():
    a, b = 0, 0
    for i in range(int(eval(input()))):
        c, d = list(map(int, input().split()))
        a, b = f(a, b, c, d)
    print((a+b))

if __name__ == '__main__':
    main()

# Optimized solution
#! /usr/bin/env python3

def f(a, b, c, d):
    n = max(1,a//c, b//d)
    while a > c * n or b > d * n : n += 1
    return c * n, d * n
    
def main():
    a, b = 0, 0
    for i in range(int(eval(input()))):
        c, d = list(map(int, input().split()))
        a, b = f(a, b, c, d)
    print((a+b))

if __name__ == '__main__':
    main()
# Original solution
N = int(eval(input()))

L = []
for i in range(N):
    L.append(tuple(map(int, input().split())))

nowT = L[0][0]
nowA = L[0][1]
for i in range(1, N):
    tmpT = L[i][0]
    tmpA = L[i][1]
    mul = 2
    while not(tmpT >= nowT and tmpA >= nowA):
        tmpT = L[i][0] * mul
        tmpA = L[i][1] * mul
        mul += 1
    nowT = tmpT
    nowA = tmpA

print((nowT + nowA))


# Optimized solution
N = int(eval(input()))

nowT = 1
nowA = 1
for i in range(N):
    nextT, nextA = list(map(int, input().split()))

    # mul = max(ceil(nowT / nextT), ceil(nowA / nextA))
    mul = max(-(-nowT // nextT), -(-nowA // nextA))
    nowT = nextT * mul
    nowA = nextA * mul

print((nowT + nowA))
# Original solution
N = int(eval(input()))
P = [0,0]

for i in range(N):
  Q = list(map(int,input().split()))
  t = Q[0]
  a = Q[1]
  m = 1
  while True:
    t = Q[0] * m
    a = Q[1] * m
    if t >= P[0] and a >= P[1]:
      P[0] = t
      P[1] = a
      break
    m += 1

print((sum(P)))

# Optimized solution
N = int(eval(input()))
P = [1,1]

for i in range(N):
  Q = list(map(int,input().split()))
  t = Q[0]
  a = Q[1]
  m = max(P[0]//t,P[1]//a,1)
  while True:
    t = Q[0] * m
    a = Q[1] * m
    if t >= P[0] and a >= P[1]:
      P[0] = t
      P[1] = a
      break
    m += 1

print((sum(P)))
# Original solution
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

def run():
    N, *A = list(map(int, read().split()))
    dic = defaultdict(lambda:0)
    for a in A:
        dic[a] += 1
    G = {}

    for key in sorted(list(dic.keys())):
        G[N] = key
        N -= dic[key]

    criteria = 0
    for key in list(G.keys()):
        for _ in range(G[key]):
            criteria ^= key

    if not criteria:
        print('second')
    else:
        print('first')
if __name__ == "__main__":
    run()


# Optimized solution
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

def run():
    N, *A = list(map(int, read().split()))
    dic = defaultdict(lambda:0)
    for a in A:
        dic[a] += 1
    G = {}

    for key in sorted(list(dic.keys())):
        G[N] = key
        N -= dic[key]

    criteria = 0
    for key in list(G.keys()):
        if G[key] % 2:
            criteria ^= key

    if not criteria:
        print('second')
    else:
        print('first')
if __name__ == "__main__":
    run()
# Original solution
import sys
input = sys.stdin.readline
from collections import *

def dfs(x, y):
    if x==0 and y==0:
        t[x][y] = False
        return False
    
    if x>=1:
        t[x][y] |= not dfs(x-1, y)
        
    if y>=1:
        t[x][y] |= not dfs(x, y-1)
        
    if min(x, y)>=1:
        t[x][y] |= not dfs(x-1, y-1)
   
    return t[x][y]
    
t = [[False]*7 for _ in range(7)]

for i in range(7):
    for j in range(7):
        dfs(i, j)

"""
for ti in t:
    print(*ti)
"""

N = int(eval(input()))
flag = True

for _ in range(N):
    a = int(eval(input()))
    
    if a%2==1:
        flag = False
        
if flag:
    print('second')
else:
    print('first')

# Optimized solution
import sys
input = sys.stdin.readline

"""
def dfs(x, y):
    if x==0 and y==0:
        return False
        
    res = False
    
    if x>0:
        res |= not dfs(x-1, y)
    
    if y>0:
        res |= not dfs(x, y-1)
    
    if min(x, y)>0:
        res |= not dfs(x-1, y-1)
    
    return res
    
t = [[False]*5 for _ in range(5)]

for i in range(5):
    for j in range(5):
        t[i][j] = dfs(i, j)

for ti in t:
    print(*ti)
"""

N = int(eval(input()))
a = [int(eval(input())) for _ in range(N)]

for ai in a:
    if ai%2==1:
        print('first')
        exit()

print('second')
# Original solution
n = int(eval(input()))
for i in range(n):
    a = int(eval(input()))
    if a%2 == 1:
        print('first')
        exit()
else:
    print('second')


# Optimized solution
n = int(eval(input()))
A = [int(eval(input())) for _ in range(n)]

for a in A:
    if a != 1:
        break
else:
    print('first')
    exit()

cnt = 0
for a in A:
    if a%2 == 0:
        cnt += 1
if cnt == n:
    print('second')
else:
    print('first')
# Original solution
n=int(eval(input()))
ans="second"
for i in range(n):
  if int(eval(input()))%2:ans="first"
print(ans)

# Optimized solution
n=int(eval(input()))
a=[int(eval(input()))%2 for _ in range(n)]
if 1 in a:print("first")
else:print("second")
# Original solution
print(("second" if all(int(eval(input()))%2 == 0 for i in range(int(eval(input())))) else 'first'))


# Optimized solution
import sys
print(('second' if all(i%2==0 for i in list(map(int,sys.stdin))[1:]) else 'first'))
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
if all(a % 2 == 0 for a in A):
    print("second")
else:
    print("first")


# Optimized solution
def main() -> None:
    N = int(eval(input()))
    P = [int(eval(input())) for _ in range(N)]
    print(("first" if any(x % 2 == 1 for x in P) else "second"))


if __name__ == '__main__':
    main()
# Original solution
import collections
N = int(eval(input()))
a = [0] * N
for i in range(N):
    a[i] = int(eval(input()))
def solve():
    return any(x % 2 == 1 for x in a)
print(('first' if solve() else 'second'))


# Optimized solution
_,*a=open(0);print(('first' if any(int(x)%2 for x in a)else'second'))
# Original solution
'''input
3
1
30000
20000
'''
import time
import math

n = int(eval(input()))
print(("second" if all([int(eval(input())) % 2 == 0 for i in range(n)]) else "first"))


# Optimized solution
print(("second" if all([int(eval(input())) % 2 == 0 for i in range(int(eval(input())))]) else "first"))
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
cnt = 0
for i in range(N):
    if A[i]%2==1:
        cnt += 1
if cnt>0:
    print("first")
else:
    print("second")

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
flag = 0
for i in range(N):
    if A[i]%2==1:
        flag = 1
        break
if flag==1:
    print("first")
else:
    print("second")
# Original solution
import sys
def input(): return sys.stdin.readline().strip()
def main():
    N = int(input())
    A = (int(input()) for _ in range(N))
    print("second") if all(( a%2==0 for a in A)) else print("first")
if __name__ == "__main__":
    main()


# Optimized solution
import sys
def input(): return sys.stdin.readline().strip()
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    print("second") if all(( a%2==0 for a in A)) else print("first")
if __name__ == "__main__":
    main()
# Original solution
import sys
def input(): return sys.stdin.readline().strip()
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    print("second") if all(( a%2==0 for a in A)) else print("first")
if __name__ == "__main__":
    main()


# Optimized solution
import sys
def input(): return sys.stdin.readline().strip()
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    print("first") if any([a%2 for a in A]) else print("second")
if __name__ == "__main__":
    main()
# Original solution

def main():
	n = int(eval(input()))
	ans =0
	f=0
	for i in range(0 , n):
		t = int(eval(input()))
		if t%2!=0:
			f=1
	if f==1:
		print("first")
	else:
		print("second")
if __name__=="__main__":
	main()

# Optimized solution
# if any tree contains an odd no of table then first is the winner
# First strategy is to make a tree with odd no of apples
# second strategy is to make a tree with even no of apples
# if the tree doesn't contain any odd apples when first takes an apples he will make it odd
# second would try to make it even by taking one apple from that tree
def main():
	n = int(eval(input()))
	ans =0
	f=0
	for i in range(0 , n):
		t = int(eval(input()))
		if t%2!=0:
			f=1
	if f==1:
		print("first")
	else:
		print("second")
if __name__=="__main__":
	main()
# Original solution
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())

def main():
  n=I()
  l=[I() for _ in range(n)]

  for x in l:
    if x%2==1:
      return 'first'
  return 'second'

# main()
print((main()))


# Optimized solution
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())

def main():
  # 最後に食べたら勝ち
  # 1を引けば勝ち
  # 奇数調整をする
  # 相手に全て偶数を与えるよう調整する
  # all偶数だと負け

  n=I()
  f=False
  for _ in range(n):
    if I()%2==1:
      f=True
  if f:
    return 'first'
  return 'second'

# main()
print((main()))
# Original solution
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())

def main():
  # 最後に食べたら勝ち
  # 1を引けば勝ち
  # 奇数調整をする
  # 相手に全て偶数を与えるよう調整する
  # all偶数だと負け

  n=I()
  f=False
  for _ in range(n):
    if I()%2==1:
      f=True
  if f:
    return 'first'
  return 'second'

# main()
print((main()))


# Optimized solution
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())

def main():
  N=I()
  a=[I() for _ in range(N)]

  for x in a:
    if x%2!=0:
      return 'first'

  return 'second'

# main()
print((main()))
# Original solution
import sys

read = sys.stdin.read

N, *a = list(map(int, read().split()))
a = [i % 2 for i in a]
if 1 in a:
    print('first')
else:
    print('second')


# Optimized solution
import sys

read = sys.stdin.read

N, *a = list(map(int, read().split()))
a = [i for i in a if i % 2 == 1]
if len(a) > 0:
    print('first')
else:
    print('second')
# Original solution
N=int(input())
P=list(map(int, input().split()))
X=[0]+list(map(int, input().split()))
ko=[[] for _ in range(N+1)]
for i, p in enumerate(P, 2):
  ko[p].append(i)
  
def f(p):
  n=len(ko[p])
  if n==0:
    return X[p], 0
  
  dp=[[float('inf')]*5001 for _ in range(n+1)]
  dp[0][0]=0
  for i, c in enumerate(ko[p], 1):
    a, b=f(c)
    for j in range(a, 5001):
      dp[i][j]=min(dp[i][j], dp[i-1][j-a]+b)
    for j in range(b, 5001):
      dp[i][j]=min(dp[i][j], dp[i-1][j-b]+a)
      
  out=min(dp[-1][:X[p]+1])
  if out==float('inf'):
    print('IMPOSSIBLE')
    exit()
  elif out>X[p]:
    return out, X[p]
  else:
    return X[p], out
  
print('POSSIBLE') if min(f(1))<=X[1] else print('IMPOSSIBLE')


# Optimized solution
N=int(input())
P=list(map(int, input().split()))
X=[0]+list(map(int, input().split()))
ko=[[] for _ in range(N+1)]
for i, p in enumerate(P, 2):
  ko[p].append(i)
  
def f(p):
  n=len(ko[p])
  if n==0:
    return X[p], 0
  
  dp=[[float('inf')]*(X[p]+1) for _ in range(n+1)]
  dp[0][0]=0
  for i, c in enumerate(ko[p], 1):
    a, b=f(c)
    for j in range(a, X[p]+1):
      dp[i][j]=min(dp[i][j], dp[i-1][j-a]+b)
    for j in range(b, X[p]+1):
      dp[i][j]=min(dp[i][j], dp[i-1][j-b]+a)
      
  out=min(dp[-1])
  if out==float('inf'):
    print('IMPOSSIBLE')
    exit()
  elif out>X[p]:
    return out, X[p]
  else:
    return X[p], out
  
print('POSSIBLE') if min(f(1))<=X[1] else print('IMPOSSIBLE')
# Original solution
from itertools import product

n = int(eval(input()))
P = [0, 0] + [int(i) for i in input().split()]
X = [0] + [int(i) for i in input().split()]

C = [[] for i in range (n+1)]

for i, p in enumerate(P):
    C[p].append(i)

def dfs(i):
    if not C[i]:
        return X[i], 0

    A = []
    
    for c in C[i]:
        A.append(dfs(c))

    S = 0
    for a in A:
        S += sum(a)

    B = []
    for bits in range(2**(len(A))):
        a = 0
        for j, c in enumerate(A):
            a += c[bits >> j & 1]
            if a > X[i]:
                break
        if a <= X[i]:
            B.append(a)
    if not B:
        print('IMPOSSIBLE')
        exit()

    return X[i], S - max(B)

dfs(1)
print('POSSIBLE')

# Optimized solution
from itertools import product

n = int(eval(input()))
P = [0, 0] + [int(i) for i in input().split()]
X = [0] + [int(i) for i in input().split()]

C = [[] for i in range (n+1)]

for i, p in enumerate(P):
    C[p].append(i)

def dfs(i):
    if not C[i]:
        return X[i], 0

    A = []
    
    for c in C[i]:
        A.append(dfs(c))

    S = 0
    for a in A:
        S += sum(a)

    dp = [[False]*(X[i]+1) for j in range(len(A)+1)]
    dp[0][0] = True

    for j in range(len(A)):
        for k in range(X[i]+1):
            a, b = A[j]
            if a <= k and dp[j][k-a]:
                dp[j+1][k] = True
            elif b <= k and dp[j][k-b]:
                dp[j+1][k] = True
        if not any(dp[j+1]):
            print('IMPOSSIBLE')
            exit()

    b = 0
    for j in range(X[i], -1, -1):
        if dp[len(A)][j]:
            b = j
            break

    return X[i], S - b

dfs(1)
print('POSSIBLE')
# Original solution
#copy for experience
import sys
sys.setrecursionlimit(10**8)
N=int(eval(input()))
P=[int(i) for i in input().split()]
X=[int(i) for i in input().split()]
table=[[] for i in range(N)]
for i in range(N-1):
    table[P[i]-1].append(i+1)
dp=[0]*N #shiro

def tree(pa):
    for i in table[pa]:
        tree(i)
    t=len(table[pa])
    if t==0:
        return
    T=set()
    s=0
    for i in range(t):
        x=table[pa][i]
        s+=X[x]+dp[x]
        if i==0:
            if X[x]<=X[pa]:
                T.add(X[x])
            if dp[x]<=X[pa]:
                T.add(dp[x])
            continue
        S=set()
        for k in T:
            if k+X[x]<=X[pa]:
                S.add(k+X[x])
            if k+dp[x]<=X[pa]:
                S.add(k+dp[x])
        T=S
    if len(T)==0:
        print('IMPOSSIBLE')
        sys.exit()
    dp[pa]=s-max(T)
    return

tree(0)    
print('POSSIBLE')


# Optimized solution
#copy for experience
# E
N = int(eval(input()))
P_list = list(map(int, input().split()))
X_list = list(map(int, input().split()))

# graph
child_list = [[] for _ in range(N+1)]
for i in range(2, N+1):
    child_list[P_list[i-2]].append(i)

# from root
# minimize local total weight

color1 = [0]+X_list
color2 = [0]*(N+1)

# solve knapsack
def solve_knapsack(L, M):
    min_acc = sum([min(color1[j], color2[j]) for j in L])
    if min_acc > M:
        return -1
    else:
        add_can = M - min_acc
        add_set = set([0])
        for j in L:
            add_j = max(color1[j], color2[j]) - min(color1[j], color2[j])
            add_set_ = set(add_set)
            for s in add_set:
                if s + add_j <= add_can:
                    add_set_.add(s + add_j)
            add_set = add_set_
        
        total = sum([color1[j]+color2[j] for j in L])
        return total - max(add_set) - min_acc

res = "POSSIBLE"

for i in range(N, 0, -1):
    if len(child_list[i]) == 0:
        pass
    elif len(child_list[i]) == 1:
        j = child_list[i][0]
        if min(color1[j], color2[j]) > X_list[i-1]:
            res = "IMPOSSIBLE"
            break
        elif max(color1[j], color2[j]) > X_list[i-1]:
            color2[i] = max(color1[j], color2[j])
        else:
            color2[i] = min(color1[j], color2[j])
    else:
        c2 = solve_knapsack(child_list[i], X_list[i-1])
        if c2 < 0:
            res = "IMPOSSIBLE"
            break
        else:
            color2[i] = c2
    
print(res)
# Original solution
while True:
    n, r = list(map(int, input().split()))
    if not n:
        break

    sheets = sorted(tuple(map(int, input().split())) for _ in range(n))
    table = [[0, 0, 0] for _ in range(10001)]

    for x1, y1, x2, y2 in sheets:
        for y in range(y1, y2):
            t = table[y]
            rx = t[1]
            if not rx or rx < x1:
                t[0] += x2 - x1
                t[1] = x2
                t[2] += 2
            elif rx < x2:
                t[0] += x2 - rx
                t[1] = x2

    print((sum(t[0] for t in table)))
    if r == 1:
        continue

    around = 0
    prev_w = 0
    for y, (w, rx, e) in enumerate(table):
        around += abs(w - prev_w) + (e if w else 0)
        prev_w = w
    around += prev_w

    print(around)

# Optimized solution
while True:
    n, r = list(map(int, input().split()))
    if not n:
        break

    sheets = sorted(tuple(map(int, input().split())) for _ in range(n))

    table_c = [0] * 10001
    table_r = [0] * 10001
    table_e = [0] * 10001

    for x1, y1, x2, y2 in sheets:
        for y in range(y1, y2):
            rx = table_r[y]
            if rx < x1 or not rx:
                table_c[y] += x2 - x1
                table_r[y] = x2
                table_e[y] += 2
            elif rx < x2:
                table_c[y] += x2 - rx
                table_r[y] = x2

    print((sum(table_c)))
    if r == 1:
        continue

    around = 0
    prev_w = 0
    for y, w in enumerate(table_c):
        around += abs(w - prev_w) + (table_e[y] if w else 0)
        prev_w = w
    around += prev_w

    print(around)