Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define pb push_back
  4. #define int long long
  5. typedef long double ld;
  6.  
  7. int n;
  8. pair<int, int> a[200005];
  9.  
  10. main() {
  11. ios_base::sync_with_stdio(0), cin.tie(0);
  12. cin >> n;
  13. for (int i = 1; i <= n; ++i) {cin >> a[i].first, a[i].second = i;
  14. }
  15. sort(a + 1, a + n + 1);
  16. if (n == 2) {
  17. cout << 2 << '\n';
  18. return 0;
  19. }
  20. if (n == 3) {
  21. cout << 3 << '\n';
  22. return 0;
  23. }
  24. int d = a[2].first - a[1].first, lst = a[2].first, cnt = 0;
  25. bool f = 1;
  26. for (int i = 3; i <= n; ++i) {
  27. if (a[i].first != lst + d) {
  28. if (cnt) {
  29. f = 0;
  30. break;
  31. }
  32. cnt = a[i].second;
  33. } else lst = a[i].first;
  34. }
  35. if (f) {
  36. cout << (cnt == 0 ? 1 : cnt) << '\n';
  37. return 0;
  38. }
  39. d = a[3].first - a[1].first, lst = a[3].first, cnt = a[2].second;
  40. f = 1;
  41. for (int i = 4; i <= n; ++i) {
  42. if (a[i].first != lst + d) {
  43. if (cnt) {
  44. f = 0;
  45. break;
  46. }
  47. assert(false);
  48. cnt = a[i].second;
  49. } else lst = a[i].first;
  50. }
  51. if (f) {
  52. cout << cnt << '\n';
  53. return 0;
  54. }
  55. d = a[3].first - a[2].first, lst = a[3].first, cnt = a[1].second;
  56. f = 1;
  57. for (int i = 4; i <= n; ++i) {
  58. if (a[i].first != lst + d) {
  59. if (cnt) {
  60. f = 0;
  61. break;
  62. }
  63. assert(false);
  64. cnt = a[i].second;
  65. } else lst = a[i].first;
  66. }
  67. if (f) {
  68. cout << cnt << '\n';
  69. return 0;
  70. }
  71. cout << -1;
  72. return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement