Stephen Queen wants to write a story. He is a very unusual writer, he uses only letters 'a', 'b', 'c', 'd' and 'e'!To compose a story, Stephen wrote out $$$n$$$ words consisting of the first $$$5$$$ lowercase letters of the Latin alphabet. He wants to select the maximum number of words to make an interesting story.Let a story be a sequence of words that are not necessarily different. A story is called interesting if there exists a letter which occurs among all words of the story more times than all other letters together.For example, the story consisting of three words "bac", "aaada", "e" is interesting (the letter 'a' occurs $$$5$$$ times, all other letters occur $$$4$$$ times in total). But the story consisting of two words "aba", "abcde" is not (no such letter that it occurs more than all other letters in total).You are given a sequence of $$$n$$$ words consisting of letters 'a', 'b', 'c', 'd' and 'e'. Your task is to choose the maximum number of them to make an interesting story. If there's no way to make a non-empty story, output $$$0$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 5000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of the words in the sequence. Then $$$n$$$ lines follow, each of them contains a word — a non-empty string consisting of lowercase letters of the Latin alphabet. The words in the sequence may be non-distinct (i. e. duplicates are allowed). Only the letters 'a', 'b', 'c', 'd' and 'e' may occur in the words. It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$; the sum of the lengths of all words over all test cases doesn't exceed $$$4 \cdot 10^5$$$.

For each test case, output the maximum number of words that compose an interesting story. Print 0 if there's no way to make a non-empty interesting story.

6
3
bac
aaada
e
3
aba
abcde
aba
2
baba
baba
4
ab
ab
c
bc
5
cbdca
d
a
d
e
3
b
c
ca

NoteIn the first test case of the example, all $$$3$$$ words can be used to make an interesting story. The interesting story is "bac aaada e".In the second test case of the example, the $$$1$$$-st and the $$$3$$$-rd words can be used to make an interesting story. The interesting story is "aba aba". Stephen can't use all three words at the same time.In the third test case of the example, Stephen can't make a non-empty interesting story. So the answer is $$$0$$$.In the fourth test case of the example, Stephen can use the $$$3$$$-rd and the $$$4$$$-th words to make an interesting story. The interesting story is "c bc".

package main

import (
	"fmt"
	"sort"
	"strings"
)

var a, b, c, d, e int
var count = [5]int{0, 0, 0, 0, 0}
var rescount = [5]int{0, 0, 0, 0, 0}
var values []int
var words []string

func main() {
	var (
		t, n  int
		s     string
		words []string
	)
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		a, b, c, d, e = 0, 0, 0, 0, 0
		fmt.Scanln(&n)
		for j := 0; j < n; j++ {
			fmt.Scanln(&s)
			words = append(words, s)
		}
		fmt.Println(interestingStory(words))
		words = []string{}
	}
}

func interestingStory(words []string) int {
	values = []int{}
	for _, element := range words {
		fillMap(element, "a")
	}
	rescount[0] = countMax()
	for _, element := range words {
		fillMap(element, "b")
	}
	rescount[1] = countMax()
	for _, element := range words {
		fillMap(element, "c")
	}
	rescount[2] = countMax()
	for _, element := range words {
		fillMap(element, "d")
	}
	rescount[3] = countMax()
	for _, element := range words {
		fillMap(element, "e")
	}
	rescount[4] = countMax()
	m := 0
	for _, e := range rescount {
		if e > m {
			m = e
		}
	}
	rescount[0], rescount[1], rescount[2], rescount[3], rescount[4] = 0, 0, 0, 0, 0
	return m
}

func countMax() int {
	sort.Ints(values)
	count := 0
	sum := 0
	for i := len(values) - 1; i >= 0; i-- {
		sum += values[i]
		if sum > 0 {
			count++
		}
	}
	values = []int{}
	return count
}

func fillMap(word string, letter string) {
	value := 2*strings.Count(word, letter) - len(word)
	values = append(values, value)
}

package main

import (
	"fmt"
	"strings"
)

type word struct {
	Num        int64
	LetterSum  int64
	LetterList map[int32]int64
	Differents []int64
}

func main() {
	var t int64
	var n int64
	_, err := fmt.Scan(&t)
	if err != nil {
		return
	}

	for i := int64(0); i < t; i++ {
		_, err = fmt.Scan(&n)
		if err != nil {
			return
		}
		var stringArray []string
		var str string
		for j := int64(0); j < n; j++ {
			_, err := fmt.Scan(&str)
			if err != nil {
				return
			}
			stringArray = append(stringArray, str)
		}
		wordsInfo := countLetters(stringArray)
		result := getResult(n, wordsInfo)
		fmt.Println(result)
	}
}

func countLetters(stringArray []string) map[string]*word {
	m := make(map[string]*word)
	for _, str := range stringArray {
		if _, ok := m[str]; ok {
			m[str].Num++
			m[str].LetterSum += int64(len(str))
		} else {
			m[str] = &word{}
			m[str].LetterList = map[int32]int64{
				'a': 0,
				'b': 0,
				'c': 0,
				'd': 0,
				'e': 0,
			}
			m[str].Num = 1
			for _, c := range str {
				m[str].LetterList[c]++
			}
			m[str].LetterSum += int64(len(str))
			m[str].Differents = append(m[str].Differents, int64(len(str)-2*strings.Count(str, "a")),
				int64(len(str)-2*strings.Count(str, "b")),
				int64(len(str)-2*strings.Count(str, "c")),
				int64(len(str)-2*strings.Count(str, "d")),
				int64(len(str)-2*strings.Count(str, "e")))
		}
	}

	return m
}

func getResult(n int64, wordInfo map[string]*word) int64 {
	var max int64
	for i := 'a'; i < 'f'; i++ {
		m := n
		words := sort(wordInfo, i)
		letterNum := map[int32]int64{
			'a': 0,
			'b': 0,
			'c': 0,
			'd': 0,
			'e': 0,
		}
		var sum int64
		for _, word := range wordInfo {
			letterNum['a'] += word.Num * word.LetterList['a']
			letterNum['b'] += word.Num * word.LetterList['b']
			letterNum['c'] += word.Num * word.LetterList['c']
			letterNum['d'] += word.Num * word.LetterList['d']
			letterNum['e'] += word.Num * word.LetterList['e']
		}
		sum += letterNum['a'] + letterNum['b'] + letterNum['c'] + letterNum['d'] + letterNum['e']
		othersSum := sum - letterNum[i]
		if letterNum[i] > othersSum {
			if max < m {
				max = m
			}
			continue
		}

		for _, word := range words {
			for j := int64(0); j < word.Num; j++ {
				d := word.LetterSum/word.Num - word.LetterList[i]
				if word.LetterList[i] < d {
					letterNum[i] -= word.LetterList[i]
					othersSum -= d
					m--
				}
				if letterNum[i] > othersSum {
					if max < m {
						max = m

					}
				}
			}

		}
	}

	return max
}

func sort(m map[string]*word, l int32) []*word {
	index := l - 'a'
	var words []*word
	for _, w := range m {
		words = append(words, w)
	}

	for i := len(words) - 1; i > 0; i-- {
		for j := 0; j < i; j++ {
			if words[j].Differents[index] < words[j+1].Differents[index] {
				words[j], words[j+1] = words[j+1], words[j]
			}
		}
	}

	return words
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
	"sort"
)

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)

		words := make([]string, n)
		for i := 0; i < n; i++ {
			Fscan(in, &words[i])
		}

		ans := 0
		for c := 0; c < 5; c++ {
			extras := make([]int, n)
			for i := 0; i < n; i++ {
				for _, char := range words[i] {
					if char == rune('a' + c) {
						extras[i]++
					} else {
						extras[i]--
					}
				}
			}
			sort.Slice(extras, func(i, j int) bool {
				return extras[i] > extras[j]
			})
			sum := 0
			for i, val := range extras {
				sum += val
				if sum <= 0 {
					break
				}
				ans = max(ans, i + 1)
			}
		}
		Fprintln(out, ans)
	}

}

func main() { run(os.Stdin, os.Stdout) }

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
	"sort"
)

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)

		words := make([]string, n)
		for i := 0; i < n; i++ {
			Fscan(in, &words[i])
		}
		ans := 0

		for c := 0; c < 5; c++ {
			f := make([]int, n)
			for i := 0; i < n; i++ {
				for _, letter := range words[i]	{
					if letter == rune('a' + c) {
						f[i]++

					} else {
						f[i]--
					}
				}
			}

			sort.Slice(f, func(i, j int) bool {
				return f[i] > f[j]
			})
			sum := 0
			for i := 0; i < n; i++ {
				sum += f[i]
				if sum <= 0 {
					break
				}
				ans = max(ans, i+1)
			}
		}
		Fprintln(out, ans)
	}
}

func main() { run(os.Stdin, os.Stdout) }

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
)

type Scanner struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) *Scanner {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	return &Scanner{scanner}
}

func (s *Scanner) Word() string {
	s.Scan()
	return s.Text()
}

func (s *Scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *Scanner) Int64() int64 {
	s.Scan()
	n, _ := strconv.ParseInt(s.Text(), 10, 64)
	return n
}

func (s *Scanner) Words(count int) []string {
	words := make([]string, count)
	for i := range words {
		words[i] = s.Word()
	}
	return words
}

func (s *Scanner) Ints(count int) []int {
	ints := make([]int, count)
	for i := range ints {
		ints[i] = s.Int()
	}
	return ints
}

func (s *Scanner) Int64s(count int) []int64 {
	int64s := make([]int64, count)
	for i := range int64s {
		int64s[i] = s.Int64()
	}
	return int64s
}

type word struct {
	count  map[byte]int
	length int
}

func newWord(w string) word {
	count := make(map[byte]int)
	for _, ch := range []byte(w) {
		count[ch] += 1
	}
	return word{count: count, length: len(w)}
}

func (w word) delta(ch byte) int {
	return 2*w.count[ch] - w.length
}

func solve(w []string) int {
	words := make([]word, len(w))
	for i := range w {
		words[i] = newWord(w[i])
	}

	res := 0
	for _, ch := range []byte("abcde") {
		sort.Slice(words, func(i, j int) bool {
			return words[i].delta(ch) > words[j].delta(ch)
		})

		delta := 0
		for i := range words {
			delta += words[i].delta(ch)
			if delta <= 0 {
				break
			}
			if i+1 > res {
				res = i + 1
			}
		}
	}
	return res
}

func main() {
	stdin := NewWordScanner(os.Stdin)
	tests := stdin.Int()

	for i := 0; i < tests; i += 1 {
		n := stdin.Int()
		w := stdin.Words(n)
		fmt.Println(solve(w))
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
)

type Scanner struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) *Scanner {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	return &Scanner{scanner}
}

func (s *Scanner) Word() string {
	s.Scan()
	return s.Text()
}

func (s *Scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *Scanner) Int64() int64 {
	s.Scan()
	n, _ := strconv.ParseInt(s.Text(), 10, 64)
	return n
}

func (s *Scanner) Ints(count int) []int {
	ints := make([]int, count)
	for i := range ints {
		ints[i] = s.Int()
	}
	return ints
}

func (s *Scanner) Int64s(count int) []int64 {
	int64s := make([]int64, count)
	for i := range int64s {
		int64s[i] = s.Int64()
	}
	return int64s
}

func calcDelta(word []byte, special byte) int {
	delta := 0
	for _, ch := range word {
		if ch == special {
			delta += 1
		} else {
			delta -= 1
		}
	}
	return delta
}

func score(words [][]byte, special byte) int {
	deltas := make([]int, len(words))
	for i := range words {
		deltas[i] = calcDelta(words[i], special)
	}

	sort.Slice(deltas, func(i, j int) bool {
		return deltas[i] > deltas[j]
	})

	count := 0
	delta := 0

	for i := range deltas {
		delta += deltas[i]
		if delta <= 0 {
			break
		} else {
			count += 1
		}
	}
	return count
}

func solve(words [][]byte) int {
	res := 0
	for _, ch := range []byte("abcde") {
		if attempt := score(words, ch); attempt > res {
			res = attempt
		}
	}
	return res
}

func main() {
	stdin := NewWordScanner(os.Stdin)
	tests := stdin.Int()

	for i := 0; i < tests; i += 1 {
		n := stdin.Int()
		words := make([][]byte, n)
		for j := 0; j < n; j += 1 {
			words[j] = []byte(stdin.Word())
		}
		fmt.Println(solve(words))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var test int
	fmt.Fscan(in, &test)
	for ; test > 0; test-- {
		var n int
		fmt.Fscan(in, &n)

		ar := make([]int, n)
		br := make([]int, n)
		cr := make([]int, n)
		dr := make([]int, n)
		er := make([]int, n)
		var s string
		for i := range ar {
			fmt.Fscan(in, &s)
			var ta, tb, tc, td, te, all int
			for j := range s {
				switch s[j] {
				case 'a':
					ta++
				case 'b':
					tb++
				case 'c':
					tc++
				case 'd':
					td++
				case 'e':
					te++
				}
			}
			all = ta + tb + tc + td + te
			ar[i] = ta + ta - all
			br[i] = tb + tb - all
			cr[i] = tc + tc - all
			dr[i] = td + td - all
			er[i] = te + te - all
		}

		sort.Sort(sort.Reverse(sort.IntSlice(ar)))
		sort.Sort(sort.Reverse(sort.IntSlice(br)))
		sort.Sort(sort.Reverse(sort.IntSlice(cr)))
		sort.Sort(sort.Reverse(sort.IntSlice(dr)))
		sort.Sort(sort.Reverse(sort.IntSlice(er)))

		rr := [5]int{
			count(ar),
			count(br),
			count(cr),
			count(dr),
			count(er),
		}

		max := 0
		for i := range rr {
			if rr[i] > rr[max] {
				max = i
			}
		}

		fmt.Fprintln(out, rr[max])
	}
}

func count(ar []int) int {
	c := 0
	for i := range ar {
		if t := c + ar[i]; t < 1 {
			return i
		}
		c += ar[i]
	}
	return len(ar)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

var in *bufio.Reader

type word struct {
	a, b, c, d, e int
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func calMaxWords(words []word, getDiff func(word) int) int {
	diffs := make([]int, len(words))
	for i, w := range words {
		diffs[i] = getDiff(w)
	}

	// sort.Slice(diffs, func(i, j int) bool {
	// 	return diffs[i] > diffs[j]
	// })
	sort.Sort(sort.Reverse(sort.IntSlice(diffs)))

	acc, cnt := 0, 0
	for _, di := range diffs {
		if acc+di > 0 {
			acc += di
			cnt++
			continue
		}
		break
	}
	return cnt
}

func solve() {
	var n int
	fmt.Fscan(in, &n)

	words := make([]word, n)
	for i := 0; i < n; i++ {
		var tmp string
		fmt.Fscan(in, &tmp)
		for _, ch := range tmp {
			switch ch {
			case 'a':
				words[i].a++
			case 'b':
				words[i].b++
			case 'c':
				words[i].c++
			case 'd':
				words[i].d++
			case 'e':
				words[i].e++
			default:
				panic("unknown character")
			}
		}
	}
	result := calMaxWords(words, func(w word) int {
		return w.a - (w.b + w.c + w.d + w.e)
	})
	result = max(result, calMaxWords(words, func(w word) int {
		return w.b - (w.a + w.c + w.d + w.e)
	}))
	result = max(result, calMaxWords(words, func(w word) int {
		return w.c - (w.a + w.b + w.d + w.e)
	}))
	result = max(result, calMaxWords(words, func(w word) int {
		return w.d - (w.a + w.b + w.c + w.e)
	}))
	result = max(result, calMaxWords(words, func(w word) int {
		return w.e - (w.a + w.b + w.c + w.d)
	}))
	fmt.Println(result)
}

func main() {
	in = bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(in, &t)

	for i := 0; i < t; i++ {
		solve()
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

		type e struct {
			s string
			c []int
		}

		arr := make([]e, n)
		count := make([]int, 5)
		for i := 0; i < n; i++ {
			var s string
			fmt.Fscan(in, &s)

			c := make([]int, 5)
			for _, ch := range s {
				c[ch-'a']++
				count[ch-'a']++
			}

			arr[i] = e{s, c}
		}

		// sort words by majority letter - total length
		sortFn := func(idx int) {
			sort.Slice(arr, func(i, j int) bool {
				c1 := arr[i].c[idx]
				c2 := arr[j].c[idx]
				return c1-(len(arr[i].s)-c1) > c2-(len(arr[j].s)-c2)
			})
		}

		var max int
		for i := 0; i < 5; i++ {
			sortFn(i)
			var tally int
			var x, y int
			for _, e := range arr {
				x += e.c[i]
				y += len(e.s) - e.c[i]

				if y >= x {
					break
				}
				tally++
			}

			if tally > max {
				max = tally
			}
		}
		fmt.Fprintln(out, max)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	var TC int
	fmt.Fscan(reader, &TC)

	TOKENS := []rune{'a', 'b', 'c', 'd', 'e'}

	for tc := 0; tc < TC; tc += 1 {
		var N int
		fmt.Fscan(reader, &N)

		words := make([]string, N, N)
		for i := 0; i < N; i += 1 {
			fmt.Fscan(reader, &words[i])
		}

		maxWordCnt := 0
		for _, token := range TOKENS {
			scores := make([]int, N, N)
			for i, word := range words {
				for _, r := range word {
					// debug
					// fmt.Printf("DEBUG: matching token %c vs wordchar %c\n", token, r)
					if token == r {
						scores[i] += 1
					} else {
						scores[i] -= 1
					}
				}
			}
			// debug
			// for i, word := range words {
			// 	fmt.Printf("DEBUG: token %c word %s score: %d\n", token, word, scores[i])
			// }
			sort.Ints(scores)
			sum := 0
			wordCnt := 0
			for i := len(scores)-1; i >= 0; i -= 1 {
				score := scores[i]
				if score + sum < 1 {
					break
				}
				sum += score
				wordCnt += 1
			}
			if maxWordCnt < wordCnt {
				maxWordCnt = wordCnt
			}
		}
		fmt.Printf("%d\n", maxWordCnt)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

var (
	out = bufio.NewWriter(os.Stdout)
	in  = bufio.NewReader(os.Stdin)
)

func printf(f string, a ...interface{}) {
	fmt.Fprintf(out, f, a...)
}

func main() {
	defer out.Flush()

	var (
		n, t int
	)
	fmt.Fscanf(in, "%d", &t)
	for t > 0 {
		t--
		var str [200000]string
		fmt.Fscan(in, &n)

		for i := 0; i < n; i++ {
			fmt.Fscan(in, &str[i])
		}
		cnt := 0
		for i := 0; i < 5; i++ {
			num := make([]int, n)
			for j := 0; j < n; j++ {
				ans := 0
				for k := 0; k < len(str[j]); k++ {
					if int(str[j][k]) == 97+i {
						ans++
					} else {
						ans--
					}

				}
				num[j] = ans
			}
			sort.Slice(num, func(i, j int) bool { return num[i] > num[j] })
			for j := 1; j < n; j++ {
				num[j] += num[j-1]
			}
			for j := 0; j < n; j++ {
				if num[j] <= 0 {
					if cnt < j {
						cnt = j
					}
					break
				}
				if num[j] > 0 && j+1 == n {
					cnt = n
				}
			}
		}
		printf("%d\n", cnt)

	}

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

var (
	writer  = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
)

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func _int() int {
	s := _string()
	i := 0
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int(r - '0')
	}
	return i
}

func _int64() int64 {
	s := _string()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func _string() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func main() {
	defer writer.Flush()
	for t := _int(); t > 0; t-- {
		n := _int()
		a := make([]string, n)
		for i := range a {
			a[i] = _string()
		}
		printf("%d\n", sol(n, a))
	}
}

func sol(n int, a []string) int {
	counts := make([]map[rune]int, n)
	for i := range a {
		counts[i] = makeCounts(a[i])
	}
	ret := 0
	for _, r := range []rune{'a', 'b', 'c', 'd', 'e'} {
		deltas := make([]int, n)
		for i := range counts {
			countR := counts[i][r]
			countO := counts[i][0] - counts[i][r]
			deltas[i] = countR - countO
		}
		sort.Ints(deltas)
		// printf("%v %v\n", string(r), deltas)
		cum := 0
		curr := 0
		for i := len(deltas) - 1; i >= 0; i-- {
			cum += deltas[i]
			if cum <= 0 {
				break
			}
			curr++
		}
		ret = max(ret, curr)
	}
	return ret
}

func makeCounts(w string) map[rune]int {
	ret := map[rune]int{}
	for _, r := range w {
		ret[r]++
		ret[0]++ // total
	}
	return ret
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

package main

import (
	"bufio"
	"bytes"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"sort"
	"strings"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		a := make([][]byte, n)
		cnt := make([][6]int, n)
		for i := range a {
			Fscan(in, &a[i])
			for ch := byte('a'); ch <= 'e'; ch++ {
				cnt[i][ch-'a'] = bytes.Count(a[i], []byte{ch})
			}
			cnt[i][5] = len(a[i])
		}
		ans := 0
		for k := 0; k < 5; k++ {
			sort.Slice(cnt, func(i, j int) bool {
				a, b := cnt[i], cnt[j]
				ak, ao := a[k], a[5]-a[k]
				bk, bo := b[k], b[5]-b[k]
				return ak-ao > bk-bo
			})

			s := 0
			ct := 0
			for _, c := range cnt {
				ak, ao := c[k], c[5]-c[k]
				d := ak - ao
				s += d
				if s <= 0 {
					break
				}
				ct++
			}
			ans = max(ans, ct)
		}
		Fprintln(out, ans)
	}

	T := 1
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

func main() { run(os.Stdin, os.Stdout) }
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

package main

import (
	"fmt"
	"strings"
)

var a, b, c, d, e int
var count = [5]int{0, 0, 0, 0, 0}
var values []int
var words []string

func main() {
	var (
		t, n  int
		s     string
		words []string
	)
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		a, b, c, d, e = 0, 0, 0, 0, 0
		fmt.Scanln(&n)
		for j := 0; j < n; j++ {
			fmt.Scanln(&s)
			words = append(words, s)
		}
		fmt.Println(interestingStory(words))
		words = []string{}
	}
}

func interestingStory(words []string) int {
	letter := ""
	for _, element := range words {
		count[0] += strings.Count(element, "a")
		count[1] += strings.Count(element, "b")
		count[2] += strings.Count(element, "c")
		count[3] += strings.Count(element, "d")
		count[4] += strings.Count(element, "e")
	}
	m := 0
	mInd := 0
	for i, e := range count {
		if i == 0 || e > m {
			m = e
			mInd = i
		}
	}
	switch mInd {
	case 0:
		letter = "a"
	case 1:
		letter = "b"
	case 2:
		letter = "c"
	case 3:
		letter = "d"
	case 4:
		letter = "e"
	}
	values = []int{}
	for _, element := range words {
		fillMap(element, letter)
	}
	count[0], count[1], count[2], count[3], count[4] = 0, 0, 0, 0, 0
	return countMax()
}

func countMax() int {
	count := 0
	sum := 0
	for i := len(values) - 1; i >= 0; i-- {
		sum += values[i]
		if sum > 0 {
			count++
		}
	}
	return count
}

func fillMap(word string, letter string) {
	value := 2*strings.Count(word, letter) - len(word)
	for i, e := range values {
		if len(values) == 0 {
			values = append(values, value)
			return
		}
		if e > value {
			values = append(values, 0)
			copy(values[i+1:], values[i:])
			values[i] = value
			return
		}
	}
	values = append(values, value)
}

package main

import "fmt"

type word struct {
	Num        int64
	LetterSum  int64
	LetterList map[int32]int64
}

func main() {
	var t int64
	var n int64
	_, err := fmt.Scan(&t)
	if err != nil {
		return
	}

	for i := int64(0); i < t; i++ {
		_, err = fmt.Scan(&n)
		if err != nil {
			return
		}
		var stringArray []string
		var str string
		for j := int64(0); j < n; j++ {
			_, err := fmt.Scan(&str)
			if err != nil {
				return
			}
			stringArray = append(stringArray, str)
		}
		wordsInfo := countLetters(stringArray)
		result := getResult(n, wordsInfo)
		fmt.Println(result)
	}
}

func countLetters(stringArray []string) map[string]*word {
	m := make(map[string]*word)
	for _, str := range stringArray {
		if _, ok := m[str]; ok {
			m[str].Num++
			m[str].LetterSum += int64(len(str))
		} else {
			m[str] = &word{}
			m[str].LetterList = map[int32]int64{
				'a': 0,
				'b': 0,
				'c': 0,
				'd': 0,
				'e': 0,
			}
			m[str].Num = 1
			for _, c := range str {
				m[str].LetterList[c]++
			}
			m[str].LetterSum += int64(len(str))
		}
	}

	return m
}

func getResult(n int64, wordInfo map[string]*word) int64 {
	var max int64
	for i := 'a'; i < 'f'; i++ {
		m := n
		letterNum := map[int32]int64{
			'a': 0,
			'b': 0,
			'c': 0,
			'd': 0,
			'e': 0,
		}
		var sum int64
		for _, word := range wordInfo {
			letterNum['a'] += word.Num * word.LetterList['a']
			letterNum['b'] += word.Num * word.LetterList['b']
			letterNum['c'] += word.Num * word.LetterList['c']
			letterNum['d'] += word.Num * word.LetterList['d']
			letterNum['e'] += word.Num * word.LetterList['e']
		}
		sum += letterNum['a'] + letterNum['b'] + letterNum['c'] + letterNum['d'] + letterNum['e']
		othersSum := sum - letterNum[i]
		if letterNum[i] > othersSum {
			if max < m {
				max = m
			}
		}

		for _, word := range wordInfo {
			for j := int64(0); j < word.Num; j++ {
				d := word.LetterSum/word.Num - word.LetterList[i]
				if word.LetterList[i] < d {
					letterNum[i] -= word.LetterList[i]
					othersSum -= d
					m--
				}
				if letterNum[i] > othersSum {
					if max < m {
						max = m
					}
				}
			}

		}
	}

	return max
}


In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation F1 = 1; F2 = 1; Fn = Fn - 1 + Fn - 2 (n > 2).DZY loves Fibonacci numbers very much. Today DZY gives you an array consisting of n integers: a1, a2, ..., an. Moreover, there are m queries, each query has one of the two types:  Format of the query "1 l r". In reply to the query, you need to add Fi - l + 1 to each element ai, where l ≤ i ≤ r.  Format of the query "2 l r". In reply to the query you should output the value of  modulo 1000000009 (109 + 9). Help DZY reply to all the queries.

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 300000). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — initial array a. Then, m lines follow. A single line describes a single query in the format given in the statement. It is guaranteed that for each query inequality 1 ≤ l ≤ r ≤ n holds.

For each query of the second type, print the value of the sum on a single line.

NoteAfter the first query, a = [2, 3, 5, 7].For the second query, sum = 2 + 3 + 5 + 7 = 17.After the third query, a = [2, 4, 6, 9].For the fourth query, sum = 2 + 4 + 6 = 12.

package main

import (
	"fmt"
	"bufio"
	"os"
)

const (
	mod = 1000000009
	maxn = 4*300000+5
)

var (
	t [maxn]Segment
	fib [maxn]int64
)

type Segment struct {
	x0 int64
	x1 int64
	sum int64
}

func updateS(a, b int, x0, x1 int64) {
	x0 %= mod
	x1 %= mod

	t[a+b].x0 += x0
	t[a+b].x0 %= mod
	t[a+b].x1 += x1
	t[a+b].x1 %= mod

	t[a+b].sum += x0*fib[b-a] + x1*(fib[b-a+1]-1)
	t[a+b].sum %= mod
}

func Split(a, c, b int) {
	updateS(a, c, t[a+b].x0, t[a+b].x1)
	updateS(c, b,
		t[a+b].x0 * fib[c-a-1] + t[a+b].x1 * fib[c-a],
		t[a+b].x0 * fib[c-a] + t[a+b].x1 * fib[c-a+1])
	t[a+b].x0 = 0
	t[a+b].x1 = 0
	t[a+b].sum = 0
}

func Merge(a, c, b int) {
	t[a+b].sum = 0
	t[a+b].sum += t[a+c].sum
	t[a+b].sum += t[b+c].sum
	// if t[a+b].sum >= mod { t[a+b].sum -= mod }
	t[a+b].sum %= mod
}

func query(a, b, l, r int) int64 {
	if l <= a && b <= r {
		return t[a + b].sum
	}
	c := (a + b)/2
	Split(a, c, b)
	var res int64
	if l < c { res += query(a, c, l, r) }
	if c < r { res += query(c, b, l, r) }
	Merge(a, c, b)
	// if res >= mod { res -= mod }
	res %= mod
	return res
}
func update(a, b, l, r int, i int) {
	if l <= a && b <= r {
		updateS(a, b, fib[i], fib[i+1])
		return
	}
	c := (a + b)/2
	Split(a, c, b)
	if l < c { update(a, c, l, r, i) }
	if c < r { update(c, b, l, r, i+(c-a)) }
	Merge(a, c, b)
}
func fullMerge(a, b int) {
	if a + 1 == b {
		return
	}
	c := (a+b)/2
	fullMerge(a, c)
	fullMerge(c, b)
	Merge(a, c, b)
}
func print(a, b int, pref string) {
	fmt.Println(pref, t[a+b])
	if a+1 == b {
		return
	}
	c := (a+b)/2
	print(a,c,pref+"  ")
	print(c,b,pref+"  ")
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	fib[1] = 1
	for i := 2; i < maxn; i++ {
		fib[i] = fib[i-1] + fib[i-2]
		// if fib[i] >= mod { fib[i] -= mod }
		fib[i] %= mod
	}

	var n, m int
	fmt.Fscan(in, &n, &m)

	b := 1
	for b < n {
		b *= 2
	}

	var x int64
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &x)
		t[i+i+1].sum = x
	}
	fullMerge(0, b)

	// print(0,b,"")

	var typ, l, r int
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &typ, &l, &r)
		switch typ {
		case 1:
			update(0, b, l-1, r, 1-l+1)
		case 2:
			fmt.Fprintln(out, query(0, b, l-1, r))
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func LL(n int) int { return n * 2 }
func RR(n int) int { return n*2 + 1 }

var sum, l, r, c, d []int
var f [310000]int

const MOD int = 1000000009

func InitDetail(a []int, ll, rr, n int) {
	l[n] = ll
	r[n] = rr
	c[n] = 0
	d[n] = 0
	if ll == rr {
		sum[n] = a[ll] % MOD
		return
	}

	var mid int = (ll + rr) / 2
	InitDetail(a, ll, mid, LL(n))
	InitDetail(a, mid+1, rr, RR(n))
	sum[n] = (sum[LL(n)] + sum[RR(n)]) % MOD
}

func Init(n int, a []int) {
	sum = make([]int, n*4)
	l = make([]int, n*4)
	r = make([]int, n*4)
	c = make([]int, n*4)
	d = make([]int, n*4)
	InitDetail(a, 1, n, 1)
}

func GetF(a, b, n int) int {
	if n == 1 {
		return a
	} else if n == 2 {
		return b
	} else {
		return int((int64(b)*int64(f[n-1]) + int64(a)*int64(f[n-2])) % int64(MOD))
	}
}

func GetSumF(a, b, n int) int {
	return ((GetF(a, b, n+2)-b)%MOD + MOD) % MOD
}

func Assign(a, b, length, n int) {
	// fmt.Println("Assign:", a, b, "for", l[n], r[n], "sum", GetSumF(a, b, length))
	c[n] = (c[n] + a) % MOD
	d[n] = (d[n] + b) % MOD
	sum[n] += GetSumF(a, b, length)
	sum[n] %= MOD
}

// define f(n) as fib sequeue
// define F[1] = a, F[2] = b, then F(n) = b*f(n-1) + a*f(n-2)
func Update(n int) {
	if c[n] == 0 && d[n] == 0 {
		return
	}
	var mid int = (l[n] + r[n]) / 2
	var lhalf = mid - l[n] + 1
	Assign(c[n], d[n], lhalf, LL(n))
	Assign(GetF(c[n], d[n], lhalf+1), GetF(c[n], d[n], lhalf+2), r[n]-l[n]+1-lhalf, RR(n))
	c[n] = 0
	d[n] = 0
}

func Query(ll, rr, n int) int {
	if ll == l[n] && rr == r[n] {
		return sum[n]
	}
	var mid int = (l[n] + r[n]) / 2
	var res int = 0
	Update(n)
	if rr <= mid {
		res = Query(ll, rr, LL(n))
	} else if ll > mid {
		res = Query(ll, rr, RR(n))
	} else {
		res = (Query(ll, mid, LL(n)) + Query(mid+1, rr, RR(n))) % MOD
	}
	sum[n] = (sum[LL(n)] + sum[RR(n)]) % MOD
	// fmt.Println("Query:", ll, rr, "->", res)
	return res
}

func Insert(ll, rr, n, prefix, seq_len int) {
	// fmt.Println("Interval:", l[n], r[n], "insert:", ll, rr, "seq:", prefix, seq_len)
	if l[n] == ll && r[n] == rr {
		Assign(f[prefix+1], f[prefix+2], seq_len-prefix, n)
		return
	}

	Update(n)
	var mid int = (l[n] + r[n]) / 2
	if rr <= mid {
		Insert(ll, rr, LL(n), prefix, seq_len)
	} else if mid < ll {
		Insert(ll, rr, RR(n), prefix, seq_len)
	} else {
		var l_len int = mid - ll + 1
		Insert(ll, mid, LL(n), prefix, l_len+prefix)
		Insert(mid+1, rr, RR(n), l_len+prefix, seq_len)
	}
	sum[n] = (sum[LL(n)] + sum[RR(n)]) % MOD
}

func main() {
	f[0] = 0
	f[1] = 1
	for i := 2; i < len(f); i++ {
		f[i] = (f[i-1] + f[i-2]) % MOD
	}

	reader := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscan(reader, &n, &m)

	var a []int = make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &a[i+1])
	}

	Init(n, a)
	var cmd, li, ri int
	for i := 0; i < m; i++ {
		// fmt.Println(i, "Debug info")
		fmt.Fscan(reader, &cmd, &li, &ri)
		if cmd == 2 {
			fmt.Println(Query(li, ri, 1))
		} else {
			Insert(li, ri, 1, 0, ri-li+1)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func LL(n int) int { return n * 2 }
func RR(n int) int { return n*2 + 1 }

var sum, l, r, c, d []int
var f, sumf [310000]int

const MOD int = 1000000009

func InitDetail(a []int, ll, rr, n int) {
	l[n] = ll
	r[n] = rr
	c[n] = 0
	d[n] = 0
	if ll == rr {
		sum[n] = a[ll] % MOD
		return
	}

	var mid int = (ll + rr) / 2
	InitDetail(a, ll, mid, LL(n))
	InitDetail(a, mid+1, rr, RR(n))
	sum[n] = (sum[LL(n)] + sum[RR(n)]) % MOD
}

func Init(n int, a []int) {
	sum = make([]int, n*4)
	l = make([]int, n*4)
	r = make([]int, n*4)
	c = make([]int, n*4)
	d = make([]int, n*4)
	InitDetail(a, 1, n, 1)
}

func GetF(a, b, n int) int {
	if n == 1 {
		return a
	} else if n == 2 {
		return b
	} else {
		return (b*f[n-1] + a*f[n-2]) % MOD
	}
}

func GetSumF(a, b, n int) int {
	return ((GetF(a, b, n+2)-b)%MOD + MOD) % MOD
}

func Assign(a, b, length, n int) {
	// fmt.Println("Assign:", a, b, "for", l[n], r[n])
	c[n] = (c[n] + a) % MOD
	d[n] = (d[n] + b) % MOD
	sum[n] += GetSumF(a, b, length)
}

// define f(n) as fib sequeue
// define F[1] = a, F[2] = b, then F(n) = b*f(n-1) + a*f(n-2)
func Update(n int) {
	if c[n] == 0 && d[n] == 0 {
		return
	}
	var mid int = (l[n] + r[n]) / 2
	var lhalf = mid - l[n] + 1
	Assign(c[n], d[n], lhalf, LL(n))
	Assign(GetF(c[n], d[n], lhalf+1), GetF(c[n], d[n], lhalf+2), r[n]-lhalf, RR(n))
	c[n] = 0
	d[n] = 0
}

func Query(ll, rr, n int) int {
	if ll == l[n] && rr == r[n] {
		return sum[n]
	}
	var mid int = (l[n] + r[n]) / 2
	var res int = 0
	Update(n)
	if rr <= mid {
		res = Query(ll, rr, LL(n))
	} else if ll > mid {
		res = Query(ll, rr, RR(n))
	} else {
		res = (Query(ll, mid, LL(n)) + Query(mid+1, rr, RR(n))) % MOD
	}
	// fmt.Println("Query:", ll, rr, "->", res)
	return res
}

func Insert(ll, rr, n, prefix, seq_len int) {
	// fmt.Println("Interval:", l[n], r[n], "insert:", ll, rr, "seq:", prefix, seq_len)
	if l[n] == ll && r[n] == rr {
		Assign(f[prefix+1], f[prefix+2], seq_len, n)
		return
	}

	Update(n)
	var mid int = (l[n] + r[n]) / 2
	if rr <= mid {
		Insert(ll, rr, LL(n), prefix, seq_len)
	} else if mid < ll {
		Insert(ll, rr, RR(n), prefix, seq_len)
	} else {
		var l_len int = mid - ll + 1
		Insert(ll, mid, LL(n), prefix, l_len+prefix)
		Insert(mid+1, rr, RR(n), l_len+prefix, seq_len)
	}
	sum[n] = sum[LL(n)] + sum[RR(n)]
}

func main() {
	sumf[0], f[0] = 0, 0
	sumf[1], f[1] = 1, 1
	for i := 2; i < len(f); i++ {
		f[i] = (f[i-1] + f[i-2]) % MOD
		sumf[i] = (sumf[i-1] + f[i]) % MOD
	}

	reader := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscan(reader, &n, &m)

	var a []int = make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &a[i+1])
	}

	Init(n, a)
	var cmd, li, ri int
	for i := 0; i < m; i++ {
		// fmt.Println(i, "Debug info")
		fmt.Fscan(reader, &cmd, &li, &ri)
		if cmd == 2 {
			fmt.Println(Query(li, ri, 1))
		} else {
			Insert(li, ri, 1, 0, ri-li+1)
		}
	}
}

package main

import (
	"fmt"
	"bufio"
	"os"
)

const (
	mod = 1000000009
	maxn = 4*300000+5
)

var (
	t [maxn]Segment
	fib [maxn]int64
)

type Segment struct {
	x0 int64
	x1 int64
	sum int64
}

func updateS(a, b int, x0, x1 int64) {
	t[a+b].x0 += x0
	if t[a+b].x0 >= mod { t[a+b].x0 -= mod }
	t[a+b].x1 += x1
	if t[a+b].x1 >= mod { t[a+b].x1 -= mod }

	t[a+b].sum += x0*(fib[b-a]) + x1*(fib[b-a+1]-1)
	t[a+b].sum %= mod
}

func Split(a, c, b int) {
	updateS(a, c, t[a+b].x0, t[a+b].x1)
	updateS(c, b,
		t[a+b].x0 * fib[c-a-1] + t[a+b].x1 * fib[c-a],
		t[a+b].x0 * fib[c-a] + t[a+b].x1 * fib[c-a+1])
	t[a+b].x0 = 0
	t[a+b].x1 = 0
	t[a+b].sum = 0
}

func Merge(a, c, b int) {
	t[a+b].sum = 0
	t[a+b].sum += t[a+c].sum
	t[a+b].sum += t[b+c].sum
	if t[a+b].sum >= mod { t[a+b].sum -= mod }
}

func query(a, b, l, r int) int64 {
	if l <= a && b <= r {
		return t[a + b].sum
	}
	c := (a + b)/2
	Split(a, c, b)
	var res int64
	if l < c { res += query(a, c, l, r) }
	if c < r { res += query(c, b, l, r) }
	Merge(a, c, b)
	if res >= mod { res -= mod }
	return res
}
func update(a, b, l, r int, i int) {
	if l <= a && b <= r {
		updateS(a, b, fib[i], fib[i+1])
		return
	}
	c := (a + b)/2
	Split(a, c, b)
	if l < c { update(a, c, l, r, i) }
	if c < r { update(c, b, l, r, i+(c-a)) }
	Merge(a, c, b)
}
func fullMerge(a, b int) {
	if a + 1 == b {
		return
	}
	c := (a+b)/2
	fullMerge(a, c)
	fullMerge(c, b)
	Merge(a, c, b)
}
func print(a, b int, pref string) {
	fmt.Println(pref, t[a+b])
	if a+1 == b {
		return
	}
	c := (a+b)/2
	print(a,c,pref+"  ")
	print(c,b,pref+"  ")
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	fib[1] = 1
	for i := 2; i < maxn; i++ {
		fib[i] = fib[i-1] + fib[i-2]
		if fib[i] >= mod { fib[i] -= mod }
	}

	var n, m int
	fmt.Fscan(in, &n, &m)

	b := 1
	for b < n {
		b *= 2
	}

	var x int64
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &x)
		t[i+i+1].sum = x
		// t[i+i+1].sum %= mod
		// TODO: Do we also need to update x0, x1?
		// No
	}
	fullMerge(0, b)

	// print(0,b,"")

	var typ, l, r int
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &typ, &l, &r)
		switch typ {
		case 1:
			update(0, b, l-1, r, 1-l+1)
		case 2:
			fmt.Fprintln(out, query(0, b, l-1, r))
		}
	}
}

package main

import (
	"fmt"
	"bufio"
	"os"
)

const (
	mod = 1000000009
	maxn = 4*300000+5
)

var (
	t [maxn]Segment
	fib [maxn]int64
)

type Segment struct {
	x0 int64
	x1 int64
	sum int64
}

func updateS(a, b int, x0, x1 int64) {
	t[a+b].x0 += x0
	t[a+b].x0 %= mod
	t[a+b].x1 += x1
	t[a+b].x1 %= mod

	t[a+b].sum += x0*fib[b-a] + x1*(fib[b-a+1]-1)
	t[a+b].sum %= mod
}

func Split(a, c, b int) {
	updateS(a, c, t[a+b].x0, t[a+b].x1)
	updateS(c, b,
		t[a+b].x0 * fib[c-a-1] + t[a+b].x1 * fib[c-a],
		t[a+b].x0 * fib[c-a] + t[a+b].x1 * fib[c-a+1])
	t[a+b].x0 = 0
	t[a+b].x1 = 0
	t[a+b].sum = 0
}

func Merge(a, c, b int) {
	t[a+b].sum = 0
	t[a+b].sum += t[a+c].sum
	t[a+b].sum += t[b+c].sum
	// if t[a+b].sum >= mod { t[a+b].sum -= mod }
	t[a+b].sum %= mod
}

func query(a, b, l, r int) int64 {
	if l <= a && b <= r {
		return t[a + b].sum
	}
	c := (a + b)/2
	Split(a, c, b)
	var res int64
	if l < c { res += query(a, c, l, r) }
	if c < r { res += query(c, b, l, r) }
	Merge(a, c, b)
	// if res >= mod { res -= mod }
	res %= mod
	return res
}
func update(a, b, l, r int, i int) {
	if l <= a && b <= r {
		updateS(a, b, fib[i], fib[i+1])
		return
	}
	c := (a + b)/2
	Split(a, c, b)
	if l < c { update(a, c, l, r, i) }
	if c < r { update(c, b, l, r, i+(c-a)) }
	Merge(a, c, b)
}
func fullMerge(a, b int) {
	if a + 1 == b {
		return
	}
	c := (a+b)/2
	fullMerge(a, c)
	fullMerge(c, b)
	Merge(a, c, b)
}
func print(a, b int, pref string) {
	fmt.Println(pref, t[a+b])
	if a+1 == b {
		return
	}
	c := (a+b)/2
	print(a,c,pref+"  ")
	print(c,b,pref+"  ")
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	fib[1] = 1
	for i := 2; i < maxn; i++ {
		fib[i] = fib[i-1] + fib[i-2]
		if fib[i] >= mod { fib[i] -= mod }
	}

	var n, m int
	fmt.Fscan(in, &n, &m)

	b := 1
	for b < n {
		b *= 2
	}

	var x int64
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &x)
		t[i+i+1].sum = x
	}
	fullMerge(0, b)

	// print(0,b,"")

	var typ, l, r int
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &typ, &l, &r)
		switch typ {
		case 1:
			update(0, b, l-1, r, 1-l+1)
		case 2:
			fmt.Fprintln(out, query(0, b, l-1, r))
		}
	}
}

package main

import (
	"fmt"
	"bufio"
	"os"
)

const (
	mod = 1000000009
	maxn = 4*300000+5
)

var (
	t [maxn]Segment
	fib [maxn]int64
)

type Segment struct {
	x0 int64
	x1 int64
	sum int64
}

func updateS(a, b int, x0, x1 int64) {
	x0 %= mod
	x1 %= mod

	t[a+b].x0 += x0
	t[a+b].x0 %= mod
	t[a+b].x1 += x1
	t[a+b].x1 %= mod

	t[a+b].sum += x0*(fib[b-a]) + x1*(fib[b-a+1]-1)
	t[a+b].sum %= mod
}

func Split(a, c, b int) {
	updateS(a, c, t[a+b].x0, t[a+b].x1)
	updateS(c, b,
		t[a+b].x0 * fib[c-a-1] + t[a+b].x1 * fib[c-a],
		t[a+b].x0 * fib[c-a] + t[a+b].x1 * fib[c-a+1])
	t[a+b].x0 = 0
	t[a+b].x1 = 0
	t[a+b].sum = 0
}

func Merge(a, c, b int) {
	t[a+b].sum = 0
	t[a+b].sum += t[a+c].sum
	t[a+b].sum += t[b+c].sum
	t[a+b].sum %= mod
}

func query(a, b, l, r int) int64 {
	if l <= a && b <= r {
		return t[a + b].sum
	}
	c := (a + b)/2
	Split(a, c, b)
	var res int64
	if l < c { res += query(a, c, l, r) }
	if c < r { res += query(c, b, l, r) }
	Merge(a, c, b)
	return res
}
func update(a, b, l, r int, i int) {
	if l <= a && b <= r {
		updateS(a, b, fib[i], fib[i+1])
		return
	}
	c := (a + b)/2
	Split(a, c, b)
	if l < c { update(a, c, l, r, i) }
	if c < r { update(c, b, l, r, i+(c-a)) }
	Merge(a, c, b)
}
func fullMerge(a, b int) {
	if a + 1 == b {
		return
	}
	c := (a+b)/2
	fullMerge(a, c)
	fullMerge(c, b)
	Merge(a, c, b)
}
func print(a, b int, pref string) {
	fmt.Println(pref, t[a+b])
	if a+1 == b {
		return
	}
	c := (a+b)/2
	print(a,c,pref+"  ")
	print(c,b,pref+"  ")
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	fib[1] = 1
	for i := 2; i < maxn; i++ {
		fib[i] = fib[i-1] + fib[i-2]
		fib[i] %= mod
	}

	var n, m int
	fmt.Fscan(in, &n, &m)

	b := 1
	for b < n {
		b *= 2
	}

	var x int64
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &x)
		t[i+i+1].sum = x
		// TODO: Do we also need to update x0, x1?
	}
	fullMerge(0, b)

	// print(0,b,"")

	var typ, l, r int
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &typ, &l, &r)
		if typ == 1 {
			// fmt.Println("Update")
			update(0, b, l-1, r, 1-l+1)
			// print(0,b,"")
		} else {
			// fmt.Println("Query")
			fmt.Fprintln(out, query(0, b, l-1, r))
			// print(0,b,"")
		}
	}
}

package main

import (
	"fmt"
	"bufio"
	"os"
)

const (
	mod = 1000000009
	maxn = 4*300000+5
)

var (
	t [maxn]Segment
	fib [maxn]int64
)

type Segment struct {
	x0 int64
	x1 int64
	sum int64
}

func updateS(a, b int, x0, x1 int64) {
	t[a+b].x0 += x0
	t[a+b].x0 %= mod
	t[a+b].x1 += x1
	t[a+b].x1 %= mod

	t[a+b].sum += x0*fib[b-a] + x1*(fib[b-a+1]-1)
	t[a+b].sum %= mod
}

func Split(a, c, b int) {
	updateS(a, c, t[a+b].x0, t[a+b].x1)
	updateS(c, b,
		t[a+b].x0 * fib[c-a-1] + t[a+b].x1 * fib[c-a],
		t[a+b].x0 * fib[c-a] + t[a+b].x1 * fib[c-a+1])
	t[a+b].x0 = 0
	t[a+b].x1 = 0
	t[a+b].sum = 0
}

func Merge(a, c, b int) {
	t[a+b].sum = 0
	t[a+b].sum += t[a+c].sum
	t[a+b].sum += t[b+c].sum
	if t[a+b].sum >= mod { t[a+b].sum -= mod }
}

func query(a, b, l, r int) int64 {
	if l <= a && b <= r {
		return t[a + b].sum
	}
	c := (a + b)/2
	Split(a, c, b)
	var res int64
	if l < c { res += query(a, c, l, r) }
	if c < r { res += query(c, b, l, r) }
	Merge(a, c, b)
	// if res >= mod { res -= mod }
	res %= mod
	return res
}
func update(a, b, l, r int, i int) {
	if l <= a && b <= r {
		updateS(a, b, fib[i], fib[i+1])
		return
	}
	c := (a + b)/2
	Split(a, c, b)
	if l < c { update(a, c, l, r, i) }
	if c < r { update(c, b, l, r, i+(c-a)) }
	Merge(a, c, b)
}
func fullMerge(a, b int) {
	if a + 1 == b {
		return
	}
	c := (a+b)/2
	fullMerge(a, c)
	fullMerge(c, b)
	Merge(a, c, b)
}
func print(a, b int, pref string) {
	fmt.Println(pref, t[a+b])
	if a+1 == b {
		return
	}
	c := (a+b)/2
	print(a,c,pref+"  ")
	print(c,b,pref+"  ")
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	fib[1] = 1
	for i := 2; i < maxn; i++ {
		fib[i] = fib[i-1] + fib[i-2]
		if fib[i] >= mod { fib[i] -= mod }
	}

	var n, m int
	fmt.Fscan(in, &n, &m)

	b := 1
	for b < n {
		b *= 2
	}

	var x int64
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &x)
		t[i+i+1].sum = x
	}
	fullMerge(0, b)

	// print(0,b,"")

	var typ, l, r int
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &typ, &l, &r)
		switch typ {
		case 1:
			update(0, b, l-1, r, 1-l+1)
		case 2:
			fmt.Fprintln(out, query(0, b, l-1, r))
		}
	}
}

package main

import (
	"fmt"
	"bufio"
	"os"
)

const (
	mod = 1000000009
	maxn = 4*300000+5
)

var (
	t [maxn]Segment
	fib [maxn]int64
)

type Segment struct {
	x0 int64
	x1 int64
	sum int64
}

func updateS(a, b int, x0, x1 int64) {
	t[a+b].x0 += x0
	t[a+b].x0 %= mod
	t[a+b].x1 += x1
	t[a+b].x1 %= mod

	t[a+b].sum += x0*fib[b-a] + x1*(fib[b-a+1]-1)
	t[a+b].sum %= mod
}

func Split(a, c, b int) {
	updateS(a, c, t[a+b].x0, t[a+b].x1)
	updateS(c, b,
		t[a+b].x0 * fib[c-a-1] + t[a+b].x1 * fib[c-a],
		t[a+b].x0 * fib[c-a] + t[a+b].x1 * fib[c-a+1])
	t[a+b].x0 = 0
	t[a+b].x1 = 0
	t[a+b].sum = 0
}

func Merge(a, c, b int) {
	t[a+b].sum = 0
	t[a+b].sum += t[a+c].sum
	t[a+b].sum += t[b+c].sum
	if t[a+b].sum >= mod { t[a+b].sum -= mod }
}

func query(a, b, l, r int) int64 {
	if l <= a && b <= r {
		return t[a + b].sum
	}
	c := (a + b)/2
	Split(a, c, b)
	var res int64
	if l < c { res += query(a, c, l, r) }
	if c < r { res += query(c, b, l, r) }
	Merge(a, c, b)
	if res >= mod { res -= mod }
	return res
}
func update(a, b, l, r int, i int) {
	if l <= a && b <= r {
		updateS(a, b, fib[i], fib[i+1])
		return
	}
	c := (a + b)/2
	Split(a, c, b)
	if l < c { update(a, c, l, r, i) }
	if c < r { update(c, b, l, r, i+(c-a)) }
	Merge(a, c, b)
}
func fullMerge(a, b int) {
	if a + 1 == b {
		return
	}
	c := (a+b)/2
	fullMerge(a, c)
	fullMerge(c, b)
	Merge(a, c, b)
}
func print(a, b int, pref string) {
	fmt.Println(pref, t[a+b])
	if a+1 == b {
		return
	}
	c := (a+b)/2
	print(a,c,pref+"  ")
	print(c,b,pref+"  ")
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	fib[1] = 1
	for i := 2; i < maxn; i++ {
		fib[i] = fib[i-1] + fib[i-2]
		if fib[i] >= mod { fib[i] -= mod }
	}

	var n, m int
	fmt.Fscan(in, &n, &m)

	b := 1
	for b < n {
		b *= 2
	}

	var x int64
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &x)
		t[i+i+1].sum = x
	}
	fullMerge(0, b)

	// print(0,b,"")

	var typ, l, r int
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &typ, &l, &r)
		switch typ {
		case 1:
			update(0, b, l-1, r, 1-l+1)
		case 2:
			fmt.Fprintln(out, query(0, b, l-1, r))
		}
	}
}

package main

import (
	"fmt"
	"bufio"
	"os"
)

const (
	mod = 1000000009
	maxn = 4*300000+5
)

var (
	t [maxn]Segment
	fib [maxn]int64
)

type Segment struct {
	x0 int64
	x1 int64
	sum int64
}

func updateS(a, b int, x0, x1 int64) {
	t[a+b].x0 += x0
	t[a+b].x0 %= mod
	t[a+b].x1 += x1
	t[a+b].x1 %= mod

	t[a+b].sum += x0*fib[b-a] + x1*(fib[b-a+1]-1)
	t[a+b].sum %= mod
}

func Split(a, c, b int) {
	updateS(a, c, t[a+b].x0, t[a+b].x1)
	updateS(c, b,
		t[a+b].x0 * fib[c-a-1] + t[a+b].x1 * fib[c-a],
		t[a+b].x0 * fib[c-a] + t[a+b].x1 * fib[c-a+1])
	t[a+b].x0 = 0
	t[a+b].x1 = 0
	t[a+b].sum = 0
}

func Merge(a, c, b int) {
	t[a+b].sum = 0
	t[a+b].sum += t[a+c].sum
	t[a+b].sum += t[b+c].sum
	// if t[a+b].sum >= mod { t[a+b].sum -= mod }
	t[a+b].sum %= mod
}

func query(a, b, l, r int) int64 {
	if l <= a && b <= r {
		return t[a + b].sum
	}
	c := (a + b)/2
	Split(a, c, b)
	var res int64
	if l < c { res += query(a, c, l, r) }
	if c < r { res += query(c, b, l, r) }
	Merge(a, c, b)
	// if res >= mod { res -= mod }
	res %= mod
	return res
}
func update(a, b, l, r int, i int) {
	if l <= a && b <= r {
		updateS(a, b, fib[i], fib[i+1])
		return
	}
	c := (a + b)/2
	Split(a, c, b)
	if l < c { update(a, c, l, r, i) }
	if c < r { update(c, b, l, r, i+(c-a)) }
	Merge(a, c, b)
}
func fullMerge(a, b int) {
	if a + 1 == b {
		return
	}
	c := (a+b)/2
	fullMerge(a, c)
	fullMerge(c, b)
	Merge(a, c, b)
}
func print(a, b int, pref string) {
	fmt.Println(pref, t[a+b])
	if a+1 == b {
		return
	}
	c := (a+b)/2
	print(a,c,pref+"  ")
	print(c,b,pref+"  ")
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	fib[1] = 1
	for i := 2; i < maxn; i++ {
		fib[i] = fib[i-1] + fib[i-2]
		// if fib[i] >= mod { fib[i] -= mod }
		fib[i] %= mod
	}

	var n, m int
	fmt.Fscan(in, &n, &m)

	b := 1
	for b < n {
		b *= 2
	}

	var x int64
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &x)
		t[i+i+1].sum = x
	}
	fullMerge(0, b)

	// print(0,b,"")

	var typ, l, r int
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &typ, &l, &r)
		switch typ {
		case 1:
			update(0, b, l-1, r, 1-l+1)
		case 2:
			fmt.Fprintln(out, query(0, b, l-1, r))
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func LL(n int) int { return n * 2 }
func RR(n int) int { return n*2 + 1 }

var sum, l, r, length, prev []int
var f, sumf [310000]int

const MOD int = 1000000009

func InitDetail(a []int, ll, rr, n int) {
	l[n] = ll
	r[n] = rr
	length[n] = 0
	prev[n] = -1
	sum[n] = 0
	if ll == rr {
		sum[n] = a[ll]
		return
	}

	var mid int = (ll + rr) / 2
	InitDetail(a, ll, mid, LL(n))
	InitDetail(a, mid+1, rr, RR(n))
	sum[n] = (sum[LL(n)] + sum[RR(n)]) % MOD
}

func Init(n int, a []int) {
	sum = make([]int, n*4)
	l = make([]int, n*4)
	r = make([]int, n*4)
	length = make([]int, n*4)
	prev = make([]int, n*4)
	InitDetail(a, 1, n, 1)
}

func Assign(n, prefix, seq_len int) {
	prev[n] = prefix
	length[n] = seq_len
	// fmt.Println(l[n], r[n], "+", sumf[seq_len]-sumf[prefix])
	sum[n] += sumf[seq_len] - sumf[prefix]
	sum[n] = (sum[n] + MOD) % MOD
}

func Update(n int) {
	if prev[n] == -1 || l[n] == r[n] {
		return
	}
	var mid int = (l[n] + r[n]) / 2
	Update(LL(n))
	Update(RR(n))
	Assign(LL(n), prev[n], prev[n]+mid-l[n]+1)
	Assign(RR(n), prev[n]+mid-l[n]+1, length[n])
	prev[n] = -1
}

func Query(ll, rr, n int) int {
	if ll == l[n] && rr == r[n] {
		return sum[n]
	}
	var mid int = (l[n] + r[n]) / 2
	var res int = 0
	Update(n)
	if rr <= mid {
		res = Query(ll, rr, LL(n))
	} else if ll > mid {
		res = Query(ll, rr, RR(n))
	} else {
		res = (Query(ll, mid, LL(n)) + Query(mid+1, rr, RR(n))) % MOD
	}
	// fmt.Println("Query:", ll, rr, "->", res)
	return res
}

func Insert(ll, rr, n, prefix, seq_len int) {
	// fmt.Println("Interval:", l[n], r[n], "insert:", ll, rr, "seq:", prefix, seq_len)
	if l[n] == ll && r[n] == rr {
		Update(n)
		Assign(n, prefix, seq_len)
		return
	}
	sum[n] += sumf[seq_len] - sumf[prefix]
	sum[n] = (sum[n] + MOD) % MOD
	Update(n)
	var mid int = (l[n] + r[n]) / 2
	if rr <= mid {
		Insert(ll, rr, LL(n), prefix, seq_len)
	} else if mid < ll {
		Insert(ll, rr, RR(n), prefix, seq_len)
	} else {
		var l_len int = mid - ll + 1
		Insert(ll, mid, LL(n), prefix, l_len+prefix)
		Insert(mid+1, rr, RR(n), l_len, seq_len)
	}
}

func main() {
	sumf[0], f[0] = 0, 0
	sumf[1], f[1] = 1, 1
	for i := 2; i < len(f); i++ {
		f[i] = (f[i-1] + f[i-2]) % MOD
		sumf[i] = (sumf[i-1] + f[i]) % MOD
	}

	reader := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscan(reader, &n, &m)

	var a []int = make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &a[i+1])
	}

	Init(n, a)
	var cmd, li, ri int
	for i := 0; i < m; i++ {
		fmt.Fscan(reader, &cmd, &li, &ri)
		if cmd == 2 {
			fmt.Println(Query(li, ri, 1))
		} else {
			Insert(li, ri, 1, 0, ri-li+1)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func LL(n int) int { return n * 2 }
func RR(n int) int { return n*2 + 1 }

var sum, l, r, c, d []int
var f [310000]int

const MOD int = 1000000009

func InitDetail(a []int, ll, rr, n int) {
	l[n] = ll
	r[n] = rr
	c[n] = 0
	d[n] = 0
	if ll == rr {
		sum[n] = a[ll] % MOD
		return
	}

	var mid int = (ll + rr) / 2
	InitDetail(a, ll, mid, LL(n))
	InitDetail(a, mid+1, rr, RR(n))
	sum[n] = (sum[LL(n)] + sum[RR(n)]) % MOD
}

func Init(n int, a []int) {
	sum = make([]int, n*4)
	l = make([]int, n*4)
	r = make([]int, n*4)
	c = make([]int, n*4)
	d = make([]int, n*4)
	InitDetail(a, 1, n, 1)
}

func GetF(a, b, n int) int {
	if n == 1 {
		return a
	} else if n == 2 {
		return b
	} else {
		return (b*f[n-1] + a*f[n-2]) % MOD
	}
}

func GetSumF(a, b, n int) int {
	return ((GetF(a, b, n+2)-b)%MOD + MOD) % MOD
}

func Assign(a, b, length, n int) {
	// fmt.Println("Assign:", a, b, "for", l[n], r[n], "sum", GetSumF(a, b, length))
	c[n] = (c[n] + a) % MOD
	d[n] = (d[n] + b) % MOD
	sum[n] += GetSumF(a, b, length)
}

// define f(n) as fib sequeue
// define F[1] = a, F[2] = b, then F(n) = b*f(n-1) + a*f(n-2)
func Update(n int) {
	if c[n] == 0 && d[n] == 0 {
		return
	}
	var mid int = (l[n] + r[n]) / 2
	var lhalf = mid - l[n] + 1
	Assign(c[n], d[n], lhalf, LL(n))
	Assign(GetF(c[n], d[n], lhalf+1), GetF(c[n], d[n], lhalf+2), r[n]-l[n]+1-lhalf, RR(n))
	c[n] = 0
	d[n] = 0
}

func Query(ll, rr, n int) int {
	if ll == l[n] && rr == r[n] {
		return sum[n]
	}
	var mid int = (l[n] + r[n]) / 2
	var res int = 0
	Update(n)
	if rr <= mid {
		res = Query(ll, rr, LL(n))
	} else if ll > mid {
		res = Query(ll, rr, RR(n))
	} else {
		res = (Query(ll, mid, LL(n)) + Query(mid+1, rr, RR(n))) % MOD
	}
	sum[n] = sum[LL(n)] + sum[RR(n)]
	// fmt.Println("Query:", ll, rr, "->", res)
	return res
}

func Insert(ll, rr, n, prefix, seq_len int) {
	// fmt.Println("Interval:", l[n], r[n], "insert:", ll, rr, "seq:", prefix, seq_len)
	if l[n] == ll && r[n] == rr {
		Assign(f[prefix+1], f[prefix+2], seq_len-prefix, n)
		return
	}

	Update(n)
	var mid int = (l[n] + r[n]) / 2
	if rr <= mid {
		Insert(ll, rr, LL(n), prefix, seq_len)
	} else if mid < ll {
		Insert(ll, rr, RR(n), prefix, seq_len)
	} else {
		var l_len int = mid - ll + 1
		Insert(ll, mid, LL(n), prefix, l_len+prefix)
		Insert(mid+1, rr, RR(n), l_len+prefix, seq_len)
	}
	sum[n] = sum[LL(n)] + sum[RR(n)]
}

func main() {
	f[0] = 0
	f[1] = 1
	for i := 2; i < len(f); i++ {
		f[i] = (f[i-1] + f[i-2]) % MOD
	}

	reader := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscan(reader, &n, &m)

	var a []int = make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &a[i+1])
	}

	Init(n, a)
	var cmd, li, ri int
	for i := 0; i < m; i++ {
		// fmt.Println(i, "Debug info")
		fmt.Fscan(reader, &cmd, &li, &ri)
		if cmd == 2 {
			fmt.Println(Query(li, ri, 1))
		} else {
			Insert(li, ri, 1, 0, ri-li+1)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func LL(n int) int { return n * 2 }
func RR(n int) int { return n*2 + 1 }

var sum, l, r, length, prev []int
var f, sumf [310000]int

const MOD int = 1000000009

func InitDetail(a []int, ll, rr, n int) {
	l[n] = ll
	r[n] = rr
	length[n] = 0
	prev[n] = -1
	sum[n] = 0
	if ll == rr {
		sum[n] = a[ll] % MOD
		return
	}

	var mid int = (ll + rr) / 2
	InitDetail(a, ll, mid, LL(n))
	InitDetail(a, mid+1, rr, RR(n))
	sum[n] = (sum[LL(n)] + sum[RR(n)]) % MOD
}

func Init(n int, a []int) {
	sum = make([]int, n*4)
	l = make([]int, n*4)
	r = make([]int, n*4)
	length = make([]int, n*4)
	prev = make([]int, n*4)
	InitDetail(a, 1, n, 1)
}

func Assign(n, prefix, seq_len int) {
	prev[n] = prefix
	length[n] = seq_len
	// fmt.Println(l[n], r[n], "+", sumf[seq_len]-sumf[prefix])
	sum[n] += ((sumf[seq_len]-sumf[prefix])%MOD + MOD) % MOD
	sum[n] = (sum[n] + MOD) % MOD
}

func Update(n int) {
	if prev[n] == -1 || l[n] == r[n] {
		return
	}
	var mid int = (l[n] + r[n]) / 2
	Update(LL(n))
	Update(RR(n))
	Assign(LL(n), prev[n], prev[n]+mid-l[n]+1)
	Assign(RR(n), prev[n]+mid-l[n]+1, length[n])
	prev[n] = -1
}

func Query(ll, rr, n int) int {
	if ll == l[n] && rr == r[n] {
		return sum[n]
	}
	var mid int = (l[n] + r[n]) / 2
	var res int = 0
	Update(n)
	if rr <= mid {
		res = Query(ll, rr, LL(n))
	} else if ll > mid {
		res = Query(ll, rr, RR(n))
	} else {
		res = (Query(ll, mid, LL(n)) + Query(mid+1, rr, RR(n))) % MOD
	}
	// fmt.Println("Query:", ll, rr, "->", res)
	return res
}

func Insert(ll, rr, n, prefix, seq_len int) {
	// fmt.Println("Interval:", l[n], r[n], "insert:", ll, rr, "seq:", prefix, seq_len)
	if l[n] == ll && r[n] == rr {
		Update(n)
		Assign(n, prefix, seq_len)
		return
	}
	sum[n] += ((sumf[seq_len]-sumf[prefix])%MOD + MOD) % MOD
	sum[n] = (sum[n] + MOD) % MOD
	Update(n)
	var mid int = (l[n] + r[n]) / 2
	if rr <= mid {
		Insert(ll, rr, LL(n), prefix, seq_len)
	} else if mid < ll {
		Insert(ll, rr, RR(n), prefix, seq_len)
	} else {
		var l_len int = mid - ll + 1
		Insert(ll, mid, LL(n), prefix, l_len+prefix)
		Insert(mid+1, rr, RR(n), l_len, seq_len)
	}
}

func main() {
	sumf[0], f[0] = 0, 0
	sumf[1], f[1] = 1, 1
	for i := 2; i < len(f); i++ {
		f[i] = (f[i-1] + f[i-2]) % MOD
		sumf[i] = (sumf[i-1] + f[i]) % MOD
	}

	reader := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscan(reader, &n, &m)

	var a []int = make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &a[i+1])
	}

	Init(n, a)
	var cmd, li, ri int
	for i := 0; i < m; i++ {
		fmt.Fscan(reader, &cmd, &li, &ri)
		if cmd == 2 {
			fmt.Println(Query(li, ri, 1))
		} else {
			Insert(li, ri, 1, 0, ri-li+1)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func LL(n int) int { return n * 2 }
func RR(n int) int { return n*2 + 1 }

var sum, l, r, length, prev []int
var f, sumf [310000]int

const MOD int = 1000000009

func InitDetail(a []int, ll, rr, n int) {
	l[n] = ll
	r[n] = rr
	length[n] = 0
	prev[n] = -1
	sum[n] = 0
	if ll == rr {
		sum[n] = a[ll] % MOD
		return
	}

	var mid int = (ll + rr) / 2
	InitDetail(a, ll, mid, LL(n))
	InitDetail(a, mid+1, rr, RR(n))
	sum[n] = (sum[LL(n)] + sum[RR(n)]) % MOD
}

func Init(n int, a []int) {
	sum = make([]int, n*4)
	l = make([]int, n*4)
	r = make([]int, n*4)
	length = make([]int, n*4)
	prev = make([]int, n*4)
	InitDetail(a, 1, n, 1)
}

func Assign(n, prefix, seq_len int) {
	prev[n] = prefix
	length[n] = seq_len
	// fmt.Println(l[n], r[n], "+", sumf[seq_len]-sumf[prefix])
	sum[n] += ((sumf[seq_len]-sumf[prefix])%MOD + MOD) % MOD
	sum[n] = (sum[n] + MOD) % MOD
}

func Update(n int) {
	if prev[n] == -1 || l[n] == r[n] {
		return
	}
	var mid int = (l[n] + r[n]) / 2
	Update(LL(n))
	Update(RR(n))
	Assign(LL(n), prev[n], prev[n]+mid-l[n]+1)
	Assign(RR(n), prev[n]+mid-l[n]+1, length[n])
	prev[n] = -1
}

func Query(ll, rr, n int) int {
	if ll == l[n] && rr == r[n] {
		return sum[n]
	}
	var mid int = (l[n] + r[n]) / 2
	var res int = 0
	Update(n)
	if rr <= mid {
		res = Query(ll, rr, LL(n))
	} else if ll > mid {
		res = Query(ll, rr, RR(n))
	} else {
		res = (Query(ll, mid, LL(n)) + Query(mid+1, rr, RR(n))) % MOD
	}
	// fmt.Println("Query:", ll, rr, "->", res)
	return res
}

func Insert(ll, rr, n, prefix, seq_len int) {
	// fmt.Println("Interval:", l[n], r[n], "insert:", ll, rr, "seq:", prefix, seq_len)
	if l[n] == ll && r[n] == rr {
		Update(n)
		Assign(n, prefix, seq_len)
		return
	}
	sum[n] += ((sumf[seq_len]-sumf[prefix])%MOD + MOD) % MOD
	sum[n] = (sum[n] + MOD) % MOD
	Update(n)
	var mid int = (l[n] + r[n]) / 2
	if rr <= mid {
		Insert(ll, rr, LL(n), prefix, seq_len)
	} else if mid < ll {
		Insert(ll, rr, RR(n), prefix, seq_len)
	} else {
		var l_len int = mid - ll + 1
		Insert(ll, mid, LL(n), prefix, l_len+prefix)
		Insert(mid+1, rr, RR(n), l_len+prefix, seq_len)
	}
}

func main() {
	sumf[0], f[0] = 0, 0
	sumf[1], f[1] = 1, 1
	for i := 2; i < len(f); i++ {
		f[i] = (f[i-1] + f[i-2]) % MOD
		sumf[i] = (sumf[i-1] + f[i]) % MOD
	}

	reader := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscan(reader, &n, &m)

	var a []int = make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &a[i+1])
	}

	Init(n, a)
	var cmd, li, ri int
	for i := 0; i < m; i++ {
		// fmt.Println(i, "Debug info")
		fmt.Fscan(reader, &cmd, &li, &ri)
		if cmd == 2 {
			fmt.Println(Query(li, ri, 1))
		} else {
			Insert(li, ri, 1, 0, ri-li+1)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func LL(n int) int { return n * 2 }
func RR(n int) int { return n*2 + 1 }

var sum, l, r, length, prev []int
var f, sumf [310000]int

const MOD int = 1000000009

func InitDetail(a []int, ll, rr, n int) {
	l[n] = ll
	r[n] = rr
	length[n] = 0
	prev[n] = -1
	sum[n] = 0
	if ll == rr {
		sum[n] = a[ll]
		return
	}

	var mid int = (ll + rr) / 2
	InitDetail(a, ll, mid, LL(n))
	InitDetail(a, mid+1, rr, RR(n))
	sum[n] = (sum[LL(n)] + sum[RR(n)]) % MOD
}

func Init(n int, a []int) {
	sum = make([]int, n*4)
	l = make([]int, n*4)
	r = make([]int, n*4)
	length = make([]int, n*4)
	prev = make([]int, n*4)
	InitDetail(a, 1, n, 1)
}

func Assign(n, prefix, seq_len int) {
	prev[n] = prefix
	length[n] = seq_len
	// fmt.Println(l[n], r[n], "+", sumf[seq_len]-sumf[prefix])
	sum[n] += sumf[seq_len] - sumf[prefix]
}

func Update(n int) {
	if prev[n] == -1 || l[n] == r[n] {
		return
	}
	var mid int = (l[n] + r[n]) / 2
	Update(LL(n))
	Update(RR(n))
	Assign(LL(n), prev[n], prev[n]+mid-l[n]+1)
	Assign(RR(n), prev[n]+mid-l[n]+1, length[n])
	prev[n] = -1
}

func Query(ll, rr, n int) int {
	if ll == l[n] && rr == r[n] {
		return sum[n]
	}
	var mid = (l[n] + r[n]) / 2
	var res = 0
	Update(n)
	if rr <= mid {
		res = Query(ll, rr, LL(n))
	} else if ll > mid {
		res = Query(ll, rr, RR(n))
	} else {
		res = (Query(ll, mid, LL(n)) + Query(mid+1, rr, RR(n))) % MOD
	}
	// fmt.Println("Query:", ll, rr, "->", res)
	return res
}

func Insert(ll, rr, n, prefix, seq_len int) {
	// fmt.Println("Interval:", l[n], r[n], "insert:", ll, rr, "seq:", prefix, seq_len)
	if l[n] == ll && r[n] == rr {
		Update(n)
		Assign(n, prefix, seq_len)
		return
	}
	sum[n] += sumf[seq_len] - sumf[prefix]
	Update(n)
	var mid int = (l[n] + r[n]) / 2
	if rr <= mid {
		Insert(ll, rr, LL(n), prefix, seq_len)
	} else if mid < ll {
		Insert(ll, rr, RR(n), prefix, seq_len)
	} else {
		var l_len int = mid - ll + 1
		Insert(ll, mid, LL(n), prefix, l_len)
		Insert(mid+1, rr, RR(n), l_len, seq_len)
	}
}

func main() {
	sumf[0], f[0] = 0, 0
	sumf[1], f[1] = 1, 1
	for i := 2; i < len(f); i++ {
		f[i] = (f[i-1] + f[i-2]) % MOD
		sumf[i] = sumf[i-1] + f[i]
	}

	reader := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscan(reader, &n, &m)

	var a []int = make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &a[i+1])
	}

	Init(n, a)
	var cmd, li, ri int
	for i := 0; i < m; i++ {
		fmt.Fscan(reader, &cmd, &li, &ri)
		if cmd == 2 {
			fmt.Println(Query(li, ri, 1))
		} else {
			Insert(li, ri, 1, 0, ri-li+1)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func LL(n int) int { return n * 2 }
func RR(n int) int { return n*2 + 1 }

var sum, l, r, c, d []int
var f [310000]int

const MOD int = 1000000009

func InitDetail(a []int, ll, rr, n int) {
	l[n] = ll
	r[n] = rr
	c[n] = 0
	d[n] = 0
	if ll == rr {
		sum[n] = a[ll] % MOD
		return
	}

	var mid int = (ll + rr) / 2
	InitDetail(a, ll, mid, LL(n))
	InitDetail(a, mid+1, rr, RR(n))
	sum[n] = (sum[LL(n)] + sum[RR(n)]) % MOD
}

func Init(n int, a []int) {
	sum = make([]int, n*4)
	l = make([]int, n*4)
	r = make([]int, n*4)
	c = make([]int, n*4)
	d = make([]int, n*4)
	InitDetail(a, 1, n, 1)
}

func GetF(a, b, n int) int {
	if n == 1 {
		return a
	} else if n == 2 {
		return b
	} else {
		return int((int64(b)*int64(f[n-1]) + int64(a)*int64(f[n-2])) % int64(MOD))
	}
}

func GetSumF(a, b, n int) int {
	return ((GetF(a, b, n+2)-b)%MOD + MOD) % MOD
}

func Assign(a, b, length, n int) {
	// fmt.Println("Assign:", a, b, "for", l[n], r[n], "sum", GetSumF(a, b, length))
	c[n] = (c[n] + a) % MOD
	d[n] = (d[n] + b) % MOD
	sum[n] += GetSumF(a, b, length)
}

// define f(n) as fib sequeue
// define F[1] = a, F[2] = b, then F(n) = b*f(n-1) + a*f(n-2)
func Update(n int) {
	if c[n] == 0 && d[n] == 0 {
		return
	}
	var mid int = (l[n] + r[n]) / 2
	var lhalf = mid - l[n] + 1
	Assign(c[n], d[n], lhalf, LL(n))
	Assign(GetF(c[n], d[n], lhalf+1), GetF(c[n], d[n], lhalf+2), r[n]-l[n]+1-lhalf, RR(n))
	c[n] = 0
	d[n] = 0
}

func Query(ll, rr, n int) int {
	if ll == l[n] && rr == r[n] {
		return sum[n]
	}
	var mid int = (l[n] + r[n]) / 2
	var res int = 0
	Update(n)
	if rr <= mid {
		res = Query(ll, rr, LL(n))
	} else if ll > mid {
		res = Query(ll, rr, RR(n))
	} else {
		res = (Query(ll, mid, LL(n)) + Query(mid+1, rr, RR(n))) % MOD
	}
	sum[n] = (sum[LL(n)] + sum[RR(n)]) % MOD
	// fmt.Println("Query:", ll, rr, "->", res)
	return res
}

func Insert(ll, rr, n, prefix, seq_len int) {
	// fmt.Println("Interval:", l[n], r[n], "insert:", ll, rr, "seq:", prefix, seq_len)
	if l[n] == ll && r[n] == rr {
		Assign(f[prefix+1], f[prefix+2], seq_len-prefix, n)
		return
	}

	Update(n)
	var mid int = (l[n] + r[n]) / 2
	if rr <= mid {
		Insert(ll, rr, LL(n), prefix, seq_len)
	} else if mid < ll {
		Insert(ll, rr, RR(n), prefix, seq_len)
	} else {
		var l_len int = mid - ll + 1
		Insert(ll, mid, LL(n), prefix, l_len+prefix)
		Insert(mid+1, rr, RR(n), l_len+prefix, seq_len)
	}
	sum[n] = (sum[LL(n)] + sum[RR(n)]) % MOD
}

func main() {
	f[0] = 0
	f[1] = 1
	for i := 2; i < len(f); i++ {
		f[i] = (f[i-1] + f[i-2]) % MOD
	}

	reader := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscan(reader, &n, &m)

	var a []int = make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &a[i+1])
	}

	Init(n, a)
	var cmd, li, ri int
	for i := 0; i < m; i++ {
		// fmt.Println(i, "Debug info")
		fmt.Fscan(reader, &cmd, &li, &ri)
		if cmd == 2 {
			fmt.Println(Query(li, ri, 1))
		} else {
			Insert(li, ri, 1, 0, ri-li+1)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func LL(n int) int { return n * 2 }
func RR(n int) int { return n*2 + 1 }

var sum, l, r, c, d []int
var f [310000]int

const MOD int = 1000000009

func InitDetail(a []int, ll, rr, n int) {
	l[n] = ll
	r[n] = rr
	c[n] = 0
	d[n] = 0
	if ll == rr {
		sum[n] = a[ll] % MOD
		return
	}

	var mid int = (ll + rr) / 2
	InitDetail(a, ll, mid, LL(n))
	InitDetail(a, mid+1, rr, RR(n))
	sum[n] = (sum[LL(n)] + sum[RR(n)]) % MOD
}

func Init(n int, a []int) {
	sum = make([]int, n*4)
	l = make([]int, n*4)
	r = make([]int, n*4)
	c = make([]int, n*4)
	d = make([]int, n*4)
	InitDetail(a, 1, n, 1)
}

func GetF(a, b, n int) int {
	if n == 1 {
		return a
	} else if n == 2 {
		return b
	} else {
		return int((int64(b)*int64(f[n-1]) + int64(a)*int64(f[n-2])) % int64(MOD))
	}
}

func GetSumF(a, b, n int) int {
	return ((GetF(a, b, n+2)-b)%MOD + MOD) % MOD
}

func Assign(a, b, length, n int) {
	// fmt.Println("Assign:", a, b, "for", l[n], r[n], "sum", GetSumF(a, b, length))
	c[n] = (c[n] + a) % MOD
	d[n] = (d[n] + b) % MOD
	sum[n] += GetSumF(a, b, length)
}

// define f(n) as fib sequeue
// define F[1] = a, F[2] = b, then F(n) = b*f(n-1) + a*f(n-2)
func Update(n int) {
	if c[n] == 0 && d[n] == 0 {
		return
	}
	var mid int = (l[n] + r[n]) / 2
	var lhalf = mid - l[n] + 1
	Assign(c[n], d[n], lhalf, LL(n))
	Assign(GetF(c[n], d[n], lhalf+1), GetF(c[n], d[n], lhalf+2), r[n]-l[n]+1-lhalf, RR(n))
	c[n] = 0
	d[n] = 0
}

func Query(ll, rr, n int) int {
	if ll == l[n] && rr == r[n] {
		return sum[n]
	}
	var mid int = (l[n] + r[n]) / 2
	var res int = 0
	Update(n)
	if rr <= mid {
		res = Query(ll, rr, LL(n))
	} else if ll > mid {
		res = Query(ll, rr, RR(n))
	} else {
		res = (Query(ll, mid, LL(n)) + Query(mid+1, rr, RR(n))) % MOD
	}
	sum[n] = sum[LL(n)] + sum[RR(n)]
	// fmt.Println("Query:", ll, rr, "->", res)
	return res
}

func Insert(ll, rr, n, prefix, seq_len int) {
	// fmt.Println("Interval:", l[n], r[n], "insert:", ll, rr, "seq:", prefix, seq_len)
	if l[n] == ll && r[n] == rr {
		Assign(f[prefix+1], f[prefix+2], seq_len-prefix, n)
		return
	}

	Update(n)
	var mid int = (l[n] + r[n]) / 2
	if rr <= mid {
		Insert(ll, rr, LL(n), prefix, seq_len)
	} else if mid < ll {
		Insert(ll, rr, RR(n), prefix, seq_len)
	} else {
		var l_len int = mid - ll + 1
		Insert(ll, mid, LL(n), prefix, l_len+prefix)
		Insert(mid+1, rr, RR(n), l_len+prefix, seq_len)
	}
	sum[n] = sum[LL(n)] + sum[RR(n)]
}

func main() {
	f[0] = 0
	f[1] = 1
	for i := 2; i < len(f); i++ {
		f[i] = (f[i-1] + f[i-2]) % MOD
	}

	reader := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscan(reader, &n, &m)

	var a []int = make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &a[i+1])
	}

	Init(n, a)
	var cmd, li, ri int
	for i := 0; i < m; i++ {
		// fmt.Println(i, "Debug info")
		fmt.Fscan(reader, &cmd, &li, &ri)
		if cmd == 2 {
			fmt.Println(Query(li, ri, 1))
		} else {
			Insert(li, ri, 1, 0, ri-li+1)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func LL(n int) int { return n * 2 }
func RR(n int) int { return n*2 + 1 }

var sum, l, r, length, prev []int
var f, sumf [310000]int

const MOD int = 1000000009

func InitDetail(a []int, ll, rr, n int) {
	l[n] = ll
	r[n] = rr
	length[n] = 0
	prev[n] = -1
	sum[n] = 0
	if ll == rr {
		sum[n] = a[ll]
		return
	}

	var mid int = (ll + rr) / 2
	InitDetail(a, ll, mid, LL(n))
	InitDetail(a, mid+1, rr, RR(n))
	sum[n] = (sum[LL(n)] + sum[RR(n)]) % MOD
}

func Init(n int, a []int) {
	sum = make([]int, n*4)
	l = make([]int, n*4)
	r = make([]int, n*4)
	length = make([]int, n*4)
	prev = make([]int, n*4)
	InitDetail(a, 1, n, 1)
}

func Assign(n, prefix, seq_len int) {
	prev[n] = prefix
	length[n] = seq_len
	// fmt.Println(l[n], r[n], "+", sumf[seq_len]-sumf[prefix])
	sum[n] += sumf[seq_len] - sumf[prefix]
	sum[n] = (sum[n] + MOD) % MOD
}

func Update(n int) {
	if prev[n] == -1 || l[n] == r[n] {
		return
	}
	var mid int = (l[n] + r[n]) / 2
	Update(LL(n))
	Update(RR(n))
	Assign(LL(n), prev[n], prev[n]+mid-l[n]+1)
	Assign(RR(n), prev[n]+mid-l[n]+1, length[n])
	prev[n] = -1
}

func Query(ll, rr, n int) int {
	if ll == l[n] && rr == r[n] {
		return sum[n]
	}
	var mid int = (l[n] + r[n]) / 2
	var res int = 0
	Update(n)
	if rr <= mid {
		res = Query(ll, rr, LL(n))
	} else if ll > mid {
		res = Query(ll, rr, RR(n))
	} else {
		res = (Query(ll, mid, LL(n)) + Query(mid+1, rr, RR(n))) % MOD
	}
	// fmt.Println("Query:", ll, rr, "->", res)
	return res
}

func Insert(ll, rr, n, prefix, seq_len int) {
	// fmt.Println("Interval:", l[n], r[n], "insert:", ll, rr, "seq:", prefix, seq_len)
	if l[n] == ll && r[n] == rr {
		Update(n)
		Assign(n, prefix, seq_len)
		return
	}
	sum[n] += sumf[seq_len] - sumf[prefix]
	sum[n] = (sum[n] + MOD) % MOD
	Update(n)
	var mid int = (l[n] + r[n]) / 2
	if rr <= mid {
		Insert(ll, rr, LL(n), prefix, seq_len)
	} else if mid < ll {
		Insert(ll, rr, RR(n), prefix, seq_len)
	} else {
		var l_len int = mid - ll + 1
		Insert(ll, mid, LL(n), prefix, l_len+prefix)
		Insert(mid+1, rr, RR(n), l_len, seq_len)
	}
}

func main() {
	sumf[0], f[0] = 0, 0
	sumf[1], f[1] = 1, 1
	for i := 2; i < len(f); i++ {
		f[i] = (f[i-1] + f[i-2]) % MOD
		sumf[i] = sumf[i-1] + f[i]
	}

	reader := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscan(reader, &n, &m)

	var a []int = make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &a[i+1])
	}

	Init(n, a)
	var cmd, li, ri int
	for i := 0; i < m; i++ {
		fmt.Fscan(reader, &cmd, &li, &ri)
		if cmd == 2 {
			fmt.Println(Query(li, ri, 1))
		} else {
			Insert(li, ri, 1, 0, ri-li+1)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func LL(n int) int { return n * 2 }
func RR(n int) int { return n*2 + 1 }

var sum, l, r, c, d []int
var f, sumf [310000]int

const MOD int = 1000000009

func InitDetail(a []int, ll, rr, n int) {
	l[n] = ll
	r[n] = rr
	c[n] = 0
	d[n] = 0
	if ll == rr {
		sum[n] = a[ll] % MOD
		return
	}

	var mid int = (ll + rr) / 2
	InitDetail(a, ll, mid, LL(n))
	InitDetail(a, mid+1, rr, RR(n))
	sum[n] = (sum[LL(n)] + sum[RR(n)]) % MOD
}

func Init(n int, a []int) {
	sum = make([]int, n*4)
	l = make([]int, n*4)
	r = make([]int, n*4)
	c = make([]int, n*4)
	d = make([]int, n*4)
	InitDetail(a, 1, n, 1)
}

func GetF(a, b, n int) int {
	if n == 1 {
		return a
	} else if n == 2 {
		return b
	} else {
		return (b*f[n-1] + a*f[n-2]) % MOD
	}
}

func GetSumF(a, b, n int) int {
	return GetF(a, b, n+2) - b
}

func Assign(a, b, length, n int) {
	// fmt.Println("Upddate:", a, b, "for", l[n], r[n])
	c[n] = (c[n] + a) % MOD
	d[n] += (d[n] + b) % MOD
	sum[n] += GetSumF(a, b, length)
}

// define f(n) as fib sequeue
// define F[1] = a, F[2] = b, then F(n) = b*f(n-1) + a*f(n-2)
func Update(n int) {
	if c[n] == 0 && d[n] == 0 {
		return
	}
	var mid int = (l[n] + r[n]) / 2
	var lhalf = mid - l[n] + 1
	Assign(c[n], d[n], lhalf, LL(n))
	Assign(GetF(c[n], d[n], lhalf+1), GetF(c[n], d[n], lhalf+2), r[n]-lhalf, RR(n))
	c[n] = 0
	d[n] = 0
}

func Query(ll, rr, n int) int {
	if ll == l[n] && rr == r[n] {
		return sum[n]
	}
	var mid int = (l[n] + r[n]) / 2
	var res int = 0
	Update(n)
	if rr <= mid {
		res = Query(ll, rr, LL(n))
	} else if ll > mid {
		res = Query(ll, rr, RR(n))
	} else {
		res = (Query(ll, mid, LL(n)) + Query(mid+1, rr, RR(n))) % MOD
	}
	// fmt.Println("Query:", ll, rr, "->", res)
	return res
}

func Insert(ll, rr, n, prefix, seq_len int) {
	// fmt.Println("Interval:", l[n], r[n], "insert:", ll, rr, "seq:", prefix, seq_len)
	sum[n] += ((sumf[seq_len]-sumf[prefix])%MOD + MOD) % MOD
	sum[n] %= MOD
	if l[n] == ll && r[n] == rr {
		c[n] += f[prefix+1]
		d[n] += f[prefix+2]
		return
	}

	Update(n)
	var mid int = (l[n] + r[n]) / 2
	if rr <= mid {
		Insert(ll, rr, LL(n), prefix, seq_len)
	} else if mid < ll {
		Insert(ll, rr, RR(n), prefix, seq_len)
	} else {
		var l_len int = mid - ll + 1
		Insert(ll, mid, LL(n), prefix, l_len+prefix)
		Insert(mid+1, rr, RR(n), l_len+prefix, seq_len)
	}
}

func main() {
	sumf[0], f[0] = 0, 0
	sumf[1], f[1] = 1, 1
	for i := 2; i < len(f); i++ {
		f[i] = (f[i-1] + f[i-2]) % MOD
		sumf[i] = (sumf[i-1] + f[i]) % MOD
	}

	reader := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscan(reader, &n, &m)

	var a []int = make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &a[i+1])
	}

	Init(n, a)
	var cmd, li, ri int
	for i := 0; i < m; i++ {
		// fmt.Println(i, "Debug info")
		fmt.Fscan(reader, &cmd, &li, &ri)
		if cmd == 2 {
			fmt.Println(Query(li, ri, 1))
		} else {
			Insert(li, ri, 1, 0, ri-li+1)
		}
	}
}