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++: //============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
//============================================================================
//?????°?????????
//============================================================================
	int N,K;
	int A[101],B[101];
//============================================================================
//??\???
//============================================================================
	cin>>N>>K;
	for (int i=0;i<K;i++){
		cin>>A[i]>>B[i];
	}
	int D[101]={};
	for (int i=0;i<K;i++){
		D[A[i]]=B[i];
	}
//============================================================================
//????¨??????????
//============================================================================
	int R;

	int oldTT=0,newTT=1,oldCT=0,newCT=1,oldVT=0,newVT=1;
	int oldTC=0,newTC=1,oldCC=0,newCC=1,oldVC=0,newVC=1;
	int oldTV=0,newTV=1,oldCV=0,newCV=1,oldVV=0,newVV=1;
///
	if (D[1]==1){
		newCT=0;
		newVT=0;
		newCC=0;
		newCV=0;
		newVC=0;
		newVV=0;
	}
	if (D[1]==2){
		newTT=0;
		newTV=0;
		newVC=0;
		newTC=0;
		newVT=0;
		newVV=0;
	}
	if (D[1]==3){
		newTT=0;
		newTC=0;
		newCT=0;
		newCC=0;
		newCV=0;
		newTV=0;
	}
	if (D[2]==1){
		newTC=0;
		newTV=0;
		newCC=0;
		newCV=0;
		newVC=0;
		newVV=0;
	}
	if (D[2]==2){
		newTT=0;
		newTV=0;
		newCT=0;
		newCV=0;
		newVT=0;
		newVV=0;
	}
	if (D[2]==3){
		newTT=0;
		newTC=0;
		newCT=0;
		newCC=0;
		newVT=0;
		newVC=0;
	}


	for (int i=3;i<N+1;i++){
		oldTT=newTT;
		oldTC=newTC;
		oldTV=newTV;
		oldCT=newCT;
		oldCC=newCC;
		oldCV=newCV;
		oldVT=newVT;
		oldVC=newVC;
		oldVV=newVV;

		newTT=(oldCT+oldVT)%10000;
		newTC=(oldTT+oldCT+oldVT)%10000;
		newTV=(oldTT+oldCT+oldVT)%10000;
		newCT=(oldCC+oldTC+oldVC)%10000;
		newCC=(oldTC+oldVC)%10000;
		newCV=(oldCC+oldTC+oldVC)%10000;
		newVT=(oldVV+oldCV+oldTV)%10000;
		newVC=(oldVV+oldCV+oldTV)%10000;
		newVV=(oldCV+oldTV)%10000;

		if (D[i]==1){
			newTC=0;
			newTV=0;
			newCC=0;
			newCV=0;
			newVC=0;
			newVV=0;
		}
		if (D[i]==2){
			newTT=0;
			newTV=0;
			newCT=0;
			newCV=0;
			newVT=0;
			newVV=0;
		}
		if (D[i]==3){
			newTT=0;
			newTC=0;
			newCT=0;
			newCC=0;
			newVT=0;
			newVC=0;
		}
	}

	R=(newTT+newCT+newVT+newTC+newCC+newVC+newTV+newCV+newVV)%10000;

//============================================================================
//????????????R
//============================================================================
	cout<<R<<endl;
	return 0;

}

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

int N, K, mem[100][3][3], decided[100];

int dp(int n, int b1, int b2)
{
  if(n == N)
    return 1;
  int ans = 0;
  if(decided[n] != 0)
  {
    if(b1 == b2 && decided[n] == b1)
      return 0;
    mem[n][b1][b2] = dp(n + 1, decided[n], b1);
    return mem[n][b1][b2];
  }
  for(int i = 1; i <= 3; i++)
  {
    if(b1 == b2 && b1 == i)
      continue;
    ans += dp(n + 1, i, b1);
  }
  return ans % 10000;
}

int main()
{
  cin >> N >> K;
  for(int i = 0;i < K; i++)
  {
    int a, b;
    cin >> a >> b;
    decided[a] = b;
  }
  cout << dp(0, 0, 0) << endl;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

int pasta(int i,int af1,int af2);
//int pastac(int i,int p,int pn);

int day[102];
int memo[102][4][4];
int n,k;

main(){
  int temp;
  scanf("%d %d",&n,&k);
  for(int i=0;i<k;i++){
    scanf("%d",&temp);
    scanf("%d",&day[temp-1]);
  }
  //  printf("%d\n",pastac(0,0,0));
  printf("%d\n",pasta(0,0,0));
}




int pasta(int i,int af1,int af2){
  int f[4]={0};
  int res=0;

  if(i==n) return 1;
  if(memo[i][af1][af2]) return memo[i][af1][af2];

  if(af1==af2) f[af1]=1;
  if(af1==day[i+1]) f[af1]=1;
  if(day[i+1]==day[i+2]) f[day[i+1]]=1;

  for(int j=1;j<=3;j++){
    if(f[j])continue;
    if(day[i]){
      if(day[i]==j) res+=(pasta(i+1,day[i],af1))%10000;
    }
    else res+=(pasta(i+1,j,af1))%10000;
  }
  return  memo[i][af1][af2]=(res)%10000;
}

/*
int pastac(int i,int p,int pn){
  int res=0;
  if(i>=n) return 1;
  if(memo[i][p][pn]) return memo[i][p][pn];

  if(day[i]){
    if(p==day[i]){
      if(pn==2) return 0;
      return memo[i][p][pn]=(pastac(i+1,p,pn+1))%10000;
    }
    return memo[i][p][pn]=(pastac(i+1,day[i],1))%10000;
  }

  for(int j=1;j<=3;j++){
    if(j==p){
      if(pn!=2)res+=(pastac(i+1,p,pn+1))%10000;
    }
    else res+=(pastac(i+1,j,1))%10000;
  }

  return memo[i][p][pn]=res%10000;

}
*/