Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, x = 0; char a, b; cin >> a >> b; cin >> n; n %= 4; if (a == '^') { x = 0; } else if (a == '>') { x = 90; } else if (a == 'v') { x = 180; } else if (a == '<') { x = 270; } int y = 0, z = 0; y = (x + n * 90) % 360; z = (x + (4 - n) * 90) % 360; if (b == '^') { x = 0; } else if (b == '>') { x = 90; } else if (b == 'v') { x = 180; } else if (b == '<') { x = 270; } if (z == x && y == x) { cout << "undefined"; } else if (x == y) { cout << "cw"; } else if (z == x) { cout << "ccw"; } else { cout << "undefined"; } return 0; }
CPP
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastScanner in = new FastScanner(inputStream); PrintWriter out = new PrintWriter(outputStream); A834 solver = new A834(); solver.solve(1, in, out); out.close(); } static class A834 { String cc = "^>v<"; public void solve(int testNumber, FastScanner s, PrintWriter out) { int a = cc.indexOf(s.next().charAt(0) + ""); int b = cc.indexOf(s.next().charAt(0) + ""); int k = s.nextInt(); if (k % 2 == 0) { out.println("undefined"); return; } k %= 4; boolean cw = (a + 1) % 4 == b; if ((k % 4 == 1 && cw) || (k % 4 == 3 && !cw)) out.println("cw"); else out.println("ccw"); } } static class FastScanner { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public FastScanner(InputStream stream) { this.stream = stream; } int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public int nextInt() { return Integer.parseInt(next()); } public String next() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.io.*; import java.math.*; import java.util.*; public class poogramA { public static void main (String[] args)throws IOException { Scanner scan = new Scanner(System.in); char s = scan.next().charAt(0); char s1 = scan.next().charAt(0); long n = scan.nextLong(); int a=0,e=0; if(s=='^') { a=0; }else if(s=='>') { a=1; }else if(s=='v') { a=2; }else if(s=='<') { a=3; } if(s1=='^') { e=0; }else if(s1=='>') { e=1; }else if(s1=='v') { e=2; }else if(s1=='<') { e=3; } n= n%4; int x = (e-a)%4; if(x<0) { x+=4; } if(n==2 || n==0) { System.out.println("undefined"); }else if(n == x) { System.out.println("cw"); }else if(n == 4-x){ System.out.println("ccw"); } } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
from sys import maxsize, stdout, stdin,stderr mod = int(1e9 + 7) import re #can use multiple splits def tup():return map(int,stdin.readline().split()) def I(): return int(stdin.readline()) def lint(): return [int(x) for x in stdin.readline().split()] def S(): return input().strip() def grid(r, c): return [lint() for i in range(r)] def debug(*args, c=6): print('\033[3{}m'.format(c), *args, '\033[0m', file=stderr) from math import log2,sqrt from collections import defaultdict s= S().split() n = I() d='^>v<' if n%2==0:print('undefined') else: st =d.find(s[0]).__index__() en = d[(st+n)%4] if en==s[1]:print('cw') elif d[(st-n)%4]==s[1]:print('ccw') else:print('undefined')
PYTHON3
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int dist(char x, char y, string a) { int occ = -1; for (int i = 0; i < 8; ++i) { if (a[i] == x) { occ = i; } else if (a[i] == y && occ != -1) return i - occ; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); char a, b; int n; cin >> a >> b >> n; string cw = "v<^>v<^>"; string ccw = "v>^<v>^<"; n %= 4; int x = dist(a, b, cw); int y = dist(a, b, ccw); if (x == y) cout << "undefined" << '\n'; else if (x == n) cout << "cw" << '\n'; else if (y == n) cout << "ccw" << '\n'; else cout << "undefined" << '\n'; }
CPP
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
val = ['v', '<', '^', '>'] val2 = ['>', '^', '<', 'v'] s = raw_input().split() n = int(raw_input()) index = val.index(s[0]) index2 = val.index(s[1]) index3 = val2.index(s[0]) index4 = val2.index(s[1]) if val[(index+n)%4] == val[index2] and val2[(index3+n)%4] == val2[index4]: print 'undefined' elif val[(index+n)%4] == val[index2]: print 'cw' else: print 'ccw'
PYTHON
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.util.*; import java.io.*; public class Test { public static void main (String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] arr=br.readLine().split(" "); long n=Long.parseLong(br.readLine()); long step=n%4; char a=arr[0].charAt(0); char b=arr[1].charAt(0); if(a=='v'&&b=='v'){ System.out.println("undefined"); } if(a=='v'&&b=='<'){ if(step==1){ System.out.println("cw"); } else if(step==3){ System.out.println("ccw"); } else{ System.out.println("undefined"); } } if(a=='v'&&b=='^'){ System.out.println("undefined"); } if(a=='v'&&b=='>'){ if(step==1){ System.out.println("ccw"); } else if(step==3){ System.out.println("cw"); } else{ System.out.println("undefined"); } } if(a=='<'&&b=='<'){ System.out.println("undefined"); } if(a=='<'&&b=='^'){ if(step==1){ System.out.println("cw"); } else if(step==3){ System.out.println("ccw"); } else{ System.out.println("undefined"); } } if(a=='<'&&b=='>'){ System.out.println("undefined"); } if(a=='<'&&b=='v'){ if(step==1){ System.out.println("ccw"); } else if(step==3){ System.out.println("cw"); } else{ System.out.println("undefined"); } } if(a=='^'&&b=='^'){ System.out.println("undefined"); } if(a=='^'&&b=='>'){ if(step==1){ System.out.println("cw"); } else if(step==3){ System.out.println("ccw"); } else{ System.out.println("undefined"); } } if(a=='^'&&b=='v'){ System.out.println("undefined"); } if(a=='^'&&b=='<'){ if(step==1){ System.out.println("ccw"); } else if(step==3){ System.out.println("cw"); } else{ System.out.println("undefined"); } } if(a=='>'&&b=='>'){ System.out.println("undefined"); } if(a=='>'&&b=='v'){ if(step==1){ System.out.println("cw"); } else if(step==3){ System.out.println("ccw"); } else{ System.out.println("undefined"); } } if(a=='>'&&b=='<'){ System.out.println("undefined"); } if(a=='>'&&b=='^'){ if(step==1){ System.out.println("ccw"); } else if(step==3){ System.out.println("cw"); } else{ System.out.println("undefined"); } } } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
def FindDirection(start, end, n): modelTab = ['v', '<', '^', '>'] iStart = 0 iEnd = 0 for i in range(4): if start == modelTab[i]: iStart = i if end == modelTab[i]: iEnd = i if (n%4) == 2 or (n%4) == 4: return 'undefined' elif ((n%4) == 1 and (iEnd-iStart)%4 == 1) or ((n%4) == 3 and (iEnd-iStart)%4 == 3): return 'cw' elif ((n%4) == 1 and (iEnd-iStart)%4 == 3) or ((n%4) == 3 and (iEnd-iStart)%4 == 1): return 'ccw' else: return 'undefined' def read_str(): return map(str, raw_input().split(' ')) start, end = read_str() n = map(int, raw_input().split(' '))[0] print (FindDirection(start, end, n))
PYTHON
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.io.*; import java.util.*; public class A { public static void main(String[] args) { FastScannerA sc = new FastScannerA(System.in); String start = sc.next(); String end = sc.next(); int dura = sc.nextInt(); int left = dura % 4; if(left == 0 || start == end){ System.out.println("undefined"); System.exit(0); } char[] arr = new char[] {'v', '<', '^', '>'}; int stIdx = -1; int endIdx = -1; for(int i = 0 ; i < 4 ; i++){ if(arr[i] == start.charAt(0)){ stIdx = i; } if(arr[i] == end.charAt(0)){ endIdx = i; } } if(Math.abs(stIdx - endIdx) == left && 4 - Math.abs(stIdx - endIdx) == left){ System.out.println("undefined"); } else if(Math.abs(stIdx - endIdx) == left){ if(stIdx < endIdx){ System.out.println("cw"); } else{ System.out.println("ccw"); } } else if(4 - Math.abs(stIdx - endIdx) == left){ if(stIdx < endIdx){ System.out.println("ccw"); } else{ System.out.println("cw"); } } else{ System.out.println("undefined"); } } } class FastScannerA{ private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public FastScannerA(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String next() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isLineEndChar(c)); return res.toString(); } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public boolean isLineEndChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == '\n' || c == '\r' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
s=list(map(str,input().split())) n=int(input()) re=n%4 if s[0]=='^': if re==1: if s[1]=='>': print('cw') else: print('ccw') elif re==3 : if s[1]=='<': print('cw') else: print('ccw') else: print('undefined') elif s[0]=='>': if re==1: if s[1]=='v': print('cw') else: print('ccw') elif re==3 : if s[1]=='^': print('cw') else: print('ccw') else: print('undefined') elif s[0]=='v': if re==1: if s[1]=='<': print('cw') else: print('ccw') elif re==3: if s[1]=='>': print('cw') else: print('ccw') else: print('undefined') elif s[0]=='<': if re==1: if s[1]=='^': print('cw') else: print('ccw') elif re==3: if s[1]=='v': print('cw') else: print('ccw') else: print('undefined')
PYTHON3
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; const int maxN = 15, maxK = 8, MOD = 1e9 + 7; string dir[4] = {"v", "<", "^", ">"}; map<string, int> m; string st, en; int n; void mmap() { m.clear(); for (int i = 0; i < 4; i++) { m[dir[i]] = i; } } bool good() { return (m[st] + n) % 4 == m[en]; } int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> st >> en >> n; mmap(); bool cwb = good(); reverse(dir, dir + 4); mmap(); bool ccwb = good(); if (ccwb && cwb) { cout << "undefined\n"; } else if (ccwb) { cout << "ccw\n"; } else { cout << "cw\n"; } }
CPP
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
char1, char2 = input().split() n = int(input())%4 cw = "v<^>v<^>" ccw = "v>^<v>^<" if n%2==1 and cw[cw.find(char1)+n]==char2: print("cw") elif n%2==1 and ccw[ccw.find(char1)+n]==char2: print("ccw") else: print("undefined")
PYTHON3
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; public class A { public static void main(String[] args) { InputReader in = new InputReader(); PrintWriter out = new PrintWriter(System.out); String start = in.next(); String end = in.next(); char[] dir = new char[]{'^', '>', 'v', '<'}; int n = in.nextInt(); n = n % 4; if (n == 0) out.println("undefined"); else { for (int i = 0; i < dir.length; i++) { if (start.charAt(0) == dir[i]) { if (dir[(i + n) % dir.length] == end.charAt(0) && dir[i - n >= 0 ? i - n : (i - n) + dir.length] == end.charAt(0)) out.println("undefined"); else if (dir[i - n >= 0 ? i - n : (i - n) + dir.length] == end.charAt(0)) out.println("ccw"); else { out.println("cw"); } out.close(); return; } } } out.close(); } static class InputReader { BufferedReader br; StringTokenizer st; public InputReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
/** * @author Finn Lidbetter */ import java.util.*; import java.io.*; import java.awt.geom.*; public class A { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); String[] s= br.readLine().split(" "); long[] pair = new long[2]; for (int i=0; i<s.length; i++) { if (s[i].charAt(0)=='v') pair[i] = 0; else if (s[i].charAt(0)=='<') { pair[i] = 1; } else if (s[i].charAt(0)=='^') { pair[i] = 2; } else if (s[i].charAt(0)=='>') { pair[i] = 3; } } long n = Long.parseLong(br.readLine()); boolean cw = false; boolean ccw = false; if ((pair[0]+n)%4==pair[1]) { cw = true; } if (((pair[0]-n)+4_000_000_000L)%4==pair[1]) { ccw = true; } if ((cw && ccw) || (!cw && !ccw)) { System.out.println("undefined"); }else if (cw) { System.out.println("cw"); } else if (ccw) { System.out.println("ccw"); } } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
arr = [chr(118) , chr(60) , chr(94) , chr(62)] a , b = input().split() n = int(input()) n = n%4 x = arr.index(a) # print(arr) o = arr[(x + n)%4] p = arr[(x + 4 - n)%4] if o==p: print("undefined") elif o==b: print("cw") else: print("ccw")
PYTHON3
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
# your code goes here start, end = raw_input().split() arr = dict() arr["v"] = 0 arr["<"] = 1 arr["^"] = 2 arr[">"] = 3 n = int(raw_input()) n = n%4 if(n == 2 or n==0): print "undefined" elif((arr[start] + n) %4 == arr[end]): print "cw" else: print "ccw"
PYTHON
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int main() { long long int t, x, y, spos, epos; string s; getline(cin, s); cin >> t; x = t % 4; if (x == 2 || x == 0) { cout << "undefined"; } else if (x == 1) { if ((s[0] == '^' && s[2] == '>') || (s[0] == '>' && s[2] == 'v') || (s[0] == 'v' && s[2] == '<') || (s[0] == '<' && s[2] == '^')) { cout << "cw"; } else if ((s[0] == '^' && s[2] == '<') || (s[0] == '>' && s[2] == '^') || (s[0] == 'v' && s[2] == '>') || (s[0] == '<' && s[2] == 'v')) { cout << "ccw"; } } else if (x == 3) { if ((s[0] == '^' && s[2] == '<') || (s[0] == '>' && s[2] == '^') || (s[0] == 'v' && s[2] == '>') || (s[0] == '<' && s[2] == 'v')) { cout << "cw"; } else if ((s[0] == '^' && s[2] == '>') || (s[0] == '>' && s[2] == 'v') || (s[0] == 'v' && s[2] == '<') || (s[0] == '<' && s[2] == '^')) { cout << "ccw"; } } return 0; }
CPP
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.util.*; public class MyClass { public static void main(String args[]) { Scanner scan = new Scanner(System.in); char r=scan.next().charAt(0),l=scan.next().charAt(0),a [] = {'v','<','^','>'},b [] = {'v','>','^','<'}; int n=scan.nextInt(),x=0,y=0; for (int i=0;i<4;i++){if(a[i]==r)x=i;if(b[i]==r)y=i;} if(n%2==0) System.out.print("undefined"); else if(a[(x+n%4)%4]==l)System.out.print("cw"); else if (b[(y+n%4)%4]==l)System.out.print("ccw"); } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int dir(char c) { if (c == '^') { return 0; } if (c == '>') { return 1; } if (c == 'v') { return 2; } if (c == '<') { return 3; } } int main() { char c1, c2; int n; cin >> c1 >> c2; cin >> n; int a1, a2; a1 = dir(c1); a2 = dir(c2); if (abs(a1 - a2) == 2 || abs(a1 - a2) == 0) { cout << "undefined"; return 0; } if ((a1 + n) % 4 == (a2)) { cout << "cw"; } else { cout << "ccw"; } }
CPP
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
a,b=input().split() c=int(input()) if c%4==0: print('undefined') elif c%4==2: print('undefined') elif a=='>': if c%4==1: if b=='v': print('cw') elif b=='^': print('ccw') else: print('undefined') elif c%4==3: if b=='v': print('ccw') elif b=='^': print('cw') else: print('undefined') elif a=='<': if c%4==3: if b=='v': print('cw') elif b=='^': print('ccw') else: print('undefined') elif c%4==1: if b=='v': print('ccw') elif b=='^': print('cw') else: print('undefined') elif a=='v': if c%4==1: if b=='<': print('cw') elif b=='>': print('ccw') else: print('undefined') elif c%4==3: if b=='<': print('ccw') elif b=='>': print('cw') else: print('undefined') elif a=='^': if c%4==1: if b=='<': print('ccw') elif b=='>': print('cw') else: print('undefined') elif c%4==3: if b=='<': print('cw') elif b=='>': print('ccw') else: print('undefined')
PYTHON3
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
# -*- coding:utf-8 -*- #[n, m] = [int(x) for x in raw_input().split()] def some_func(): """ """ s1,s2 = raw_input().split(' ') n = input() cache1 = {'^':1,">":2,"v":3,"<":0} cache2 = {'^':1,">":0,"v":3,"<":2} f1,f2 = 0,0 if (cache1[s1]+n) %4 == cache1[s2]: f1=1 if (cache2[s1]+n ) %4 == cache2[s2]: f2=1 if f1 and not f2: return "cw" elif f2 and not f1: return "ccw" else: return "undefined" if __name__ == '__main__': print some_func()
PYTHON
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
''' Thruth can only be found at one place - THE CODE ''' ''' Copyright 2018, SATYAM KUMAR''' from sys import stdin, stdout import cProfile, math from collections import Counter from bisect import bisect_left,bisect,bisect_right import itertools from copy import deepcopy from fractions import Fraction import sys, threading sys.setrecursionlimit(10**6) # max depth of recursion threading.stack_size(2**27) # new thread will get stack of such size printHeap = str() memory_constrained = False P = 10**9+7 import sys sys.setrecursionlimit(10000000) class Operation: def __init__(self, name, function, function_on_equal, neutral_value=0): self.name = name self.f = function self.f_on_equal = function_on_equal def add_multiple(x, count): return x * count def min_multiple(x, count): return x def max_multiple(x, count): return x sum_operation = Operation("sum", sum, add_multiple, 0) min_operation = Operation("min", min, min_multiple, 1e9) max_operation = Operation("max", max, max_multiple, -1e9) class SegmentTree: def __init__(self, array, operations=[sum_operation, min_operation, max_operation]): self.array = array if type(operations) != list: raise TypeError("operations must be a list") self.operations = {} for op in operations: self.operations[op.name] = op self.root = SegmentTreeNode(0, len(array) - 1, self) def query(self, start, end, operation_name): if self.operations.get(operation_name) == None: raise Exception("This operation is not available") return self.root._query(start, end, self.operations[operation_name]) def summary(self): return self.root.values def update(self, position, value): self.root._update(position, value) def update_range(self, start, end, value): self.root._update_range(start, end, value) def __repr__(self): return self.root.__repr__() class SegmentTreeNode: def __init__(self, start, end, segment_tree): self.range = (start, end) self.parent_tree = segment_tree self.range_value = None self.values = {} self.left = None self.right = None if start == end: self._sync() return self.left = SegmentTreeNode(start, start + (end - start) // 2, segment_tree) self.right = SegmentTreeNode(start + (end - start) // 2 + 1, end, segment_tree) self._sync() def _query(self, start, end, operation): if end < self.range[0] or start > self.range[1]: return None if start <= self.range[0] and self.range[1] <= end: return self.values[operation.name] self._push() left_res = self.left._query(start, end, operation) if self.left else None right_res = self.right._query(start, end, operation) if self.right else None if left_res is None: return right_res if right_res is None: return left_res return operation.f([left_res, right_res]) def _update(self, position, value): if position < self.range[0] or position > self.range[1]: return if position == self.range[0] and self.range[1] == position: self.parent_tree.array[position] = value self._sync() return self._push() self.left._update(position, value) self.right._update(position, value) self._sync() def _update_range(self, start, end, value): if end < self.range[0] or start > self.range[1]: return if start <= self.range[0] and self.range[1] <= end: self.range_value = value self._sync() return self._push() self.left._update_range(start, end, value) self.right._update_range(start, end, value) self._sync() def _sync(self): if self.range[0] == self.range[1]: for op in self.parent_tree.operations.values(): current_value = self.parent_tree.array[self.range[0]] if self.range_value is not None: current_value = self.range_value self.values[op.name] = op.f([current_value]) else: for op in self.parent_tree.operations.values(): result = op.f( [self.left.values[op.name], self.right.values[op.name]]) if self.range_value is not None: bound_length = self.range[1] - self.range[0] + 1 result = op.f_on_equal(self.range_value, bound_length) self.values[op.name] = result def _push(self): if self.range_value is None: return if self.left: self.left.range_value = self.range_value self.right.range_value = self.range_value self.left._sync() self.right._sync() self.range_value = None def __repr__(self): ans = "({}, {}): {}\n".format(self.range[0], self.range[1], self.values) if self.left: ans += self.left.__repr__() if self.right: ans += self.right.__repr__() return ans def display(string_to_print): stdout.write(str(string_to_print) + "\n") def primeFactors(n): #n**0.5 complex factors = dict() for i in range(2,math.ceil(math.sqrt(n))+1): while n % i== 0: if i in factors: factors[i]+=1 else: factors[i]=1 n = n // i if n>2: factors[n]=1 return (factors) def isprime(n): """Returns True if n is prime.""" if n < 4: return True if n % 2 == 0: return False if n % 3 == 0: return False i = 5 w = 2 while i * i <= n: if n % i == 0: return False i += w w = 6 - w return True def test_print(*args): if testingMode: print(args) def display_list(list1, sep=" "): stdout.write(sep.join(map(str, list1)) + "\n") def get_int(): return int(stdin.readline().strip()) def get_tuple(): return map(int, stdin.readline().split()) def get_list(): return list(map(int, stdin.readline().split())) memory = dict() def clear_cache(): global memory memory = dict() def cached_fn(fn, *args): global memory if args in memory: return memory[args] else: result = fn(*args) memory[args] = result return result # -------------------------------------------------------------- MAIN PROGRAM TestCases = False testingMode = False optimiseForReccursion = False #Can not be used clubbed with TestCases def main(): x = list(input().split()) for i,ele in enumerate([94,62,118,60]): if x[0]==chr(ele): a = i if x[1]==chr(ele): b = i n = get_int() x = n%4 a1 = (a+x)%4==b a2 = (a-x)%4==b if a1 and a2: print("undefined") elif a1: print("cw") else: print("ccw") # --------------------------------------------------------------------- END if TestCases: for _ in range(get_int()): cProfile.run('main()') if testingMode else main() else: (cProfile.run('main()') if testingMode else main()) if not optimiseForReccursion else threading.Thread(target=main).start()
PYTHON3
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
def solve(s, n, seq): x = seq.find(s[0]) y = seq[x + n] return y == s[2] def main(): cw = '^>v<' * 10 ccw = '^<v>' * 10 s = input() n = int(input()) x = solve(s, n % 4, cw) y = solve(s, n % 4, ccw) if x and y: print('undefined') elif x: print('cw') elif y: print('ccw') else: print('undefined') if __name__ == '__main__': main()
PYTHON3
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
table = ["<","v",">","^"] s = input().split() final = s[1] n = int(input())%4 start = table.index(s[0]) forwardans = table[(start+n)%4] backwardans = table[(start-n)%4] #print(forwardans, backwardans) if forwardans == backwardans: print("undefined") elif forwardans==final: print("ccw") else: print("cw")
PYTHON3
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
if __name__ == '__main__': a = raw_input().split() n = int(raw_input()) % 4 for i in range(2): if a[i] == '^': a[i] = 1 if a[i] == '>': a[i] = 2 if a[i] == 'v': a[i] = 3 if a[i] == '<': a[i] = 4 if n == 0 or n == 2: print 'undefined' elif a[0] + n == a[1] or a[0] + n - 4 == a[1]: print 'cw' elif a[0] - n == a[1] or a[0] - n + 4 == a[1]: print 'ccw' else: print 'undefined'
PYTHON
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
a,b=map(str,input().split());c=int(input());e="v<^>" if c%2==0:print("undefined") elif (e.find(a)+c)%4==e.find(b):print("cw") else:print("ccw")
PYTHON3
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.io.InputStreamReader; import java.io.BufferedReader; import java.util.StringTokenizer; public class CF426B { public static void main(String[]args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(br.readLine()); int a=st.nextToken().charAt(0); int b=st.nextToken().charAt(0); // System.out.println(a+" "+b); int time=Integer.parseInt(br.readLine())%4; int arr[]={118,60,94,62}; int in=-1; for(int i=0;i<4;i++) if(a==arr[i]) { in =i; break; } int in2=-1; for(int i=0;i<4;i++) if(b==arr[i]) { in2 =i; break; } // System.out.println(in+" "+in2); if(((in+time+4)%4==in2)&&((in-time+4)%4==in2)) System.out.println("undefined"); else if((in+time+4)%4==in2) System.out.println("cw"); else if((in-time+4)%4==in2) System.out.println("ccw"); else System.out.println("undefined"); } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.util.Scanner; public class UselessToy { private static final int[][] CW = { {-1,1,-1,3}, {3,-1,1,-1}, {-1,3,-1,1}, {1,-1,3,-1} }; private static final int[][] CCW = { {-1,3,-1,1}, {1,-1,3,-1}, {-1,1,-1,3}, {3,-1,1,-1} }; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int startPos = posIdx(scanner.next().charAt(0)); int endPos = posIdx(scanner.next().charAt(0)); int transitions = scanner.nextInt() % 4; if (CW[startPos][endPos]==transitions) { System.out.println("cw"); } else if (CCW[startPos][endPos]==transitions) { System.out.println("ccw"); } else { System.out.println("undefined"); } } public static int posIdx(char pos) { return pos=='v'? 0 : pos=='<' ? 1 : pos=='^'? 2 : 3; } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Ejercicio1 { public static void main(String[] args) { Scanner s = new Scanner(System.in); String start = s.next(); String end = s.next(); int n = s.nextInt(); n %= 4; Map<String, Integer> positions = new HashMap<>(); positions.put("^", 0); positions.put(">", 1); positions.put("v", 2); positions.put("<", 3); int startI = positions.get(start); int endI = positions.get(end); boolean clock = ((startI+n)%4 == endI); boolean antiClock = Math.floorMod((startI-n), 4)== endI; if(clock && antiClock) System.out.println("undefined"); else if(clock) System.out.println("cw"); else System.out.println("ccw"); } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int main() { char aa, bb; cin >> aa >> bb; int n; cin >> n; n = n % 4; int a, b; switch (aa) { case 'v': a = 0; break; case '<': a = 1; break; case '^': a = 2; break; case '>': a = 3; break; } switch (bb) { case 'v': b = 0; break; case '<': b = 1; break; case '^': b = 2; break; case '>': b = 3; break; } int f1, f2; f1 = 0; f2 = 0; if ((a + n) % 4 == b) f1 = 1; if ((a - n + 4) % 4 == b) f2 = 1; if (f1 == 1 && f2 == 1) cout << "undefined"; else if (f1 == 1) cout << "cw"; else cout << "ccw"; }
CPP
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.util.*; public class CF { static Scanner sc = new Scanner(System.in); static char[] cw = {'^', '>', 'v', '<'}; static char[] ccw = {'^', '<', 'v', '>'}; static int getStartCW(char c) { for (int i = 0; i < 4; i++) { if (c == cw[i]) { return i; } } return -1; } static int getStartCCW(char c) { for (int i = 0; i < 4; i++) { if (c == ccw[i]) { return i; } } return -1; } public static void main(String[] args) { char f = sc.next().charAt(0); char s = sc.next().charAt(0); int n = sc.nextInt(); int startCW = getStartCW(f); int startCCW = getStartCCW(f); char endCW = cw[(n + startCW) % 4]; char endCCW = ccw[(n + startCCW) % 4]; if (endCW == endCCW) { if (endCW == s) { System.out.println("undefined"); return; } } if (endCW == s) { System.out.println("cw"); } else { System.out.println("ccw"); } } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.util.HashMap; import java.util.Scanner; public class Main { public static int getSymbolValue(String symbol){ if (symbol.equals("v")) return 0; else if (symbol.equals("<")) return 1; else if (symbol.equals("^")) return 2; else return 3; } public static int compute(int value,String symbolFrom, String symbolTo){ int val = value%4; if (val == 0) return 0; else if (val == 2) return 0; else { int symbolFromValue = getSymbolValue(symbolFrom); int symbolToValue=getSymbolValue(symbolTo); int add = (symbolFromValue+val)%4; if(add==getSymbolValue(symbolTo)) return 1; else return 2; } } public static void main(String[] args) { Scanner reader = new Scanner(System.in); String symbolFrom = reader.next(); String symbolTo= reader.next(); int value = reader.nextInt(); int val = compute(value,symbolFrom,symbolTo); if (val==0){ System.out.println("undefined"); } else if (val ==1){ System.out.println("cw"); } else if (val==2){ System.out.println("ccw"); } } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int main() { long long int h[] = {94, 62, 118, 60}, n; char s, e; cin >> s >> e >> n; if (s == e || n == 0) cout << "undefined" << endl; else { n = n % 4; int ds = -1, de = -1; for (int i = 0; i < 4; i++) { if (h[i] == s && ds == -1) ds = i; if (h[i] == e && de == -1) de = i; } int cw = (ds + n) % 4; int ccw = (4 + ds - n) % 4; if ((cw == de && ccw == de) || (cw != de && ccw != de)) cout << "undefined" << endl; else if (cw == de) cout << "cw" << endl; else cout << "ccw" << endl; } return 0; }
CPP
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import sys def f(a): if a == '>': return 1 elif a == 'v': return 2 elif a == '<': return 3 else: return 4 def g(a): if a == '>': return 1 elif a == '^': return 2 elif a == '<': return 3 else: return 4 inital, final = raw_input().split() n = input() s = f(inital) + n t = g(inital) + n if t > 4: if t % 4 != 0: t = t % 4 else: t = 4 if s > 4: if s % 4 != 0: s = s % 4 else: s = 4 if s == f(final) and t == g(final): print 'undefined' sys.exit() if t == g(final): print 'ccw' sys.exit() print 'cw'
PYTHON
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int get(char x) { if (x == 118) return 0; if (x == 60) return 1; if (x == 94) return 2; return 3; } int main() { char s, e; int n, si, ei; cin >> s >> e; cin >> n; si = get(s); ei = get(e); n = n % 4; bool a = false, b = false; int sii = si, eii = si; for (int i = 0; i < n; i++) { sii++; } sii = sii % 4; a = sii == ei; for (int i = 0; i < n; i++) { eii--; } while (eii < 0) eii += 4; eii = eii % 4; b = eii == ei; if (a && !b) { cout << "cw" << endl; } else if (b && !a) { cout << "ccw" << endl; } else { cout << "undefined" << endl; } }
CPP
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int main() { char a, b; int n, c[1001]; c[118] = 1, c[60] = 2, c[94] = 3, c[62] = 4; cin >> a >> b >> n; int x = a, y = b; bool xx = 0, yy = 0; if ((c[x] + n) % 4 == c[y] % 4) xx = 1; if (((c[x] - n) % 4 + 4) % 4 == c[y] % 4) yy = 1; if ((xx == 1 && yy == 1) || !(xx == 1 || yy == 1)) cout << "undefined" << endl; else if (xx == 1) cout << "cw" << endl; else if (yy == 1) cout << "ccw" << endl; return 0; }
CPP
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int cw_char[4][4] = {118, 60, 94, 62, 60, 94, 62, 118, 94, 62, 118, 60, 62, 118, 60, 94}; int ccw_char[4][4] = {118, 62, 94, 60, 60, 118, 62, 94, 94, 60, 118, 62, 62, 94, 60, 118}; int main() { char s, e; int n, t; cin >> s >> e >> n; if (n % 2 == 0) cout << "undefined" << endl; else { n %= 4; switch (s) { case 'v': if (cw_char[0][n] == e) cout << "cw" << endl; else cout << "ccw" << endl; return 0; case '<': if (cw_char[1][n] == e) cout << "cw" << endl; else cout << "ccw" << endl; return 0; case '^': if (cw_char[2][n] == e) cout << "cw" << endl; else cout << "ccw" << endl; return 0; case '>': if (cw_char[3][n] == e) cout << "cw" << endl; else cout << "ccw" << endl; return 0; default: break; } } return 0; }
CPP
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int main() { char a, b; int n; cin >> a >> b >> n; if (n % 2 == 0 || n == 0) { cout << "undefined"; return 0; } if ((a == 94 && b == 62) || (a == 62 && b == 118) || (a == 118 && b == 60) || (a == 60 && b == 94)) { if (n % 4 == 1) cout << "cw"; else cout << "ccw"; } if ((a == 94 && b == 60) || (a == 60 && b == 118) || (a == 118 && b == 62) || (a == 62 && b == 94)) { if (n % 4 == 1) cout << "ccw"; else cout << "cw"; } }
CPP
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
start, end = [ str(x) for x in input().split()] n = int(input()) spinner_sides = ['^', '>', 'v', '<'] def get_side(spinner): if(spinner == '^'): return 0 elif spinner == '>': return 1 elif spinner == 'v': return 2 else: return 3 # ignore full rotations n = n % 4 if( n % 2 == 0 ): print('undefined') exit() else: # final turns are 1 or 3 # see which side it rotates curr_side = get_side(start) while(n): curr_side = (curr_side+1)%4 n -= 1 if(spinner_sides[curr_side] == end): print('cw') else: print('ccw')
PYTHON3
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
alph = "v<^>" pos = input() n = int(input()) if n % 2 == 0: print("undefined") else: if (alph.find(pos[0]) - alph.find(pos[2])) % 4 - n % 4 == 0: print("ccw") else: print("cw")
PYTHON3
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
st1, ed = map(str, input().split()) m = ['v', '<', '^', '>'] si = m.index(st1) ei = m.index(ed) n = int(input()) n %= 4 if n % 2 == 0: print('undefined') elif m[si - n] == ed: print('ccw') else: print('cw')
PYTHON3
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
from collections import deque def main(): START, END = input().split() N = int(input()) cw = deque('v<^>') while True: if cw[0] == START: break else: cw.rotate(1) ccw = deque(cw) n = N % 4 for i in range(n): cw.rotate(-1) ccw.rotate(1) if cw[0] == ccw[0]: print('undefined') elif cw[0] == END: print('cw') else: print('ccw') main()
PYTHON3
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
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')
PYTHON3
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
s,f = raw_input().split() n = input() if n%2 == 0: print 'undefined' quit() n = n%4 if n == 1: if s == 'v': if f == '<': print 'cw' else: print 'ccw' if s == '<': if f == '^': print 'cw' else: print 'ccw' if s == '^': if f == '>': print 'cw' else: print 'ccw' if s == '>': if f == 'v': print 'cw' else: print 'ccw' else: if s == 'v': if f == '<': print 'ccw' else: print 'cw' if s == '<': if f == '^': print 'ccw' else: print 'cw' if s == '^': if f == '>': print 'ccw' else: print 'cw' if s == '>': if f == 'v': print 'ccw' else: print 'cw'
PYTHON
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
a, b=input().split() n=int(input()) m = {j: i for i, j in enumerate(['v', '>', '^', '<'])} if n%2==0: print("undefined") else: print("c" + ("c" if (m[a]+n)%4==m[b] else "") + "w")
PYTHON3
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
a=dict([('^',0),('>',1),('v',2),('<',3)]) x,y = raw_input().strip().split() k = int(raw_input().strip()) x = a[x] y = a[y] if (x+k)%4==y and (x-k)%4==y: print 'undefined' elif (x+k)%4==y: print 'cw' elif (x-k)%4==y: print 'ccw' else: print 'undefined'
PYTHON
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int main() { int a = 0; int b = 0; char s[] = {'<', '^', '>', 'v'}; char ca = getchar(); getchar(); char cb = getchar(); int n; cin >> n; n %= 4; for (int i = 0; i < 4; i++) { if (s[i] == ca) { a = i; } if (s[i] == cb) { b = i; } } int t = a; for (int k = 0; k < n; k++) { a++; if (a == 4) { a = 0; } } bool cw = false; bool ccw = false; if (a == b) { cw = true; } a = t; for (int k = 0; k < n; k++) { b++; if (b == 4) { b = 0; } } if (a == b) { ccw = true; } if (cw && ccw) { cout << "undefined" << endl; } else if (cw || ccw) { if (cw) { cout << "cw" << endl; } else { cout << "ccw" << endl; } } else { cout << "undefined" << endl; } return 0; }
CPP
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.util.*; import java.lang.*; import java.math.*; import java.io.*; /* spar5h */ public class codeforces implements Runnable { public void run() { InputReader s = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); char start = s.next().charAt(0); char end = s.next().charAt(0); long n = Long.parseLong(s.next()); if(start == '^') { if(n % 2 == 0) w.println("undefined"); else if(end == '>') { if(n % 4 == 1) w.println("cw"); else w.println("ccw"); } else if(end == '<') { if (n % 4 == 1) w.println("ccw"); else w.println("cw"); } } else if(start == '>') { if(n % 2 == 0) w.println("undefined"); else if(end == 'v') { if(n % 4 == 1) w.println("cw"); else w.println("ccw"); } else if(end == '^') { if (n % 4 == 1) w.println("ccw"); else w.println("cw"); } } else if(start == 'v') { if(n % 2 == 0) w.println("undefined"); else if(end == '<') { if(n % 4 == 1) w.println("cw"); else w.println("ccw"); } else if(end == '>') { if (n % 4 == 1) w.println("ccw"); else w.println("cw"); } } else { if(n % 2 == 0) w.println("undefined"); else if(end == '^') { if(n % 4 == 1) w.println("cw"); else w.println("ccw"); } else if(end == 'v') { if (n % 4 == 1) w.println("ccw"); else w.println("cw"); } } w.close(); } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars==-1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if(numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { int c = read(); while(isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if(c<'0'||c>'9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } public static void main(String args[]) throws Exception { new Thread(null, new codeforces(),"codeforces",1<<26).start(); } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.util.*; import java.util.stream.*; public class Solution { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String s = scan.nextLine(); int n = scan.nextInt(); Integer start = state(s.charAt(0)); Integer end = state(s.charAt(2)); n = n%4; List<Integer> cw = Arrays.asList(1,2,3,4,1,2,3,4); List<Integer> ccw = Arrays.asList(1,4,3,2,1,4,3,2); String result; boolean isCw = cw.get(cw.indexOf(start) + n) == end; boolean isCcw = ccw.get(ccw.indexOf(start) + n) == end; if(isCw && !isCcw) { result = "cw"; } else if(isCcw && !isCw) { result = "ccw"; } else { result = "undefined"; } System.out.println(result); } private static int state(char ch) { if(ch == 'v') { return 1; } else if(ch == '<') { return 2; } else if(ch == '^') { return 3; } else if(ch == '>') { return 4; } else { return -1; } } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
a,b=raw_input().split() c={"^":1,">":2,"<":4,"v":3} t=input() t=t%4 flag=0 flag2=0 if (c[a]-c[b])%4==t: flag=1 if (c[b]-c[a])%4==t:flag2=1 if flag==1 and flag2==1: print "undefined";exit() if flag==1: print "ccw";exit() if flag2==1: print "cw";exit()
PYTHON
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); char CW[4] = {'^', '>', 'v', '<'}; char CCW[4] = {'^', '<', 'v', '>'}; char st, en; int n; cin >> st >> en >> n; int s1, s2; for (int i = 0; i < 4; ++i) { if (CW[i] == st) s1 = i; } for (int i = 0; i < 4; ++i) { if (CCW[i] == st) s2 = i; } int e1, e2; e1 = CW[(s1 + n) % 4]; e2 = CCW[(s2 + n) % 4]; if (e1 == e2) { cout << "undefined\n"; return 0; } if (e1 == en) { cout << "cw\n"; } else { cout << "ccw\n"; } return 0; }
CPP
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.io.PrintStream; import java.util.Scanner; import java.util.ArrayList; public class JavaApplication1 { static PrintStream p = System.out; public static void main(String[] args) { Scanner sc = new Scanner(System.in); char x = sc.next().charAt(0); char y = sc.next().charAt(0); int k = sc.nextInt(); ArrayList e = new ArrayList(); e.add('v'); e.add('<'); e.add('^'); e.add('>'); int del = (e.indexOf(y)-e.indexOf(x)+4) % 4; if(del==0 || del==2) p.print("undefined"); else if (del == k%4) p.print("cw"); else p.print("ccw"); } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.util.Scanner; public class A { public static void main(String[] args) { Scanner in = new Scanner(System.in); char st = in.next().charAt(0),en = in.next().charAt(0); int n = in.nextInt(); boolean cw = false,ccw = false; char st1 = st; n = n%4; for(int i = 0 ; i < n ; i++){ if(st1 == '<') st1 = '^'; else if(st1 == '^') st1 = '>'; else if(st1 == '>') st1 = 'v'; else if(st1 == 'v') st1 = '<'; } if(st1==en) cw = true; st1 = st; for(int i = 0 ; i < n ; i++){ if(st1 == '<') st1 = 'v'; else if(st1 == 'v') st1 = '>'; else if(st1 == '>') st1 = '^'; else if(st1 == '^') st1 = '<'; } if(st1==en) ccw = true; if(ccw&&cw) System.out.println("undefined"); else if(cw) System.out.println("cw"); else if(ccw) System.out.println("ccw"); else System.out.println("undefined"); } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int direction(int asc) { int UP = 94; int LEFT = 60; int RIGHT = 62; int DOWN = 118; if (asc == UP) { return 0; } else if (asc == RIGHT) { return 1; } else if (asc == DOWN) { return 2; } else { return 3; } } int main(int argc, char *argv[]) { char s_in, e_in; int t; cin >> s_in >> e_in; cin >> t; int s = int(s_in); int e = int(e_in); int remainder = t % 4; int sdir = direction(s); int edir = direction(e); string answer = "undefined"; int move = (sdir + remainder) % 4; if (move == edir) { answer = "cw"; } else { answer = "ccw"; } if (sdir == edir || remainder == 2) { answer = "undefined"; } cout << answer; }
CPP
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; map<char, int> m; int n, a, b; char s[3], ss[3]; void input() { scanf("%s%s", s, ss); scanf("%d", &n); } void output() { if (b == n && a != n) printf("ccw\n"); else if (a == n && b != n) printf("cw\n"); else printf("undefined\n"); } int main() { m['V'] = 0; m['<'] = 1; m['^'] = 2; m['>'] = 3; input(); n = n % 4; b = (m[s[0]] + 4 - m[ss[0]]) % 4; a = (m[ss[0]] + 4 - m[s[0]]) % 4; output(); return 0; }
CPP
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
st, nd = input().split() n = int(input()) x = ['<', '^', '>', 'v'] st = x.index(st) nd = x.index(nd) if (st + nd) % 2 == 0: print('undefined') else: n %= 4 if (st + n) % 4 == nd: print('cw') else: print('ccw')
PYTHON3
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub //DisjointSet set = new DisjointSet(26); InputReader sc1 = new InputReader(System.in); PrintWriter sc2 = new PrintWriter(System.out); char start = sc1.readString().charAt(0); char end = sc1.readString().charAt(0); int time = sc1.nextInt(); time = time%4; int s=0,e=0; char c[] = {'v', '<', '^', '>'}; for(int i=0;i<4;i++) { if(start==c[i]) { s = i; break; } } for(int i=0;i<4;i++) { if(end==c[i]) { e = i; break; } } boolean cw = false, ccw = false; if((s+time)%4==e) { cw = true; } s = (s - time)%4; if(s<0) { s = 4 + s; } if(s==e) { ccw = true; } if(cw==true && ccw==true) { System.out.println("undefined"); } else if(cw==true) { sc2.println("cw"); } else { sc2.println("ccw"); } sc2.close(); } /* * DIVISORS * */ public static void divsors(int n) { for(int i=1;i<=Math.sqrt(n)+1;i++) { if(n%i==0) { if(n/i==i) { System.out.print(i+" "); } else { System.out.print (i+" "+n/i); } } } } /* * GCD * */ public static int GCD(int x, int y) { if(x==0) { return y; } return GCD(y%x, x); } /* * GCD EXTENDED * */ public static int gcdExtended(int a, int b, int x, int y) { if(a==0) { x = 0; y = 1; return b; } int x1 = 1, y1 = 1; int gcd = gcdExtended(b%a, a, x1, y1); x = y1 - (b/a)*x1; y = x1; return gcd; } static class DisjointSet{ static StringBuilder str = new StringBuilder(); static int count = 0; int rank[]; int parent[]; int n; DisjointSet(int n){ this.n = n; rank = new int[n]; Arrays.fill(rank, 0); parent = new int[n]; makeSet(); } void makeSet() { for(int i=0;i<n;i++) { parent[i] = i; } } int find(int x) { if(parent[x]!=x) { parent[x] = find(parent[x]); } return parent[x]; } void union(int x, int y) { int xRoot = find(x); int yRoot = find(y); if(xRoot==yRoot) { return; } if(rank[xRoot]>rank[yRoot]) { parent[yRoot] = xRoot; Append(x,y); count++; } else if(rank[xRoot]<rank[yRoot]) { parent[xRoot] = yRoot; Append(x,y); count++; } else { parent[yRoot] = xRoot; rank[xRoot] = rank[xRoot] + 1; count++; Append(x,y); } } void Append(int x, int y) { str.append((char)(x+97)+" "+(char)(y+97)+"\n"); } } static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) c = snext(); int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) c = snext(); int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public String readString() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.io.*; import java.util.*; public class Main { void howUdoin() { String st=inps(); char a='^',d='<',b='>',c='v'; char s=st.charAt(0); st=inps(); char e=st.charAt(0); int n=inpi(); int f=0; double x,y; String ans=""; if((s==a || s==c) && (e==a || e==c)){ System.out.println("undefined"); return; } else if((s==b || s==d) && (e==b || e==d)){ System.out.println("undefined"); return; } x=(double)(n+3)/4; y=(double)(n+1)/4; if(x-Math.floor(x)==0){ f=1; } else if(y-Math.floor(y)==0){ f=2; } else { System.out.println("undefined"); return; } if(s==a){ if((f==1 && e==b) || (f==2 && e==d)){ ans="cw"; } else{ ans="ccw"; } } else if(s==b){ if((f==1 && e==c) || (f==2 && e==a)){ ans="cw"; } else{ ans="ccw"; } } else if(s==c){ if((f==1 && e==d) || (f==2 && e==b)){ ans="cw"; } else{ ans="ccw"; } } else{ if((f==1 && e==a) || (f==2 && e==c)){ ans="cw"; } else{ ans="ccw"; } } System.out.println(ans); } InputStream obj; PrintWriter out; String check = ""; public static void main(String[] args) throws IOException { new Main().main1(); } void main1() throws IOException { out = new PrintWriter(System.out); obj = check.isEmpty() ? System.in : new ByteArrayInputStream(check.getBytes()); howUdoin(); out.flush(); out.close(); } byte inbuffer[] = new byte[1024]; int lenbuffer = 0, ptrbuffer = 0; int readByte() { if (lenbuffer == -1) { throw new InputMismatchException(); } if (ptrbuffer >= lenbuffer) { ptrbuffer = 0; try { lenbuffer = obj.read(inbuffer); } catch (IOException e) { throw new InputMismatchException(); } } if (lenbuffer <= 0) { return -1; } return inbuffer[ptrbuffer++]; } boolean isSpaceChar(int c) { return (!(c >= 33 && c <= 126)); } int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)); return b; } String inps() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } String inpsl() { int b = skip(); StringBuilder sb = new StringBuilder(); while (b!='\n') { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } int inpi() { int num = 0, b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } long inpl() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } float inpf() { return Float.parseFloat(inps()); } double inpd() { return Double.parseDouble(inps()); } char inpc() { return (char) skip(); } int[] inpia(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = inpi(); } return a; } long[] inpla(int n) { long a[] = new long[n]; for (int i = 0; i < n; i++) { a[i] = inpl(); } return a; } String[] inpsa(int n) { String a[] = new String[n]; for (int i = 0; i < n; i++) { a[i] = inps(); } return a; } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
start, end = input().split() n = int(input()) l = ['^', '>', 'v', '<'] * 2 ni = n % 4 ans = [] if l[l.index(start) + ni] == end: ans.append('cw') if l[[i for i, n in enumerate(l) if n == start][1] - ni] == end: ans.append('ccw') if len(ans) == 2 or len(ans) == 0: print('undefined') else: print(*ans)
PYTHON3
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.util.Scanner; import java.util.stream.IntStream; public class Main { static char[] POSITIONS = { 'v', '<', '^', '>' }; public static void main(String[] args) { Scanner sc = new Scanner(System.in); char start = sc.next().charAt(0); char end = sc.next().charAt(0); int n = sc.nextInt(); System.out.println(solve(start, end, n)); sc.close(); } static String solve(char start, char end, int n) { int startIndex = IntStream.range(0, POSITIONS.length).filter(i -> POSITIONS[i] == start).findAny().getAsInt(); boolean isClockwise = POSITIONS[(startIndex + n) % POSITIONS.length] == end; boolean isCounterClockwise = POSITIONS[((startIndex - n) % POSITIONS.length + POSITIONS.length) % POSITIONS.length] == end; if (isClockwise && isCounterClockwise) { return "undefined"; } else if (isClockwise) { return "cw"; } else { return "ccw"; } } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int n; char s1, s2; map<char, int> m; void nhap() { scanf("%c", &s1); scanf("%c", &s2); scanf("%c", &s2); scanf("%d", &n); m['^'] = 1; m['>'] = 2; m['v'] = 3; m['<'] = 4; } int main() { nhap(); if (n % 2 == 0) { cout << "undefined"; return 0; } int so1 = m[s1]; int so2 = m[s2]; n %= 4; so1 = (so1 + n) % 4; if (so1 == 0) so1 = 4; if (so1 == so2) cout << "cw"; else cout << "ccw"; return 0; }
CPP
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
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')
PYTHON3
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import sys [a, b] = sys.stdin.readline().split() [n] = [int(x) for x in sys.stdin.readline().split()] pos = ["<", "^", ">", "v"] if n % 2 == 0: print "undefined" else: if (pos.index(a) - pos.index(b) + 4 + n) % 4 == 0: print "cw" else: print "ccw" ''' === ^ > 1 --- cw === < ^ 3 --- ccw === ^ v 6 --- undefined === '''
PYTHON
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
s1, s2 = input().split() n = int(input()) % 4 i1 = "^>v<".index(s1) i2 = "^>v<".index(s2) delta = (i2-i1)%4 if n & 1 == 0: print("undefined") elif delta == n: print("cw") else: print("ccw")
PYTHON3
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int main() { char ch1, ch2; cin >> ch1 >> ch2; int n; cin >> n; if (ch1 == 118) { if (n % 4 == 1) { if (ch2 == 60) { cout << "cw"; return 0; } else if (ch2 == 62) { cout << "ccw"; return 0; } } else if (n % 4 == 2) { if (ch2 == 94) { cout << "undefined"; return 0; } } else if (n % 4 == 3) { if (ch2 == 62) { cout << "cw"; return 0; } else if (ch2 == 60) { cout << "ccw"; return 0; } } else if (n % 4 == 0) { if (ch2 == 118) { cout << "undefined"; return 0; } } } else if (ch1 == 60) { if (n % 4 == 1) { if (ch2 == 94) { cout << "cw"; return 0; } else if (ch2 == 118) { cout << "ccw"; return 0; } } else if (n % 4 == 2) { if (ch2 == 62) { cout << "undefined"; return 0; } } else if (n % 4 == 3) { if (ch2 == 118) { cout << "cw"; return 0; } else if (ch2 == 94) { cout << "ccw"; return 0; } } else if (n % 4 == 0) { if (ch2 == 60) { cout << "undefined"; return 0; } } } else if (ch1 == 94) { if (n % 4 == 1) { if (ch2 == 62) { cout << "cw"; return 0; } else if (ch2 == 60) { cout << "ccw"; return 0; } } else if (n % 4 == 2) { if (ch2 == 118) { cout << "undefined"; return 0; } } else if (n % 4 == 3) { if (ch2 == 60) { cout << "cw"; return 0; } else if (ch2 == 62) { cout << "ccw"; return 0; } } else if (n % 4 == 0) { if (ch2 == 94) { cout << "undefined"; return 0; } } } else if (ch1 == 62) { if (n % 4 == 1) { if (ch2 == 118) { cout << "cw"; return 0; } else if (ch2 == 94) { cout << "ccw"; return 0; } } else if (n % 4 == 2) { if (ch2 == 60) { cout << "undefined"; return 0; } } else if (n % 4 == 3) { if (ch2 == 94) { cout << "cw"; return 0; } else if (ch2 == 118) { cout << "ccw"; return 0; } } else if (n % 4 == 0) { if (ch2 == 62) { cout << "undefined"; return 0; } } } cout << "undefined"; return 0; }
CPP
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> inline int idx(char c) { if (c == 'v') return 0; if (c == '<') return 1; if (c == '^') return 2; if (c == '>') return 3; return 0; } char c2[3], c1[3]; int n, a, b; int main() { scanf("%s%s%d", c1, c2, &n); a = idx(*c1); b = idx(*c2); n %= 4; if (!n || ((a + n) % 4 == b && n == 2)) puts("undefined"); else if ((a + n) % 4 == b) puts("cw"); else if ((b + n) % 4 == a) puts("ccw"); return 0; }
CPP
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int n; char a[5]; char s1[3], s2[3]; void solve() { int i, vt, kq1, kq2; scanf("%d", &n); n = n % 4; a[0] = 'v'; a[1] = '<'; a[2] = '^'; a[3] = '>'; for (i = 0; i < 4; i++) if (a[i] == s1[0]) vt = i; kq1 = 0; kq2 = 0; if (a[(vt + n) % 4] == s2[0]) kq1 = 1; if (a[(vt - n + 4) % 4] == s2[0]) kq2 = 1; if (kq1 == 1 && kq2 == 0) printf("cw\n"); if (kq1 == 0 && kq2 == 1) printf("ccw\n"); if ((kq1 == 0 && kq2 == 0) || (kq1 == 1 && kq2 == 1)) printf("undefined\n"); } int main() { while (scanf("%s %s", &s1, &s2) > 0) { solve(); } return 0; }
CPP
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
# Description of the problem can be found at http://codeforces.com/problemset/problem/834/A d = {"v": 0, "<": 1, "^": 2, ">": 3} f1, f2 = input().split() s = int(input()) x1 = (d[f1] + s) % 4 == d[f2] x2 = (d[f1] - s) % 4 == d[f2] if x1 and x2: print("undefined") elif x1: print("cw") else: print("ccw")
PYTHON3
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Scanner; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Toni Rajkovski */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } static class TaskA { public void solve(int testNumber, Scanner in, PrintWriter out) { char[] chars = new char[]{'v', '<', '^', '>'}; char start = in.next().charAt(0); char end = in.next().charAt(0); int rotations = in.nextInt(); int startPos = findPos(start, chars); int endPos = findPos(end, chars); rotations %= 4; boolean cw = endPos == ((startPos + rotations) % 4); boolean ccw = endPos == ((startPos - rotations + 4) % 4); if (cw && !ccw) out.println("cw"); else if (ccw && !cw) out.println("ccw"); else out.println("undefined"); } private int findPos(char c, char[] arr) { for (int i = 0; i < arr.length; i++) { if (arr[i] == c) return i; } return -1; } } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
a, b= input().split() n= int(input()) n%=4 if(n%2==0): print('undefined') exit() a, b = ord(a), ord(b) d={118: 60, 60: 94, 94: 62, 62:118} if(n==1): if(d[a]== b): print('cw') else: print('ccw') else: if(d[a]== b): print('ccw') else: print('cw')
PYTHON3
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
string =input() rotation =int(input()) start =string[0] cstart =start end =string[2] if rotation%2 == 0: print ("undefined") quit() if rotation > 4:rotation =rotation%4 for i in range(rotation): if start == ">":start ="v" elif start == "v":start ="<" elif start == "<":start ="^" elif start == "^":start =">" if start == end: print ("cw") quit() start =cstart for i in range(rotation): if start == ">":start ="^" elif start == "v":start =">" elif start == "<":start ="v" elif start == "^":start ="<" if start == end: print ("ccw") quit() print ("undefined")
PYTHON3
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
s,e = raw_input().split() n = int(raw_input())%4 #print n ccw = ['^', '<', 'v', '>'] cw = ['^', '>', 'v', '<'] cws = cw.index(s) cwe = cw.index(e) cwn = cwe - cws if (cwn < 0): cwn = 4 + cwn #print cwn ccws = ccw.index(s) ccwe = ccw.index(e) ccwn = ccwe - ccws if (ccwn < 0): ccwn = 4 + ccwn #print ccwn if (cwn != ccwn): if (cwn == n): print "cw" elif (ccwn == n): print "ccw" else: print "undefined"
PYTHON
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.io.BufferedReader; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import javax.swing.plaf.synth.SynthSpinnerUI; import javax.swing.text.AbstractDocument.LeafElement; public class Main2 { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); String start = sc.next(); String end= sc.next(); int n = sc.nextInt()%4; int s= getPos(start); int e = getPos(end); int dif = (e-s+ 4)%4; if(dif == 1 && n == 1 || dif == 3 && n == 3) System.out.println("cw"); else if(dif == 1 && n == 3 || dif == 3 && n == 1) System.out.println("ccw"); else System.out.println("undefined"); } static int getPos(String s) { if(s.equals("^")) return 0; if(s.equals(">")) return 1; if(s.equals("v")) return 2; return 3; } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
read = lambda: map(int, input().split()) a, b = input().split() n = int(input()) % 4 s = 'v<^>' k1 = (s.index(b) - s.index(a)) % 4 k2 = (s.index(a) - s.index(b)) % 4 print('cw' if k1 == n and k2 != n else 'ccw' if k1 != n and k2 == n else 'undefined')
PYTHON3
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; map<char, int> ma; int main() { ma['v'] = 0; ma['<'] = 1; ma['^'] = 2; ma['>'] = 3; char c1, c2; cin >> c1 >> c2; int n; cin >> n; n %= 4; if (n == 2 || n == 0) { cout << "undefined" << endl; } else if (n == 1) { int temp = ma[c2] - ma[c1]; if (temp < 0) { temp += 4; } if (temp == 1) { cout << "cw" << endl; } else if (temp == 3) { cout << "ccw" << endl; } else { cout << "undefined" << endl; } } else if (n == 3) { int temp = ma[c2] - ma[c1]; if (temp < 0) { temp += 4; } if (temp == 1) { cout << "ccw" << endl; } else if (temp == 3) { cout << "cw" << endl; } else { cout << "undefined" << endl; } } return 0; }
CPP
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
a=str(input()) #print(a) t=int(input()) t1=t%4 if t1==0: print('undefined') if t1==1: if a=='^ >' or a=='> v' or a=='v <' or a=='< ^': print('cw') else: print('ccw') if t1==2: print('undefined') if t1==3: if a=='^ >' or a=='> v' or a=='v <' or a=='< ^': print('ccw') else: print('cw')
PYTHON3
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
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')
PYTHON3
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
a = ["^",">","v","<"] b = ["^","<","v",">"] s = raw_input().split() n = input() currentPos = a.index(s[0]) afterNMovesA = a[(currentPos+n)%4] currentPos = b.index(s[0]) afterNMovesB = b[(currentPos+n)%4] if s[1] == afterNMovesB and s[1] == afterNMovesA: print "undefined" elif s[1] == afterNMovesA: print "cw" elif s[1] == afterNMovesB: print "ccw" else: print "undefined"
PYTHON
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Main { static Scanner sc = new Scanner(System.in); static PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) throws IOException { char down = 118, left = 60, up = 94, right = 62; String s1 = sc.next(), s2 = sc.next(); char c1 = s1.charAt(0), c2 = s2.charAt(0); int n = sc.nextInt() % 4; boolean cw = false, ccw = false; if (n == 0 || n == 2) { // undefined } else if (n == 1) { if(c1==down&&c2==left|| c1 == left && c2==up || c1 == up && c2 == right || c1 ==right && c2 == down){ cw = true ; }else if(c1 == down && c2 == right|| c1 == right && c2 == up|| c1 == up && c2 == left|| c1 == left && c2 == down) { ccw = true ; } } else if (n == 3) { if(c1==down&&c2==left|| c1 == left && c2==up || c1 == up && c2 == right || c1 ==right && c2 == down){ ccw = true ; }else if(c1 == down && c2 == right|| c1 == right && c2 == up|| c1 == up && c2 == left|| c1 == left && c2 == down) { cw = true ; } } if(!cw && !ccw){ System.out.println("undefined"); }else if(cw)System.out.println("cw"); else System.out.println("ccw"); pw.flush(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public boolean ready() throws IOException { return br.ready(); } public int[] nextIntArray(int n) throws IOException { int[] array = new int[n]; for (int i = 0; i < n; i++) { array[i] = nextInt(); } return array; } } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1}; int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1}; int xChange[] = {0, 1, 0, -1}; int yChange[] = {1, 0, -1, 0}; int main() { ios::sync_with_stdio(false), cin.tie(NULL); char st, en; int n; cin >> st >> en >> n; n %= 4; bool clockwise, counter_clockwise; clockwise = counter_clockwise = false; char x = st; int nn = n; while (n--) { if (x == '<') x = '^'; else if (x == '>') x = 'v'; else if (x == '^') x = '>'; else if (x == 'v') x = '<'; } if (x == en) clockwise = true; x = st; while (nn--) { if (x == '<') x = 'v'; else if (x == '>') x = '^'; else if (x == '^') x = '<'; else if (x == 'v') x = '>'; } if (x == en) counter_clockwise = true; if (clockwise && !counter_clockwise) cout << "cw"; else if (!clockwise && counter_clockwise) cout << "ccw"; else cout << "undefined"; return 0; }
CPP
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.io.*; import java.util.StringTokenizer; /** * 834A * ΞΈ(1) time * ΞΈ(1) space * * @author artyom */ public class _834A implements Runnable { private BufferedReader in; private StringTokenizer tok; private Object solve() throws IOException { String s = nextToken(), t = nextToken(); int n = nextInt(); if ((n & 1) == 0) { return "undefined"; } if (n % 4 == 1) { switch (s) { case "^": return t.equals(">") ? "cw" : "ccw"; case ">": return t.equals("v") ? "cw" : "ccw"; case "v": return t.equals("<") ? "cw" : "ccw"; default: return t.equals("^") ? "cw" : "ccw"; } } switch (s) { case "^": return t.equals("<") ? "cw" : "ccw"; case ">": return t.equals("^") ? "cw" : "ccw"; case "v": return t.equals(">") ? "cw" : "ccw"; default: return t.equals("v") ? "cw" : "ccw"; } } //-------------------------------------------------------------- public static void main(String[] args) { new _834A().run(); } @Override public void run() { try { in = new BufferedReader(new InputStreamReader(System.in)); tok = null; System.out.print(solve()); in.close(); } catch (IOException e) { System.exit(0); } } private String nextToken() throws IOException { while (tok == null || !tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); } return tok.nextToken(); } private int nextInt() throws IOException { return Integer.parseInt(nextToken()); } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { // InputReader in = new InputReader(new BufferedInputStream(System.in)); Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); String str = in.nextLine(); int[] dir = {118, 60, 94, 62}; int k = in.nextInt() % 4; int dir1 = 0; while (str.charAt(0) != dir[dir1]) { ++dir1; } int dir2 = 0; while (str.charAt(2) != dir[dir2]) { ++dir2; } if(dir2 - dir1 == 2 || dir1 - dir2 == 2 || dir1 == dir2) { System.out.println("undefined"); } else if (dir2 - dir1 == k || dir2 - dir1 + 4 == k) { System.out.println("cw"); } else if (dir1 - dir2 == k || dir1 - dir2 + 4 == k) { System.out.println("ccw"); } } } class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { e.printStackTrace(); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.util.*; public class A_TheUselessToy { public static void main(String[] args) { Scanner in = new Scanner(System.in); String ch1 = in.next(); String ch2 = in.next(); int num = in.nextInt(); String str[] = new String[4]; str[0] = "^"; str[1] = ">";str[2] = "v"; str[3] = "<"; int start = 0, end = 0; for (int i = 0; i < 4; i++){ if (ch1.equals(str[i])) start = i; if (ch2.equals(str[i])) end = i; } boolean cw = false; boolean ccw = false; if (((start + num) % 4) == end) cw = true; if ((((start - (num % 4))+4)%4)== end) ccw = true; if(ccw == true && cw ==true) System.out.println("undefined"); else System.out.println(cw?"cw":"ccw"); } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int main() { char s, c; int n; cin >> s >> c; cin >> n; string s1 = "v<^>"; int f, f3, f4; for (int i = 0; i < 4; i++) { if (s1[i] == s) f = i; } f3 = (f + n) % 4; f4 = ((f - n) % 4 + 4) % 4; if (s1[f3] == s1[f4]) cout << "undefined" << endl; else if (s1[f3] == c) cout << "cw" << endl; else cout << "ccw" << endl; return 0; }
CPP
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } static class TaskA { public void solve(int testNumber, InputReader in, PrintWriter out) { int st = parse(in.nextCharacter()); int end = parse(in.nextCharacter()); int n = in.nextInt() % 4; if (n % 2 == 0) out.print("undefined"); else if ((end + 4 - st) % 4 == n) out.print("cw"); else out.print("ccw"); } int parse(char c) { switch (c) { case 'v': return 0; case '<': return 1; case '^': return 2; case '>': return 3; } return -1; } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public char nextCharacter() { int c = read(); while (isSpaceChar(c)) { c = read(); } return (char) c; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.util.*; import java.io.*; import java.lang.*; public class A834 { private static long mod = 1000000007; public static void main(String[] args) { InputReader in=new InputReader(System.in); PrintWriter pw=new PrintWriter(System.out); String a=in.nextLine(); char c1=a.charAt(0); char c2=a.charAt(2); long l=in.nextLong(); int[] arr=new int[2]; //pw.println(c1+" "+c2); if(c1=='^') arr[0]=0; else if(c1=='<') arr[0]=3; else if(c1=='>') arr[0]=1; else arr[0]=2; if(c2=='^') arr[1]=0; else if(c2=='<') arr[1]=3; else if(c2=='>') arr[1]=1; else arr[1]=2; l=l%4; // pw.println(l); //pw.println(arr[1]+" "+arr[0]+" "+l); if(Math.abs(arr[0]-arr[1])==2 ||Math.abs(arr[0]-arr[1])==0) pw.println("undefined"); else if(arr[1]>arr[0] &&Math.abs(arr[1]-arr[0])==(4-l)) pw.println("ccw"); else if(arr[1]>arr[0] && Math.abs(arr[1]-arr[0])==l) pw.print("cw"); else if(arr[1]<arr[0] && Math.abs(arr[1]-arr[0])==(4-l)) pw.println("cw"); else if(arr[1]<arr[0] && Math.abs(arr[1]-arr[0])==l) pw.println("ccw"); pw.flush(); pw.close(); } static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public long[] nextLongArray(int n) { long a[] = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextLong(); } return a; } public String readString() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } public static int[] suffle(int[] a,Random gen) { int n = a.length; for(int i=0;i<n;i++) { int ind = gen.nextInt(n-i)+i; int temp = a[ind]; a[ind] = a[i]; a[i] = temp; } return a; } public static void swap(int a, int b){ int temp = a; a = b; b = temp; } public static ArrayList<Integer> primeFactorization(int n) { ArrayList<Integer> a =new ArrayList<Integer>(); for(int i=2;i*i<=n;i++) { while(n%i==0) { a.add(i); n/=i; } } if(n!=1) a.add(n); return a; } public static void sieve(boolean[] isPrime,int n) { for(int i=1;i<n;i++) isPrime[i] = true; isPrime[0] = false; isPrime[1] = false; for(int i=2;i*i<n;i++) { if(isPrime[i] == true) { for(int j=(2*i);j<n;j+=i) isPrime[j] = false; } } } public static int GCD(int a,int b) { if(b==0) return a; else return GCD(b,a%b); } public static long GCD(long a,long b) { if(b==0) return a; else return GCD(b,a%b); } public static long LCM(long a,long b) { return (a*b)/GCD(a,b); } public static int LCM(int a,int b) { return (a*b)/GCD(a,b); } public static int binaryExponentiation(int x,int n) { int result=1; while(n>0) { if(n % 2 ==1) result=result * x; x=x*x; n=n/2; } return result; } public static long binaryExponentiation(long x,long n) { long result=1; while(n>0) { if(n % 2 ==1) result=result * x; x=x*x; n=n/2; } return result; } public static int modularExponentiation(int x,int n,int M) { int result=1; while(n>0) { if(n % 2 ==1) result=(result * x)%M; x=(x*x)%M; n=n/2; } return result; } public static long modularExponentiation(long x,long n,long M) { long result=1; while(n>0) { if(n % 2 ==1) result=(result * x)%M; x=(x*x)%M; n=n/2; } return result; } public static int modInverse(int A,int M) { return modularExponentiation(A,M-2,M); } public static long modInverse(long A,long M) { return modularExponentiation(A,M-2,M); } public static boolean isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n%2 == 0 || n%3 == 0) return false; for (int i=5; i*i<=n; i=i+6) { if (n%i == 0 || n%(i+2) == 0) return false; } return true; } static class pair implements Comparable<pair> { Integer x, y; pair(int x,int y) { this.x=x; this.y=y; } public int compareTo(pair o) { int result = x.compareTo(o.x); if(result==0) result = y.compareTo(o.y); return result; } } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.util.Scanner; public class Driver { public static Scanner scanner; public static void main(String[] args) { scanner = new Scanner(System.in); String a = scanner.next(); String b = scanner.next(); int x = scanner.nextInt(); x = x%4; String s[] = {"<", "^", ">", "v" }; int pos = 0; for(int i=0; i<4; i++) { if(s[i].equals(a)) pos = i; } int n = pos+x; if(n>=4) n-=4; int m = pos-x; if(m<0) m+=4; if(b.equals(s[n]) && !b.equals(s[m])) System.out.println("cw"); else if(b.equals(s[m]) && !b.equals(s[n])) System.out.println("ccw"); else System.out.println("undefined"); } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int main() { char a, b; int n, i; cin >> a >> b >> n; n = n % 4; bool cw = false, ccw = false; char temp = a; for (i = 0; i < n; i++) { if (temp == '^') temp = '>'; else if (temp == '>') temp = 'v'; else if (temp == 'v') temp = '<'; else if (temp == '<') temp = '^'; } if (temp == b) cw = true; temp = a; for (i = 0; i < n; i++) { if (temp == '^') temp = '<'; else if (temp == '<') temp = 'v'; else if (temp == 'v') temp = '>'; else if (temp == '>') temp = '^'; } if (temp == b) ccw = true; if (cw && ccw) cout << "undefined"; else if (cw) cout << "cw"; else if (ccw) cout << "ccw"; else cout << "undefined"; return 0; }
CPP
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
positions = {"v": 0, "<": 1, "^": 2, ">": 3} q = input().split() n = int(input()) start = positions.get(q[0]) finish = positions.get(q[1]) if n % 2 == 0: print("undefined") elif (start+n) % 4 == finish: print("cw") else: print("ccw")
PYTHON3
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
cw = "^>v<" x,y = raw_input().split(" ") t = int(raw_input()) def opp(x,y): if x==">" and y=="<": return True elif y==">" and x=="<": return True elif x=="^" and y=="v": return True elif y=="^" and x=="v": return True else: return False if x==y or opp(x,y): print "undefined" else: print "cw" if cw[(cw.index(x)+t)%4]==y else "ccw"
PYTHON
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
i,f=input().split() n=int(input()) a={'^':0,'>':90,'v':180,'<':270} b={0:'^',90:'>',180:'v',270:'<'} if b[(a[i]+n*90)%360]==f and b[(a[i]-n*90)%360]==f: print('undefined') exit() if b[(a[i]+n*90)%360]==f: print('cw') elif b[(a[i]-n*90)%360]==f: print('ccw') else: print('undefined')
PYTHON3
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
def some(x): if(x=="v"): return(0) elif(x=="<"): return(1) elif(x=="^"): return(2) else: return(3) x,y=raw_input().split(" ") n=input() a=(some(x)+n)%4==some(y) b=(some(x)-n)%4==some(y) if(a==b and a==True): print("undefined") elif(a==True): print("cw") elif(b==True): print("ccw") else: print("undefined")
PYTHON
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.util.ArrayList; import java.util.InputMismatchException; import java.util.Locale; import java.util.Scanner; import java.util.regex.Pattern; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.math.BigInteger; public class TheUselessToy { public static int[] pattern = {94, 62, 118, 60}; public static void main(String[] args) { solve(1); } public static void solve(int testCases){ String s1 = StdIn.readString(); String s2 = StdIn.readString(); char src = s1.charAt(0); char dest = s2.charAt(0); //StdOut.println("src = " + src + " dest = " + dest); int n = StdIn.readInt(); int d1 = clockWise(src, n); int d2 = anticlockWise(src, n); char cd1 = (char) d1; char cd2 = (char) d2; if(cd1 == dest && cd2 != dest){ StdOut.println("cw"); }else if(cd1 != dest && cd2 == dest){ StdOut.println("ccw"); }else{ StdOut.println("undefined"); } } public static int clockWise(char src, int n){ int t = src; for(int i = 0 ; i < 4 ; i++) if(t == pattern[i]) t = i; int r = n % 4; t += r; t = t % 4; return pattern[t]; } public static int anticlockWise(char src, int n){ int t = src; for(int i = 0 ; i < 4 ; i++) if(t == pattern[i]) t = i; int r = n % 4; t -= r; if(t < 0) t += 4; return pattern[t]; } } final class StdIn { private StdIn() { } private static Scanner scanner; private static final String CHARSET_NAME = "UTF-8"; private static final Locale LOCALE = Locale.US; private static final Pattern WHITESPACE_PATTERN = Pattern.compile("\\p{javaWhitespace}+"); private static final Pattern EMPTY_PATTERN = Pattern.compile(""); private static final Pattern EVERYTHING_PATTERN = Pattern.compile("\\A"); public static boolean isEmpty() { return !scanner.hasNext(); } public static boolean hasNextLine() { return scanner.hasNextLine(); } public static boolean hasNextChar() { scanner.useDelimiter(EMPTY_PATTERN); boolean result = scanner.hasNext(); scanner.useDelimiter(WHITESPACE_PATTERN); return result; } public static String readLine() { String line; try { line = scanner.nextLine(); } catch (Exception e) { line = null; } return line; } public static char readChar() { scanner.useDelimiter(EMPTY_PATTERN); String ch = scanner.next(); assert (ch.length() == 1) : "Internal (Std)In.readChar() error!" + " Please contact the authors."; scanner.useDelimiter(WHITESPACE_PATTERN); return ch.charAt(0); } public static String readAll() { if (!scanner.hasNextLine()) return ""; String result = scanner.useDelimiter(EVERYTHING_PATTERN).next(); // not that important to reset delimeter, since now scanner is empty scanner.useDelimiter(WHITESPACE_PATTERN); // but let's do it anyway return result; } public static String readString() { return scanner.next(); } public static int readInt() { return scanner.nextInt(); } public static double readDouble() { return scanner.nextDouble(); } public static float readFloat() { return scanner.nextFloat(); } public static long readLong() { return scanner.nextLong(); } public static short readShort() { return scanner.nextShort(); } public static byte readByte() { return scanner.nextByte(); } public static boolean readBoolean() { String s = readString(); if (s.equalsIgnoreCase("true")) return true; if (s.equalsIgnoreCase("false")) return false; if (s.equals("1")) return true; if (s.equals("0")) return false; throw new InputMismatchException(); } public static String[] readAllStrings() { // we could use readAll.trim().split(), but that's not consistent // because trim() uses characters 0x00..0x20 as whitespace String[] tokens = WHITESPACE_PATTERN.split(readAll()); if (tokens.length == 0 || tokens[0].length() > 0) return tokens; // don't include first token if it is leading whitespace String[] decapitokens = new String[tokens.length-1]; for (int i = 0; i < tokens.length - 1; i++) decapitokens[i] = tokens[i+1]; return decapitokens; } public static String[] readAllLines() { ArrayList<String> lines = new ArrayList<String>(); while (hasNextLine()) { lines.add(readLine()); } return lines.toArray(new String[0]); } public static int[] readAllInts() { String[] fields = readAllStrings(); int[] vals = new int[fields.length]; for (int i = 0; i < fields.length; i++) vals[i] = Integer.parseInt(fields[i]); return vals; } public static double[] readAllDoubles() { String[] fields = readAllStrings(); double[] vals = new double[fields.length]; for (int i = 0; i < fields.length; i++) vals[i] = Double.parseDouble(fields[i]); return vals; } static { resync(); } private static void resync() { setScanner(new Scanner(new java.io.BufferedInputStream(System.in), CHARSET_NAME)); } private static void setScanner(Scanner scanner) { StdIn.scanner = scanner; StdIn.scanner.useLocale(LOCALE); } public static int[] readInts() { return readAllInts(); } public static double[] readDoubles() { return readAllDoubles(); } public static String[] readStrings() { return readAllStrings(); } } final class StdOut { private static final String CHARSET_NAME = "UTF-8"; private static final Locale LOCALE = Locale.US; private static PrintWriter out; static { try { out = new PrintWriter(new OutputStreamWriter(System.out, CHARSET_NAME), true); } catch (UnsupportedEncodingException e) { System.out.println(e); } } private StdOut() { } public static void close() { out.close(); } public static void println() { out.println(); } public static void println(Object x) { out.println(x); } public static void println(boolean x) { out.println(x); } public static void println(char x) { out.println(x); } public static void println(double x) { out.println(x); } public static void println(float x) { out.println(x); } public static void println(int x) { out.println(x); } public static void println(long x) { out.println(x); } public static void println(short x) { out.println(x); } public static void println(byte x) { out.println(x); } public static void print() { out.flush(); } public static void print(Object x) { out.print(x); out.flush(); } public static void print(boolean x) { out.print(x); out.flush(); } public static void print(char x) { out.print(x); out.flush(); } public static void print(double x) { out.print(x); out.flush(); } public static void print(float x) { out.print(x); out.flush(); } public static void print(int x) { out.print(x); out.flush(); } public static void print(long x) { out.print(x); out.flush(); } public static void print(short x) { out.print(x); out.flush(); } public static void print(byte x) { out.print(x); out.flush(); } public static void printf(String format, Object... args) { out.printf(LOCALE, format, args); out.flush(); } public static void printf(Locale locale, String format, Object... args) { out.printf(locale, format, args); out.flush(); } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int main() { char c1, c2; cin >> c1 >> c2; long long n; cin >> n; n = n % 4; if (n == 0 || n == 2) { cout << "undefined"; return 0; } if (n == 1) { if ((c1 == char(118) && c2 == char(60)) || (c1 == char(60) && c2 == char(94)) || (c1 == char(94) && c2 == char(62)) || (c1 == char(62) && c2 == char(118))) { cout << "cw"; return 0; } if ((c1 == char(118) && c2 == char(62)) || (c1 == char(60) && c2 == char(118)) || (c1 == char(94) && c2 == char(60)) || (c1 == char(62) && c2 == char(94))) { cout << "ccw"; return 0; } } if (n == 3) { if ((c1 == char(118) && c2 == char(60)) || (c1 == char(60) && c2 == char(94)) || (c1 == char(94) && c2 == char(62)) || (c1 == char(62) && c2 == char(118))) { cout << "ccw"; return 0; } if ((c1 == char(118) && c2 == char(62)) || (c1 == char(60) && c2 == char(118)) || (c1 == char(94) && c2 == char(60)) || (c1 == char(62) && c2 == char(94))) { cout << "cw"; return 0; } } }
CPP
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
d = raw_input().split(' ') n = int(input()) n = n%4 c = ['v','<','^','>']* (n/4+n+1) if (c[(c.index(d[0]))-n]) == (c[(c.index(d[0]))+n]): print ('undefined') elif (c[(c.index(d[0]))+n]) == d[1]: print ('cw') else:# print (c[(c.index(d[0]))-n]) == d[1]: print ('ccw')
PYTHON
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> char data[5] = "v<^>"; int i; void test(int a, int b, char c) { if (data[(a + b) % 4] == c) i = 0; else if (data[(a - b + 4) % 4] == c) i = 1; else i = -1; } int main(void) { long n; char a, b; scanf("%c %c%ld", &a, &b, &n); n = n % 4; if (n == 0 || n == 2) { printf("undefined"); return 0; } switch (a) { case 'v': test(0, n, b); break; case '<': test(1, n, b); break; case '^': test(2, n, b); break; case '>': test(3, n, b); break; } if (i == 1) printf("ccw"); else if (i == 0) printf("cw"); else printf("undefined"); return 0; }
CPP
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int main() { char str, end; int sec; cin >> str; cin >> end; cin >> sec; switch (str) { case '^': if (sec % 4 == 0) cout << "undefined"; else if (sec % 4 == 1 && end == '<') cout << "ccw"; else if (sec % 4 == 1 && end == '>') cout << "cw"; else if (end == 'v') cout << "undefined"; else if (sec % 4 == 3 && end == '<') cout << "cw"; else if (sec % 4 == 3 && end == '>') cout << "ccw"; break; case 'v': if (sec % 4 == 0) cout << "undefined"; else if (sec % 4 == 1 && end == '<') cout << "cw"; else if (sec % 4 == 1 && end == '>') cout << "ccw"; else if (end == '^') cout << "undefined"; else if (sec % 4 == 3 && end == '>') cout << "cw"; else if (sec % 4 == 3 && end == '<') cout << "ccw"; break; case '<': if (sec % 4 == 0) cout << "undefined"; else if (sec % 4 == 1 && end == 'v') cout << "ccw"; else if (sec % 4 == 1 && end == '^') cout << "cw"; else if (end == '>') cout << "undefined"; else if (sec % 4 == 3 && end == 'v') cout << "cw"; else if (sec % 4 == 3 && end == '^') cout << "ccw"; break; case '>': if (sec % 4 == 0) cout << "undefined"; else if (sec % 4 == 1 && end == 'v') cout << "cw"; else if (sec % 4 == 1 && end == '^') cout << "ccw"; else if (end == '<') cout << "undefined"; else if (sec % 4 == 3 && end == '^') cout << "cw"; else if (sec % 4 == 3 && end == 'v') cout << "ccw"; } return 0; }
CPP
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const int inf = 0x3f3f3f3f; int T, n, k, u, v; char a, b; char str[5] = "^>v<"; void solve() { int st = 0, en = 0; for (int i = 0; i < 4; i++) { if (str[i] == a) { st = i; break; } } if (str[(st + n) % 4] == b && str[((st - n) % 4 + 4) % 4] == b) { cout << "undefined" << endl; } else if (str[(st + n) % 4] == b) { cout << "cw" << endl; } else if (str[((st - n) % 4 + 4) % 4] == b) { cout << "ccw" << endl; } else cout << "undefined" << endl; } int main() { scanf(" %c %c %d", &a, &b, &n); solve(); return 0; }
CPP
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.util.HashMap; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author MaxHeap */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastReader in = new FastReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Spinner solver = new Spinner(); solver.solve(1, in, out); out.close(); } static class Spinner { HashMap<Character, Integer> pos = new HashMap<>(); char[] dir = {'^', '>', 'v', '<'}; { pos.put('^', 0); pos.put('>', 1); pos.put('v', 2); pos.put('<', 3); } char spin(char c, int direction) { return dir[(direction + 4 + pos.get(c)) % 4]; } public void solve(int testNumber, FastReader in, PrintWriter out) { char start = in.next().charAt(0); char end = in.next().charAt(0); int n = in.nextInt() % 4; char cw = start, ccw = start; while (n-- > 0) { cw = spin(cw, 1); ccw = spin(ccw, -1); } if (cw == ccw || (cw != end && ccw != end)) { out.println("undefined"); } else { out.println(cw == end ? "cw" : "ccw"); } } } static class FastReader { BufferedReader reader; StringTokenizer st; public FastReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); st = null; } public String next() { while (st == null || !st.hasMoreTokens()) { try { String line = reader.readLine(); if (line == null) { return null; } st = new StringTokenizer(line); } catch (Exception e) { throw new RuntimeException(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
JAVA
834_A. The Useless Toy
<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 ≀ 109) – 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { char a, b; cin >> a >> b; int n; cin >> n; n %= 4; map<char, int> mp; mp['v'] = 0; mp['<'] = 1; mp['^'] = 2; mp['>'] = 3; bool x = (mp[a] + n) % 4 == mp[b]; bool y = ((mp[a] - n + 4) % 4) == mp[b]; if (x && y) puts("undefined"); else if (x) puts("cw"); else puts("ccw"); }
CPP