public class HaveLoop {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String str = scanner.nextLine();
char[] s = str.toCharArray();
NodeList[] nodeLists = new NodeList[s.length];
//初始化鏈表
for(int i=0;i<s.length;i++){
nodeLists[i] = new NodeList(s[i]);
}
//將鏈表連接起來
for(int i=0;i<s.length;i++){
if(i == s.length-1){
//將單鏈表設置爲環
nodeLists[i].next = nodeLists[0];
}else {
nodeLists[i].next = nodeLists[i+1];
}
}
System.out.println(haveLoop(nodeLists[0]));
}
//判斷鏈表是否有環
public static boolean haveLoop(NodeList nodeList){
boolean flat = false;
if(nodeList !=null && nodeList.next !=null){
NodeList slow = nodeList;
NodeList fast = nodeList;
while (fast !=null && fast.next !=null) {
slow = slow.next;
fast = fast.next.next;
if(slow == fast){
//相遇則有環
flat = true;
break;
}
}
}
return flat;
}
}