#include using namespace std; int n; int a[51]; int turu, kame; bool count(int t) { int tmp = t; turu = 0; kame = 0; for( int i = 0; i < n; i++ ) { if ( t == 2 ) turu++; else if ( t == 4 ) kame++; else return false; t = -(a[i+1] - a[i] - t); } //最後に0番目の動物の足の本数が矛盾していないかも確かめる!! if ( t == tmp ) return true; return false; } int main() { cin >> n; for( int i = 0; i < n; i++ ) cin >> a[i]; a[n] = a[0]; //a[i+1]-a[i] = i番目の動物の足の本数 - i+1番目の動物の足の本数 //0番目の動物の足の本数(鶴orカメ)を決めれば、そのあとは一意(であり矛盾するかどうかはO(N)で分かる) //矛盾しないルートを選択して、このときの各動物の足のから、各動物が鶴か亀かを判定する。最後にカウント。 if ( count(2) ) { cout << turu << " " << kame << endl; return 0; } count(4); cout << turu << " " << kame << endl; return 0; }