fork(1) download
  1. def testIfAdjacent(white, black, a):
  2. set1 = []
  3. set2 = []
  4. set3 = []
  5. set4 = []
  6. m = 1
  7. while m <= 5:
  8. set1.append(5 * m - 4)
  9. set2.append(5 * m)
  10. set3.append(m)
  11. set4.append(m + 20)
  12. m += 1
  13. x = []
  14. z = []
  15. if white[a] - 1 in black and white[a] not in set1:
  16. x.append(white[a])
  17. z.append(1)
  18. if white[a] + 1 in black and white[a] not in set2:
  19. x.append(white[a])
  20. z.append(2)
  21. if white[a] - 5 in black and white[a] not in set3:
  22. x.append(white[a])
  23. z.append(3)
  24. if white[a] + 5 in black and white[a] not in set4:
  25. x.append(white[a])
  26. z.append(4)
  27. if len(x) == 4 or len(x) == 0:
  28. pass
  29. else:
  30. return [a, z]
  31.  
  32. def testIfMoveTo(white, black):
  33. a = 0
  34. set1 = []
  35. set2 = []
  36. set3 = []
  37. set4 = []
  38. m = 1
  39. while m <= 5:
  40. set1.append(5 * m - 3)
  41. set2.append(5 * m - 1)
  42. set3.append(m + 5)
  43. set4.append(m + 15)
  44. m += 1
  45. while a < len(white):
  46. x = []
  47. y = []
  48. z = []
  49. if white[a] - 1 not in white and white[a] - 1 not in black and white[a] and white[a] - 1 in range(1, 26):
  50. white[a] -= 1
  51. y.append(testIfAdjacent(white, black, a))
  52. z.append(1)
  53. if y[0] != None and y[0][0] != a:
  54. y[0] = None
  55. z[0] = 0
  56. white[a] += 1
  57. else:
  58. y.append(None)
  59. z.append(0)
  60. if white[a] + 1 not in white and white[a] + 1 not in black and white[a] and white[a] + 1 in range(1, 26):
  61. white[a] += 1
  62. y.append(testIfAdjacent(white, black, a))
  63. z.append(2)
  64. if y[1] != None and y[1][0] != a:
  65. y[1] = None
  66. z[1] = 0
  67. white[a] -= 1
  68. else:
  69. y.append(None)
  70. z.append(0)
  71. if white[a] - 5 not in white and white[a] - 5 not in black and white[a] and white[a] - 5 in range(1, 26):
  72. white[a] -= 5
  73. y.append(testIfAdjacent(white, black, a))
  74. z.append(3)
  75. if y[2] != None and y[2][0] != a:
  76. y[2] = None
  77. z[2] = 0
  78. white[a] += 5
  79. else:
  80. y.append(None)
  81. z.append(0)
  82. if white[a] + 5 not in white and white[a] + 5 not in black and white[a] and white[a] + 5 in range(1, 26):
  83. white[a] += 5
  84. y.append(testIfAdjacent(white, black, a))
  85. z.append(4)
  86. if y[3] != None and y[3][0] != a:
  87. y[3] = None
  88. z[3] = 0
  89. white[a] -= 5
  90. else:
  91. y.append(None)
  92. z.append(0)
  93. b = 0
  94. while b < len(y):
  95. if y[b] == None:
  96. z[b] = 0
  97. else:
  98. x.append(y[b])
  99. b += 1
  100. t = []
  101. c = 0
  102. while c < len(z):
  103. if z[c] != 0:
  104. t.append(z[c])
  105. c += 1
  106. if len(t) != 0:
  107. return [a, t]
  108. a += 1
  109.  
  110. def main():
  111. a = 0
  112. set1 = []
  113. m = 1
  114. while m <= 5:
  115. set1.append(5 * m - 4)
  116. set1.append(5 * m)
  117. set1.append(m)
  118. set1.append(m + 20)
  119. m += 1
  120. while a < 5:
  121. x = input()
  122. numOfWhite = x[0]
  123. white = list(x[1:numOfWhite + 1])
  124. black = list(x[numOfWhite + 2:])
  125. b = 0
  126. adjacent = []
  127. while b < numOfWhite:
  128. y = testIfAdjacent(white, black, b)
  129. if y != None:
  130. adjacent.append(y)
  131. b += 1
  132. len1 = -1
  133. try:
  134. len1 = len(adjacent)
  135. except:
  136. pass
  137. if len1 == 0 or len1 == -1:
  138. moveTo = testIfMoveTo(white, black)
  139. setOfMovement = [-1, 1, -5, 5]
  140. if moveTo != None:
  141. white[moveTo[0]] += setOfMovement[moveTo[1][0] - 1]
  142. adjacent = list(adjacent)
  143. adjacent = [testIfAdjacent(white, black, moveTo[0])]
  144. movement = adjacent[0][1][0]
  145. setOfMovement = [-1, 1, -5, 5]
  146. endUp = white[adjacent[0][0]] + setOfMovement[movement - 1]
  147. n = [0, 0, 0, 0]
  148. c = movement - 1
  149. if endUp + setOfMovement[c] in black and endUp + setOfMovement[c] in set1:
  150. if endUp + 2 * setOfMovement[c] in black and endUp + 2 * setOfMovement[c] in set1:
  151. if endUp + 3 * setOfMovement[c] in black and endUp + 3 * setOfMovement[c] in set1:
  152. if endUp + 4 * setOfMovement[c] in black and endUp + 4 * setOfMovement[c] in set1:
  153. n[c] = 4
  154. else:
  155. n[c] = 3
  156. else:
  157. n[c] = 2
  158. else:
  159. n[c] = 1
  160. else:
  161. n[c] = 0
  162. d = 0
  163. while d < 4:
  164. if n[d] >= n[0] and n[d] >= n[1] and n[d] >= n[2] and n[d] >= n[3]:
  165. z = d
  166. d += 1
  167. chainMovement = setOfMovement[z]
  168. startChain = endUp
  169. setToBeCaptured = []
  170. e = 0
  171. while e < 5:
  172. possibleList = startChain + e * chainMovement
  173. if possibleList <= 25 and possibleList > 0 and possibleList in black:
  174. setToBeCaptured.append(startChain + e * chainMovement)
  175. else:
  176. break
  177. e += 1
  178. setToBeCaptured.sort()
  179. f = 0
  180. g = ""
  181. while f < len(setToBeCaptured) - 1:
  182. g += str(setToBeCaptured[f])
  183. g += ", "
  184. f += 1
  185. g += str(setToBeCaptured[f])
  186. print g
  187. else:
  188. print "NONE"
  189. else:
  190. adjacent = list(adjacent)
  191. movement = adjacent[0][1][0]
  192. setOfMovement = [-1, 1, -5, 5]
  193. endUp = white[adjacent[0][0]] + setOfMovement[movement - 1]
  194. c = 0
  195. n = [0, 0, 0, 0]
  196. c = movement - 1
  197. if endUp + setOfMovement[c] in black and endUp + setOfMovement[c] in set1:
  198. if endUp + 2 * setOfMovement[c] in black and endUp + 2 * setOfMovement[c] in set1:
  199. if endUp + 3 * setOfMovement[c] in black and endUp + 3 * setOfMovement[c] in set1:
  200. if endUp + 4 * setOfMovement[c] in black and endUp + 4 * setOfMovement[c] in set1:
  201. n[c] = 4
  202. else:
  203. n[c] = 3
  204. else:
  205. n[c] = 2
  206. else:
  207. n[c] = 1
  208. else:
  209. n[c] = 0
  210. d = 0
  211. while d < 4:
  212. if n[d] >= n[0] and n[d] >= n[1] and n[d] >= n[2] and n[d] >= n[3]:
  213. z = d
  214. d += 1
  215. chainMovement = setOfMovement[z]
  216. startChain = endUp
  217. setToBeCaptured = []
  218. e = 0
  219. while e < 5:
  220. possibleList = startChain + e * chainMovement
  221. if possibleList <= 25 and possibleList > 0 and possibleList in black:
  222. setToBeCaptured.append(possibleList)
  223. else:
  224. break
  225. e += 1
  226. if len(setToBeCaptured) == 0:
  227. print "NONE"
  228. else:
  229. setToBeCaptured.sort()
  230. f = 0
  231. g = ""
  232. while f < len(setToBeCaptured) - 1:
  233. g += str(setToBeCaptured[f])
  234. g += ", "
  235. f += 1
  236. g += str(setToBeCaptured[f])
  237. print g
  238. a += 1
  239.  
  240. main()
Success #stdin #stdout 0.01s 7900KB
stdin
3, 9, 17, 21, 3, 2, 23, 25
3, 9, 16, 18, 3, 2, 23, 25
4, 9, 13, 16, 18, 4, 2, 5, 23, 25
4, 9, 13, 18, 21, 4, 2, 5, 23, 24
3, 8, 9, 22, 3, 23, 24, 25
stdout
23
23
23
23
23, 24, 25