Go: package main

import (
	"bufio"
	"os"
		"strconv"
	"fmt"
	)

var scanner= bufio.NewScanner(os.Stdin)

func main() {
	MAX := 10001
	SQRT := 100
	isPrime := make([]bool, MAX)
	for i :=range isPrime {
		isPrime[i] = true
	}
	for i := 3; i < SQRT; i += 2 {
		if isPrime[i] {
			for j := i*i; j < MAX; j += i {
				isPrime[j] = false
			}
		}
	}
	// log.Println(isPrime)
	tbl := make([]int, MAX)
	ans := 0
	for i := 5; i < MAX; i += 2 {
		if isPrime[i] && isPrime[i-2] {
			ans = i
		}
		tbl[i] = ans
	}
	// log.Println(tbl)
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		if n&1 == 0 {
			n--
		}
		fmt.Printf("%d %d\n", tbl[n]-2, tbl[n])
	}
}

C++: #include <iostream>
#include <utility>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in(gcu());}
_sc(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
//_sc(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
template <typename H,typename... T> _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
template <typename T>
_vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
//_vo(string &s){for (char c: s) pcu(c);}
template <typename H,typename... T> _vo(H&& h, T&&... t){out(h);out(move(t)...);}
//template <typename T> _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
_vl(){out('\n');}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

template<int N>
struct sieve {
	bool s[N];
	constexpr sieve() : s() {
		for (int i = 0; i < N; i++)
			s[i] = true;
		for (int i = 4; i < N; i += 2)
			s[i] = false;
		for (int i = 9; i < N; i += 6)
			s[i] = false;
		for (int i = 6, e = sqrt(N); i <= e; i += 6) {
			for (int j : {i - 1, i + 1})
				if (s[j])
					for (int k = j * j; k < N; k += j)
						s[k] = false;
		}
	}
};

template<int N>
struct twin {
	int t[N/10], l;
	constexpr twin() : t(), l(1) {
		sieve<N> s;
		t[0] = 5;
		for (int i = 0; i < N; i++)
			if (s.s[i - 2] && s.s[i])
				t[l++] = i;
	}
};

int main() {
	enum {N = 10001};
	twin<N> t;
	for (int n; (n = in());) {
		auto r = upper_bound(t.t, t.t + t.l, n) - 1;
		outl(*r - 2, ' ', *r);
	}
}

C++: #include <iostream>
#include <cstdio>
int prime[10001];

int main(){
	prime[0] = prime[1] = 0;
	for(int i=2;i<=10000;++i){
		if(prime[i]==0){
			prime[i]=1;
			for(int j=i*2;j<=10000;j+=i){
				prime[j]=2;
			}
		}else{
			continue;
		}
	}
	int n;
	while(scanf("%d", &n), n){
		for(int i = n; i >= 2; --i){
			if(prime[i]==1 && prime[i-2]==1){
				printf("%d %d\n",i-2, i);
				break;
			}
		}
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    bool prime[10001];
    memset(prime,0,sizeof(prime));
    for(int i=2;i<sqrt(10001);i++){
        if(!prime[i])for(int j=i*2;j<10001;j+=i)prime[j]=1;
    }
    int num[210],co=0;
    for(int i=3;i<10001;i++){
        if(!prime[i]&&!prime[i+2]){
            num[co]=i;
            co++;
        }
    }
    int n;
    while(cin>>n,n){
        for(int i=0;i<co;i++){
            if(num[i]>=n&&num[i-1]+2<=n){
                cout<<num[i-1]<<" "<<num[i-1]+2<<endl;
                break;
            }
            else if(num[i]>n){
                cout<<num[i-2]<<" "<<num[i-2]+2<<endl;
                break;
            }
        }
    }
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	vi is_prime(10001,true);
	is_prime[0]=is_prime[1]=false;
	repi(i,2,is_prime.size()){
		if(is_prime[i])
			for(int j=i+i;j<is_prime.size();j+=i)
				is_prime[j]=false;
	}
	vi primes;
	rep(i,is_prime.size())
		if(is_prime[i])
			primes.push_back(i);
	for(int n;cin>>n,n;){
		int i=primes.size()-1;
		while(n<primes[i] || primes[i]-primes[i-1]!=2)
			i--;
		cout<<primes[i-1]<<" "<<primes[i]<<endl;
	}
	
	return 0;
}

C++: #include<iostream>
#include<list>
#include<set>
#include<cmath>

int main()
{
    //accept input
    std::list<int> inputs;
    int input_max = 5, n;
    while( true ){
        std::cin >> n;
        if( n == 0 ) break;
        if( n > input_max ) input_max = n;
        inputs.push_back(n);
    }

    //find prime numbers( <= input_max )
    std::list<int> primes;
    primes.push_back(3);
    std::list<int>::iterator itr;
    int sqrt_i;
    for( int i = 5; i <= input_max; i += 2 ) {
        sqrt_i = (int)std::sqrt(i);
        for( itr = primes.begin(); itr != primes.end(); itr++ ){
            if( i % *itr == 0 ) break;
            else if( *itr > sqrt_i ){
                primes.push_back(i);
                break;
            }
        }
    }

    //prime numbers -> twin prime set
    std::set<int> twin_prime_st;
    int prev = 2;
    for( itr = primes.begin(); itr != primes.end(); itr++ ){
        if( *itr == prev + 2 ) twin_prime_st.insert(*itr);
        prev = *itr;
    }

    //find each max twin price
    std::set<int>::iterator st_itr;
    for( itr = inputs.begin(); itr != inputs.end(); itr++ ){
        st_itr = twin_prime_st.upper_bound(*itr);
        st_itr--;
        std::cout << *st_itr - 2 << " " << *st_itr << std::endl;
    }

    return 0;

}