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>
using namespace std;
#include <cstring>

const int MOD = 10000;

int rec(int today,int pasta1,int pasta2);

int n;
int sch[128];//?????±?????\??????????????¢
int memo[128][4][4];

int main(void){

	memset(sch, 0, sizeof(sch));
	memset(memo, -1, sizeof(memo));

	int k, a, b;

	cin >> n >> k;

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

	cout << rec(1,0,0) << endl;
}

int rec(int today,int pasta1,int pasta2){

	if (today > n)return 1;
	if (memo[today][pasta1][pasta2] != -1)return memo[today][pasta1][pasta2];
	if (sch[today] != 0){
		if (pasta1 == pasta2 && pasta1 == sch[today])return 0;
		else return rec(today+1, sch[today], pasta1) % MOD;
	}

	int cnt = 0;
	for (int i = 1; i <= 3; i++){
		if (pasta1 == pasta2 && pasta1 == i)continue;
		cnt += rec(today + 1, i, pasta1);
	}
	return memo[today][pasta1][pasta2] = cnt % MOD;
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <map>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define MAX_N 105
int vx [4]= {1,0,-1,0};
int vy [4]= {0,1,0,-1};
int dp[MAX_N][4][4];//dp[date][today][yesterday]
int V[MAX_N],W[MAX_N];
int data[MAX_N],B[MAX_N];
int K ,N;
using namespace std;
void init(){
    REP(i,4)REP(j,4)dp[2][i][j]=1;
    REP(j,K){
      if(data[j]==1)
        switch (B[j]) {
          case 1 : FOR(l,1,4){dp[2][l][2]=0;dp[2][l][3]=0;}break;
          case 2 : FOR(l,1,4){dp[2][l][1]=0;dp[2][l][3]=0;}break;
          case 3 : FOR(l,1,4){dp[2][l][1]=0;dp[2][l][2]=0;}break;
        }
        else if (data[j]==2)
        switch (B[j]) {
          case 1 : FOR(l,1,4){dp[2][2][l]=0;dp[2][3][l]=0;}break;
          case 2 : FOR(l,1,4){dp[2][1][l]=0;dp[2][3][l]=0;}break;
          case 3 : FOR(l,1,4){dp[2][1][l]=0;dp[2][2][l]=0;}break;
        }

      }
  for(int i=3;i<=N;i++){
    dp[i][1][1]= dp[i-1][1][2]+dp[i-1][1][3];
    dp[i][2][2]= dp[i-1][2][1]+dp[i-1][2][3];
    dp[i][3][3]= dp[i-1][3][2]+dp[i-1][3][1];
    dp[i][1][2]= dp[i-1][2][1]+dp[i-1][2][2]+dp[i-1][2][3];
    dp[i][1][3]= dp[i-1][3][1]+dp[i-1][3][2]+dp[i-1][3][3];
    dp[i][2][1]= dp[i-1][1][1]+dp[i-1][1][2]+dp[i-1][1][3];
    dp[i][2][3]= dp[i-1][3][1]+dp[i-1][3][2]+dp[i-1][3][3];
    dp[i][3][1]= dp[i-1][1][1]+dp[i-1][1][2]+dp[i-1][1][3];
    dp[i][3][2]= dp[i-1][2][1]+dp[i-1][2][2]+dp[i-1][2][3];
    REP(j,K){
      if(data[j]==i){
        switch (B[j]) {
          case 1 : FOR(l,1,4){dp[i][2][l]=0;dp[i][3][l]=0;}break;
          case 2 : FOR(l,1,4){dp[i][1][l]=0;dp[i][3][l]=0;}break;
          case 3 : FOR(l,1,4){dp[i][1][l]=0;dp[i][2][l]=0;}break;
        }
      }
    }
  }
  int total=0;
    for(int j =1 ;j<=3;j++){
      for(int l =1;l<=3;l++){
        total += dp[N][j][l];
      }

  }
  cout << total%10000 <<endl;

}
void solve(){
  cin >> N >> K;
  REP(i,K){
    cin >> data[i]>>B[i];
  }
  init();

}
int main(){
    solve();
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
	int dp[101][4][4];
int main() {
	int N, K; cin >> N >> K;
	vector<int>pasta(N);
	for (int i = 0; i < K; ++i) {
		int A, B; cin >> A >> B;
		A--;  pasta[A] = B;
	}
	memset(dp, 0, sizeof(dp));
	dp[0][0][0]= 1;
	for (int d = 0; d < N; ++d) {
		for (int a = 0; a < 4; ++a) {
			for (int b = 0; b < 4; ++b) {
				for (int c = 1; c <= 3; ++c) {
					if (a == b&&b == c)continue;
					if (pasta[d] && pasta[d] != c)continue;
					dp[d + 1][b][c] += dp[d][a][b];
					dp[d + 1][b][c] %= 10000;
				}
			}
		}
	}
	int ans = 0;
	for (int a = 0; a < 4; ++a) {
		for (int b = 0; b < 4; ++b) {
			ans += dp[N][a][b];
		}
	}
	cout << ans % 10000 << endl;
	return 0;
}

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

int dp[101][4][4];//何日目から、どのぱすたを、何日連続で食べているか
int plan[101];//先に決められている予定　要素：日付

#define MOD 10000;

int main(void)
{
	while(1){
		int day;
		int k;
		cin >> day >> k;
		memset(plan,0,sizeof(plan));
		for(int i=0;i<k;++i){
			int d,p;
			cin >> d >> p;
			plan[d] = p;
		}
		memset(dp,0,sizeof(dp));

		for(int i=1;i<=3;++i){
			if(plan[1] != 0)
				dp[1][plan[1]][1] = 1;
			else
				dp[1][i][1] = 1;
		}

		for(int d=2;d<=day;++d){//どの日から？
			for(int p=1;p<=3;++p){//どのパスタを？
				if(plan[d]){
					dp[d][plan[d]][1] = (dp[d-1][(plan[d]+1)%3+1][1] + dp[d-1][(plan[d]+1)%3+1][2] + dp[d-1][plan[d]%3+1][1] + dp[d-1][plan[d]%3+1][2])%MOD;
					dp[d][plan[d]][2] = dp[d-1][plan[d]][1] % MOD;
				}
				else{
					dp[d][p][1] = (dp[d-1][(p+1)%3+1][1] + dp[d-1][(p+1)%3+1][2] + dp[d-1][p%3+1][1] + dp[d-1][p%3+1][2])%MOD;
					dp[d][p][2] = dp[d-1][p][1] % MOD;
				}
			}
		}
		int ans = dp[day][1][1] + dp[day][2][1] + dp[day][3][1] + dp[day][1][2] + dp[day][2][2] + dp[day][3][2];
		cout << ans << endl;
	}
	return 0;
}