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

int d[100], n, k, dp[100][6];
// 0:aa, 1:bb, 2:cc, 3:a, 4:b, 5:c

int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  for (int i = 0; i < n; i++) d[i] = 0;
  for (int i = 0; i < k; i++) scanf("%d%d", &a, &b), d[a-1] = b;
  dp[0][0] = dp[0][1] = dp[0][2] = dp[0][3] = dp[0][4] = dp[0][5] = 0;
  if (d[0] == 0) dp[0][3] = dp[0][4] = dp[0][5] = 1;
  if (d[0] == 1) dp[0][3] = 1;
  if (d[0] == 2) dp[0][4] = 1;
  if (d[0] == 3) dp[0][5] = 1;
  for (int i = 1; i < n; i++) {
    dp[i][0] = dp[i-1][3];
    dp[i][1] = dp[i-1][4];
    dp[i][2] = dp[i-1][5];
    dp[i][3] = dp[i-1][1] + dp[i-1][2] + dp[i-1][4] + dp[i-1][5];
    dp[i][4] = dp[i-1][0] + dp[i-1][2] + dp[i-1][3] + dp[i-1][5];
    dp[i][5] = dp[i-1][0] + dp[i-1][1] + dp[i-1][3] + dp[i-1][4];
    for (int j = 0; j < 6; j++) dp[i][j] = dp[i][j] % 10000;
    if (d[i] == 0) continue;
    if (d[i] == 1) dp[i][1] = dp[i][2] = dp[i][4] = dp[i][5] = 0;
    if (d[i] == 2) dp[i][0] = dp[i][2] = dp[i][3] = dp[i][5] = 0;
    if (d[i] == 3) dp[i][0] = dp[i][1] = dp[i][3] = dp[i][4] = 0;
  }
  int ans = 0;
  for (int j = 0; j < 6; j++) ans += dp[n-1][j];
  printf("%d\n", ans % 10000);
}

C++: #include<iostream>
#define MOD 10000
using namespace std;
int main(){
    int n,k,P[100]={0};
    cin>>n>>k;
    for(int i=0;i<k;i++){
        int d,s;
        cin>>d>>s;
        P[d-1]=s;
    }
    int dp[100][3][2]={{{0}}};
    for(int i=0;i<3;i++)dp[0][i][0]=1;

    for(int i=0;i<n-1;i++){
        if(P[i])
            for(int j=0;j<3;j++)
                if(!(P[i]-1==j))dp[i][j][0]=dp[i][j][1]=0;

        for(int j=0;j<3;j++){
            for(int k=0;k<2;k++){
                int c;
                for(int l=0;l<3;l++){
                    if(j==l)c=k+1;
                    else c=0;
                    if(c==2)continue;
                    dp[i+1][l][c]+=dp[i][j][k];
                    dp[i+1][l][c]%=MOD;
                }
            }
        }

    }
    int sum=0;
    for(int i=0;i<3;i++){
        for(int j=0;j<2;j++){
            sum+=dp[n-1][i][j];
            sum%=MOD;
        }
    }
    cout<<sum<<endl;

}

C++: #include<bits/stdc++.h>
#define N 101
using namespace std;
int dp[N][4][4],n,k,d[N];

int solve(int x,int d1,int d2){
   if(x==0) return 1;
   if(dp[x][d1][d2]>0) return dp[x][d1][d2];
  if(d[x]>0){
    if(d1!=d[x] && d2!=d[x]) dp[x][d1][d2]=(dp[x][d1][d2]+solve(x-1,d[x],d1))%10000;
  }
  else {
    for(int i=1;i<4;i++){
      if(d1==i && d2==i)continue;
      else dp[x][d1][d2]=(dp[x][d1][d2]+solve(x-1,i,d1))%10000;
    }
  }
}

int main(){
  cin>>n>>k;
  int a,b;
  for(int i=0;i<n;i++)
    for(int j=0;j<4;j++)
      for(int k=0;k<4;k++)dp[i][j][k]=0;

  for(int i=0;i<k;i++)cin>>a>>b,d[a]=b;
  cout<<solve(n,0,0)<<endl;
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int const m = 10000;

int dp[100][4][4]={}; // i日目の、[当日パスタ]、[前日パスタ]の場合の数
int p[100]={},n,k;

int main(){
    cin.tie(0); ios::sync_with_stdio(false);

    cin>>n>>k;
    for (int i = 0; i < k; i++){
        int a,b; cin>>a>>b; p[--a]=b;
    }
    if(p[0])dp[0][p[0]][0]=1;
    else for (int i = 1; i < 4; i++)dp[0][i][0]=1;
    for (int i = 1; i < n; i++){
        for (int j = 0; j < 4; j++){
            for (int l = 0; l < 4; l++){
                if(p[i]){
                    if(p[i]!=j||j!=l)dp[i][p[i]][j]+=dp[i-1][j][l]%m;
                }else{
                    for (int o = 1; o < 4; o++){
                        if(o!=j||j!=l)dp[i][o][j]+=dp[i-1][j][l]%m;
                    }
                }
            }
        }
    }
    int ans=0;
    for (int i = 0; i < 4; i++){
        for (int j = 0; j < 4; j++)ans+=dp[n-1][i][j];
    }
    cout<<ans%m<<'\n';
}

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

int main(){
  int n,m;
  while(cin >> n >> m){
    vector<vector<int> > v(m,vector<int>(2));
    int dp[2][3][2], c = 0;
    for(int i=0;i<m;i++) cin >> v[i][0] >> v[i][1];
    sort(v.begin(),v.end());

    for(int i=0;i<3;i++){
      for(int j=0;j<2;j++){
	for(int k=0;k<2;k++){
	  dp[k][i][j] = 0;
	}
      }
      if(v[c][0] != 1 || v[c][0] == 1 && v[c][1] == i + 1) dp[0][i][0] = 1;
    }
    if(v[c][0] == 1) c++;
   
    for(int i=2;i<=n;i++){
      if(c < m && v[c][0] == i){
	for(int j=0;j<3;j++){
	  if(v[c][1]-1 != j){
	    for(int k=0;k<2;k++){
	      dp[1][v[c][1]-1][0] += dp[0][j][k];
	    }	    
	  }
	  else dp[1][j][1] += dp[0][j][0];
	}
	c++;
      }
      else{
	for(int j=0;j<3;j++){
	  for(int k=0;k<3;k++){
	    if(j == k) dp[1][k][1] += dp[0][j][0];
	    else{
	      for(int l=0;l<2;l++) dp[1][k][0] += dp[0][j][l];
	    }
	  }
	}
      }
      for(int j=0;j<3;j++){
	for(int k=0;k<2;k++){
	  dp[0][j][k] = dp[1][j][k] % 10000;
	  dp[1][j][k] = 0;
	}
      }
    }
     
    int ans = 0;
    for(int i=0;i<3;i++) for(int j=0;j<2;j++) ans += dp[0][i][j];
    cout << ans % 10000  << endl;
      
  }
  return 0;
}