// Solution for NCPC/UKIEPC 2014 problem "clockpictures" // Written by Jaap Eldering // Uses KMP substring search to find difference sequence X of first // set of hand angles in Y+Y of second difference sequence Y. #include #include #include using namespace std; const int maxa = 360000; vector readhands(int n) { vector a(n); for(int i=0; i> a[i]; sort(a.begin(),a.end()); int tmp = a[n-1]; for(int i=n-1; i>0; i--) a[i] -= a[i-1]; a[0] = (a[0] - tmp + maxa)%maxa; return a; } int kmp_search(vector needle, vector hay) { if ( needle.size()==0 ) return 0; vector table(needle.size()); table[0] = -1; if ( needle.size()>=1 ) table[1] = 0; int pos = 2; int cnd = 0; while ( pos-1 ) { m = m + i - table[i]; i = table[i]; } else { m++; i = 0; } } } return -1; } int main() { int n; cin >> n; vector a, b; a = readhands(n); b = readhands(n); for(int i=0; i=0 ) { cout << "possible" << endl; } else { cout << "impossible" << endl; } return 0; }