← Home
```go
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	var n int
	fmt.Sscanf(scanner.Text(), "%d", &n)

	globalKV := make(map[string]string)
	sections := make(map[string]map[string]string)
	currentSection := ""

	for i := 0; i < n; i++ {
		scanner.Scan()
		line := strings.TrimSpace(scanner.Text())

		if line == "" || strings.HasPrefix(line, ";") {
			continue
		}

		if strings.HasPrefix(line, "[") && strings.HasSuffix(line, "]") {
			sectionName := strings.TrimSpace(line[1 : len(line)-1])
			currentSection = sectionName
			if sections[sectionName] == nil {
				sections[sectionName] = make(map[string]string)
			}
		} else {
			parts := strings.SplitN(line, "=", 2)
			if len(parts) == 2 {
				key := strings.TrimSpace(parts[0])
				value := strings.TrimSpace(parts[1])
				if currentSection == "" {
					globalKV[key] = value
				} else {
					sections[currentSection][key] = value
				}
			}
		}
	}

	var globalKeys []string
	for key := range globalKV {
		globalKeys = append(globalKeys, key)
	}
	sort.Strings(globalKeys)
	for _, key := range globalKeys {
		fmt.Printf("%s=%s\n", key, globalKV[key])
	}

	var sectionNames []string
	for name := range sections {
		sectionNames = append(sectionNames, name)
	}
	sort.Strings(sectionNames)

	for _, name := range sectionNames {
		fmt.Printf("[%s]\n", name)
		var keys []string
		for key := range sections[name] {
			keys = append(keys, key)
		}
		sort.Strings(keys)
		for _, key := range keys {
			fmt.Printf("%s=%s\n", key, sections[name][key])
		}
	}
}
```