import java.io.*;
import java.util.*;
class GFG{
static final int MAX = 100000;
@SuppressWarnings("unchecked")
static List<List<Integer> > adj = new ArrayList();
@SuppressWarnings("unchecked")
static List<List<Integer> > adjInv = new ArrayList();
static boolean[] visited = new boolean[MAX];
static boolean[] visitedInv = new boolean[MAX];
static Stack<Integer> s = new Stack<Integer>();
static int[] scc = new int[MAX];
static int counter = 1;
static void addEdges(int a, int b)
{
adj.get(a).add(b);
}
static void addEdgesInverse(int a, int b)
{
adjInv.get(b).add(a);
}
static void dfsFirst(int u)
{
if (visited[u])
return;
visited[u] = true;
for(int i = 0; i < adj.get(u).size(); i++)
dfsFirst(adj.get(u).get(i));
s.push(u);
}
static void dfsSecond(int u)
{
if (visitedInv[u])
return;
visitedInv[u] = true;
for(int i = 0; i < adjInv.get(u).size(); i++)
dfsSecond(adjInv.get(u).get(i));
scc[u] = counter;
}
static void is2Satisfiable(int n, int m,
int a[], int b[])
{
for(int i = 0; i < m; i++)
{
if (a[i] > 0 && b[i] > 0)
{
addEdges(a[i] + n, b[i]);
addEdgesInverse(a[i] + n, b[i]);
addEdges(b[i] + n, a[i]);
addEdgesInverse(b[i] + n, a[i]);
}
else if (a[i] > 0 && b[i] < 0)
{
addEdges(a[i] + n, n - b[i]);
addEdgesInverse(a[i] + n, n - b[i]);
addEdges(-b[i], a[i]);
addEdgesInverse(-b[i], a[i]);
}
else if (a[i] < 0 && b[i] > 0)
{
addEdges(-a[i], b[i]);
addEdgesInverse(-a[i], b[i]);
addEdges(b[i] + n, n - a[i]);
addEdgesInverse(b[i] + n, n - a[i]);
}
else
{
addEdges(-a[i], n - b[i]);
addEdgesInverse(-a[i], n - b[i]);
addEdges(-b[i], n - a[i]);
addEdgesInverse(-b[i], n - a[i]);
}
}
for(int i = 1; i <= 2 * n; i++)
if (!visited[i])
dfsFirst(i);
while (!s.isEmpty())
{
int top = s.peek();
s.pop();
if (!visitedInv[top])
{
dfsSecond(top);
counter++;
}
}
for(int i = 1; i <= n; i++)
{
if (scc[i] == scc[i + n])
{
System.out.println("The given expression" +
"is unsatisfiable.");
return;
}
}
System.out.println("The given expression " +
"is satisfiable.");
}
public static void main(String[] args)
{
int n = 5, m = 7;
for(int i = 0; i < MAX; i++)
{
adj.add(new ArrayList<Integer>());
adjInv.add(new ArrayList<Integer>());
}
int a[] = { 1, -2, -1, 3, -3, -4, -3 };
int b[] = { 2, 3, -2, 4, 5, -5, 4 };
is2Satisfiable(n, m, a, b);
}
}