#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 10;
pair<double, double> operator+(const pair<double, double> &a,
                               const pair<double, double> &b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
pair<double, double> operator-(const pair<double, double> &a,
                               const pair<double, double> &b) {
  return make_pair(a.first - b.first, a.second - b.second);
}
pair<double, double> operator*(const pair<double, double> &a, double k) {
  return make_pair(a.first * k, a.second * k);
}
pair<double, double> operator/(const pair<double, double> &a, double k) {
  return make_pair(a.first / k, a.second / k);
}
double dot(const pair<double, double> &a, const pair<double, double> &b) {
  return a.first * b.first + a.second * b.second;
}
double det(const pair<double, double> &a, const pair<double, double> &b) {
  return a.first * b.second - b.first * a.second;
}
double len2(const pair<double, double> &a) {
  return a.first * a.first + a.second * a.second;
}
double len(const pair<double, double> &a) { return sqrt(len2(a)); }
int n, m;
pair<double, double> a[MAXN], p[MAXN], c;
int cmp(double first) {
  if (fabs(first) < 1e-8) return 0;
  if (first > 0) return 1;
  return -1;
}
bool Inside(pair<double, double> c) {
  for (int i = 1; i < m; ++i)
    if (det(p[i + 1] - p[i], c - p[i]) > 1e-7) return false;
  return true;
}
void Print(pair<double, double> c) {
  double Tohka = 0;
  for (int i = 1; i <= n; ++i) Tohka += len2(a[i] - c);
  printf("%.10lf\n", Tohka);
  exit(0);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i)
    scanf("%lf%lf", &a[i].first, &a[i].second), c = c + a[i];
  cin >> m;
  for (int i = 1; i <= m; ++i) scanf("%lf%lf", &p[i].first, &p[i].second);
  p[++m] = p[1];
  c = c / (double)n;
  if (Inside(c)) Print(c);
  double h = 1e18;
  pair<double, double> o;
  for (int i = 1; i < m; ++i) {
    pair<double, double> A = p[i + 1] - p[i], B = c - p[i];
    double t = dot(A, B) / len2(A);
    if (len(p[i] - c) < h) h = len(p[i] - c), o = p[i];
    if (t >= 0 && t < 1 + 1e-7)
      if (fabs(det(A, B)) / len(A) / 2 < h)
        h = fabs(det(A, B)) / len(A) / 2, o = p[i] + A * t;
  }
  if (!Inside(o)) puts("Error");
  Print(o);
  fclose(stdin);
  fclose(stdout);
  return 0;
}
