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 <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <climits>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define ALL(A)		(A).begin(),(A).end()
#define DUMP(A)    cout<<#A<<"="<<(A)<< endl
#define SIZE(A)    (int)((A).size())
#define MP  make_pair
using namespace std;
typedef long long ll;

int vx[]={1,0,-1,0},vy[]={0,1,0,-1};

const int MOD=10000;
int dp[100][3][3],bs[100];
int main(){
    int N,K;
    scanf("%d%d",&N,&K);
    for(int i=0;i<N;i++){
        bs[i]=-1;
    }
    int a,b;
    for(int i=0;i<K;i++){
        scanf("%d%d",&a,&b);
        a--;b--;
        bs[a]=b;
    }
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            if((bs[0]==i||bs[0]==-1)&&(bs[1]==j||bs[1]==-1)) dp[1][i][j]=1;
            else dp[1][i][j]=0;
        }
    }
    for(int i=2;i<N;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                dp[i][j][k]=0;
                if((bs[i-1]==j||bs[i-1]==-1)&&(bs[i]==k||bs[i]==-1)){
                    for(int l=0;l<3;l++){
                        if(l==j&&j==k) continue;
                        dp[i][j][k]+=dp[i-1][l][j];
                        dp[i][j][k]%=MOD;
                    }
                }
            }
        }
    }
    int ret=0;
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            ret+=dp[N-1][i][j];
            ret%=MOD;
        }
    }
    printf("%d\n",ret);
}

C++: #include<iostream>

using namespace std;

const int MAX = 105;
const int MOD = 10000;

int N,K;
int pasta[MAX];
int dp[MAX][3][3];

void input(){
  cin >> N >> K;
  for(int i = 0; i < K; i++){
    int a,b;
    cin >> a >> b;
    pasta[a] = b;
  }
}

void solve(){
 

  if(pasta[1] == 0){
    for(int i = 0; i < 3; i++) dp[1][i][0] = 1;
  }else{
    dp[1][pasta[1]-1][0] = 1;
  }
  
  for(int i = 1; i < N; i++){//day
    if(pasta[i+1] != 0){
    
      for(int j = 0; j < 3; j++)// previous pasta
	for(int k = 0; k < 2; k++) //number of day of eating same pasta
	  if(pasta[i+1]-1 == j){
	    if(k < 1) dp[i+1][j][k+1] = (dp[i+1][j][k+1]+dp[i][j][k])%MOD;
	  }else{
	    dp[i+1][pasta[i+1]-1][0] = (dp[i+1][pasta[i+1]-1][0]+dp[i][j][k])%MOD;
	  }
	 
    
    }else{
    
      for(int j = 0; j < 3; j++)//next pasta
	for(int k = 0; k < 3; k++)// previous pasta
	  for(int l = 0; l < 2; l++)//number of day of eating same pasta
	    if(j == k){
	      if(l < 1) dp[i+1][j][l+1] = (dp[i+1][j][l+1]+dp[i][j][l])%MOD;
	    }else{
	      dp[i+1][j][0] = (dp[i+1][j][0]+dp[i][k][l])%MOD;
	    }
	  
    }
  }

  long long ans = 0;

  for(int i = 0; i < 3; i++)
    for(int j = 0; j < 2; j++)
      ans += dp[N][i][j];
  cout << ans%MOD << endl;
}

int main(){
  input();
  solve();
  return 0;
}

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

const int MAX_N = 100;
int N, K;
int plan[MAX_N + 1];
int memo[MAX_N + 1][4][4];
int solve(int n, int b1, int b2){
	if(n == N+1) return 1;
	if(memo[n][b1][b2] != -1) return memo[n][b1][b2];
	if(plan[n] != 0){
		if(b1 == b2 && b1 == plan[n])
			return 0;
		else
			return solve(n+1, plan[n], b1)%10000;
	}
	int t=0;
	for(int i=1; i<=3; ++i){
		if(b1==b2 && b1==i ) continue;
		t+=solve(n+1, i, b1)%10000;
	}
	return memo[n][b1][b2] = t%10000;
}
int main(){
	scanf("%d %d", &N, &K);
	for(int i=0; i<K; ++i){
		int d, k;
		scanf("%d %d", &d, &k);
		plan[d] = k;
	}
	for(int i=0; i<=N; ++i)
		for(int j=0; j<4; ++j)
			for(int k=0; k<4; ++k)
				memo[i][j][k] = -1;
	printf("%d\n", solve(1, 0, 0));
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define MOD 10000

int a[101];

int dp[101][4][4];

int n, k;

int rec(int day, int pp, int p)
{
    if (day > n) return 1;

    if (dp[day][pp][p] >= 0) return dp[day][pp][p];

    int res = 0;

    if (a[day]) {
        if (a[day] != pp || a[day] != p) {
            res = rec(day + 1, p, a[day]);
            res %= MOD;
        }
    } else {
        for (int i = 1; i <= 3; ++i) {
            if (pp == p && p == i) continue;
            res += rec(day + 1, p, i);
            res %= MOD;
        }
    }

    return dp[day][pp][p] = res;
}

int main()
{
    cin >> n >> k;

    for (int i = 0; i < k; ++i) {
        int day; cin >> day;
        cin >> a[day];
    }

    memset(dp, -1, sizeof(dp));

    printf("%d\n", rec(1, 0, 0));
}