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 <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector <int> p(n, -1);
    rep (i, k) {
        int a, b;
        cin >> a >> b;
        p[--a] = --b;
    }
    vector <vector <vector <int>>> dp(n, vector <vector <int>> (3, vector <int> (3, 0)));
    rep (i, 3) rep (j, 3) {
        dp[0][p[0] == -1 ? i : p[0]][p[1] == -1 ? j : p[1]] = 1;
    }

    range (i, 1, n) {
        if (p[i + 1] != -1) {
            rep (j, 3) rep (k, 3) if (p[i + 1] != j || j != k) {
                (dp[i][j][p[i + 1]] += dp[i - 1][k][j]) %= 10000;
            }
        }
        else {
            rep (j, 3) rep (k, 3) rep (l, 3) if (j != k || k != l) {
                (dp[i][j][k] += dp[i - 1][l][j]) %= 10000;
            }
        }
    }

    int cnt = 0;
    rep (i, 3) rep (j, 3) (cnt += dp[n - 2][i][j]) %= 10000;
    cout << cnt << endl;

    return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
#define mod 10000
int set[101],dp[101][4][4],n,k;
int solve(int today,int mae,int maemae){ //今日の日付,昨日の服,一昨日の服
  if( today == n ) return 1;
  if( dp[today][mae][maemae] ) return dp[today][mae][maemae];
  if( set[today] ){
    if( mae == maemae && mae == set[today]) return 0;
    else return solve(today+1,set[today],mae) % mod;
  }
  int rec = 0;
  for(int i = 1 ; i < 4 ; i++ ){
    if(mae == maemae && mae == i) continue;
    rec += solve(today+1,i,mae) % mod;
  }
  return dp[today][mae][maemae] = rec % mod;
}
int main(){
  cin >> n >> k;
  for(int i = 0 ; i < k ; i++ ){
    int a,b;
    cin >> a >> b;
    set[--a] = b;
  }
  cout << solve( 0, 0, 0) << endl;
}

C++: #include<iostream>

using namespace std;

int n,m;
const int mod=10000;
int yotei[101];
int dp[101][3][3]={};	

int pasta(int day,int tdby,int y){//日日　おととい　昨日
	if(dp[day][tdby][y]!=0)return dp[day][tdby][y];
	if(day==n+1)return 1;
	if(yotei[day]!=-1){
		if(tdby==y&&y==yotei[day]){
			return 0;
		}else {
			return dp[day][tdby][y]=pasta(day+1,y,yotei[day])%mod;
		}
	}else {
		int ans=0;
		for(int k=1;k<=3;k++){
			if(tdby!=k||y!=k){
				ans+=pasta(day+1,y,k)%mod;
			}
		}
		return dp[day][tdby][y]=ans%mod;
	}
}
//dayは１から　便宜上
int main(){
	memset(yotei,-1,sizeof(yotei));
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int a;
		cin>>a;
		cin>>yotei[a];
	}
	cout<<pasta(1,0,0)<<endl;
	return 0;
}

C++: // 2013/11/09 Tazoe

#include <iostream>
using namespace std;

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

	int DP[100][3];
	for(int i=0; i<N; 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 if(B==3){
			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;
	}

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

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

			s += DP[0][k];
		}

		DP[1][j] = s;
	}

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

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

				s += DP[i-1][k];
			}

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

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

					if(j==k)
						continue;

					t += DP[i-2][k];
				}

				DP[i][j] = (DP[i][j]-(DP[i-1][j]-t+20000)+30000)%10000;
			}
		}
	}
/*
	for(int i=0; i<N; i++){
		for(int j=0; j<3; j++){
			cout << DP[i][j] << ' ';
		}
		cout << endl;
	}
*/
	cout << (DP[N-1][0]+DP[N-1][1]+DP[N-1][2])%10000 << endl;

	return 0;
}

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

int dp[200][5][5];

int main()
{
  int n,k,a,b[108]={},ans=0;
  cin>>n>>k;
  for(int i=1;i<=k;i++){
    cin>>a;
    cin>>b[a];
  }
  if(b[1]==0){
    for(int j=1;j<=3;j++){
      dp[2][j][0]=1;
    }
  }else {
    dp[2][b[1]][0]=1;
  }
  for(int i=3;i<=n+1;i++){                 //?????\?????\??°
    for(int j=0;j<=3;j++){              //?????\???????????????????¨????
      for(int k=0;k<=3;k++){            //?????\???????????????????¨????
        if(dp[i-1][j][k]!=0){           //??¨??\????????????????£??????????
          if(b[i-1]!=0){                  //?????\????????????????±??????£????????????
            if(!(j==k && b[i-1]==j)){     //?????\??£?¶????????????????
              dp[i][b[i-1]][j]+=dp[i-1][j][k];
              dp[i][b[i-1]][j]%=10000;
            }
          }else{                        //?????\????????????????±??????£???????????´???
            for(int l=1;l<=3;l++){
              if(!(j==k && l==j)){      //?????\??£?¶????????????????
                dp[i][l][j]+=dp[i-1][j][k];
                dp[i][l][j]%=10000;
              }
            }
          }
        }
      }
    }
  }
  for(int i=1;i<=3;i++){
    for(int j=1;j<=3;j++){
      ans+=dp[n+1][i][j];
      ans%=10000;
    }
  }
  ans%=10000;
  cout<<ans<<endl;
  return 0;
}