Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define pb push_back
- #define int long long
- typedef long double ld;
- int n;
- pair<int, int> a[200005];
- main() {
- ios_base::sync_with_stdio(0), cin.tie(0);
- cin >> n;
- for (int i = 1; i <= n; ++i) {cin >> a[i].first, a[i].second = i;
- }
- sort(a + 1, a + n + 1);
- if (n == 2) {
- cout << 2 << '\n';
- return 0;
- }
- if (n == 3) {
- cout << 3 << '\n';
- return 0;
- }
- int d = a[2].first - a[1].first, lst = a[2].first, cnt = 0;
- bool f = 1;
- for (int i = 3; i <= n; ++i) {
- if (a[i].first != lst + d) {
- if (cnt) {
- f = 0;
- break;
- }
- cnt = a[i].second;
- } else lst = a[i].first;
- }
- if (f) {
- cout << (cnt == 0 ? 1 : cnt) << '\n';
- return 0;
- }
- d = a[3].first - a[1].first, lst = a[3].first, cnt = a[2].second;
- f = 1;
- for (int i = 4; i <= n; ++i) {
- if (a[i].first != lst + d) {
- if (cnt) {
- f = 0;
- break;
- }
- assert(false);
- cnt = a[i].second;
- } else lst = a[i].first;
- }
- if (f) {
- cout << cnt << '\n';
- return 0;
- }
- d = a[3].first - a[2].first, lst = a[3].first, cnt = a[1].second;
- f = 1;
- for (int i = 4; i <= n; ++i) {
- if (a[i].first != lst + d) {
- if (cnt) {
- f = 0;
- break;
- }
- assert(false);
- cnt = a[i].second;
- } else lst = a[i].first;
- }
- if (f) {
- cout << cnt << '\n';
- return 0;
- }
- cout << -1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement