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

int dp[100][5][5];
int mp[100]={0};
int mod=10000,n;

int dfs(int d,int ppr,int pre){
    int res=0;
    if(d==n) return 1;
    if(dp[d][ppr][pre]!=-1) return dp[d][ppr][pre];
    if(mp[d]!=0){
        int t=mp[d];
        if(ppr==pre&&t==pre) return 0;
        res +=dfs(d+1,pre,t);
    }
    else{
        for(int i=1;i<4;++i){
            if(ppr==pre&&i==pre) continue;
            res +=dfs(d+1,pre,i);
        }
    }
    res %=mod;
    dp[d][ppr][pre]=res;
    return res;
}

int main(){
    int k,a,b;
    cin>>n>>k;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<k;++i){
        cin>>a>>b;
        mp[a-1]=b;
    }
    cout<<dfs(0,4,4)%mod<<endl;
    return 0;
}

C++: #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define INF 1000000001
#define MOD 10000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const ull B=100000007;
int dp[100][3][2];
int main(){
      int n,k,a[100],b[100];
      bool f[100][3];
      memset(f,true,sizeof(f));
      cin>>n>>k;
      REP(i,k){
            cin>>a[i]>>b[i];a[i]--;b[i]--;
            REP(j,3)if(j!=b[i])f[a[i]][j]=false;
      }
      REP(i,3)if(f[0][i])dp[0][i][0]++;
      REP(i,n){
            if(i==0)continue;
            REP(j,3){
                  if(!f[i][j])continue;
                  REP(k,6)if(j!=k/2)dp[i][j][0]=(dp[i][j][0]+dp[i-1][k/2][k%2])%MOD;
                  dp[i][j][1]=(dp[i][j][1]+dp[i-1][j][0])%MOD;
            }
      }
      int ans=0;
      REP(i,6)ans=(ans+dp[n-1][i/2][i%2])%MOD;
      cout<<ans%MOD<<endl;
}

C++: //Solution for aoj 0568:Pasta
#include <iostream>
using namespace std;
const int surplus = 10000;
int n, k, a, b, ans;
int pasta[101][4][2], save[101];
void dp(int day){
	if (day > n)
		return;
	if (save[day]){
		for (int i = 1; i <= 3; i++){
			if (save[day] != i)
				pasta[day][save[day]][0] += pasta[day - 1][i][0] + pasta[day - 1][i][1];
			else
				pasta[day][i][1] += pasta[day - 1][i][0];
		}
		pasta[day][save[day]][0] %= surplus;
		pasta[day][save[day]][1] %= surplus;
	}
	else{
		for (int i = 1; i <= 3; i++){
			for (int j = 1; j <= 3; j++){
				if (i != j){
					pasta[day][i][0] += pasta[day - 1][j][0] + pasta[day - 1][j][1];
				}
				else{
					pasta[day][i][1] += pasta[day - 1][j][0];
				}
			}
			pasta[day][i][0] %= surplus;
			pasta[day][i][1] %= surplus;
		}
	}
	dp(day + 1);
}
int main(){
	cin >> n >> k;
	for (int i = 0; i < k; i++){
		cin >> a >> b;
		save[a] = b;
	}
	if (save[1])
		pasta[1][save[1]][0] = 1;
	else{
		for (int i = 1; i <= 3; i++){
			pasta[1][i][0] = 1;
		}
	}
	dp(2);
	for (int i = 1; i <= 3; i++){
		ans += pasta[n][i][0] + pasta[n][i][1];
	}
	ans %= surplus;
	cout << ans << endl;
	return 0;
}

C++: #include<stdio.h>
int main()
{
    int n,m,dp[3][110],a,b;
    scanf("%d%d",&n,&m);
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            dp[j][i] = -1;
        }
    }
    for(int i = 0; i < m; i++)
    {
        scanf("%d%d",&a,&b);
        for(int j = 0; j < 3; j++)
        {
            if(j == b - 1);
            else dp[j][a - 1] = 0;
        }
    }
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < 3; j++)
        {

            if(dp[j][i] == 0);
            else if(i == 0)dp[j][i] = 1;
            else if(i == 1)dp[j][i] = dp[0][i - 1] + dp[1][i - 1] + dp[2][i - 1];
            else
            {
                dp[j][i] = 0;
                for(int k = 0; k < 3; k++)
                {
                    for(int l = 1; l < 3; l++)
                    {
                        dp[j][i] = dp[j][i] + dp[k][i - l];
                    }
                }
                if(dp[j][i - 1] == 0)
                {
                    for(int k = 0; k < 3; k++)
                    {
                        dp[j][i] = dp[j][i] - dp[k][i - 2];
                    }
                }
                else
                {
                    for(int k = 1; k < 3; k++)
                    {
                        dp[j][i] = dp[j][i] - dp[j][i - k];
                    }
                }
            }
        }
    }
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            printf("%10d ",dp[j][i]);
        }
        printf("\n");
    }
    printf("%d\n",(dp[0][n - 1] + dp[1][n - 1] + dp[2][n - 1]) % 10000);
}