Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

// 文字列を1行取得
func StrStdin() (stringReturned string) {
//	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	stringInput := scanner.Text()

	stringReturned = strings.TrimSpace(stringInput)
	return
}

// 整数値1つ取得
func IntStdin() (int, error) {
	stringInput := StrStdin()
	return strconv.Atoi(strings.TrimSpace(stringInput))
}

// 空白や空文字だけの値を除去したSplit()
func SplitWithoutEmpty(stringTargeted string, delim string) (stringReturned []string) {
	stringSplited := strings.Split(stringTargeted, delim)

	for _, str := range stringSplited {
		if str != "" {
			stringReturned = append(stringReturned, str)
		}
	}

	return
}

// デリミタで分割して文字列スライスを取得
func SplitStrStdin(delim string) (stringReturned []string) {
	// 文字列で1行取得
	stringInput := StrStdin()

	// 空白で分割
	// stringSplited := strings.Split(stringInput, delim)
	stringReturned = SplitWithoutEmpty(stringInput, delim)

	return
}

// デリミタで分割して整数値スライスを取得
func SplitIntStdin(delim string) (intSlices []int, err error) {
	// 文字列スライスを取得
	stringSplited := SplitStrStdin(" ")

	// 整数スライスに保存
	for i := range stringSplited {
		var iparam int
		iparam, err = strconv.Atoi(stringSplited[i])
		if err != nil {
			return
		}
		intSlices = append(intSlices, iparam)
	}
	return
}

func main() {
	nk, _ := SplitIntStdin(" ")
	n, k := nk[0], nk[1]
	kind := make([]int, n)
	for i := 0; i < k; i++ {
		var tmp []int
		var err error
		if tmp, err = SplitIntStdin(" "); err != nil {
			panic(err)
		}
		kind[tmp[0]-1] = tmp[1]
	}
	dp := make([][3][3]int, n)
	if kind[0] > 0 {
		dp[0][0][kind[0]-1] = 1
	} else {
		for i := 0; i < 3; i++ {
			dp[0][0][i] = 1
		}
	}
	if kind[1] > 0 {
		for i := 0; i < 3; i++ {
			dp[1][i][kind[1]-1] = dp[0][0][i]
		}
	} else {
		for i := 0; i < 3; i++ {
			for j := 0; j < 3; j++ {
				dp[1][i][j] = dp[0][0][i]
			}
		}
	}
	for i := 1; i < n-1; i++ {
		if kind[i+1] > 0 {
			for j := 0; j < 3; j++ {
				if j == kind[i+1]-1 {
					for k := 0; k < 3; k++ {
						if j != k {
							dp[i+1][j][kind[i+1]-1] += dp[i][k][j]
							dp[i+1][j][kind[i+1]-1] %= 10000
						}
					}
				} else {
					for k := 0; k < 3; k++ {
						dp[i+1][j][kind[i+1]-1] += dp[i][k][j]
						dp[i+1][j][kind[i+1]-1] %= 10000
					}
				}
			}
		} else {
			for j := 0; j < 3; j++ {
				for k := 0; k < 3; k++ {
					for l := 0; l < 3; l++ {
						if j != k || k != l {
							dp[i+1][k][j] += dp[i][l][k]
							dp[i+1][k][j] %= 10000
						}
					}
				}
			}
		}
	}
	result := 0
	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			result += dp[n-1][i][j]
		}
	}
	// fmt.Println(dp)
	// fmt.Println(kind)
	fmt.Println(result % 10000)
}

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

int main(){
	int n,m,d[100],t[100],type[4][4],c[4][3];
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>d[i]>>t[i];
	}
	for(int i=0;i<m;i++){
		if(d[i]==1){
			type[1][i]=1;
			goto Exit1;
		}
	}
	type[1][1]=1;
	type[2][1]=1;
	type[3][1]=1;
	
Exit1:
	for(int i=1;i<=3;i++){
		if(type[i][1]!=1){
			type[i][1]=0;
		}
	}
	type[1][2]=0;
	type[2][2]=0;
	type[3][2]=0;
	for(int i=2;i<=n;i++){
		for(int j=0;j<m;j++){

			if(d[j]==i){
				type[t[j]][2]=type[t[j]][1];
				type[t[j]][1]=0;
				for(int k=1;k<=3;k++){
					if(t[j]!=k){
						for(int l=1;l<=2;l++){
						type[t[j]][1] += type[k][l];
						type[k][l]=0;
						}
					}
				}
				goto Exit2;
			}

		}
		memset(c,0,sizeof(c));
		for(int k=1;k<=3;k++){
			for(int l=1;l<=3;l++){
				if(k==l){
					c[l][2] += type[k][1];
				}
				else{
					c[l][1] += type[k][1]+type[k][2];
				}
			}
		}
		for(int k=1;k<=3;k++){
			type[k][1]=c[k][1];
			type[k][2]=c[k][2];
		}
Exit2:
		for(int j=1;j<=3;j++){
			for(int k=1;k<=2;k++){
				type[j][k]=type[j][k]%10000;
			}
		}
	}
	cout<<(type[1][1]+type[1][2]+type[2][1]+type[2][2]+type[3][1]+type[3][2])%10000<<endl;
	return 0;
}

C++: // 2014/12/10 Tazoe

#include <iostream>
using namespace std;

int main()
{
	int N, K;
	cin >> N >> K;

	int DP[100][3];
	for(int i=0; i<100; i++){
		for(int j=0; j<3; j++){
			DP[i][j] = 0;
		}
	}

	for(int i=0; i<K; i++){
		int A, B;
		cin >> A >> B;

		if(B==1){
			DP[A-1][1] = DP[A-1][2] = -1;
		}
		else if(B==2){
			DP[A-1][0] = DP[A-1][2] = -1;
		}
		else{
			DP[A-1][0] = DP[A-1][1] = -1;
		}
	}

	for(int j=0; j<3; j++){
		if(DP[0][j]==-1)
			continue;

		DP[0][j] = 1;
	}

	int sum0 = 0;
	for(int j=0; j<3; j++){
		if(DP[0][j]==-1)
			continue;

		sum0 += DP[0][j];
	}

	for(int j=0; j<3; j++){
		if(DP[1][j]==-1)
			continue;

		DP[1][j] = sum0;
	}

	for(int i=2; i<N; i++){
		int sum = 0;
		for(int j=0; j<3; j++){
			if(DP[i-1][j]==-1)
				continue;

			sum += DP[i-1][j];
		}

		for(int j=0; j<3; j++){
			if(DP[i][j]==-1)
				continue;

			DP[i][j] = sum;

			if(DP[i-1][j]!=-1 && DP[i-2][j]!=-1){
				for(int k=0; k<3; k++){
					if(j==k){
						DP[i][j] += 10000;
						DP[i][j] -= DP[i-1][k];
					}
					else{
						if(DP[i-2][k]!=-1){
							DP[i][j] += DP[i-2][k];
						}
					}
				}
			}

			DP[i][j] %= 10000;
		}
	}

//	for(int i=0; i<N; i++){
//		for(int j=0; j<3; j++){
//			cout << DP[i][j] << ' ';
//		}
//		cout << endl;
//	}

	int sum1 = 0;
	for(int j=0; j<3; j++){
		if(DP[N-1][j]==-1)
			continue;

		sum1 += DP[N-1][j];
	}

	cout << sum1%10000 << endl;

	return 0;
}

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;



int main(void){
	int dp[102][5][5],f[102];
	int n,k;
	int a,b,c;
	int x,y;
	for(a=0;a<102;a++){
		f[a]=0;
		for(b=0;b<5;b++){
			for(c=0;c<5;c++){
				dp[a][b][c]=0;
			}
		}
	}
	cin >> n >> k;
	for(a=0;a<k;a++){
		cin >> x >> y;
		f[x]=y;
	}
	if(f[1]!=0)dp[1][f[1]][1]=1;
	else dp[1][1][1]=dp[1][2][1]=dp[1][3][1]=1; 
	for(a=2;a<=n;a++){
		if(f[a]==0){
			dp[a][1][1]=(dp[a-1][2][1]+dp[a-1][2][2]+dp[a-1][3][1]+dp[a-1][3][2])%10000;
			dp[a][1][2]=dp[a-1][1][1]%10000;

			dp[a][2][1]=(dp[a-1][1][1]+dp[a-1][1][2]+dp[a-1][3][1]+dp[a-1][3][2])%10000;
			dp[a][2][2]=dp[a-1][2][1]%10000;

			dp[a][3][1]=(dp[a-1][1][1]+dp[a-1][1][2]+dp[a-1][2][1]+dp[a-1][2][2])%10000;
			dp[a][3][2]=dp[a-1][3][1]%10000;
		}else{
			dp[a][f[a]][2]=dp[a-1][f[a]][1]%10000;
			for(b=1;b<=3;b++){
				if(b!=f[a])dp[a][f[a]][1]+=(dp[a-1][b][1]+dp[a-1][b][2])%10000;

			}
		}
	}
	printf("%d\n",(dp[n][1][1]+dp[n][1][2]+dp[n][2][1]+dp[n][2][2]+dp[n][3][1]+dp[n][3][2])%10000);
	return 0;
}