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<cstdio>
#include<cstring>
using namespace std;

int main(){
	int N,K,A,B[102];
	int dp[102][7]={},ans=0;
	memset(B,-1,sizeof(B));
	cin>>N>>K;
	for(int i=0;i<K;i++){
		cin>>A;
		cin>>B[A];
	}

	dp[0][0]=1;
	for(int i=0;;i++){
		for(int j=0;j<=6;j++){
			dp[i][j]%=10000;
			//printf("%d ",dp[i][j]);
			if(B[i]!=-1 && (j!=B[i] && j!=B[i]+3)){
				dp[i][j]=0;
				continue;
			}
			for(int k=1;k<=3;k++){
				if(j-3==k) continue;
				else if(j==k) dp[i+1][j+3] += dp[i][j]%10000;
				else dp[i+1][k] += dp[i][j]%10000;
			}
		}//puts("");
		if(i==N) break;
	}
	for(int i=0;i<=6;i++){
		//printf("%d ",dp[N][i]);
		ans += dp[N][i]%10000;
	}//puts("");
	printf("%d\n",ans%10000);
	return 0;
}

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

#define N 107
#define MOD 10000

#define rep(i, n) for(int i=0; i<n; ++i)
#define repl(i, j, n) for(int i=j; i<n; ++i)

int main() {
	int dp[N][3][2], spe[N], n, k;
	cin >> n >> k;
	rep(i, n+1) {
		spe[i] = -1;
		rep(j, 3) rep(k, 2) dp[i][j][k] = 0;
	}
	rep(i, k) {
		int a, b;
		cin >> a >> b;
		spe[a-1] = b-1;
	}
	if(spe[0]==-1) rep(i, 3) dp[0][i][0] = 1;
	else dp[0][spe[0]][0] = 1;
	rep(i, n-1) {
		if(spe[i+1]==-1) {
			rep(j, 3) {
				rep(k, 3) {
					if(j==k) {
						dp[i+1][j][1] = (dp[i+1][j][1] + dp[i][j][0])%MOD;
					}else {
						dp[i+1][j][0] = (dp[i+1][j][0] + dp[i][k][0] + dp[i][k][1])%MOD;
					}
				}
				//cout << i+1 << " " << j << " : " << dp[i+1][j][0] << " " << dp[i+1][j][1] << endl;
			}
		}else {
			int s = spe[i+1];
			rep(j, 3) {
				if(s==j) {
					dp[i+1][s][1] = (dp[i+1][s][1] + dp[i][s][0])%MOD; 
				}else {
					dp[i+1][s][0] = (dp[i+1][s][0] + dp[i][j][0] + dp[i][j][1])%MOD;
				}
			}
			//cout << i+1 << " " << s << " : " << dp[i+1][s][0] << " " << dp[i+1][s][1] << endl;
		}
	}
	int sum = 0;
	rep(i, 3) sum += dp[n-1][i][0] + dp[n-1][i][1];
	cout << sum%MOD << endl;
	return 0;
}

C++: #include<iostream>
//#include<windows.h>
//#include<errno.h>

#define Iset int i,j,l
#define man 10000
#define cn continue

int pas[101], dt[101][4][4];

using namespace std;

int main() {
	int n, k;
	Iset;
	int ans = 0;
	//scanf("%d%d", &n, &k);
	cin >> n >> k;
	for (i = 0; i < k; i++) {
		int a, b;
	//	scanf("%d%d", &a, &b);
		cin >> a >> b;
		pas[a] = b;
	}
	dt[0][0][0] = 1;
	for (i = 1; i <= n; i++) {
		if (pas[i] == 0) {
			for (j = 1; j <= 3; j++) {
				for (k = 0; k <= 3; k++) {
					for (l = 0; l <= 3; l++) {
						if (j == k && l == k) cn;
						dt[i][j][k] += dt[i - 1][k][l];
						dt[i][j][k] %= man;
					}
				}
			}
		}
		else {
			for (k = 0; k <= 3; k++) {
				for (l = 0; l <= 3; l++) {
					if (pas[i] == k && l == k)cn;
					dt[i][pas[i]][k] += dt[i - 1][k][l];
					dt[i][pas[i]][k] %= man;
				}
			}
		}
	}
	for (i = 1; i <= 3; i++) {
		for (j = 1; j <= 3; j++) {
			ans += dt[n][i][j];
			ans %= man;
		}
	}
	//printf("%d\n", ans);
	cout << ans << endl;
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  int d[101]={};
  int i,j,l,m;
  int a,b;
  for(i=0;i<n;i++){
    cin >> a >> b;
    d[a-1]=b;
  }
  int dp[101][4][4]={{{}}};
  if(d[0]!=0){
    dp[0][0][d[0]]=1;
  }else{
    dp[0][0][1]=1;
    dp[0][0][2]=1;
    dp[0][0][3]=1;
  }
  for(i=1;i<n;i++){
    for(j=0;j<4;j++){
      for(l=1;l<4;l++){
        if(d[i]!=0){
          if(!(j==l&&l==d[i]))
          dp[i][l][d[i]]+=dp[i-1][j][l]%10000;
        }else{
          for(m=1;m<4;m++){
            if(j==l&&l==m) continue;
             
            dp[i][l][m]+=dp[i-1][j][l]%10000;
          }
        }
      }
    }
  }
  int o=0;
  for(j=0;j<4;j++){
    for(l=0;l<4;l++){
      o+=dp[n-1][j][l];
    }
  }
  cout << o%10000 << endl;
  return 0;
}

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

int N,K;
int schedule[100];
int dp[100][3][3];

int solve(int now, int kind, int t){ //now日目の予定を決める、前日はkindのパスタを食べていてt日連続
    if(t >= 3) return 0;
    if(now == N) return 1;
    if(dp[now][kind][t] != -1) return dp[now][kind][t];
    if(schedule[now] != -1){
        //予定が決まっている場合
        if(schedule[now] == kind) dp[now][kind][t] = solve(now+1,kind,t+1);
        else dp[now][kind][t] = solve(now+1,schedule[now],1);
    }
    else{
        //予定が決まっていない場合
        dp[now][kind][t] = solve(now+1,kind,t+1) + solve(now+1,(kind+1)%3,1) + solve(now+1,(kind+2)%3,1);
    }
    dp[now][kind][t] %= 10000;

    return dp[now][kind][t];
}

int main(){
    cin >> N >> K;
    for(int i=0; i<N; i++){
        schedule[i] = -1;
        for(int j=0; j<3; j++){
            for(int k=0; k<3; k++){
                dp[i][j][k] = -1;
            }
        }
    }
    for(int i=0; i<K; i++){
        int tmp;
        cin >> tmp;
        cin >> schedule[tmp-1];
        schedule[tmp-1]--;
    }

    cout << solve(0,0,0) % 10000 << endl;
    return 0;
}