Problem:


Mysterious Gems

宇宙暦 1603〜1867 年，人々はその時代のことを EDO 時代と呼ぶ．EDO とは当時最先端の宇宙航行技術，Enhanced Driving Operation のことであり、1603 年に Dr.Izy によって開発された．

あなたは宇宙冒険家であり，宇宙を飛び回って様々な惑星を冒険していた．その冒険の途中で，あなたはとても不思議な惑星を発見した．その惑星には，至るところに七色に輝く不思議な宝石が落ちていた．あなたはその惑星への降下を試みようと考えたが，重大な問題のためにそれは不可能であることがわかった．その惑星の空気には，人間が触れただけで即死してしまうような猛毒の成分が含まれていたのだ．

そこで，あなたはロボットを使って宝石を回収することを考えついた．あなたはその惑星の周回軌道にて待機する．そして，降下させたロボットを遠隔操作することによって宝石を回収するのだ．あなたは，ロボットに「移動する方向」と「移動する距離」の組からなる命令の列によってロボットを遠隔操作する．ロボットは移動経路上（到達点を含む）に宝石を見つけると，それらを全て回収する．

あなたの仕事は，ロボットが与えられた全ての命令の実行を終えたときに，全ての宝石を回収することができたかどうかを判定するプログラムを書くことである．

なお，ロボットが不思議な宝石を回収する範囲はそれほど広くない．そのため，ロボットが移動する範囲は全て 2 次元の平面で表すことができる．そして，ロボットが移動する範囲は (0,0) および (20,20) をそれぞれ左下隅および右上隅とする正方形の内部（境界線を含む）である．ロボットは常に範囲の中央，すなわち (10,10) の座標に降下する．また，全ての宝石は中央以外の格子点上にあることが保証されている．

Input

入力は複数のデータセットにより構成される．

それぞれのデータセットの先頭行には，単一の正の整数 N (1 <= N <= 20) が含まれる。これはロボットが移動可能な範囲内にある不思議な宝石の個数を表す．次の N 行には，それぞれ xi および yi (0 <= xi , yi <= 20) が含まれ，これは i 番目の不思議な宝石の落ちている座標を表す．なお，1 つの場所に複数の宝石が落ちていることはない．

次の行には単一の整数 M (1 <= M <= 30) が含まれ，これはロボットに与えた命令の個数を表す．この後の M 行にはそれぞれ dj とひとつの正の整数 lj が含まれる．これは j 番目の命令における方向および移動量を表す．ただし，方向は N，E，S，W のいずれかの文字であり，順に北，東，南，西を表す（北は y 軸の正方向，東は x 軸の正方向）．なお，ロボットが移動可能な範囲を超えるような命令は与えられないことが保証されている．

入力は N = 0 のときに終了し，これはデータセットに含まれない．

Output

それぞれのデータセットについて，ロボットが全ての宝石を収集できるときは「Yes」と，そうでないときは「No」と 1 行に出力しなさい．

Sample Input

2
10 11
11 12
2
N 2
E 1
2
10 11
11 12
2
N 2
W 1
3
0 15
5 10
5 15
5
W 10
S 10
N 20
E 10
S 10
0

Output for the Sample Input

Yes
No
No



Sample input:
2
10 11
11 12
2
N 2
E 1
2
10 11
11 12
2
N 2
W 1
3
0 15
5 10
5 15
5
W 10
S 10
N 20
E 10
S 10
0


Sample output:
Yes
No
No

Submission status: Accepted

Solution code:
# your code goes here

while True:
	n = raw_input()
	if n == "0":
		break

	n = int(n)
	jewels = []

	for i in xrange(n):
		string = raw_input()
		x = string.split(" ")
		jewels.append(tuple(map(lambda y : int(y), x)))
	
	m = raw_input()
	
	m = int(m)
	ops = []
	
	for j in xrange(m):
		string = raw_input()
		x = string.split(" ")
		#print x
		ops.append(tuple(x))
	
	#print jewels
	#print ops
	
	pos = (10,10)
	
	path = []
	path.append(pos)
	
	for direct, amount in ops:
		for i in xrange(int(amount)):
			if direct == "N":
				pos = (pos[0], pos[1]+1)
			elif direct == "E":
				pos = (pos[0]+1, pos[1])
			elif direct == "W":
				pos = (pos[0]-1, pos[1])
			elif direct == "S":
				pos = (pos[0], pos[1]-1)
			path.append(pos)
	isIn = []
	for jx, jy in jewels:
		isIn.append((jx, jy) in path)
		
	if all(isIn):
		print "Yes"
	else:
		print "No"

Submission status: Accepted

Solution code:
import sys
f = sys.stdin



func = {
'N':lambda x, y:(x, y + 1),
'S':lambda x, y:(x, y - 1),
'E':lambda x, y:(x + 1, y),
'W':lambda x, y:(x - 1, y)}

while True:
    n = int(f.readline())
    if n == 0:
        break
    gems = {tuple(map(int, f.readline().split())):False for _ in range(n)}
    m = int(f.readline())
    pos = (10, 10)
    for way, step in [f.readline().split() for _ in range(m)]:
        for i in range(int(step)):
            pos = func[way](*pos)
            try:
                gems[pos] = True
            except KeyError:
                pass

    print('Yes' if all(gems.values()) else 'No')

Submission status: Accepted

Solution code:
comm = {
        'N': ( 0, 1),
        'E': ( 1, 0),
        'W': (-1, 0),
        'S': ( 0,-1),
        }
while True:
    n = input()
    if n==0:
        break
    p = [[0]*21 for i in xrange(21)]
    for i in xrange(n):
        x, y = map(int, raw_input().split())
        p[y][x] = 1
    m = input()
    px, py = 10, 10
    count = 0
    for i in xrange(m):
        d, l = raw_input().split(); l = int(l);
        com = comm[d]
        while l>0:
            px += com[0]; py += com[1];
            if p[py][px]==1:
                p[py][px] = 0
                count += 1
            l -= 1
    print "Yes" if count==n else "No"

Submission status: Accepted

Solution code:
dirs = { 'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}

while True:
	area = [[False for j in range(21)] for i in range(21)]

	n = int(input())
	if n == 0:
		break
	for i in range(n):
		x, y = map(int, input().split())
		area[x][y] = True

	(x, y) = (10, 10)
	count = 0
	for i in range(int(input())):
		d, l = input().split()
		for j in range(int(l)):
			x += dirs[d][0]
			y += dirs[d][1]
			if area[x][y]:
				area[x][y] = False
				count += 1
	if count == n:
		print("Yes")
	else:
		print("No")

Submission status: Accepted

Solution code:

moves = {"N": (0, 1),
         "S": (0, -1),
         "E": (1, 0),
         "W": ( -1, 0)}

while True:
    n = int(raw_input())

    if n == 0:
        break

    houseki = set()
    pos = (10, 10)

    for i in range(n):
        x, y = map(int, raw_input().split())
        houseki.add((x, y))

    m = int(raw_input())
    for j in range(m):
        d, cnt = raw_input().split()
        move = moves[d]

        for k in range(int(cnt)):
            pos = (pos[0] + move[0], pos[1] + move[1])

            if pos in houseki:
                houseki.remove(pos)

    if len(houseki) == 0:
        print "Yes"
    else:
        print "No"

Submission status: Accepted

Solution code:
while True:
    pos=[[0]*2 for i in range(21)]
    N =input()
    if N == 0: break
    for i in range(N):
        l = map(int, raw_input().split())
        pos[i][0]=l[0]
        pos[i][1]=l[1]
    initx=10
    inity=10
    K = input()
    count=0
    for i in range(K):
        dx=0
        dy=0
        d,l = raw_input().split()
        l = int(l)
        if d == 'N': dy=1
        if d == 'S': dy=-1
        if d == 'W': dx=-1
        if d == 'E': dx=1

        for j in range(l):
         initx=initx+dx
         inity=inity+dy
         for k in range(N):
             if initx==pos[k][0] and inity==pos[k][1]:
                 count+=1
                 pos[k][0]=pos[k][1]=-1
    if count==N: print 'Yes'
    else: print 'No'

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
import collections


class Solver(object):

    deltas = {"N": (0, 1), "E": (1, 0), "S": (0, -1), "W": (-1, 0)}

    def __init__(self, gems, initial_point=(10, 10)):
        self.gems = gems
        self.current_point = initial_point
        self.visited = collections.defaultdict(bool)

    def move(self, direction, distance):
        (x0, y0) = self.current_point
        (dx, dy) = self.deltas[direction]
        for i in range(1, distance + 1):
            (x, y) = (x0 + i * dx, y0 + i * dy)
            self.current_point = (x, y)
            self.visited[(x, y)] = True

    def moves(self, commands):
        for direction, distance in commands:
            self.move(direction, distance)

    def judge(self):
        for gem in self.gems:
            if not self.visited[gem]:
                return False
        else:
            return True


def main():
    while True:
        n = int(input())
        if n == 0:
            break
        gems = [tuple(map(int, input().split())) for _ in range(n)]
        m = int(input())
        commands = []
        for _ in range(m):
            direction, distance = input().split()
            distance = int(distance)
            commands.append((direction, distance))
        solver = Solver(gems)
        solver.moves(commands)
        if solver.judge():
            print("Yes")
        else:
            print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
dm = {'N': (0, 1), 'S': (0, -1), 'E': (1, 0), 'W': (-1, 0)}

while True:
    n = int(input())
    if not n:
        break
    plain = [[False] * 21 for _ in range(21)]
    for _ in range(n):
        x, y = map(int, input().split())
        plain[x][y] = True

    cx, cy = 10, 10
    plain[10][10] = False

    m = int(input())
    for _ in range(m):
        d, l = input().split()
        dx, dy = dm[d]
        for _ in range(int(l)):
            cx += dx
            cy += dy
            plain[cx][cy] = False

    for p in plain:
        if any(p):
            print('No')
            break
    else:
        print('Yes')

Submission status: Accepted

Solution code:
while True:
    n = int(raw_input())
    if n == 0: break
    trea = [0]*n
    for i in range(n):
        trea[i] = map(int, raw_input().split())
    x,y = 10,10
    thr = [[0 for i in range(21)] for j in range(21)]
    m = int(raw_input())
    for i in range(m):
        line = raw_input().split()
        d = int(line[1])
        if line[0] == 'N':
            for i in range(1,d+1):
                thr[x][y+i] = 1
            y += d
        if line[0] == 'E':
            for i in range(1,d+1):
                thr[x+i][y] = 1
            x += d
        if line[0] == 'S':
            for i in range(1,d+1):
                thr[x][y-i] = 1
            y -= d
        if line[0] == 'W':
            for i in range(1,d+1):
                thr[x-i][y] = 1
            x -= d
    for i in range(n):
        if thr[trea[i][0]][trea[i][1]] == 0:
            print "No"
            break
        if i == n-1:
            print "Yes"

Submission status: Accepted

Solution code:
while True:
    n = int(raw_input())
    if n == 0: break
    trea = [0]*n
    for i in range(n):
        trea[i] = map(int, raw_input().split())
    x,y = 10,10
    thr = [[0 for i in range(21)] for j in range(21)]
    m = int(raw_input())
    for i in range(m):
        line = raw_input().split()
        news = line[0]
        d = int(line[1])
        dire = {"N":[0,1], "E":[1,0], "W":[-1,0], "S":[0,-1]}
        for i in range(1,d+1):
            thr[x+i*dire[news][0]][y+i*dire[news][1]] = 1
        x += d * dire[news][0]
        y += d * dire[news][1]

    for i in range(n):
        if thr[trea[i][0]][trea[i][1]] == 0:
            print "No"
            break
        if i == n-1:
            print "Yes"

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu May 12 18:42:47 2016
"""

class Plane:
    def __init__(self, num_of_jewels):
        self.jewels = []
        for i in range(21):
            self.jewels.append([False] * 21)
        self.nj = num_of_jewels
        self.robot = [10, 10]
    def putJewels(self, x, y):
        self.jewels[x][y] = True
    def moveRobot(self, direction, str_distance):
        distance = int(str_distance)
        axe, dir = {'N':[1, 1], 'S':[1, -1], 'E':[0, 1], 'W':[0, -1]}[direction]
        for dis in range(1, distance+1):
            self.robot[axe] += dir
            if self.jewels[self.robot[0]][self.robot[1]] == True:
                self.nj -= 1
                self.jewels[self.robot[0]][self.robot[1]] = False
                
    def judge(self):
        if self.nj == 0:
            return True
        else:
            return False
            
if __name__ == '__main__':
    while True:
        n = int(input())
        if n == 0:
            break
        
        p = Plane(n)
        for i in range(n):
            x, y = map(int, input().split())
            p.putJewels(x, y)
        
        m = int(input())
        for i in range(m):
            d1, d2 = input().split()
            p.moveRobot(d1, d2)
            
        print({True:'Yes', False:'No'}[p.judge()])

Submission status: Accepted

Solution code:
#?????????????????§?¨?x,y
x = 10
y = 10
i = 0
j = 0
roboPos = []
#?????????????????????????????°
gemPos = 0
#??§?¨????????????????????????°
orderPos = 0
#??????????????°
gemNum = 0
#??????????????°
orderNum = 0
#??????????????????
cnt = 0
#???????????§?¨?
gemXY = []
#???????????????????????§?¨?
gemCollectedXY = []

def get_input():
    while True:
        try:
            a = input()
            if a == "0":
                break
            yield ''.join(a)
        except EOFError:
            break
if __name__ == "__main__":
    array = list(get_input())

    while orderPos + orderNum < len(array):

        gemNum = int(array[orderPos + orderNum])
        gemPos = orderPos + orderNum + 1
        #print("??????????????°???{0}".format(gemNum))
        for i in range(gemPos,gemPos+gemNum):
            gem_x,gem_y = array[i].split()
            gem_x,gem_y = int(gem_x),int(gem_y)
            gemXY.append([gem_x,gem_y])
            #print("??????????????????{0},{1}".format(gem_x,gem_y))

        orderNum = int(array[gemPos+gemNum])
        orderPos = gemPos+gemNum+1
        #print("??????????????°???{0}".format(orderNum))
        for i in range(orderPos,orderPos+orderNum):
            #print("?????????{0}".format(array[i]))
            direction,length = array[i].split()
            length = int(length)
            if  direction == "N":
                for j in range(length):
                    y += 1
                    if y > 20:
                        y = 20
                    #print("?????¨???????????§?¨????{0},{1}".format(x,y))
                    roboPos = [x,y]
                    if roboPos in gemXY and roboPos not in gemCollectedXY:
                        #print("????????????????????°??????")
                        #print("?????¨???????????§?¨????{0},{1}".format(x,y))
                        gemCollectedXY.append([x,y])
                        cnt += 1
            elif direction == "S":
                for j in range(length):
                    y -= 1
                    if y < 0:
                        y = 0
                    #print("?????¨???????????§?¨????{0},{1}".format(x,y))
                    roboPos = [x,y]
                    if roboPos in gemXY and roboPos not in gemCollectedXY:
                        #print("????????????????????°??????")
                        #print("?????¨???????????§?¨????{0},{1}".format(x,y))
                        gemCollectedXY.append([x,y])
                        cnt += 1
            elif direction == "E":
                for j in range(length):
                    x += 1
                    if x > 20:
                        x = 20
                    #print("?????¨???????????§?¨????{0},{1}".format(x,y))
                    roboPos = [x,y]
                    if roboPos in gemXY and roboPos not in gemCollectedXY:
                        #print("????????????????????°??????")
                        #print("?????¨???????????§?¨????{0},{1}".format(x,y))
                        gemCollectedXY.append([x,y])
                        cnt += 1
            else:
                for j in range(length):
                    x -= 1
                    if x < 0:
                        x = 0
                    #print("?????¨???????????§?¨????{0},{1}".format(x,y))
                    roboPos = [x,y]
                    if roboPos in gemXY and roboPos not in gemCollectedXY:
                        #print("????????????????????°??????")
                        #print("?????¨???????????§?¨????{0},{1}".format(x,y))
                        gemCollectedXY.append([x,y])
                        cnt += 1

        if cnt >= gemNum:
            print("Yes")
        else:
            print("No")
        #print("+++++++++++1???????????????+++++++++++++")
        del gemXY[:]
        x,y = 10,10
        cnt = 0
        del roboPos[:]
        del gemCollectedXY[:]

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !
while True:
    n = int(raw_input())
    if n == 0:
        break
    else:
        posi = []
        now = [10,10]
        for i in range(n):
            l = map(int,raw_input().split())
            posi.append(l)
        n = int(raw_input())
        for i in range(n):
            l = raw_input().split()
            if str(l[0]) == 'E':
                for i in range(int(l[1])):
                    now = [now[0] + 1, now[1]]
                    if now in posi:
                        posi.remove(now)
            elif str(l[0]) == 'W':
                for i in range(int(l[1])):
                    now = [now[0] - 1, now[1]]
                    if now in posi:
                        posi.remove(now)
            elif str(l[0]) == 'N':
                for i in range(int(l[1])):
                    now = [now[0], now[1] + 1]
                    if now in posi:
                        posi.remove(now)
            elif str(l[0]) == 'S':
                for i in range(int(l[1])):
                    now = [now[0], now[1] - 1]
                    if now in posi:
                        posi.remove(now)
        if posi:
            print 'No'
        else:
            print 'Yes'

Submission status: Accepted

Solution code:
direction = {'N':(0, 1), 'E':(1, 0), 'W':(-1, 0), 'S':(0, -1)}

while True:
    N = int(raw_input())
    if N == 0:
        break
    B = [[False for j in xrange(21)] for i in xrange(21)]
    for i in xrange(N):
        x, y = map(int, raw_input().split())
        B[y][x] = True
    M = int(raw_input())
    px, py = 10, 10
    taken = 0
    for i in xrange(M):
        d, step = raw_input().split()
        d = direction[d]
        step = int(step)
        for j in xrange(step):
            px += d[0]
            py += d[1]
            if B[py][px]:
                taken += 1
                B[py][px] = False
    print 'Yes' if taken == N else 'No'

Submission status: Accepted

Solution code:
k = ['N','E','S','W']
v = [[0,1],[1,0],[0,-1],[-1,0]]
while True:
    n = int(input())
    if not(n): break
    x,y = 10,10
    p = [list(map(int,input().split())) for _ in range(n)]
    for d,r in [input().split() for _ in range(int(input()))]:
        t = v[k.index(d)]
        for _ in range(int(r)):
            x,y =  x+t[0],y+t[1]
            if [x,y] in p: del p[p.index([x,y])]
    print('Yes' if not(p)else 'No')

Submission status: Accepted

Solution code:
k = ['N','E','S','W']
v = [[0,1],[1,0],[0,-1],[-1,0]]
while True:
    n = int(input())
    if n==0: break
    x,y = 10,10
    l = [list(map(int,input().split())) for _ in range(n)]
    for d,r in [input().split() for _ in range(int(input()))]:
        dl = v[k.index(d)]
        for _ in range(int(r)):
            x,y = x+dl[0],y+dl[1]
            if [x,y] in l: del l[l.index([x,y])]
    print('No' if l else 'Yes')

Submission status: Accepted

Solution code:
while 1:
    arr = [[0 for i in range(21)] for j in range(21)]
    x = int(raw_input())
    if x == 0: break
    for i in range(x):
        y,z = map(int,raw_input().split())
        arr[z][y] = 1
    a = int(input())
    nx, ny = 10,10
    for i in range(a):
        d, l = raw_input().split()
        for j in range(int(l)):
            if d == "N":
                ny += 1
            elif d == "E":
                nx += 1
            elif d == "S":
                ny -= 1
            elif d == "W":
                nx -= 1
            arr[ny][nx] = 0    
    arr2 = [[0 for i in range(21)] for j in range(21)]
    print "Yes" if arr == arr2 else "No"

Submission status: Accepted

Solution code:
while 1:
    n=int(input())
    if n==0:break
    x=y=10
    b=[list(map(int,input().split())) for _ in range(n)]
    for i,j in [input().split() for _ in range(int(input()))]:
        for _ in range(int(j)):
            if 'N'<=i<='S': y+=1 if i=='N' else -1
            else: x+=1 if i=='E' else -1
            if [x,y] in b:del b[b.index([x,y])]
    print(['Yes','No'][bool(b)])

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    gems = set()

    for _ in range(n):
        x, y = map(int, input().split())
        gems.add((x, y))

    m = int(input())
    nx = ny = 10

    for _ in range(m):
        d, l = input().split()
        l = int(l)
        for i in range(l):
            if d == 'N':
                ny += 1
            if d == 'E':
                nx += 1
            if d == 'S':
                ny -= 1
            if d == 'W':
                nx -= 1
            if (nx, ny) in gems:
                gems.remove((nx, ny))
    if len(gems) == 0:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    gems = {tuple(int(i) for i in input().split()) for _ in range(n)}
    m = int(input())
    nx = ny = 10

    for _ in range(m):
        d, l = input().split()
        l = int(l)
        for i in range(l):
            if d == 'N':
                ny += 1
            if d == 'E':
                nx += 1
            if d == 'S':
                ny -= 1
            if d == 'W':
                nx -= 1
            if (nx, ny) in gems:
                gems.remove((nx, ny))
    if len(gems) == 0:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

while True:
	gem_count = int(input())
	if gem_count <= 0:
		break
	gems = []
	for i in range(gem_count):
		x, y = input().split()
		gems.append([ int(x), int(y) ])

	pos = [10,10]
	com_count = int(input())
	for i in range(com_count):
		d, v = input().split()
		for j in range(0,int(v)):
			if d == 'E':
				pos[0] += 1
			elif d == 'W':
				pos[0] -= 1
			elif d == 'N':
				pos[1] += 1
			elif d == 'S':
				pos[1] -= 1
			
			for k in range(len(gems)):
				if pos == gems[k]:
					gems.pop(k)
					break
	
	if len(gems) == 0:
		print('Yes')
	else:
		print('No')

Submission status: Accepted

Solution code:
class Goto(Exception):pass
while True:
    n=int(input())
    if n==0:
        break
    state=[[True for j in range(21)]for k in range(21)]
    for j in range(n):
        cor=[int(num)for num in input().split(' ')]
        state[cor[0]][cor[1]]=False
    m=int(input())
    now=[10,10]
    d=[[0,1],[1,0],[0,-1],[-1,0]]
    for i in range(m):
        com=input().split(' ')
        t=int(com[1])
        if com[0]=='N':
            for j in range(t):
                now[0]+=d[0][0]
                now[1]+=d[0][1]
                state[now[0]][now[1]]=True
        elif com[0]=='E':
            for j in range(t):
                now[0]+=d[1][0]
                now[1]+=d[1][1]
                state[now[0]][now[1]]=True
        elif com[0]=='S':
            for j in range(t):
                now[0]+=d[2][0]
                now[1]+=d[2][1]
                state[now[0]][now[1]]=True
        else:
            for j in range(t):
                now[0]+=d[3][0]
                now[1]+=d[3][1]
                state[now[0]][now[1]]=True
    try:
        for a in state:
            for s in a:
                if s==False:
                    print("No")
                    raise Goto()
        print("Yes")
    except Goto:pass

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    s = []
    for _ in range(n):
        s.append(list(map(int, input().split())))
    m = int(input())
    p = [10, 10]
    if p in s:
        s.remove(p)
    for _ in range(m):
        d, l = input().split()
        l = int(l)
        for a in range(l):
            if d == 'E':
                p[0] = p[0] + 1
            elif d == 'W':
                p[0] = p[0] - 1
            elif d == 'N':
                p[1] = p[1] + 1
            else:
                p[1] = p[1] - 1
            if p in s:
                s.remove(p)
    if s == []:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
#coding: utf-8

if __name__ == '__main__':
    while True:
        n = int(input())
        if n == 0:
            break
        flag = []
        for i in range(21):
            flag.append([0 for j in range(21)])
        for i in range(n):
            x,y = map(int,input().split())
            flag[x][y] = 1;
        m = int(input())
        nx,ny = 10,10
        for i in range(m):
            dre,num = input().split()
            num = int(num)
            if dre == 'N':
                for i in range(num):
                    ny += 1
                    if flag[nx][ny] == 1:
                        flag[nx][ny] = 0
            elif dre == 'W':
                for i in range(num):
                    nx -= 1
                    if flag[nx][ny] == 1:
                        flag[nx][ny] = 0
            elif dre == 'E':
                for i in range(num):
                    nx += 1
                    if flag[nx][ny] == 1:
                        flag[nx][ny] = 0
            else:
                for i in range(num):
                    ny -= 1
                    if flag[nx][ny] == 1:
                        flag[nx][ny] = 0
        ans = True
        for i in range(21):
            for j in range(21):
                if flag[i][j] == 1:
                    ans = False
        if ans:
            print('Yes')
        else:
            print('No')

Submission status: Accepted

Solution code:
while 1:
    lists,pla = [],[]
    x,y,count = 10,10,0
    n = int(input())
    if n==0:break
    for i in [0]*n:
         s = list(map(int, input().split()))
         lists.append(s)
    for i in [0]*int(input()):
        way,num = input().split()
        if way=="N":[pla.append([x,y+i]) for i in range(1,int(num)+1)]
        elif way=="S":[pla.append([x,y-i]) for i in range(1,int(num)+1)]
        elif way=="E":[pla.append([x+i,y]) for i in range(1,int(num)+1)]
        elif way=="W":[pla.append([x-i,y]) for i in range(1,int(num)+1)]
        x,y = pla[-1]
    for i in lists:
        if i in pla:count +=1
    if count==n:print("Yes")
    else:print("No")

Submission status: Accepted

Solution code:
if __name__ =="__main__":
    while True:
        n = int(input())
        if n ==0:break
        js = []
        robots=[10,10]
        count = 0
        dict = {'N':[0,1],'S':[0,-1],'W':[-1,0],'E':[1,0]}
        for i in range(n):
            js +=[list(map(int,input().strip().split()))]
        m = int(input())
        for i in range(m):
            line = input().strip().split()
            for j in range(int(line[1])):
                robots = [robots[0] + dict[line[0]][0],robots[1] + dict[line[0]][1]]
                for k in js:
                    if k == robots:
                        count +=1
                        js.remove(k)
        if n == count:print('Yes')
        else:print('No')

Submission status: Accepted

Solution code:
def between(x, y, a):
    lrg = max(x, y)
    sml = min(x, y)
    if (sml <= a <= lrg):
        return True
    else:
        return False

while (True):
    pos = [10, 10]
    result = 'No'
    N = int(input()) # Total number of jewels
    if N == 0:
        break
    jewelPositions = list()
    for i in range(N):
        jewelPos = list(map(int, input().split()))
        jewelPositions.append(jewelPos)

    M = int(input()) # Number of instructions
    # instructions = list()
    for i in range(M):
        # print('==== Currently at ', pos)
        instruction = input().split()
        # print('instruction : ', i)
        if (result == 'Yes'):
            continue
        instruction[1] = int(instruction[1])
        if (instruction[0] == 'E'):
            move = ('x', instruction[1])
        elif (instruction[0] == 'W'):
            move = ('x', -1*instruction[1])
        elif (instruction[0] == 'N'):
            move = ('y', instruction[1])
        elif (instruction[0] == 'S'):
            move = ('y', -1*instruction[1])
        else:
            raise NotImplementedError

        # print('>>>>>>>>>>>>>>> pos: ', pos, ', move: ', move)
        jewelToRemove = []
        for jewel in jewelPositions:

            '''
            if ((move[0] == 'x') and (pos[1] == jewel[1]) and (pos[0] <= jewel[0] <= pos[0]+move[1])) \
                    or ((move[0] == 'y') and (pos[0] == jewel[0]) and (pos[1] <= jewel[1] <= pos[1]+move[1])):
            '''


            if ((move[0] == 'x') and (pos[1] == jewel[1]) and (between(0, move[1], jewel[0]-pos[0]))) \
                    or ((move[0] == 'y') and (pos[0] == jewel[0]) and (between(0, move[1], jewel[1]-pos[1]))):
                # print('---- Collecting a jewel at ', jewel)
                # jewelPositions.remove(jewel)
                jewelToRemove.append(jewel)
            else:
                # print('xxxx Jewel not collected at ', jewel)
                pass

        for jewel in jewelToRemove:
            jewelPositions.remove(jewel)

        if (move[0] == 'x'):
            pos[0] += move[1]
        elif (move[0] == 'y'):
            pos[1] += move[1]

        if not jewelPositions:
            """
            if empty,
            all jewels are collected
            """
            result = 'Yes'
        else:
            pass
        # print('jewels are left at ', jewelPositions)
    print(result)

"""
2
10 11
11 12
2
N 2
E 1
2
10 11
11 12
2
N 2
W 1
3
0 15
5 10
5 15
5
W 10
S 10
N 20
E 10
S 10
0
"""

Submission status: Accepted

Solution code:
def between(x, y, a):
    lrg = max(x, y)
    sml = min(x, y)
    if (sml <= a <= lrg):
        return True
    else:
        return False

while (True):
    pos = [10, 10]
    result = 'No'
    N = int(input()) # Total number of jewels
    if N == 0:
        break
    jewelPositions = list()
    for i in range(N):
        jewelPos = list(map(int, input().split()))
        jewelPositions.append(jewelPos)

    M = int(input()) # Number of instructions
    # instructions = list()
    for i in range(M):
        # print('==== Currently at ', pos)
        instruction = input().split()
        # print('instruction : ', i)
        if (result == 'Yes'):
            continue
        instruction[1] = int(instruction[1])
        if (instruction[0] == 'E'):
            move = ('x', instruction[1])
        elif (instruction[0] == 'W'):
            move = ('x', -1*instruction[1])
        elif (instruction[0] == 'N'):
            move = ('y', instruction[1])
        elif (instruction[0] == 'S'):
            move = ('y', -1*instruction[1])
        else:
            raise NotImplementedError

        # print('>>>>>>>>>>>>>>> pos: ', pos, ', move: ', move)
        jewelToRemove = []
        for jewel in jewelPositions:

            '''
            if ((move[0] == 'x') and (pos[1] == jewel[1]) and (pos[0] <= jewel[0] <= pos[0]+move[1])) \
                    or ((move[0] == 'y') and (pos[0] == jewel[0]) and (pos[1] <= jewel[1] <= pos[1]+move[1])):
            '''


            if ((move[0] == 'x') and (pos[1] == jewel[1]) and (between(0, move[1], jewel[0]-pos[0]))) \
                    or ((move[0] == 'y') and (pos[0] == jewel[0]) and (between(0, move[1], jewel[1]-pos[1]))):
                # print('---- Collecting a jewel at ', jewel)
                # jewelPositions.remove(jewel)
                jewelToRemove.append(jewel)
            else:
                # print('xxxx Jewel not collected at ', jewel)
                pass

        for jewel in jewelToRemove:
            jewelPositions.remove(jewel)

        if (move[0] == 'x'):
            pos[0] += move[1]
        elif (move[0] == 'y'):
            pos[1] += move[1]

        if not jewelPositions:
            """
            if empty,
            all jewels are collected
            """
            result = 'Yes'
        else:
            pass
        # print('jewels are left at ', jewelPositions)
    print(result)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    p = [10, 10]
    l = [list(map(int,input().split())) for _ in range(n)]
    for d,s in [input().split() for _ in range(int(input()))]:
        for _ in range(int(s)):
            if d == 'N':
                p[1] += 1
            elif d == 'E':
                p[0] += 1
            elif d == 'W':
                p[0] -= 1
            elif d == 'S':
                p[1] -= 1
            if p in l:
                l.remove(p)
    if len(l) == 0:
        print('Yes')
    else:
        print('No')