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 <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int dp[100][3][2];
int fx[100];
int N,K;
int main() {
	memset(fx,-1,sizeof(fx));
	cin >> N >> K;
	for(int i=0;i<K;i++){
		int a,b;
		cin >> a >> b;
		fx[a-1]=b-1;
	}
	for(int i=0;i<N;i++){
		for(int p=0;p<3;p++){
			if(fx[i]!=-1&&fx[i]!=p){
				continue;
			}
			if(i==0){
				dp[i][p][0]=1;
				continue;
			}
			for(int q=0;q<3;q++){
				if(q==p){
					dp[i][p][1]+=dp[i-1][q][0];
				}
				else
				{
					dp[i][p][0]+=dp[i-1][q][0]+dp[i-1][q][1];
				}
			}
			dp[i][p][0]%=10000;
			dp[i][p][1]%=10000;
		}
	}
	int ret=0;
	for(int i=0;i<3;i++){
		ret+=dp[N-1][i][0]+dp[N-1][i][1];
	}
	ret%=10000;
	cout << ret << endl;
}

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

const int mod = 10000;

int N, K;
int plan[100];
int dp[100][3][2];

int main()
{
	std::cin >> N >> K;
	
	memset( plan, -1, sizeof( plan ) );

	for( int i = 0; i != K; ++i )
	{
		int A, B;
		std::cin >> A >> B;

		plan[A-1] = B - 1;
	}

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

	for( int i = 0; i != N - 1; ++i )
	{
		if( plan[i+1] != -1 )
		{
			for( int j = 0; j != 3; ++j )
				if( j != plan[i+1] )
					dp[i+1][plan[i+1]][0] = ( dp[i+1][plan[i+1]][0] + dp[i][j][0] + dp[i][j][1] ) % mod;
			
			dp[i+1][plan[i+1]][1] = ( dp[i+1][plan[i+1]][1] + dp[i][plan[i+1]][0] ) % mod;
		}
		else
		{
			for( int j = 0; j != 3; ++j )
			{
				for( int k = 0; k != 3; ++k )
					if( j != k )
						dp[i+1][j][0] = ( dp[i+1][j][0] + dp[i][k][0] + dp[i][k][1] ) % mod;

				dp[i+1][j][1] = ( dp[i+1][j][1] + dp[i][j][0] ) % mod;
			}
		}
	}

	int ans = 0;
	for( int i = 0; i != 3; ++i )
		for( int j = 0; j != 2; ++j )
			ans = ( ans + dp[N-1][i][j] ) % mod;

	std::cout << ans << std::endl;

	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <queue>
int set_pasta[101] = { 0 };
int dp[101][4][4] = { 0 };
using namespace std;
int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	for (int i = 1;i <= k;++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		set_pasta[a] = b;
	}
	if (set_pasta[1] == 0) {
		if (set_pasta[2] == 0) {
			for (int a = 1;a <= 3;++a) {
				for (int b = 1;b <= 3;++b) {
					dp[2][a][b] = 1;
				}
			}
		}
		else {
			for (int a = 1;a <= 3;++a) {
				dp[2][a][set_pasta[2]] = 1;
			}
		}
	}
	else {
		if (set_pasta[2] == 0) {
			for (int a = 1;a <= 3;++a) {
				dp[2][set_pasta[1]][a] = 1;
			}
		}
		else {
			dp[2][set_pasta[1]][set_pasta[2]] = 1;
		}
	}
	for (int day = 3;day <= n;++day) {
		if (set_pasta[day] == 0) {
			for (int oldoldpasta = 1;oldoldpasta <= 3;++oldoldpasta) {
				for (int oldpasta = 1;oldpasta <= 3;++oldpasta) {
					for (int nowpasta = 1;nowpasta <= 3;++nowpasta) {
						if (oldoldpasta != oldpasta || oldpasta != nowpasta) {
							dp[day][oldpasta][nowpasta] += dp[day - 1][oldoldpasta][oldpasta];
						}
					}
				}
			}
		}
		else {
			for (int i = 1;i <= 3;++i) {
				for (int q = 1;q <= 3;++q) {
					if (i != q || q != set_pasta[day]) {
						dp[day][q][set_pasta[day]] += dp[day - 1][i][q];
					}
				}
			}
		}
		for (int i = 1;i <= 3;++i) {
			for (int q = 1;q <= 3;++q) {
				dp[day][i][q] = dp[day][i][q] % 10000;
			}

		}
	}
	int num = 0;
	for (int a = 1;a <= 3;++a) {
		for (int b = 1;b <= 3;++b) {
			num += dp[n][a][b];
		}
	}
	num = num % 10000;
	printf("%d\n", num);
}