Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #pragma comment(linker, "/stack:200000000")
- #pragma GCC optimize("Ofast")
- #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
- #pragma GCC optimize("unroll-loops")
- #pragma GCC optimize("O3")
- #define F first
- #define S second
- #define pb push_back
- #define llong long long
- #define int llong
- #define ld long double
- #define endl '\n'
- #ifdef BUCKY_IS_ALIVE
- #define cerr if(0) cerr
- #else
- #endif // BUCKY_IS_ALIVE
- using namespace std;
- const int N = 1e5 + 5;
- const int M = 1e5 + 5;
- const int B = 2100;
- const int sum = 2e9;
- const int MOD = 1e9 + 7;
- const int MOD1 = 1e9 + 7;
- const int rx[4] = {0, 1, -1, 0};
- const int ry[4] = {1, 0, 0, -1};
- const char rr[5]= {'5', 'N', 'E', 'S', 'W'};
- main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- srand(time(0));
- #ifdef BUCKY_IS_ALIVE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- int n;
- cin >> n;
- vector <pair <int, int> > all;
- for(int i = 0; i < n; i++) {
- int x;
- cin >> x;
- all.pb({x, i});
- }
- sort(all.begin(), all.end());
- int cur = all[1].F - all[0].F;
- for(int i = 1; i < n; i++) {
- if (all[i].F - all[i - 1].F == cur)
- continue;
- else {
- vector <int> a;
- for(int j = 0; j < n; j++) {
- if (i == j)
- continue;
- a.pb(all[j].F);
- }
- bool ok = 1;
- for(int j = 1; j < a.size(); j++) {
- if (a[j] - a[j - 1] == cur)
- continue;
- ok = 0;
- break;
- }
- if (ok) {
- cout << all[i].S + 1 << endl;
- return 0;
- }
- break;
- }
- }
- if (all.size() == 2) {
- cout << all[0].S + 1 ;
- return 0;
- }
- int nom = all[0].S;
- reverse(all.begin(), all.end());
- all.pop_back();
- reverse(all.begin(), all.end());
- bool ok = 1;
- cur = all[1].F - all[0].F;
- for(int i = 1; i < all.size(); i++) {
- if (all[i].F - all[i - 1].F == cur)
- continue;
- ok = 0;
- break;
- }
- if (ok){
- cout << nom + 1;
- return 0;
- }
- cout << -1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement