Problem:
星座探し
問題
あなたは星空の写真の中から星座を探している．写真には必ず，探したい星座と同じ形・向き・大きさの図形がちょうど一つ含まれている．ただし，写真の中には星座を構成する星以外に余分な星が写っている可能性がある．
例えば，図 1 の星座は図 2 の写真に含まれている（丸で囲んで示した）．与えられた星座の星の座標を x 方向に 2， y 方向に −3 だけ平行移動すると写真の中の位置になる．
探したい星座の形と写真に写っている星の位置が与えられたとき，星座の座標を写真の中の座標に変換するために平行移動するべき量を答えるプログラムを書け．
図 1: 探したい星座
図 2: 星空の写真
入力
入力は複数のデータセットからなる．各データセットは以下の形式で与えられる．
入力の 1 行目には探したい星座を構成する星の個数
m
が書かれている．続く
m
行には探したい星座を構成する
m
個の星の x 座標と y 座標を示す整数が空白区切りで書かれている．
m
+2 行目には写真に写っている星の個数
n
が書かれている．続く
n
行には写真に写っている
n
個の星の x 座標と y 座標を示す整数が空白区切りで書かれている．
星座を構成する
m
個の星の位置はすべて異なる．また，写真に写っている
n
個の星の位置はすべて異なる． 1 ≤
m
≤ 200， 1 ≤
n
≤ 1000 である．星の x 座標と y 座標はすべて 0 以上 1000000 以下である．
m
が 0　のとき入力の終わりを示す. データセットの数は 5 を超えない．
出力
各データセットの出力は 1 行からなり， 2 個の整数を空白区切りで書く．これらは探したい星座の座標をどれだけ平行移動すれば写真の中の座標になるかを表す．最初の整数が x 方向に平行移動する量，次の整数が y 方向に平行移動する量である．
入出力例
入力例
5
8 5
6 4
4 3
7 10
0 10
10
10 5
2 7
9 7
8 10
10 2
1 2
8 1
6 7
6 0
0 9
5
904207 809784
845370 244806
499091 59863
638406 182509
435076 362268
10
757559 866424
114810 239537
519926 989458
461089 424480
674361 448440
81851 150384
459107 795405
299682 6700
254125 362183
50795 541942
0
出力例
2 -3
-384281 179674
入出力例の１つ目は上の図に対応している．
上記問題文と自動審判に使われるデータは、
情報オリンピック日本委員会
が作成し公開している問題文と採点用テストデータです。

Submitted solutions:

code_snippet: #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
// #include <atcoder/modint>
// #include <atcoder/fenwicktree>
// #include <atcoder/segtree>
// #include <atcoder/scc>

#define int long long
#define all(x) begin(x), end(x)

using namespace std;
// using namespace atcoder;
// using mint = modint998244353;
// using mint = modint1000000007;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vp = vector<pii>;
using vs = vector<string>;

void debug(vector<int> a) {
    for (auto x : a) cout << x << ' ';
    cout << endl;
}

void debug(vector<vector<int>> a) {
    for (auto y : a) debug(y);
}

template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b and (a = b, true);}

template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b and (a = b, true);}

// inline bool in(int y, int x) {return 0 <= x and x < w and 0 <= y and y < h;}

const int supl = 1e18 - 100;

pii solve(int m) {
    vp ps(m);
    for (auto& [y, x] : ps) cin >> x >> y;
    set<pii> st;
    int n; cin >> n;
    for (int _ = 0 ; _ < n ; _++) {
        int y, x; cin >> x >> y;
        st.insert(make_pair(y, x));
    }


    int ansy, ansx;
    for (auto [ny, nx] : st) {
        // cout << ny << ' ' << nx << endl;
        int movey = ny - ps[0].first;
        int movex = nx - ps[0].second;
        // cout << movey << ' ' << movex << endl << endl;
        bool ok = true;
        for (auto [y, x] : ps) {
            if (!st.count(make_pair(y + movey, x + movex))) ok = false;
        }
        if (ok) {
            ansy = movey, ansx = movex;
        }
    }

    return {ansy, ansx};
}

void main_() {
    while(1) {
        int m; cin >> m;
        if (!m) break;
        auto [y, x] = solve(m);
        cout << x << ' ' << y << endl;
    }
}

signed main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    main_();

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3224
final_rank: 12

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
#define all(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)
using pqr = priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>;

template<class T>
bool chmax(T& p, T q) {
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}
template<class T>
bool chmin(T& p, T q) {
    if (p > q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

ll gcd(ll(a), ll(b)) {
    ll c = a;
    while (a % b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return b;
}
ll modPow(long long a, long long n, long long p) {
  if (n == 0) return 1; // 0乗にも対応する場合
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
  long long t = modPow(a, n / 2, p);
  return (t * t) % p;
}


int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    while(1){
    ll N;
    cin>>N;
    if(N==0)return 0;
    vector<pair<ll,ll>> P(N);
    rep(i,N){
        cin>>P[i].first>>P[i].second;
    }
    ll M;
    cin>>M;
    set<pair<ll,ll>> Q;
    rep(i,M){
        ll X,Y;
        cin>>X>>Y;
        Q.insert({X,Y});
    }
    for(auto q:Q){
        ll dx=q.first-P[0].first;
        ll dy=q.second-P[0].second;
        bool C=1;
        rep(i,N){
            ll x=dx+P[i].first;
            ll y=dy+P[i].second;
            if(!Q.count({x,y}))C=0;
        }
        if(C){
            cout<<dx<<" "<<dy<<endl;
            break;
        }
    }}

}
accuracy: 1
time_ms: 10
memory_kb: 3428
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
const long long MOD1 = 1000000007;
const long long MOD2 = 998244353;
typedef long long ll;
typedef pair<long long, long long> P;
const long long INF = 1e9;
const ll MOD = MOD1;
template <typename T>
void input_arr(vector<T>& A, ll N) {
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
}
template <typename T, typename Q>
void input_arr(vector<pair<T, Q>>& A, ll N) {
    for (ll i = 0; i < N; i++) {
        cin >> A[i].first >> A[i].second;
    }
}
int main() {
    ll M; cin >> M;
    while (M != 0) {
        vector<P>A(M); input_arr(A, M);
        ll N; cin >> N;
        vector<vector<ll>>B(1000001);
        vector<P>C(N);
        for (ll i = 0; i < N; i++) {
            ll x, y; cin >> x >> y;
            C[i] = make_pair(x, y);
            B[x].push_back(y);
        }
      	for (ll i = 0; i <= 1000000; i++) {
          	if (B[i].empty()) continue;
          	sort(B[i].begin(),B[i].end());
        }
        for(ll i = 0; i < N; i++) {
            ll dx = C[i].first - A[0].first;
            ll dy = C[i].second - A[0].second;
            bool check = true;
            for (ll j = 0; j < M; j++) {
                if (A[j].first + dx < 0 || A[j].first + dx > 1000000 || A[j].second + dy < 0 || A[j].second + dy > 1000000) {
                    check = false;
                    break;
                }
                if (!binary_search(B[A[j].first + dx].begin(), B[A[j].first + dx].end(), A[j].second + dy)) {
                  check = false;
                    break;
                }
            }
            if (check) {
                cout << dx << ' ' << dy << endl;
                break;
            }
        }
        cin >> M;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 26916
final_rank: 18

code_snippet: #include<iostream>
#include<vector>

struct Coord{
    int x,y;
    Coord() : x(0), y(0) {}
};

bool check(std::vector<Coord> target,
           std::vector<Coord> sky,
           Coord diff){
    for(int m=1; m<target.size(); ++m){
        int dx = target[m].x + diff.x;
        int dy = target[m].y + diff.y;
        bool found=false;
        for(int n=0; n<sky.size(); ++n){
            if(sky[n].x == dx && sky[n].y == dy)
                found=true;
        }
        if(!found) return false;
    }
    std::cout << diff.x << ' ' << diff.y << std::endl;
    return true;
};

int main(){
    int M,N;
    while(std::cin >> M, M){
        std::vector<Coord> target(M);
        for(int i=0; i<M; ++i)
            std::cin >> target[i].x >> target[i].y;
        std::cin >> N;
        std::vector<Coord> sky(N);
        for(int i=0; i<N; ++i)
            std::cin >> sky[i].x >> sky[i].y;

        for(int i=0; i<N; ++i){
            Coord diff;
            diff.x = sky[i].x - target[0].x;
            diff.y = sky[i].y - target[0].y;
            if(check(target, sky, diff))
                break;
        }
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3108
final_rank: 6

code_snippet: #include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
#define rep(i, x) for(ll i = 0; i < x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll modpow(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}
ll keta(ll n) {
	ll res = 0;
	while (n >= 1) {
		res += n % 10; n /= 10;
	}
	return res;
}
ll nCk(ll n, ll k) {
	ll a = 1, b = 1;
	for (int h = n - k + 1; h <= n; h++) { a *= h; a %= mod; }
	for (int h = 1; h <= k; h++) { b *= h; b %= mod; }
	return a * modpow(b, mod - 2) % mod;
}
bool IsPrime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) { // 素数ではない
			return false;
		}
	}
	// 素数である
	return true;
}
//printf("%.10f\n", n);

ll x[1234567], y[1234567];
signed main() {
    while(true){
	ll m, n, a, b; cin >> m; map<ll, map<ll, ll>>ma;
	if(m==0){return 0;}
	vector<ll> v1, v2;
	rep(i, m) {
		cin >> x[i] >> y[i];
	}
	cin >> n;
	rep(i, n) {
		cin >> a >> b;
		rep(j, m) {
			if (ma[a - x[j]][b - y[j]] == 0) {
				v1.push_back(a - x[j]); v2.push_back(b - y[j]);
			}
			ma[a - x[j]][b - y[j]]++;
		}
	}
	rep(i, v1.size()) {
		//cout << v1[i] << ' ' << v2[i] << ' ' << ma[v1[i]][v2[i]] << endl;
		if (ma[v1[i]][v2[i]] == m) {
			cout << v1[i] << ' ' << v2[i] << endl;break;
		}
	}
    }
	return 0;
}
accuracy: 1
time_ms: 190
memory_kb: 35928
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;

using ll=long long;
const ll INF=1LL<<60;
const ll MOD=1e9+7;

struct Point{
    int x;
    int y;
};


int main(){
    while(1){
        int m; cin >> m;
        if(m == 0) break;
        vector<Point> point1(m);
        for(int i=0; i<m; i++){
            cin >> point1[i].x >> point1[i].y;  
        }
        int n; cin >> n;
        vector<Point> point2(n);
        for(int i=0; i<n; i++){
            cin >> point2[i].x >> point2[i].y;
        }
        Point res;
        for(int i=0; i<n; i++){
            int dx=point2[i].x-point1[0].x;
            int dy=point2[i].y-point1[0].y;
            bool ok;
            for(int j=1; j<m; j++){
                ok=false;
                int nx=point1[j].x+dx;
                int ny=point1[j].y+dy;
                for(int k=0; k<n; k++){
                    if(point2[k].x == nx && point2[k].y == ny) ok=true;
                }
                if(!ok) break;
            }
            if(ok){
                res.x=dx;
                res.y=dy;
            }
        }
        cout << res.x << " " << res.y << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3000
final_rank: 1

code_snippet: #include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout(n) cout << fixed << setprecision(n)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acosl(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


signed main(){
    int m;
    while(cin >> m, m){
        vector<PII> v(m);
        rep(i, 0, m) cin >> v[i].first >> v[i].second;
        int n;
        cin >> n;
        vector<PII> u(n);
        map<PII, bool> mp;
        rep(i, 0, n) cin >> u[i].first >> u[i].second, mp[u[i]] = true;
        int dx = -1, dy = -1;
        rep(i, 0, n){
            dx = u[i].first-v[0].first;
            dy = u[i].second-v[0].second;
            bool f = true;
            rep(j, 0, m) if(!mp[make_pair(v[j].first+dx, v[j].second+dy)]) f = false;
            if(f) break;
        }
        cout << dx << ' ' << dy << endl;
    }

    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 10928
final_rank: 16

code_snippet: #include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    while(N != 0){
        int x0,y0;
        cin >> x0 >> y0;
        vector<P> hosi(N-1);
        for(int i=0; i<N-1; i++){
            int a,b;
            cin >> a >> b;
            a -= x0;
            b -= y0;
            hosi[i] = P(a,b);
        }
        int M;
        cin >> M;
        set<P> suzu;
        for(int i=0; i<M; i++){
            int a,b;
            cin >> a >> b;
            suzu.emplace(a,b);
        }
        int ans_x,ans_y;
        for(auto ken: suzu){
            int x = ken.first;
            int y = ken.second;
            bool can = true;
            for(int i=0; i<N-1; i++){
                if(!suzu.count(P(x+hosi[i].first,y+hosi[i].second))) can = false;
            }
            if(can){
                ans_x = x;
                ans_y = y;
            }
        }
        cout << ans_x-x0 << " " << ans_y-y0 << enld;
        cin >> N;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3080
final_rank: 4

code_snippet: #include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

template <class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int nx[1010], ny[1010], mx[210], my[210];
set<pair<int, int>> s;

void solve(int m) {
    int n;
    REP(i, m) { cin >> mx[i] >> my[i]; }
    cin >> n;
    REP(i, n) {
        cin >> nx[i] >> ny[i];
        s.insert(make_pair(nx[i], ny[i]));
    }
    REP(i, m) {
        REP(j, n) {
            bool flag1 = true;
            bool flag2 = true;
            int dx = nx[j] - mx[i];
            int dy = ny[j] - my[i];

            REP(k, m) {
                auto nnx = dx + mx[k];
                auto nny = dy + my[k];

                if (!s.count(make_pair(nnx, nny))) {
                    flag1 = false;
                }
            }

            if (flag1) {
                cout << dx << " " << dy << endl;
                return;
            }

            dx = -dx;
            dy = -dy;

            REP(k, m) {
                auto nnx = dx + mx[k];
                auto nny = dy + my[k];

                if (!s.count(make_pair(nnx, nny))) {
                    flag2 = false;
                }
            }

            if (flag2) {
                cout << dx << " " << dy << endl;
                return;
            }
        }
    }
}

int main() {
    int m;
    while (cin >> m && m) {
        solve(m);
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3252
final_rank: 14

code_snippet: #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

void solve(int m) {
  vector<int> m_x(m), m_y(m); REP(i, m) cin >> m_x[i] >> m_y[i];
  int n; cin >> n;
  vector<int> n_x(n), n_y(n);
  set<pair<int, int> > st;
  REP(i, n) {
    cin >> n_x[i] >> n_y[i];
    st.emplace(n_x[i], n_y[i]);
  }
  REP(i, n) {
    int dX = n_x[i] - m_x[0], dY = n_y[i] - m_y[0];
    bool ans = true;
    REP(j, m) ans &= st.count(make_pair(m_x[j] + dX, m_y[j] + dY)) == 1;
    if (ans) {
      cout << dX << ' ' << dY << '\n';
      return;
    }
  }
  assert(false);
}

int main() {
  while (true) {
    int m; cin >> m;
    if (m == 0) break;
    solve(m);
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3080
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;

using P = pair<int,int>;

int main(){
    int n, m;
    while(cin >> m, m){
        vector<P> a(m);
        set<P> st;
        for(int i=0;i<m;i++){
            int x, y;
            cin >> x >> y;
            a[i] = P(x,y);
        }
        cin >> n;
        for(int i=0;i<n;i++){
            int x, y;
            cin >> x >> y;
            st.insert(P(x,y));
        }
        for(int i=1;i<m;i++){
            a[i].first -= a[0].first;
            a[i].second -= a[0].second;
        }
        for(auto p : st){
            int x0 = p.first, y0 = p.second;
            bool ok = true;
            for(int i=1;i<m;i++){
                ok &= st.count(P(a[i].first+x0,a[i].second+y0)) > 0;
            }
            if(ok){
                int dx, dy;
                dx = x0-a[0].first; dy = y0-a[0].second;
                cout << dx << " " << dy << endl;
                break;
            }
        }
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3152
final_rank: 11

code_snippet: #include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    int m,x[200],y[200],n,a,b;
    while(cin>>m,m){
    for(int i=0;i<m;i++)
        cin>>x[i]>>y[i];
    set<pair<int,int>>st;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        st.emplace(a,b);
    }
    for(auto e:st){
        bool ok=1;
        int dx=e.first-x[0],dy=e.second-y[0];
        for(int i=0;i<m;i++)
            if(!st.count(make_pair(dx+x[i],dy+y[i])))
                ok=0;
        if(ok){
            cout<<dx<<' '<<dy<<endl;
            break;
        }
    }}
}
accuracy: 1
time_ms: 10
memory_kb: 3148
final_rank: 9

code_snippet: #include<iostream>
using namespace std;

class Point
{
    private:
        int x, y;

    public:
        Point( int x = 0, int y = 0 );
        void setXY( int a, int b ){ x = a; y = b; }
        int getX(){ return x; }
        int getY(){ return y; }
        bool operator==( Point a );
        Point operator+( Point a );
        Point operator-( Point a );
};

Point::Point( int a, int b )
{
    x = a;
    y = b;
}

bool Point::operator==( Point a )
{
    if( x == a.x && y == a.y )
        return true;
    else
        return false;
}

Point Point::operator+( Point a )
{
    Point res;
    res.x = x + a.x;
    res.y = y + a.y;
    
    return res;
}

Point Point::operator-( Point a )
{
    Point res;
    res.x = x - a.x;
    res.y = y - a.y;
    
    return res;
}


int main()
{
    int n, m, x, y;

    while( cin >> n )
    {
        if( !n )
            break;

        Point a[n];
        for( int i = 0; i < n; i++ )
        {
            cin >> x >> y;
            a[i].setXY( x, y );
        }

        cin >> m;

        Point b[m];
        for( int i = 0; i < m; i++ )
        {
            cin >> x >> y;
            b[i].setXY( x, y );
        }

        Point c[m];
        for( int i = 0; i < m; i++ )
            c[i] = b[i] - a[0];

        for( int i = 0; i < m; i++ )
        {
            bool judge = true;
            for( int j = 0; j < n; j++ )
            {
                Point d = a[j] + c[i];

                bool judge2 = false;
                for( int k = 0; k < m; k++ )
                    if( d == b[k] )
                        judge2 = true;
                
                if( !judge2 )
                    judge = false;
            }
                
            if( judge )
            {
                cout << c[i].getX() << " " << c[i].getY() << endl;
                break;
            }
        }
    }
    return 0;
}
accuracy: 1
time_ms: 170
memory_kb: 3032
final_rank: 17

code_snippet: //
//
//  Codeforces: ganariya
//  AtCoder: ganariya2525
//  MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMHBYYYWMMMM#BYYTTTYWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMB9O1==?????zzCC111>>;;;;;;;;;;;<?TMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMMMMMMMMMMMM9Olll=l======??????????>>>>>>;;;;;;;;;:;?TMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMMMMMMMMM9ttlllllllll=l=======?????????>>>>>>;;;;;;;;;;?TMMMMMMMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMMMMMMBOttOtttttltlllllllll=======??????????>>>>>>>;;;;;;?TMMMMMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMMMMBttwOtttttttttttttlllllllll========?????????>>>>>>;;;;;<TMMMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMMBrwZrttttttttttttttttttlllllllllll======???????????>>>>>>;;?HMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMSw0trtrrtrtrttrtttttttttttttlllOllllll========????<<zz??>>>>>>ZMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMX0ttrtrOOttrttrttOOttttttttttttltwllllllllll========??wy?????>>>vZMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMM0ttrI+wV1rtttttttwZtttttttltttOwylOXOllllllllllll=l====1dkz???????vZdMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMSrrwrtwZCjttttttttwSttOlllltllllwtXOlZkOlllllllllllllll==z+dk===?????X2JMMMMMMMMMMMMM
//  MMMMMMMMMMMMMBrtwwtrw0<jttttttttOXllOttltllttllOZwHOtXkyltlllllllllllllll<+XZ======?dk?JMMMMMMMMMMMM
//  MMMMMMMMMMMMStwdZtwXC<+ttttttOOOd6ltZlltllllttllStWWOOHWytttttltltOllltllz:zHllll===zX=?dMMMMMMMMMMM
//  MMMMMMMMMMBrwdKOtwW3;;zrttttwZwXRlldOllltltlltttwlXvktdXWytltttttttOttlttl<<dklllllllZ===dMMMMMMMMMM
//  MMMMMMMMM8tQM#ttwW3;;;1trttwSwfUOlORltllltlllllldtX>dktDOWOtlttltttOOttltO<;+WOllllllXlllzMMMMMMMMMM
//  MMMMMMMM9OdM#Ottd$;;;;;<?1z0OKjRltd0llltOllllllldZX>?WOw_WWOtttttttttOttI<;;<dkttttllllllldMMMMMMMMM
//  MMMMMMM9wMMMSttwS<;;;;>;;;J<j>(I<?U111zltllllllld0X>~dkwl(WkttlttlOOwWk<;;:;;zHttttttwOllllMMMMMMMMM
//  MMMMMMBdMMM8tttdI+zttttttdSXt~dlzXwlllzzOzzzzzlldkW<~?kOk~?sx++++jdHmH6+++<;;jdZtttttdkOtlldMMMMMMMM
//  MMMMM#dMMM#tttw0+tttttttdKdf((RsdfRllllldZllltlldWK~~_W0w_~OWOlOdgg9ZtOWOtttz+wktttttdpktttwMMMMMMMM
//  MMMMMWMMMMSlttdIttttttOdWHH>~(IzWDRll=llzRlllzlldk$>++dkd<~_XkdgH9tttttdktttt+OkrttrtdfpkttOMMMMMMMM
//  MMMMNWMMM#Zttlk=tttttOXWWd$_.(IdW1R=llll=SlllzOldK<_._(kd6+-(MM9lltttttrWktttztWZttrwXppWttrMMMMMMMM
//  MMMMNMMMM#lltwDzttllOXyW0X:..(OXk<Rl=ll=lwOlllOld3<``.(Rd>~?CdklllltttttXdXttzOWktrwwWpfpkrtMMMMMMMM
//  MMMMMMMMM@ltldIzlttOXyW$w$```(OyD(Rl==llldZ=llIlw;~```-Xd:~~~~UkylltttAyHdgSrzObRtOXwpfppWrrMMMMMMMM
//  MMMMMMMMM@llldtlllldVyW+d>```.wZ$ wl==lI=wRl=ll=w<```` dd_..~~(RZXOQdggHH9ZwrzwHWrdXXppfppkrMMMMMMMM
//  MMMMMMMMM#llldlltlwyyyD(S-...,Wk] zI=l=llzWzl=l=P~```` jZ``...~zQkH@MBUtrZtrtldHRdSdpfpffpkwMMMMMMMM
//  MMMMNMMMMNZllXtllldVyW3(Mf=<ONMHP~(k===l=zdk=lld3```...(C````..(M96lttttrrtrrtdHWHXpfpppfpRwMMMMMMMM
//  MMMMMMMMMMNzzWZllzyyyy(W@`  =~MWK6 jz=lzlzvRz=lZ`.I+JgkWm&-. `..(ZltlttttrtttrWWHppfppfpppSdMMMMMMMM
//  MMMMMMMMMMMkAWRllzVyyS_(b    .MNHU-(Uz=lI={XkzO>.dVT7<TMHMNHHx-.(kwZyltttrtrrdHHpfppfpffpp0dMMMMMMMM
//  MMMMMMMMMMMMKyWzOzyyyk.`<!  hdWMH]``(S==t=l(kX2 ?_`    WMMHH#HH+.XwkwOttttrwrZ~(HfpfpppfpWwXMMMMMMMM
//  MMMMMMMMMMMMMHWROOyyyW;` `. (WVM#b```(0=zzz wX!```  a.dM#NM@N(4WhXkXkWtttttwd3O_(HpffpfpfWwSMMMMMMMM
//  MMMMMMMMMMMMNZvWzXXyyXP```-_ ?o+?!````.4=Z=`(:````  HpbNNMHHH (C=XXyWZWttrdwf:(>.dfppffppSXSMMMMMMMM
//  MMMMMMMMMMMMMRzuHzXyZXH.``````````````` ?zz ``````` ZKvTHHbWt `` XZyyHZWOdSZ<::~`(fpfpfffXp0WMMMMMMM
//  MMMMMMMMMMMMMKzyyHvyZZW____.`````````````.I_```````` ?nJzX7^````.WXWyyHyWKZ<:::_`Jffpfpfpfp0WMMMMMMM
//  MMMMMMMMMMMMM@zZyZWwWyXo-_~(~ ```````````` `````````````` _`````.WXkyyVWmWc::<~ .HffppfffffkXMMMMMMM
//  MMMMMMMMMMMMMKzZZZZXkUXr~....```````....```````````` ...  ````..JXWWyyW83vXx~..WfffVfWVffffkdMMMMMMM
//  MMMMMMMMMMMMMRzZZZZZZZZb````````````<````````````./<~._<_.____`(WfdyW3<:~~(XWkVVVVVVVHVVVVV0dMMMMMMM
//  MMMMMMMMMMMMMSzZZZZZZZWX-```````````````````````````.......~~._j9jX=_~~_(XZyVHHkyyyyWHyyykykOMMMMMMM
//  MMMMMMMMMMMMMSzuuuuuZXWZW,```````````````````````````````.``..(3<! ...JWyyXWyyyWHkyyWHyyyHyklMMMMMMM
//  MMMMMMMMMMMMNXzuuuXXuXSuuXh,```````` .... ```````````````````_~ .JWyyyyZyy0HyyZyyZyZXWZZZWHZIdMMMMMM
//  MMMMMMMMMMMMNwtuuuXkuXXuuuuXh,``````(:::~<?71(,``````````````.(UMNUkZZZZZZZHZZ0ZZZZZWWZZZWNXIdMMMMMM
//  MMMMMMMMMMMMNKOzuzXkuXuuuuuXuXW, ```` _~~~:~~(}```````````.(YC;::<kCfZZZZXO#ZZVZZZZZMZZuuMMNXzMMMMMM
//  MMMMMMMMMMMMHKOzzuXkzdzzzzuXXzuuU&.``````````````````` .JY>::::;;J=:dZuZuZd#uuruuuud#uuuXMMMNXdMMMMM
//  MMMMMMMMMMMMMNOvzzXkvMRzzzzXKzuzzzXh, `````````````..JC<;:;;:;;+7<:~(HHuXIdNuuzuuuXMSuuuWMMMMROMMMMM
//  MMMMMMMMMMMMMNvvvrdkvM#vzzzzHzzzzzuzzUG. ``` ...JdY<:;:;:::;;+v<~~~:(HpHmzMNXZzuzzd#zzzdMMMMMMRdMMMM
//  MMMMMMMMMMMMMNwrrvdRrMNwvvvvdRvvvzwkzzzzXWWHY=~~O+::::::::<+<~~~~~~~dppppWMMkZzzzwM#zzdMMMMMMMMNMMMM
//  MMMMMMMMMMMMMM#rrrwRrMMbOrrOZNkrvvvXwvvvvvwX;.~._W_:::::(?!~~~~~~~~(HpppppppHWdvwM#XwdMMMMMMMMMMNMMM
//  MMMMMMMMMMMMMMNyrrrRrWMMmzOrzdNyrrrZNvrwQWWfb....(r~~_J>_.....~.~~-dpfpffpfpppWHHMNdMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMNrtrStdMMMNxzrzMNmrrrdNWfVfffP._-.(~_J!............JpfpffpfpfffpppWNppppHMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMNOtXtdMMMMMNxzZMMNmgHyVVVVVW%..?/(.,(x-..........(HfffpffpffpffWHHffpffppfVyyWMMMMMM


//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

//~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

int main() {

    while (true) {

        int m;
        cin >> m;

        if (m == 0) break;

        vector<pair<int, int>> a(m);
        for (int i = 0; i < m; i++) {
            int x, y;
            cin >> x >> y;
            a[i] = make_pair(x, y);
        }

        int n;
        cin >> n;

        vector<pair<int, int>> b(n);
        map<pair<int, int>, bool> mp;
        for (int i = 0; i < n; i++) {
            int x, y;
            cin >> x >> y;
            b[i] = make_pair(x, y);
            mp[make_pair(x, y)] = true;
        }

        for (int i = 0; i < n; i++) {
            int dy = b[i].second - a[0].second;
            int dx = b[i].first - a[0].first;
            bool good = true;
            for (int j = 0; j < m; j++) {
                int toY = dy + a[j].second;
                int toX = dx + a[j].first;
                if (mp.count(make_pair(toX, toY))) continue;
                good = false;
            }
            if (good) {
                cout << dx << " " << dy << endl;
                break;
            }
        }

    }

}
accuracy: 1
time_ms: 10
memory_kb: 3148
final_rank: 9

code_snippet: #include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ull = unsigned long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
	int N,M;
	while(1){
		cin >> N;
		if(N==0) return 0;
		V<int> a(N),b(N);
		REP(i,N) cin >> a[i] >> b[i];
		cin >> M;
		V<int> c(M),d(M);
		REP(i,M) cin >> c[i] >> d[i];
		map<P<int,int>,int> mp;
		REP(i,M) mp[{c[i],d[i]}];
		for(int i = 0; i < M; ++i){
			int x = c[i] - a[0];
			int y = d[i] - b[0];
			int flg = 1;
			for(int j = 0; j < N; ++j){
				if( !mp.count({a[j]+x,b[j]+y}) ) flg = 0;
			}
			if(flg) {
				cout << x << " " << y << endl;
				break;
			}
		}
	}

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3076
final_rank: 3

code_snippet: // だーれだ？
//qqqqqqHHMqqqqqHf!(:;jHmmkf``(:;jkqqqqqqqqqmMH#HMqqK_````````````````(kqqqqqqHMMM
//qqqqqqHHmqqqqH=` :;;jkqH=?~..;;jqqqqqqqqqmM#HM#MHH!```` ```````..-``dqWbWkRqHMMM
//qqqqqqMHmqqqK!``.;;;dqH: ```.?TUqqHmqqqqmHHHM4Mqkt..```` ..JgHHW@P`.HHkqHHHqM#NN
//qqqqqmHMmqHTYWHgHmmgHR...``` :;Jkq9qqqqqgMH#1dHk$...-gW@HY"=!``dH! dHNmqqqqmM###
//qqqqqqgMmH[````` ?dHMMMHHHHHJ<;JkK>XqqqmMH#<+Hb%.WYYTHppf-````.gt`.HHMmmqqqmM###
//qqkqqqm@H?S,```` Jpbbpp:```` :!dK<;JkqqMMY(;dW^````.ppbpf!```.Y<`.HHHMgmqqqmH###
//qqqqqqqqD`` ````(ppbppW````` ~.f`:;jkqM#^.;jf!````.Wppbpf````````(HH#HmmqqmH#NN#
//qqqqqqqkP``````.fpbpbpf``` ` `.``~:;WHY``(+=``````Jppbpf\```` ``.MH#HHgqqqmHNNNN
//qqqqqqqk]```` `,fpbbpf>```` `` ``_:<? ``.?!``` `` Wpppp%``` ``` dHH##HmmqqmH####
//qqqqqqqk]``````,fpbppt``` `` `` `_~````` `` `` ```WppW=``` ````.HHHHMHmmqqmM####
//qqqqqqqk$`` ````4ppfY```` `` `` `- `` `` `` ``` ``(T=`````` ``.MH##HMMmmqqmM##HH
//qqqqqqHqP``` ````?7!```` `` `` ``` `` ` ` ``  ````````` ` ````.MHH#HgMmqmqmHHHHH
//qqqkqqmkR```` `        `` ` `` ` ` ` ``` ` ``` `   ......_. ```dH#HHgMqqgqqmH#HH
//NqqqqqHqR```  _ ........_` `` ``` ``` ````` ``` ............```,HHHHmqqqHqqmMH##
//MmqqqqHqR```  _........_ `` `` ``` `` `  `` ` ` `  `__     ` ``,HHHMmmqqMHmmMHH#
//HMqqqqXkH `````````````` ` `` `  `` `` `` `` `` ```` ````` ````.HHHMmMHm@HHqmMHH
//HHHmqqfHk;``` `  ` `` ` ` `` ``` ` ` ``` `` `` `` ````  `..```.HHHHMMHMg@HHHHHMH
//HHMmmqMHkP<.`` ``` ` ` ``` `` ``` ``` ` `` `` `` `  ````  ```.MH##HM#HMg@@@@H@HH
//##HNmqR`jW<<_ ``` ````` `` ` ` ``` `` `` `` `` ````  ````` .dHH##H#HHHMHH@@H@@@@
//HH##NqH..X2:<<-.`` ` `` ``` ``` ` `` `` `` ` `` ` ``` ` .gMHHH#H#HHH#HM@@H@@H@@H
//-WHHHNH[ =v._:::<-. ` `` ` ``  ```````.`` `````````     .MHH###H#MHHHHH@H@H@@HH@
//` 7MHHMH.l==.  ~:::::<_-.. ````` ``````` ``  ...uX;     `,MHHHH#M@@MM@@@@@@H@@@@
//  . TMHHbZl=1.   _~::::::(<::<:<___-___:<<:::::jX3=. ` ` `,MMHM@@@@Mg@@@@@@@@@H@
//
#include <bits/stdc++.h>
#define int long long
#define ll long long 
#define rep(i,a,b) for(signed i=a;i<(b);++i)
#define erep(i,a,b) for(signed i=a;i<=(b);++i)
#define per(i,a,b) for(signed i=(a);i>(b);--i)
#define eper(i,a,b) for(signed i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define pb push_back
#define mp make_pair
#define ALL(x) begin(x),end(x)
#define F first
#define S second
#define debug(x)  cout << #x << ": " << (x) << '\n';
const long long INF=1001001001001001001;
const int MOD=(int)1e9 + 7;
const double EPS=1e-9;
using namespace std;
using Pii = pair<int,int>;
using vii = vector<int>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int from, to, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
// cout << fixed;
// cout << setprecision(10) << val;

int m, n;
signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  while (cin >> m) {
    if (!m) break;
    vii x(m), y(m);
    rep(i, 0, m) {
      cin >> x[i] >> y[i];
    }
    int x0 = x[0], y0 = y[0];
    rep(i, 1, m) x[i] -= x0, y[i] -= y0;
    x[0] = 0, y[0] = 0;
    int n;
    cin >> n;
    vii px(n), py(n);
    rep(i, 0, n) cin >> px[i] >> py[i];
    rep(i, 0, n) {
      int nx = px[i], ny = py[i];
      bool used[m] = {false};
      rep(j, 0, n) {
        int vec_x = px[j] - nx, vec_y = py[j] - ny;
        rep(k, 0, m) {
          if (!used[k] && x[k] == vec_x && y[k] == vec_y) {
            used[k] = true;
            break;
          }
        }
      }
      bool flag = true;
      rep(k, 0, m) {
        if (!used[k]) flag = false;
      }
      if (flag) {
        cout << nx - x0 << " " << ny - y0 << endl;
        break;
      }
    }
  }
  return 0;
}
accuracy: 1
time_ms: 360
memory_kb: 3148
final_rank: 19

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0) break;
		int tx[n], ty[n];
		REP(i, n) cin >> tx[i] >> ty[i];
		int m;
		cin >> m;
		int sx[m], sy[m];
		REP(i, m) cin >> sx[i] >> sy[i];
		ll search[m];
		REP(i, m) search[i] = 10000000LL*sx[i]+sy[i];
		sort(search, search+m);
		int ax = -1, ay = -1;
		REP(i, m){
			int dx = sx[i]-tx[0], dy = sy[i]-ty[0];
			bool c = true;
			REP(j, n){
				int nx = tx[j] + dx, ny = ty[j] + dy;
				ll key = 10000000LL*nx+ny;
				if(!binary_search(search, search+m, key)){
					c = false;
				}
			}
			if(c){
				ax = dx; ay = dy;
			}
		}
		cout << ax << " " << ay << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3024
final_rank: 2

code_snippet: #include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main (){
    int m;
    while(cin>>m&&m){
        map<pair<int,int>,bool> mp; //pairの座標に点があるかどうか
        vector<pair<int,int>> a(m); //星座の構成点の座標
        rep(i,0,m)cin>>a[i].fi>>a[i].se;
        int n; cin>>n;
        vector<pair<int,int>> b(n); //フィールドに存在する全ての点の座標
        rep(i,0,n){
            cin>>b[i].fi>>b[i].se;
            mp[pair<int,int>(b[i].fi,b[i].se)]=true;
        }

        rep(i,0,n){
            //存在する全ての点を全探索し、まずは星座を構成する一つの点に対する移動距離をdに保存。
            pair<int,int> d=make_pair(b[i].fi-a[0].fi,b[i].se-a[0].se);
            bool ok=true;
            rep(j,0,m){ //星座の構成要素を全探索し、移動量dを加えた先に点が存在するかどうかを確認。１つでも無ければok=false
                pair<int,int> p=make_pair(a[j].fi+d.fi,a[j].se+d.se);
                if(!mp[p])ok=false;
            }
            //okがtrueのまま降りてこれば、dを出力して終了
            if(ok){
                cout<<d.fi<<" "<<d.se<<endl;
                break;
            }
        }
    }

    
}


/*
5
8 5
6 4
4 3
7 10
0 10
10
10 5
2 7
9 7
8 10
10 2
1 2
8 1
6 7
6 0
0 9
5
904207 809784
845370 244806
499091 59863
638406 182509
435076 362268
10
757559 866424
114810 239537
519926 989458
461089 424480
674361 448440
81851 150384
459107 795405
299682 6700
254125 362183
50795 541942
0
*/
accuracy: 1
time_ms: 50
memory_kb: 10904
final_rank: 15

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int cl(int a, int b) {
	return (a - (a%b)) / b;//b=0だと積む
}
int up(int a, int b) {
	return cl(a + b - 1, b);//b=0だと積む
}
int ord(int a, int p) {
	if (a%p == 0) {
		return ord(a / p, p) + 1;
	}
	else {
		return 0;
	}
}
int main() {
    int soo=1;
    while(soo==1){
    int n, m; int ans = 0;
	cin >> m;
	if(m==0){
	    soo=0;
	}
	else{
	 vector<int> sex(m);
	vector<int> sey(m);
	for (int i = 0; i < m; i++) {
		cin >> sex[i] >> sey[i];
	}
	cin >> n;
	vector<int> hox(n);
	vector<int> hoy(n);
	for(int i = 0; i < n; i++) {
		cin >> hox[i] >> hoy[i];
	}
	int das1 = 1;
	for (int i = 0; i < n and das1==1; i++) {
		int x = hox[i] - sex[0];//iは0に合わせるもの
		int y = hoy[i] - sey[0];
		int ok = 1;
		int das2=1;
		for (int j = 0; j < m and das2==1; j++) {
			int sx = sex[j] + x;
			int sy = sey[j] + y;
			int das3 = 0;
			for (int k = 0; k < n and das3 == 0; k++) {
				if (sx == hox[k] and sy == hoy[k]) {
					das3 = 1;
				}
			}
			if (das3 == 0) {
				das2 = 0;
			}

		}
		if (das2 == 1) {
			das1 = 0;
			cout << x << " " << y<<endl;
		}   
    }   
	}
	}
}
accuracy: 1
time_ms: 10
memory_kb: 3112
final_rank: 7

code_snippet: #include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>
#include <set>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int m;
    while (cin >> m, m){
        vector<pair<int, int>> v, v2;
        for (int i = 0; i < m; ++i) {
            int a, b;
            cin >> a >> b;
            v.emplace_back(a, b);
        }
        int n;
        cin >> n;
        set<pair<int, int>> s;
        for (int i = 0; i < n; ++i) {
            int a, b;
            cin >> a >> b;
            s.emplace(a, b);
            v2.emplace_back(a, b);
        }
        for (int i = 0; i < n; ++i) {
            int pp = v2[i].first-v[0].first, qq = v2[i].second-v[0].second;
            int valid = 1;
            for (int j = 0; j < m; ++j) {
                if(!s.count(make_pair(v[j].first+pp, v[j].second+qq))) valid = 0;
            }
            if(valid) {
                cout << pp << " " << qq << "\n";
            }
        }
    } 
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3112
final_rank: 7