Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		scanner.Scan()
		input := strings.Split(scanner.Text(), " ")
		s, _ := strconv.Atoi(input[0])
		e, _ := strconv.Atoi(input[1])
		a := make([]int, 0)
		if s <= 5 {
			if s > e {
				for j := s; j > e-1; j-- {
					a = append(a, j)
				}
			} else {
				for j := s; j < e+1; j++ {
					a = append(a, j)
				}
			}
		} else if s < e {
			for j := s; j < 10; j++ {
				a = append(a, j)
			}
		} else {
			for j := s; j < 10; j++ {
				a = append(a, j)
			}
			if e <= 5 {
				for j := 5; j > e-1; j-- {
					a = append(a, j)
				}
			} else {
				for j := 5; j > 0; j-- {
					a = append(a, j)
				}
				for j := 0; j < e+1; j++ {
					a = append(a, j)
				}
			}
		}
		for i, v := range a {
			if i != len(a)-1 {
				fmt.Printf("%d ", v)
			} else {
				fmt.Println(v)
			}
		}
	}
}

C++: #include <iostream>
#include <deque>
#include <set>

using namespace std;

bool data[10][10];

void init()
{
	for( int i = 0;i < 10;i++ ){
		for( int j = 0;j < 10;j++ ){
			data[i][j] = false;
		}
	}

	data[0][1] = true;
	data[1][0] = true;
	data[1][2] = true;
	data[2][1] = true;
	data[2][3] = true;
	data[3][2] = true;
	data[3][4] = true;
	data[4][3] = true;
	data[4][5] = true;
	data[5][4] = true;
	data[5][6] = true;
	data[6][7] = true;
	data[7][8] = true;
	data[8][9] = true;
	data[9][5] = true;
}

bool serch( int start, int end, deque<int> &answer, set<int> &history )
{
	if( end == start ) return true;

	for( int i = 0;i < 10;i++ ){
		if( data[start][i] ){
			if( history.count( i ) ) continue;
			history.insert( i );
			answer.push_back( i );
			bool a = serch( i, end, answer, history );
			if( a == true ) return true;
		}
	}
	answer.clear();
	return false;
}


int main(int argc, char const* argv[])
{
	int n;
	int start,end;

	deque<int> answer;
	set<int> history;
	cin >> n;

	init();
	for( int i = 0;i < n;i++ ){
		answer.clear();
		history.clear();
		cin >> start >> end;

		history.insert( start );
		serch( start, end, answer, history );

		cout << start;
		for( deque<int>::iterator it = answer.begin();it != answer.end();it++ ) cout << " " << *it;
		cout << endl;
	}

	return 0;
}

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

int from,to;
int line[1000];
int ad;

void solve()
{
	int a = 0,b = 0;

	
	cout << from-15+ad;
	for(int i = from; line[i] != to-15; i++,a++);
	for(int i = from; line[i] != to-15; i--,b++);
	
	if(a < b){
		for(int i = from+1; line[i] != to-15; i++)
			cout << ' ' << line[i];
	}
	else{
		for(int i = from-1; line[i] != to-15; i--)
			cout << ' ' << line[i];
	}
	cout << ' ' << to-15 << endl;

}


int main(void)
{

	int c = 0;
	for(int i = 0; i < 10; i++){
		for(int j = 0; j <= 9; j++,c++){
			line[c] = j;
		}
		for(int j = 5; j > 0; j--,c++){
			line[c] = j;
		}
	}
//	for(int i = 0; i < 30; i++)
//		cout << line[i] << endl;

	while(cin >> from >> to, !cin.eof()){
		ad = 0;
		if(from == 1){
			from += 13;
			ad = 2;
		}
		else
			from += 15;
		to += 15;
		solve();
	}


	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	int n,a,b;
	string str="54321012345678";
	cin>>n;
	rep(x,0,n){
		string ans="";
		cin>>a>>b;
		if(a<b){
			rep(i,a,b+1){
				if(ans!="") ans+=" ";
				ans=ans+(char)('0'+i);
			}
		}else if(a<=5){
			repb(i,a,b){
				if(ans!="") ans+=" ";
				ans=ans+(char)('0'+i);
			}
		}else{
			rep(i,a,10){
				if(ans!="") ans+=" ";
				ans=ans+(char)('0'+i);
			}
			rep(i,0,str.size()){
				if(ans!="") ans+=" ";
				ans=ans+str[i];
				if(str[i]==('0'+b)) break;
			}
		}
		cout<<ans<<endl;
	}
}

C++: #include <cstdio>
#include <cstring>
char* bus="0123456789543210123456789";
char s[25], t[25];
int main()
{
    int n; scanf("%d", &n);
    while (n--) {
        int a, b; scanf("%d%d", &a, &b);
        int k = 0;
        for (int i = 0; i < 15; ++i)
            if (bus[i] == a + '0') k = i;
        int j = 0;
        for (int i = k; i < strlen(bus); ++i) {
            s[j++] = bus[i];
            s[j++] = ' ';
            if (bus[i] == b + '0') break;
        }
        if (s[j-2] != b + '0') for (j = 0; j < 25; ++j) s[j] = 'x';
        s[j-1] = '\0';

        k = 0;
        for (int i = 0; i < 15; ++i)
            if (bus[i] == a + '0') { k = i; break; }
        j = 0;
        for (int i = k; i < strlen(bus); ++i) {
            t[j++] = bus[i];
            t[j++] = ' ';
            if (bus[i] == b + '0') break;
        }
        if (t[j-2] != b + '0') for (j = 0; j < 25; ++j) t[j] = 'x';
        t[j-1] = '\0';
        puts(strlen(s) < strlen(t) ? s : t);
    }
    return 0;
}

C++: #include <iostream>
#include <vector>

using namespace std;


int main(int argc, char const* argv[])
{
	int n;
	int start,end;
	vector<int> answer;

	cin >> n;

	for( int i = 0;i < n;i++ ){
		cin >> start >> end;
		answer.clear();

		if( start < end ){
			for( int j = start;j <= end;j++ ) answer.push_back( j );
		} else {
			if( start <= 5 ){
				for( int j = start;j >= end;j-- ) answer.push_back( j );
			} else if( end > 5 ) {
				for( int j = start;j < 10;j++ ) answer.push_back( j );
				for( int j = 5;j >= 0;j-- ) answer.push_back( j );
				for( int j = 1;j <= end;j++ ) answer.push_back( j );
			} else {
				for( int j = start;j < 10;j++ ) answer.push_back( j );
				for( int j = 5;j >= end;j-- ) answer.push_back( j );
			}
		}

		for( unsigned int i = 0;i < answer.size();i++ ) cout << ( ( i == 0 ) ? "" : " " ) << answer[i];
		cout << endl;
	}


	return 0;
}

C++: #include <iostream>
using namespace std;

char stop[] ="0123456789543210123456789";

void solve(int start,int goal) {
  int ans = 10000;int pos = 0;
  for(int i=0;i<25;i++) {
    if(stop[i] != start + '0') continue;
    //stop[i] == goal
    for(int j=i+1;j<25;j++) {
      if(stop[j] == goal + '0') {
        ans = min(ans,j-i);pos = i;
        continue;
      }
    }
  }
  for(int i = pos;i<=pos + ans;i++) {
    cout << ( i==pos ? "":" ") << stop[i];
  }
  cout << endl;
}

int main() {
  int n,f,t;
  cin >> n;
  for(int i=0;i<n;i++) {
    cin >> f >> t;
    solve(f,t);
  }
}

C++: #include <iostream>
using namespace std;

char stop[] ="0123456789543210";

void solve(int start,int goal) {
  int ans = 10000;int pos = 0;
  for(int i=0;i<16;i++) {
    if(stop[i] != start + '0') continue;
    //stop[i] == goal
    for(int j=i+1;j<16;j++) {
      if(stop[j] == goal + '0') {
        ans = min(ans,j-i);pos = i;
        continue;
      }
    }
  }
  for(int i = pos;i<=pos + ans;i++) {
    cout << ( i==pos ? "":" ") << stop[i];
  }
  cout << endl;
}

int main() {
  int n,f,t;
  cin >> n;
  for(int i=0;i<n;i++) {
    cin >> f >> t;
    solve(f,t);
  }
}