using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { public class Primer { List primes; public Primer() { primes = new List(); primes.Add(2); primes.Add(3); } public long GPF(long v) { int i = 0; long sqrt = (long)Math.Sqrt(v); while(primes[i] <= sqrt) { while(v%primes[i] == 0) { if(v == primes[i]) return v; v = v/primes[i]; sqrt = (long)Math.Sqrt(v); } i++; if(i == primes.Count) { for(long j=primes[i-1]+2; i==primes.Count; j+=2) { if(isPrime(j)) primes.Add(j); } } } return v; } public bool isPrime(long v) { long sqrt = (long)Math.Sqrt(v); int i=0; while(primes[i] <= sqrt) { if(v%primes[i] == 0) return false; i++; if(i == primes.Count) { for(long j=primes[i-1]+2; i==primes.Count; j+=2) { if(isPrime(j)) primes.Add(j); } } } return true; } } public class Tree { public class Node { public long key; public long val; public Node L; public Node R; public Node(long k, long v) { key = k; val = v; } } Node root; public Tree() { root = null; } public void Add(long k, long v) { root = Add(root, k, v); } public Node Add(Node node, long k, long v) { if(node == null) return new Node(k,v); if(k < node.key) { node.L = Add(node.L, k, v); } if(k > node.key) { node.R = Add(node.R, k, v); } return node; } public long Search(long k) { return Search(root, k); } public long Search(Node node, long k) { if(node == null) return -1; if(node.key == k) return node.val; if(k < node.key) return Search(node.L, k); return Search(node.R, k); } } public static Primer P; public static Tree T; static long longestSequence(long[] a) { long cnt = 0; for(int i=0; i