import [Link].
Scanner;
class LinkedList
{
Node head;
Node slow_ptr,fast_ptr,second_half;
class Node
{
int data;
Node next;
Node(int d)
{
data=d;
next=null;
}
}
boolean ispalindrome(Node head)
{
slow_ptr=head;
fast_ptr=head;
Node prev_of_slow_ptr=head;
Node midnode=null;
boolean res=true;
if(head !=null && [Link] !=null)
{
while(fast_ptr !=null && fast_ptr.next !=null)
{
fast_ptr=fast_ptr.[Link];
prev_of_slow_ptr=slow_ptr;
slow_ptr=slow_ptr.next;
}
if(fast_ptr !=null)
{
midnode=slow_ptr;
slow_ptr=slow_ptr.next;
}
second_half=slow_ptr;
prev_of_slow_ptr.next=null;
reverse();
res=comparelists(head,second_half);
reverse();
if(midnode !=null)
{
prev_of_slow_ptr.next=midnode;
[Link]=second_half;
}
else
prev_of_slow_ptr.next=second_half;
}
return res;
}
void reverse()
{
Node prev=null;
Node next;
Node current=second_half;
while(current!=null)
{
next=[Link];
[Link]=prev;
prev=current;
current=next;
}
second_half=prev;
}
boolean comparelists(Node head1,Node head2)
{
Node temp1=head1;
Node temp2=head2;
while(temp1 !=null && temp2 !=null)
{
if([Link] == [Link])
{
temp1=[Link];
temp2=[Link];
}
else
return false;
}
if(temp1==null && temp2==null)
return true;
return false;
}
public void push(int new_data)
{
Node new_node=new Node(new_data);
new_node.next=head;
head=new_node;
}
}
public class ListDriver
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
LinkedList b=new LinkedList();
int val=[Link]();
int a[]=new int[val];
for(int i=0;i<val;i++)
{
a[i]=[Link]();
[Link](a[i]);
}
if([Link]([Link]) != false)
{
[Link]("1");
}
else
{
[Link]("0");
}
}
}