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>
using namespace std;
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	int a[100],b[100];
	for(int i=0;i<k;i++)scanf("%d%d",&a[i],&b[i]);
	int dp[101][3][3],x;
	const int mod=10000;

	for(int i=0;i<=n;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				dp[i][j][k]=0;
			}
		}
	}
	int p=0,q=0;
	for(int i=0;i<k;i++){
		if(a[i]==1)p=b[i];
		if(a[i]==2)q=b[i];
	}
	if(p==0&&q==0)for(int X=0;X<3;X++)for(int Y=0;Y<3;Y++)dp[2][X][Y]=1;
	if(p==0&&q!=0){
		for(int X=0;X<3;X++){
			for(int Y=0;Y<3;Y++){
				if(q-1==Y){
					dp[2][X][Y]=1;
				}
				else dp[2][X][Y]=0;
			}
		}
	}
	if(p!=0&&q==0){
		for(int X=0;X<3;X++){
			for(int Y=0;Y<3;Y++){
				if(p-1==X){
					dp[2][X][Y]=1;
				}
				else dp[2][X][Y]=0;
			}
		}
	}
	if(p!=0&&q!=0){
		for(int X=0;X<3;X++){
			for(int Y=0;Y<3;Y++){
				if(p-1==X&&q-1==Y){
					dp[2][X][Y]=1;
				}
				else dp[2][X][Y]=0;
			}
		}
	}
	for(int i=3;i<=n;i++){
		x=0;
		for(int j=0;j<k;j++){
			if(a[j]==i)x=b[j];
		}
		if(x==0){
			for(int X=0;X<3;X++){
				for(int Y=0;Y<3;Y++){
					if(X==Y){
						for(int Z=0;Z<3;Z++){
							if(X!=Z){
								dp[i][X][Y]+=dp[i-1][Z][X];
								dp[i][X][Y]%=mod;
							}
						}
					}
					else{
						for(int Z=0;Z<3;Z++){
								dp[i][X][Y]+=dp[i-1][Z][X];
								dp[i][X][Y]%=mod;
						}
					}
				}
			}
		}
		else{
			for(int X=0;X<3;X++){
				for(int Y=0;Y<3;Y++){
					if(X!=Y||Y!=x-1){
						dp[i][X][x-1]+=dp[i-1][Y][X];
						dp[i][X][x-1]%=mod;
					}
				}
			}
		}
	}
	/*
	for(int i=2;i<=n;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				printf("%d ",dp[i][j][k]);
			}
			printf("\n");
		}
		printf("\n");
	}*/
	int ans=0;
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			ans+=dp[n][i][j];
		}
	}
	ans%=mod;
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;
#define mod 10000
#define MAX_N (100+1)
int n, k;
int sche[MAX_N];

int dp[MAX_N][4][4];
int cnt(int day, int one, int two) {
    if (day == n) return 1;
    if (dp[day][one][two] >= 0) return dp[day][one][two];
    if (sche[day] > 0) {
        if (one == two && two == sche[day]) return dp[day][one][two] = 0;
        return dp[day][one][two] = cnt(day+1, sche[day], one);
    }
    int ret = 0;
    for (int i = 1; i <= 3; i++) {
        if (one == two && two == i) continue;
        ret += cnt(day+1, i, one);
        ret %= mod;
    }
    return dp[day][one][two] = ret % mod;
}

int main() {
    cin >> n >> k;
    memset(sche, -1, sizeof(sche));
    memset(dp, -1, sizeof(dp));
    for (int i = 0; i < k; i++) {
        int d, p; cin >> d >> p;
        d--;
        sche[d] = p;
    }
//    for (int i = 0; i < n; i++) cout << sche[i] << ' ';cout << endl;
    cout << cnt(0, -1, -1) << endl;
    return 0;
}

C++: #include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long int LL;
typedef pair<int, int> PII;
typedef vector<PII> VP;
typedef VP::iterator VPI;
typedef string::iterator STI;
const int DIV = 10000;

int n, k;
int memo[110][5][5][5];
int plan[110];

int search(int day, int status[3])
{
  if(status[0] && status[0] == status[1] && status[1] == status[2]){
    return 0;
  }
  if(day == n + 1){
    return 1;
  }
  if(memo[day][status[0]][status[1]][status[2]] != -1){
    return memo[day][status[0]][status[1]][status[2]];
  }
  
  if(plan[day + 1]){
    int tomorrow[3] = {status[1], status[2], plan[day + 1]};
    return memo[day + 1][status[1]][status[2]][plan[day + 1]] = search(day + 1, tomorrow);
  }
  else{
    int sum = 0;
    for(int i = 1; i <= 3; i++){
      int tomorrow[3] = {status[1], status[2], i};
      sum += memo[day + 1][status[1]][status[2]][i] = search(day + 1, tomorrow);
    }
    return sum % DIV;
  }
}	     
	        
int main()
{
  cin >> n >> k;
  for(int i = 0; i < k; i++){
    int a, b;
    cin >> a >> b;
    plan[a] = b;
  }
  memset(memo, -1, sizeof memo);
  plan[n + 1] = 4;

  int status[3] = {0, 0, 0};
  cout << search(0, status) % DIV << endl;
  
  return 0;
}

C++: #include <iostream>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main() {
	int n, k;
	int s[101][3] = {};
	int b[101] = {};
	cin >> n >> k;
	REP(i, k) {
		int a;
		cin >> a;
		cin >> b[a];
	}
	s[0][0] = 1;
	FOR(i, 1, n+1) {
		REP(j, 3) {
			if(b[i]>0 && b[i]!=j+1) {
				s[i][j] = 0;
			}else {
				if(i==1 || i==2) {
					REP(k, 3) s[i][j] += s[i-1][k];
				} else if(i==3) {
					REP(k, 3) s[i][j] += s[i-1][k];
					if((b[i-1]==0 || b[i-1]==j+1) && (b[i-2]==0 || b[i-2]==j+1))s[i][j] -= 1;
				} else {
					REP(k, 3) s[i][j] += s[i-1][k];
					s[i][j] -= s[i-1][j];
					if(b[i-1]==0 || b[i-1]==j+1) {
						REP(k, 3) s[i][j] += s[i-2][k];
						s[i][j] -= s[i-2][j];
					}
				}
			}
			s[i][j] += 10000;
			s[i][j] %= 10000;
		}
	}
	
	FOR(i, 1, n+1) {
		cout << b[i];
		REP(j, 3) {
			cout << " " << s[i][j];
		}
		cout << endl;
	}
	
	int r = 0;
	REP(i, 3)r += s[n][i];
	r %= 10000;
	
	cout << r << endl;
	
	return 0;
}