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 <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

#define NUM 10000

bool fixed[101];
int fixed_menu[101];

int main(){

	int ans = 0;

	for(int i = 1; i <= 100; i++)fixed[i] = false;

	int N,K,day,menu;

	scanf("%d %d",&N,&K);
    int dp[N+1][4][4];

    for(int i = 0; i < N+1; i++){
    	for(int k = 1; k <= 3; k++){
    		for(int p = 1; p <= 3; p++){
    			dp[i][k][p] = 0;
    		}
    	}
    }

	for(int loop = 0; loop < K; loop++){
		scanf("%d %d",&day,&menu);
		fixed[day] = true;
		fixed_menu[day] = menu;
	}

	if(fixed[1] == true && fixed[2] == true){
		dp[2][fixed_menu[1]][fixed_menu[2]] = 1;
	}else if(fixed[1] == true && fixed[2] == false){
		dp[2][fixed_menu[1]][1] = 1;
		dp[2][fixed_menu[1]][2] = 1;
		dp[2][fixed_menu[1]][3] = 1;
	}else if(fixed[1] == false && fixed[2] == true){
		dp[2][1][fixed_menu[2]] = 1;
		dp[2][2][fixed_menu[2]] = 1;
		dp[2][3][fixed_menu[2]] = 1;
	}else{
		for(int row = 1; row <= 3; row++){
			for(int col = 1; col <= 3; col++){
				dp[2][row][col] = 1;
			}
		}
	}

	for(int i = 3; i <= N; i++){
		if(fixed[i] == true){
			switch(fixed_menu[i]){
			case 1:
				dp[i][1][1] = (dp[i-1][2][1] + dp[i-1][3][1])%NUM;
				dp[i][2][1] = (dp[i-1][1][2] + dp[i-1][2][2] + dp[i-1][3][2])%NUM;
				dp[i][3][1] = (dp[i-1][1][3] + dp[i-1][2][3] + dp[i-1][3][3])%NUM;
				break;
			case 2:
				dp[i][1][2] = (dp[i-1][1][1] + dp[i-1][2][1] + dp[i-1][3][1])%NUM;
				dp[i][2][2] = (dp[i-1][1][2] + dp[i-1][3][2])%NUM;
				dp[i][3][2] = (dp[i-1][1][3] + dp[i-1][2][3] + dp[i-1][3][3])%NUM;
				break;
			case 3:
				dp[i][1][3] = (dp[i-1][1][1] + dp[i-1][2][1] + dp[i-1][3][1])%NUM;
				dp[i][2][3] = (dp[i-1][1][2] + dp[i-1][2][2] + dp[i-1][3][2])%NUM;
				dp[i][3][3] = (dp[i-1][1][3] + dp[i-1][2][3])%NUM;
				break;
			}
		}else{
			dp[i][1][1] = (dp[i-1][2][1] + dp[i-1][3][1])%NUM;
			dp[i][2][1] = (dp[i-1][1][2] + dp[i-1][2][2] + dp[i-1][3][2])%NUM;
			dp[i][3][1] = (dp[i-1][1][3] + dp[i-1][2][3] + dp[i-1][3][3])%NUM;
			dp[i][1][2] = (dp[i-1][1][1] + dp[i-1][2][1] + dp[i-1][3][1])%NUM;
			dp[i][2][2] = (dp[i-1][1][2] + dp[i-1][3][2])%NUM;
			dp[i][3][2] = (dp[i-1][1][3] + dp[i-1][2][3] + dp[i-1][3][3])%NUM;
			dp[i][1][3] = (dp[i-1][1][1] + dp[i-1][2][1] + dp[i-1][3][1])%NUM;
			dp[i][2][3] = (dp[i-1][1][2] + dp[i-1][2][2] + dp[i-1][3][2])%NUM;
			dp[i][3][3] = (dp[i-1][1][3] + dp[i-1][2][3])%NUM;
		}

	}

	for(int row = 1; row <= 3; row++){
		for(int col = 1; col <= 3; col++){
			ans += dp[N][row][col];
		}
	}

	ans %= NUM;

	printf("%d\n",ans);

    return 0;
}

C++: #include <stdio.h>

int main(void) {
  int i, j, k, l, n, now = 0, t, ans = 0;
  scanf("%d%d", &n, &k);
  int dp[n][6], a[k], b[k];
  for(i = 0; i < k; ++i) {
    scanf("%d%d", &a[i], &b[i]);
    a[i]--;
  }
  for(i = 0; i < k; ++i) for(j = i + 1; j < k; ++j) if(a[i] > a[j]) {
    t = a[i], a[i] = a[j], a[j] = t;
    t = b[i], b[i] = b[j], b[j] = t;
  }
  for(i = 0; i < n; ++i) for(j = 0; j < 6; ++j) dp[i][j] = 0;
  if(!a[now]) {
    if(b[now] == 1) dp[0][0] = 1;
    if(b[now] == 2) dp[0][1] = 1;
    if(b[now] == 3) dp[0][2] = 1;
    ++now;
  } else dp[0][0] = dp[0][1] = dp[0][2] = 1;
  for(i = 1; i < n; ++i) {
    if(a[now] != i) {
      for(j = 0; j < 3; ++j) {
        for(l = 0; l < 6; ++l) {
          if(j != l && l != j + 3) {
            dp[i][j] += dp[i - 1][l];
            dp[i][j] %= 10000;
          }
        }
      }
      for(j = 0; j < 3; ++j) dp[i][j + 3] = dp[i - 1][j];
    } else {
      if(b[now] == 1) {
        for(j = 0; j < 6; ++j) if(j != 0 && j != 3) {
          dp[i][0] += dp[i - 1][j];
          dp[i][0] %= 10000;
        }
        dp[i][3] = dp[i - 1][0];
      } else if(b[now] == 2) {
        for(j = 0; j < 6; ++j) if(j != 1 && j != 4) {
          dp[i][1] += dp[i - 1][j];
          dp[i][1] %= 10000;
        }
        dp[i][4] = dp[i - 1][1];
      } else {
        for(j = 0; j < 6; ++j) if(j != 2 && j != 5) {
          dp[i][2] += dp[i - 1][j];
          dp[i][2] %= 10000;
        }
        dp[i][5] = dp[i - 1][2];
      }
      ++now;
    }
  }
  /*for(i = 0; i < n; ++i) {
    for(j = 0; j < 6; ++j) printf("%d ", dp[i][j]);
    printf("\n");
  }*/
  for(i = 0; i < 6; ++i) {
    ans += dp[n - 1][i];
    ans %= 10000;
  }
  printf("%d\n", ans);
  return 0;
}