import std.functional,
       std.algorithm,
       std.bigint,
       std.string,
       std.traits,
       std.array,
       std.range,
       std.stdio,
       std.conv;

void main() {
  int n = readln.chomp.to!int;
  int[] a = readln.chomp.split.to!(int[]);
  int[int] h;

  foreach (e; a) {
    if (e !in h) {
      h[e] = 1;
    } else {
      h[e]++;
    }
  }

  int[] b;
  foreach (k, v; h) {
    if (v >= 2) {
      b ~= k;
    }
  }
  b = b.sort!"a>b".array;
  int x = -1, y = -1;
  foreach (k; b) {
    if (x != -1 && y != -1) { break; }
    int c = h[k];
    if (c <= 3) {
      if (x == -1) {
        x = k;
      } else {
        y = k;
      }
    } else if (c >= 4) {
      if (x == -1) {
        x = k;
      }
      if (y == -1) {
        y = k;
      }
      break;
    }
  }

  if (x == -1 || y == -1) {
    writeln(0);
    return;
  }
}