Back
Close

Indexing Everywhere

Statement

 Goal

Take a list of N integers and call this list A. Start at the first element (index 0) and repeatedly move following this rule: the value of the current element is the index of the next element you should move to. Will you ever return to the first element? If so, print returns, otherwise print cycling.

Examples

Let's say that the list looks like this: 3 4 2 1 0. Here, the first element of the list is 3.

Now what is the element at index 3? That would be 1. What is the element at index 1? That would be 4. What is the element at index 4? That would be 0. What is the element at index 0? That would be 3. And now we are back where we started.

But not every list of integers permits this. Say the list was 3 4 2 1 1. Notice how if you started at the first element, which is 3, you will never return there:

3 -> 1 -> 4 -> 1 -> 4 -> 1 -> 4 -> 1 -> ...

Can you take a list of numbers and determine if performing this indexing process starting at index 0 will allow you to return back to the beginning of the list?
Input
Line 1: An integer N
Next N lines: Integers of A
Output
Line 1: Either returns or cycling, depending on whether the indexing process returns back to the first element of the list, or keeps cycling in the tail of the list.
Constraints
1 ≤ N ≤ 300
0 ≤ Every element of A < N
Example
Input
5
3
4
2
1
0
Output
returns

Game modes
Fastest, Shortest

Test cases
Example Test
Input
5 3 4 2 1 0
Output
returns

Example Validator
Input
6 4 2 5 5 1 0
Output
returns

Example 2 Test
Input
5 3 4 2 1 1
Output
cycling

Example 2 Validator
Input
6 1 4 5 5 3 2
Output
cycling

Big List 1 Test
Input
50 32 26 25 0 38 14 0 5 34 27 28 13 34 1 11 34 39 44 37 47 43 19 45 19 34 0 21 42 33 4 30 7 7 37 17 12 30 3 46 29 45 4 43 10 16 25 42 35 13 45
Output
returns

Big List 1 Validator
Input
55 36 35 31 9 44 38 35 0 22 22 47 6 19 53 32 42 20 4 0 25 41 48 19 6 16 10 0 17 49 31 23 2 26 36 13 14 24 5 3 3 6 51 19 9 50 30 29 27 38 38 34 21 1 1 35
Output
returns

Big List 2 Test
Input
55 8 12 47 47 27 26 46 5 38 0 42 30 53 35 45 31 24 46 2 42 49 8 26 45 49 13 37 18 30 28 2 29 17 33 0 43 44 44 15 16 38 9 23 32 4 0 22 1 25 13 44 37 19 39 48
Output
cycling

Big List 2 Validator
Input
60 40 43 51 9 3 56 33 32 19 31 59 52 21 5 58 55 46 8 16 50 1 37 54 7 20 16 22 34 14 27 9 45 17 4 2 19 31 21 54 48 29 6 2 10 57 10 57 35 28 43 56 30 56 3 39 5 22 7 24 25
Output
cycling

0 to 0 Test
Input
10 0 1 2 3 4 5 6 7 8 9
Output
returns

0 to 0 Validator
Input
12 0 11 10 9 8 7 6 5 4 3 2 1
Output
returns

So Much 0, But False Test
Input
20 1 9 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
Output
cycling

So Much 0, But False Validator
Input
22 9 0 0 0 18 0 0 0 0 4 0 0 0 0 0 0 0 0 19 9 0 0
Output
cycling

Huge List 1 Test
Input
250 249 67 10 33 221 79 200 248 173 99 135 194 39 152 11 237 51 186 141 13 93 247 170 92 19 66 68 49 183 37 246 87 211 227 156 205 201 131 169 113 53 126 137 74 238 32 177 28 215 123 9 69 0 233 188 208 230 189 38 151 98 239 209 129 143 223 58 34 120 105 224 96 21 43 128 36 144 150 111 78 166 212 196 140 16 136 75 214 181 154 192 162 122 27 94 72 47 15 52 222 90 155 29 175 190 127 234 163 64 145 62 117 217 12 5 118 100 6 216 185 146 195 149 48 91 40 241 168 110 20 116 218 207 240 80 119 8 97 174 42 84 132 193 191 63 59 184 61 231 219 85 25 164 46 232 56 203 3 71 109 88 243 235 187 106 142 30 35 167 108 112 17 198 178 60 18 245 14 138 73 133 171 236 82 22 86 26 103 23 4 55 202 225 101 95 220 2 180 153 104 115 125 172 83 165 134 158 147 148 70 107 161 139 89 54 210 159 31 176 102 204 213 114 124 7 244 160 182 65 197 130 179 157 57 229 81 199 242 77 44 41 228 206 45 1 226 121 24 76 50
Output
returns

Huge List 1 Validator
Input
270 269 179 62 13 71 134 133 75 39 99 204 220 230 222 193 31 33 217 46 34 151 23 238 8 55 59 157 54 191 2 147 142 215 70 211 226 259 201 242 67 216 93 119 181 53 206 91 38 36 266 149 92 29 152 49 69 109 83 205 260 208 137 234 89 188 24 127 98 248 94 252 187 255 164 174 81 214 177 4 76 195 203 100 73 112 40 84 66 213 82 162 120 1 225 0 141 264 43 87 21 22 41 63 145 117 155 118 262 140 148 180 0 56 210 126 240 189 173 158 123 178 186 168 218 6 12 97 125 19 192 144 184 47 224 221 176 17 182 11 60 253 231 160 197 170 198 51 135 249 207 175 212 45 27 167 79 131 64 150 18 61 110 136 77 233 267 128 9 124 241 105 196 72 171 107 3 50 236 163 86 165 237 261 74 57 246 28 16 115 96 247 156 113 129 199 154 85 52 190 251 209 95 161 254 114 183 257 104 239 263 80 103 130 106 139 268 35 219 14 58 44 245 26 121 7 30 169 200 229 146 166 159 153 10 65 172 42 132 239 5 250 185 143 25 102 194 227 108 122 15 20 37 32 78 138 244 232 258 235 90 256 111 88 223 116 243 228 265 101 68
Output
returns

Huge List 2 Test
Input
270 269 92 151 5 48 166 244 252 207 193 90 33 155 201 102 167 262 86 211 57 87 150 69 266 85 126 191 91 41 254 251 196 219 140 217 30 19 67 34 116 109 139 176 221 55 209 230 71 113 73 1 227 75 10 212 65 247 202 2 218 119 256 64 159 203 225 216 179 125 61 72 206 255 103 105 31 45 265 89 170 78 104 74 164 56 260 236 98 243 157 110 135 124 149 115 6 37 0 143 184 52 82 136 26 235 88 111 160 128 258 59 237 192 249 267 205 108 158 79 51 220 190 50 83 35 259 261 181 153 118 188 53 182 197 112 16 117 268 101 123 29 162 7 199 154 99 122 246 15 84 229 9 58 107 186 94 21 142 245 40 39 121 28 96 95 66 4 38 173 141 14 228 11 76 214 210 169 77 8 224 195 174 213 68 187 70 132 146 240 152 163 198 177 168 226 156 263 12 264 183 54 208 222 49 43 241 46 148 194 238 44 129 17 62 248 189 36 175 185 120 100 114 13 204 239 145 231 161 242 233 60 24 134 180 257 223 93 250 47 27 232 81 172 20 32 23 3 253 130 80 137 63 25 138 234 147 165 42 18 133 22 215 127 171 131 79 144 106 178 200
Output
cycling

Huge List 2 Validator
Input
280 279 217 221 195 92 147 49 191 180 151 193 51 172 109 115 74 242 231 150 208 141 64 103 204 88 225 161 132 219 185 241 270 38 110 181 264 81 211 140 125 153 20 124 145 216 205 86 258 1 9 57 98 31 71 156 199 223 107 3 142 195 184 236 79 65 17 78 263 50 6 265 239 48 232 249 267 152 101 273 53 229 95 27 26 104 43 190 250 206 66 11 244 116 24 8 127 218 159 173 114 23 28 260 4 162 201 25 233 94 188 91 194 117 13 168 73 10 196 189 215 148 118 176 187 120 240 146 136 164 275 262 158 274 210 163 119 213 126 226 121 235 123 139 259 96 2 34 245 69 111 106 200 90 154 18 255 203 87 12 75 68 128 266 222 212 76 80 277 22 268 42 252 165 261 169 276 234 36 149 60 39 84 248 113 45 247 171 179 160 19 198 83 135 44 227 256 155 21 202 37 46 61 166 251 271 269 243 178 214 40 59 33 29 32 54 35 5 186 192 97 99 52 30 272 58 175 16 230 254 177 129 237 62 157 246 15 56 63 134 257 93 137 228 105 174 133 70 85 207 102 55 253 0 224 112 197 122 209 89 7 67 72 47 131 41 238 167 100 220 182 170 138 144 278 77 82 14 130 183 108
Output
cycling

Solution language

Solution

Stub generator input