[Image] 

Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.

Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):

 [Image] 

After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.

Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.


-----Input-----

There are two characters in the first string – the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.

In the second strings, a single number n is given (0 ≤ n ≤ 10^9) – the duration of the rotation.

It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.


-----Output-----

Output cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise.


-----Examples-----
Input
^ >
1

Output
cw

Input
< ^
3

Output
ccw

Input
^ v
6

Output
undefined

Difficulty: interview

Starter code:

Solutions:
a, b = input().split(' ')
n = int(input())

d = {'v': 0, '>': 1, '^': 2, '<': 3}

a, b = d[a], d[b]

ccw = bool((a + n) % 4 == b)
cw = bool((a - n) % 4 == b)

if cw and not ccw:
	print('cw')
elif ccw and not cw:
	print('ccw')
else:
	print('undefined')


positions = ">v<^"

s, t = input().split()
n = int(input())

si = positions.index(s)
ti_cw = positions[(si + n) % 4]
ti_ccw = positions[(si - n) % 4]

if n % 2 == 0:
    print('undefined')
elif t == ti_cw:
    print('cw')
elif t == ti_ccw:
    print('ccw')
else:
    assert False

l = input().split()
n=int(input())

l2 = []

for c in l:
    if ord(c) == 118:
        l2.append(0)
    elif ord(c) == 60:
        l2.append(1)
    elif ord(c) == 94:
        l2.append(2)
    elif ord(c) == 62:
        l2.append(3)

diff = l2[1] - l2[0]

cw = (diff-n)%4 == 0
ccw = (diff+n)%4 == 0
if cw and ccw:
    print('undefined')
elif cw:
    print('cw')
else:
    print('ccw')


s, e = input().split()
d = dict()
d['^'] = 0
d['<'] = 1
d['v'] = 2
d['>'] = 3
n = int(input()) % 4
s = d[s]
e = d[e]
l = 0
r = 0
if (n + s) % 4 == e:
    l = 1
if (s - n) % 4 == e:
    r = 1
if l + r == 2:
    print('undefined')
elif r == 1:
    print('cw')
else:
    print('ccw')

from sys import stdin, stdout

d1,d2 = stdin.readline().rstrip().split()
n = int(stdin.readline().rstrip())

direction = []
for x in [d1,d2]:
    if x=='^':
        direction.append(0)
    elif x=='>':
        direction.append(1)
    elif x=='<':
        direction.append(3)
    else:
        direction.append(2)

n = n%4
lTrue = False
rTrue = False
if (direction[0]+n)%4==direction[1]:
    lTrue = True
if (direction[0]-n)%4==direction[1]:
    rTrue = True
    
if lTrue and rTrue:
    print("undefined")
elif lTrue:
    print("cw")
else:
    print("ccw")


k, m = input().split()
n = int(input())

n %= 4
a = ['v', '<', '^', '>', 'v', '<', '^', '>']
if n == 2 or n==0:
    print('undefined')
if n == 1:
    if m == a[a.index(k) + 1]:
        print('cw')
    else:
        print('ccw')
if n == 3:
    if m == a[a.index(k) + 3]:
        print('cw')
    else:
        print('ccw')

a, b = [i for i in input().split()]
n = int(input())
pos = ['v', '<', '^', '>']
i = pos.index(a)
f1 = pos[(i + n) % 4]
f2 = pos[(i - n) % 4]
if f1 == f2:
    print('undefined')
elif f1 == b:
    print('cw')
elif f2 == b:
    print('ccw')
else:
    print('undefined')

a,b=input().split()
n=int(input())
n=n%4
V=['^','>','v','<']
i=0
while a!=V[i]:
    i+=1
ti=(i+4-n)%4
i=(i+n)%4
if b==V[i] and b==V[ti]:
    print('undefined')
elif b==V[i]:
    print('cw')
elif b==V[ti]:
    print('ccw')
else:
    print('undefined')


s,f = input().split(' ')
n = int(input())

cw = {'^': 1, '>':2, 'v':3, '<':0}
ccw = {'^': 1, '>':0, 'v':3, '<':2}

a = (cw[s] + n) % 4
b = (ccw[s] + n) % 4

if a == cw[f] and b == ccw[f]:
    print('undefined')
elif a == cw[f]:
    print('cw')
elif b == ccw[f]:
    print('ccw')
else:
    print('undefined')


s, e = input().split()
n = int(input()) % 4
sp = ['v', '<', '^', '>']
i = sp.index(s)
j = i

while n > 0:
    i = (i+1)%4
    j = (j-1)%4
    n -= 1
if e == sp[i] and e != sp[j]:
    print('cw')
elif e == sp[j] and e != sp[i]:
    print('ccw')
else:
    print('undefined')



import math


def ria():
    return [int(i) for i in input().split()]


a, b = input().split()
n = ria()[0]
possible = []

st = "^>v<"
if (st[(st.find(a) + n) % 4])==b:
    possible.append('cw')

if (st[(st.find(a) - n) % 4])==b:
    possible.append('ccw')
if possible.__len__()>1:
    print('undefined')
else:
    print(possible[0])

start, end = input().split()
n = int(input()) % 4

if start == 'v':
	start = 0
elif start == '<':
	start = 1
elif start == '^':
	start = 2
elif start == '>':
	start = 3

if end == 'v':
	end = 0
elif end == '<':
	end = 1
elif end == '^':
	end = 2
elif end == '>':
	end = 3
	
temp1 = (4 + end - start) % 4
temp2 = (4 + start - end) % 4

if temp1 == temp2 == n:
	print('undefined')
elif temp1 == n:
	print('cw')
elif temp2 == n:
	print('ccw')
else:
	print('ERROR')


from sys import stdin

data = stdin.readline().rstrip().split()
n = int(stdin.readline().rstrip()) % 4

dmap = {
    '^': 0,
    '>': 1,
    'v': 2,
    '<': 3
}
a, b = dmap[data[0]], dmap[data[1]]

if (a + n) % 4 == b and (a - n) % 4 == b:
    print('undefined')
elif (a + n) % 4 == b:
    print('cw')
else:
    print('ccw')


s, f = input().split()
n = int(input())
spinner = ['v', '<', '^', '>']
# print(spinner)
if spinner[(spinner.index(s) + n) % 4] == spinner[(spinner.index(s) - n) % 4] == f:
    print('undefined')
elif spinner[(spinner.index(s) + n) % 4] == f:
    print('cw')
else:
    print('ccw')


s,f = input().strip().split()
n = int(input())
rot = ['^','>','v','<']
d = {'^':0,'>':1,'v':2,'<':3}
cw = (d[s] + n)%4
ccw = (d[s] - n)%4
if cw == ccw:
	print('undefined')
elif rot[cw] == f:
	print('cw')
else: print('ccw')


s, t = ["v<^>".index(x) for x in input().split()]
n = int(input())

cw = (n + s - t) % 4 == 0
ccw = (n + t - s) % 4 == 0

if cw and not ccw:
    print("cw")
elif not cw and ccw:
    print("ccw")
else:
    print("undefined")


def str_to_int(s):
    if s == "^":
        return 0
    if s == ">":
        return 1
    if s == "v":
        return 2
    if s == "<":
        return 3

inputlist = list(map(str_to_int, input().strip().split(" ")))
start = inputlist[0]
end = inputlist[1]
duration = int(input())

if (start + duration) % 4 == end and (start - duration) % 4 != end:
    print("cw")
elif (start - duration) % 4 == end and (start + duration) % 4 != end:
    print("ccw")
else:
    print("undefined")

s=input()
n=int(input())
d={}
d['^']=0
d['>']=1
d['v']=2
d['<']=3

if n%4==2 or n%4==0:
	print("undefined")
else:
	sum=(d[s[2]]-d[s[0]]+4)%4;
	if(sum==n%4):
		print("cw")
	else:
		print("ccw")


a = 'v<^>'
d = dict()
d['v'] = 0
d['<'] = 1
d['^'] = 2
d['>'] = 3
s, e = [d[x] for x in input().split()]
n = int(input()) % 4
flag_left = False
flag_right = False
if a[(s + n) % 4] == a[e]:
    flag_left = True
if a[(s - n) % 4] == a[e]:
    flag_right = True
if flag_left and flag_right:
    print('undefined')
elif flag_left:
    print('cw')
elif flag_right:
    print('ccw')
else:
    print('undefined')


s,e=input().split()
n = int(input())
n %= 4
if(n==2 or n==0):
	print("undefined")
elif(n==1):
	if((s=='<' and e=='^') or (s=='^' and e=='>') or (s=='>' and e=='v') or (s=='v' and e=='<')):
		print("cw")
	else:
		print("ccw")
else:
	if((s=='<' and e=='v') or (s=='^' and e=='<') or (s=='>' and e=='^') or (s=='v' and e=='>')):
		print("cw")
	else:
		print("ccw")

a = [i for i in input().split()]
n = int(input())
ans = None
pol = ["v", "<", "^", ">"]
if pol[((pol.index(a[1]) + n) % 4)] == a[0]:
    ans = "ccw"
if pol[((pol.index(a[1]) - n) % 4)] == a[0]:
    if ans != None:
        ans = "undefined"
    else:
        ans = "cw"
print(ans)

#!/usr/bin/env python3
from sys import stdin, stdout

def rint():
    return list(map(int, stdin.readline().split()))
#lines = stdin.readlines()

t = {'v':0, '<':1, '^':2, '>':3}

a, b = list(map(str, input().split()))
n = int(input())
n %= 4
if n == 0 or n == 2:
    print('undefined')
    return
a, b = t[a], t[b]
if b < a:
    b +=4

diff = b - a
if n == 1:
    if diff == 1:
        print("cw")
    elif diff == 3:
        print("ccw")
    else:
        print('undefined')
elif n == 3:
    if diff == 1:
        print("ccw")
    elif diff == 3:
        print("cw")
    else:
        print('undefined')



a = ['v', '<', '^', '>']
s, e = input().split()
n = int(input())
l = a.index(s)
r = l
n = n % 4
for i in range(n):
    if l == 0: l = 3
    else: l -= 1
    if r == 3: r = 0
    else: r += 1
if a[l] == e and a[r] == e:
    print('undefined')
elif a[l] == e:
    print('ccw')
elif a[r] == e:
    print('cw')

pos1, pos2 = input().split()
turns_nr = int(input())

if turns_nr % 2 == 0:
    print('undefined')
    return
elif turns_nr % 4 == 1:
    lst = '<^>v<^>v'
    for idx1, sym1 in enumerate(lst):
        if sym1 == pos1:
            if lst[idx1 - 1] == pos2:
                print('ccw')
                return
            elif lst[idx1 + 1] == pos2:
                print('cw')
                return
elif turns_nr % 4 == 3:
    lst = '<^>v<^>v'
    for idx1, sym1 in enumerate(lst):
        if sym1 == pos1:
            if lst[idx1 - 1] == pos2:
                print('cw')
                return
            elif lst[idx1 + 1] == pos2:
                print('ccw')
                return


a,b=input().split()
n=int(input())
d={'^':0,'>':1,'v':2,'<':3}
e={'^':0,'>':3,'v':2,'<':1}
f1=f2=0
if (d[a]+n)%4==d[b]:
    f1=1
if (e[a]+n)%4==e[b]:
    f2=1
if f1 and f2:
    print('undefined')
else:
    print('cw' if f1 else 'ccw')