A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database.

The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters.

Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken.

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
)

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	name := map[string]int{}
	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 0; i < n; i++ {
		var s string
		fmt.Fscanf(reader, "%s\n", &s)
		count, ok := name[s]
		if !ok {
			fmt.Printf("OK\n")
			name[s] = 0
		} else {
			fmt.Printf("%s%d\n", s, count+1)
			name[s] = count + 1
		}
	}
}

package main

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

func main() {
	var nameCount int
	var name string
	names := make(map[string]int)
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscanf(reader, "%d\n", &nameCount)
	for i := 0; i < nameCount; i++ {
		fmt.Fscanf(reader, "%s\n", &name)
		if names[name] == 0 {
			fmt.Println("OK")
		} else {
			fmt.Printf("%v%v\n", name, names[name])
		}
		names[name]++
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	db := make(map[string]int)

	var n int
	fmt.Scan(&n)

	for i := 0; i < n; i++ {
		for scanner.Scan() {
			if scanner.Text() != "" { break }
		}

		if db[scanner.Text()] != 0 {
			fmt.Fprintf(writer, "%v%v\n", scanner.Text(), db[scanner.Text()])
		} else {
			writer.WriteString("OK\n")
		}
		db[scanner.Text()]++
	}

	writer.Flush()
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	db := make(map[string]int)

	var n int
	fmt.Scan(&n)

	for i := 0; i < n; i++ {
		for scanner.Scan() {
			if scanner.Text() != "" { break }
		}

		if db[scanner.Text()] != 0 {
			writer.WriteString(scanner.Text() + strconv.Itoa(db[scanner.Text()]) + "\n")
		} else {
			writer.WriteString("OK\n")
		}
		db[scanner.Text()]++
	}

	writer.Flush()
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(r, "%d\n", &n)
	ds := make(map[string]int, n)
	for i:= 0; i<n; i++{
		var s string
		fmt.Fscanf(r, "%s\n", &s)
		if _, ok := ds[s]; ok {
			ds[s]++
			fmt.Printf("%s%d\n", s, ds[s])
			continue
		}
		fmt.Println("OK")
		ds[s] = 0
	}
}

package main

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

func main() {
	names := make(map[string]int)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	for scanner.Scan() {
		name := scanner.Text()
		v, ok := names[name]
		if ok == false {
			names[name] = 0
			fmt.Println("OK")
		}else {
			names[name] = v + 1
			fmt.Printf("%s%d\n", name, v + 1)
		}
	}
}

package main

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

func main() {
	var n int
	var nickname string
	r := bufio.NewReader(os.Stdin)
	_, _ = fmt.Fscanf(r,"%d\n", &n)
	database := make(map[string]int)
	for i := 0; i < n; i++ {
		_, _ = fmt.Fscanf(r,"%s\n", &nickname)
		value := database[nickname]
		if value == 0 {
			fmt.Printf("%s\n", "OK")
		} else {
			fmt.Printf("%s%d\n", nickname, value)
		}
		database[nickname] = value + 1
	}
}

/*
%t: для вывода значений типа boolean (true или false)
%b: для вывода целых чисел в двоичной системе
%c: для вывода символов, представленных числовым кодом
%d: для вывода целых чисел в десятичной системе
%o: для вывода целых чисел в восьмеричной системе
%q: для вывода символов в одинарных кавычках
%x: для вывода целых чисел в шестнадцатиричной системе, буквенные символы числа имеют нижний регистр a-f
%X: для вывода целых чисел в шестнадцатиричной системе, буквенные символы числа имеют верхний регистр A-F
%U: для вывода символов в формате кодов Unicode, например, U+1234
%e: для вывода чисел с плавающей точкой в экспоненциальном представлении, например, -1.234456e+78
%E: для вывода чисел с плавающей точкой в экспоненциальном представлении, например, -1.234456E+78
%f: для вывода чисел с плавающей точкой, например, 123.456
%F: то же самое, что и %f
%g: для длинных чисел с плаващей точкой используется %e, для других - %f
%G: для длинных чисел с плаващей точкой используется %E, для других - %F
%s: для вывода строки
%p: для вывода значения указателя - адреса в шестнадцатеричном представлении
*/

package main

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

func main() {
	var n int
	var s string
	input := bufio.NewScanner(os.Stdin)
    	input.Split(bufio.ScanWords)
	fmt.Scan(&n)
	simpan:= make(map[string]int)
	for i:=0;i<n;i++ {
		input.Scan()
		s =input.Text()
		if simpan[s]==0 {
			fmt.Println("OK")
			simpan[s]=1
		} else{
			fmt.Printf("%s%d\n",s,simpan[s])
			simpan[s]+=1
		}
	}
}

package main

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

func solve() {
	n := readInt()
	db := make(map[string]int)
	for i := 0; i < n; i++ {
		name := readString()

		v, exists := db[name]
		if exists {
			fmt.Print(name, v, "\n")
		} else {
			fmt.Println("OK")
			v = 0
		}
		db[name] = v + 1
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

package main

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

func main() {
	var n int
	var str string
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	t := sc.Text()
	n, _ = strconv.Atoi(t)
	userId := make(map[string]int, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		str = sc.Text()
		num, ok := userId[str]
		if ok {
			fmt.Printf("%s%d\n", str, num)
			userId[str] = num + 1
		} else {
			userId[str] = 1
			fmt.Println("OK")
		}
	}
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    writer := bufio.NewWriter(os.Stdout)
    var n int
    m := make(map[string]int)
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        for scanner.Scan() {
            if scanner.Text() != "" { break }
        }
        if m[scanner.Text()] == 0 {
            writer.WriteString("OK"+"\n")
            m[scanner.Text()]++
        } else {
            writer.WriteString(scanner.Text()+strconv.Itoa(m[scanner.Text()])+"\n")
            m[scanner.Text()]++
        }
    }
    writer.Flush()
}

// wa on test 4
package main

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

type IntIO struct {
	tmp []byte
}

func (s *IntIO) Flush() {
}

func (s *IntIO) Init() {
	s.tmp = make([]byte, 32, 32)
}

func main() {

	var (
		table   map[string]int32
		n, i, f int32
		str     string
		r       *bufio.Reader
		w       *bufio.Writer
	)

	r = bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)

	table = make(map[string]int32)
	fmt.Scan(&n)
	for i = 1; i <= n; i++ {
		fmt.Fscan(r, &str)
		f, _ = table[str]
		if 0 == f {
			fmt.Fprint(w, "OK\n")
		} else {
			fmt.Fprintf(w, "%s%d\n", str, f)
		}
		table[str]++
	}
	w.Flush()
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func readline() string {
	name, err := reader.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}

	name = strings.TrimRight(name, "\r\n")

	return name
}

func flush() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	defer flush()

	var n int
	scanf("%d\n", &n)

	names := make(map[string]int)
	for i := 0; i < n; i++ {
		name := readline()
		if len(name) == 0 {
			continue
		}

		if count, ok := names[name]; ok {
			printf("%s%d\n", name, count)
			names[name]++
		} else {
			printf("OK\n")
			names[name] = 1
		}
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func close() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	var n int
	scanf("%d\n", &n)
	names := make(map[string]int)
	for i := 0; i < n; i++ {
		name, err := reader.ReadString('\n')
		if err != nil {
			log.Fatal(err)
		}

		name = strings.TrimRight(name, "\r\n")
		if len(name) == 0 {
			continue
		}

		if count, ok := names[name]; ok {
			fmt.Fprintf(writer, "%s%d\n", name, count)
			names[name]++
		} else {
			printf("OK\n")
			names[name] = 1
		}
	}
	close()
}

package main

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

func main() {
	var n int
	fmt.Scanf("%d \n", &n)
	myMap := make(map[string]int)
	scanner := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		scanner.Scan()
		temp := scanner.Text()
		if myMap[temp] == 0 {
			fmt.Println("OK")
		} else {
			result := temp + strconv.Itoa(myMap[temp])
			fmt.Println(result)
			myMap[result]++
		}
		myMap[temp]++
	}
}

package main

import (
	"fmt"
	"io/ioutil"
	"os"
	"strconv"
	"strings"
	"text/scanner"
)

func check(e error) {
	if e != nil {
		panic(e)
	}
}

func main() {
	var n int // first input to the problem
	var counters map[string]int // keep track of entries
	counters = make(map[string]int)

	dat, err := ioutil.ReadAll(os.Stdin)
	check(err)
	var str_data string = string(dat);

	reader := strings.NewReader(str_data)

	var scn scanner.Scanner
	scn.Init(reader)

    scn.Scan()
	var text string = scn.TokenText();

	n, err = strconv.Atoi(text)
	check(err)

	var i int
	for i = 0; i < n; i++ {
		scn.Scan()
		var name string = scn.TokenText();
		check(err)

		// does name exist already?
		val, ok := counters[name]
		if ok == true {
			val++;
			var output string = name + strconv.Itoa(val)
			fmt.Println(output)
			counters[name] = val
		} else {
			fmt.Println("OK")
			counters[name] = 0
		}
	}
}

package main

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

type Acc struct {
	users map[string]int
}

func (a *Acc) Set(name string) {
	if _, ok := a.users[name]; ok {
		a.users[name]++
		fmt.Println(name + strconv.Itoa(a.users[name]))
	} else {
		a.users[name] = 0
		fmt.Println("OK")
	}

}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanLines)
	i, v := 0, 0
	var acc Acc
	acc.users = make(map[string]int)

	for sc.Scan() {
		i++
		if i == 1 {
			v, _ = strconv.Atoi(sc.Text())
			continue
		}
		if v+2 == i {
			return
		}
		acc.Set(sc.Text())
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	var userCount int

	if scanner.Scan() {
		line := scanner.Text()
		fmt.Sscanf(line, "%d", &userCount)
	}

	db := make(map[string]int)
	for i := 0; i < userCount && scanner.Scan(); i++ {
		line := scanner.Text()
		count, exist := db[line]
		if !exist {
			fmt.Println("OK")
		} else {
			fmt.Println(line + strconv.Itoa(count))
		}
		db[line] += 1
	}
}

package main

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

func djb2(s string) uint {
	h := uint(5381)
	for i, l := 0, len(s); i < l; i++ {
		h = (h << 5) + h + uint(s[i])
	}
	return h
}

type hash_value struct {
	str string
	count int
	used bool
}

type hash_table struct {
	table []hash_value
}

func newHashTable(m int) *hash_table {
	return &hash_table{make([]hash_value, m)}
}

func (h *hash_table) get(s string) *hash_value {
	hash := djb2(s)
	idx := hash % magic_m

	n := &h.table[idx]
	for n.used {
		if n.str == s {
			return n
		} else {
			if idx == 0 {
				idx = magic_m - 1
			} else {
				idx -= 1
			}
			n = &h.table[idx]
		}
	}
	n.str = s
	n.used = true
	return n
}

// a prime greater than our known "max" value - 100000
const magic_m = 100003

func main() {
	var n int
	var s string

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

	fmt.Fscanf(in, "%d\n", &n)
	h := newHashTable(magic_m)

	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%s\n", &s)

		v := h.get(s)
		if v.count == 0 {
			fmt.Fprintf(out, "OK\n")
		} else {
			fmt.Fprintf(out, "%s%d\n", s, v.count)
		}
		v.count += 1
	}
}

package main

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

func main() {
	var n int
	var s string

	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()

	fmt.Fscanf(in, "%d\n", &n)

	h := make(map[string]int)
	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%s\n", &s)

		val := h[s]
		if val == 0 {
			fmt.Fprintf(out, "OK\n")
		} else {
			fmt.Fprintf(out, "%s%d\n", s, val)
		}
		h[s] = val + 1
	}
}

package main

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

func main() {
	var n int
	var s string

	r := bufio.NewReader(os.Stdin)

	fmt.Fscanf(r, "%d\n", &n)

	h := make(map[string]int)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%s\n", &s)

		val := h[s]
		if val == 0 {
			fmt.Printf("OK\n")
		} else {
			fmt.Printf("%s%d\n", s, val)
		}
		h[s] = val + 1
	}
}

package main

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

func djb2(s string) uint {
	h := uint(5381)
	for i, l := 0, len(s); i < l; i++ {
		h = (h << 5) + h + uint(s[i])
	}
	return h
}

type hash_value struct {
	str string
	count int
	next *hash_value
}

type hash_table struct {
	table []*hash_value
}

func newHashTable(m int) *hash_table {
	return &hash_table{make([]*hash_value, m)}
}

func (h *hash_table) get(s string) *hash_value {
	hash := djb2(s)
	idx := hash % magic_m
	// fmt.Printf("%s -> %d -> %d\n", s, hash, idx)

	node := h.table[idx]
	if node == nil {
		v := &freelist[next_free_idx]
		next_free_idx += 1

		v.str = s
		h.table[idx] = v
		return v
	} else {
		for {
			if node.str == s {
				return node
			} else {
				if node.next != nil {
					node = node.next
				} else {
					v := &freelist[next_free_idx]
					next_free_idx += 1

					v.str = s
					node.next = v
					return v
				}
			}
		}
	}
}

// a prime greater than our known "max" value - 100000
const magic_m = 100003

var freelist []hash_value
var next_free_idx = 0

func main() {
	var n int
	var s string

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

	fmt.Fscanf(in, "%d\n", &n)
	h := newHashTable(magic_m)
	freelist = make([]hash_value, n)

	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%s\n", &s)

		v := h.get(s)
		// fmt.Printf("%v\n", v)
		if v.count == 0 {
			fmt.Fprintf(out, "OK\n")
		} else {
			fmt.Fprintf(out, "%s%d\n", s, v.count)
		}
		v.count += 1
	}
}

package main

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

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 1024*1024)
	n, err := strconv.ParseInt(readLine(reader), 10, 0)
	checkError(err)

	m := make(map[string]int)
	for i := 0; i < int(n); i++ {
		s := readLine(reader)
		_, ok := m[s]
		if ok {
			m[s] += 1
			fmt.Printf("%v%v\n", s, m[s])
		} else {
			m[s] = 0
			fmt.Println("OK")
		}
	}
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

package main

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

func main() {
	var n int
	var s string
	mp := make(map[string]int)
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	fmt.Fscanf(in, "%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%s\n", &s)
		if mp[s] == 0 {
			fmt.Fprintf(out, "OK\n")
		} else {
			fmt.Fprintf(out, "%s%d\n", s, mp[s])
		}
		mp[s]++
	}
	out.Flush()
}

package main

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

func main() {
	var n int
	var s string
	mp := make(map[string]int)
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%s\n", &s)
		if mp[s] == 0 {
			fmt.Println("OK")
		} else {
			fmt.Printf("%v%v\n", s, mp[s])
		}
		mp[s]++
	}
}

package main

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

func main() {
	var n int
	var s string
	mp := make(map[string]int)
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	fmt.Fscanf(in, "%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%s\n", &s)
		if mp[s] == 0 {
			fmt.Fprintf(out, "OK\n")
		} else {
			fmt.Fprintf(out, "%s%d\n", s, mp[s])
		}
		mp[s]++
	}
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func main() {

	defer writer.Flush()
	var t int
	scanf("%d\n", &t)

	db := make(map[string]*int)

	for i := 0; i < t; i++ {
		var name string
		scanf("%s \n", &name)

		names, ok := db[name]
		if !ok {
			var a = 0
			db[name] = &a
			printf("OK\n")
			continue
		}

		*names = *names + 1
		newName := name + strconv.Itoa(*names)
		printf("%s\n", newName)
	}
}

package main
import (
  "fmt"
  "bufio"
  "os"
)

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

func main() {
  var n, i int
  var s string
  var dict map[string]int
  dict = make(map[string]int)
  fmt.Fscan(in, &n)
  for i=0; i<n; i++ {
    fmt.Fscan(in, &s)
    if (dict[s] == 0) {
      fmt.Println("OK")
      dict[s] = 1
    } else {
      fmt.Printf("%s%d\n", s, dict[s])
      dict[s] = dict[s] + 1
    }
  }
}

package main

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

func resp(db map[string]int, query string) string {
	asked_for, ok := db[query]
	if !ok {
		db[query] = 0
		return "OK"
	}
	asked_for += 1
	db[query] = asked_for
	query = query + strconv.Itoa(asked_for)
	db[query] = 0
	return query
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var n int
	var query string
	fmt.Fscanln(reader, &n)
	db := make(map[string]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanln(reader, &query)
		fmt.Fprintln(writer, resp(db, query))
	}
}

package main

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

var reader *bufio.Reader

func init() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader = bufio.NewReaderSize(stdin, 1<<20)
}

var n int
var s string

func main() {
	fmt.Fscan(reader, &n)
	m := make(map[string]int)
	for ; n != 0; n-- {
		fmt.Fscan(reader, &s)
		if m[s] == 0 {
			fmt.Println("OK")
		} else {
			fmt.Print(s, m[s], "\n")
		}
		m[s]++
	}
}

package main

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

var DEBUG = true

func main() {
	defer Flush()

	N := readi()
	m := make(map[string]bool)
	k := make(map[string]int)
	for i := 0; i < N; i++ {
		s := reads()
		if !m[s] {
			println("OK")
			m[s] = true
			k[s] = 1
			continue
		}
		printf("%s%d\n", s, k[s])
		k[s]++
	}

}

// -----------------------------------------------------------------------------

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

// -----------------------------------------------------------------------------

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func dbgf(f string, args ...interface{}) {
	if !DEBUG {
		return
	}
	fmt.Fprintf(os.Stderr, f, args...)
}

func dbg(args ...interface{}) {
	if !DEBUG {
		return
	}
	fmt.Fprintln(os.Stderr, args...)
}

// -----------------------------------------------------------------------------

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

// -----------------------------------------------------------------------------

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minll(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minf(a, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

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

func maxll(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxf(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func absf(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)
func main(){
	var n int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n,_ = strconv.Atoi(scanner.Text())
	arrString := make([]string,n)
	for i:=0;i<n;i++{
		scanner.Scan()
		arrString[i] = scanner.Text()
	}
	read(arrString)
}

func read(dataArr []string){
	memory := map[string]int{}
	for _,data := range(dataArr){
		if memory[data] != 0{
			fmt.Printf("%s%d\n",data,memory[data])
		}else{
			fmt.Println("OK")
		}
		memory[data] += 1
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var n int
	fmt.Fscanf(in, "%d\n", &n)

	db := make(map[string]int, 0)

	for i := 0; i < n; i++ {
		var name string
		fmt.Fscanf(in, "%s\n", &name)

		count := db[name]
		db[name] = count + 1
		if count == 0 {
			fmt.Fprintln(out, "OK")
		} else {
			fmt.Fprintf(out, "%s%d\n", name, count)
		}
	}
	out.Flush()
}

package main

import (
	"bufio"
	"os"
	"strings"
	"fmt"
	"strconv"
	"errors"
	"runtime"
)

func main() {
	n := nextInt()
	m := make(map[string]int)
	for i := 0; i < n; i++ {
		x := nextWord()
		if next, ok := m[x]; ok {
			printf("%s%d\n", x, next)
			m[x] = next + 1
		} else {
			printf("OK\n")
			m[x] = 1
		}
		if i % 1000 == 0 {
			runtime.GC()
		}
	}
}

var lineScanner *bufio.Scanner
var wordScanner *bufio.Scanner

func init() {
	lineScanner = bufio.NewScanner(os.Stdin)
	wordScanner = bufio.NewScanner(strings.NewReader(""))
	wordScanner.Split(bufio.ScanWords)
}
func printf(format string, a ...interface{}) {
	fmt.Printf(format, a...)
}
func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = bufio.NewScanner(strings.NewReader(line))
		wordScanner.Split(bufio.ScanWords)
	}
	return wordScanner.Text()
}

func nextInt() int {
	res, err := strconv.Atoi(nextWord())
	if err != nil {
		panic(err)
	}
	return res
}

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

package main

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

func main() {
	var n int
	var s string
	input := bufio.NewScanner(os.Stdin)
    	input.Split(bufio.ScanWords)
	fmt.Scan(&n)
	simpan:= make(map[string]int)
	for i:=0;i<n;i++ {
		input.Scan()
		s =input.Text()
		if simpan[s]==0 {
			fmt.Println("OK")
			simpan[s]=1
		} else{
			fmt.Printf("%s%d\n",s,simpan[s])
			simpan[s]+=1
		}
	}
}

package main

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

func main() {
        m := make(map[string]int)
        var n int
        var s string
        r := bufio.NewReader(os.Stdin)
        fmt.Fscanf(r, "%d\n", &n)
        for i := 0; i < n; i++ {
                fmt.Fscanf(r, "%s\n", &s)
                v := m[s]
                if v == 0 {
                        fmt.Println("OK")
                } else {
                        fmt.Printf("%s%d\n", s, v)
                }
                v++
                m[s] = v
        }
}

package main

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

var n int
var s string
var m = make(map[string]int)
var r = bufio.NewReader(os.Stdin)

func main() {
        fmt.Fscanf(r, "%d\n", &n)
        for i := 0; i < n; i++ {
                fmt.Fscanf(r, "%s\n", &s)
                v := m[s]
                if v == 0 {
                        fmt.Println("OK")
                } else {
                        fmt.Printf("%s%d\n", s, v)
                }
                v++
                m[s] = v
        }
}

package main

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

func main() {
	names := make(map[string]int)

	reader := bufio.NewReader(os.Stdin)

	nStr, _, _ := reader.ReadLine()
	n, _ := strconv.ParseInt(string(nStr), 10, 64)

	for i := 0; i < int(n); i++ {
		nameBytes, _, _ := reader.ReadLine()
		name := string(nameBytes)

		if indices, ok := names[name]; ok {
			names[name]++
			fmt.Printf("%s%d\n", name, indices)
		} else {
			names[name] = 1
			fmt.Println("OK")
		}
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	dict := map[string]int {}
	for i := 0; i < n; i++ {
		scanner.Scan()
		name := scanner.Text()
		if val, ok := dict[name]; ok {
			fmt.Printf("%s\n", (name+strconv.Itoa(val)))
			dict[name] += 1
		} else {
			fmt.Printf("%s\n", "OK")
			dict[name] = 1
		}
	}
}

//	URL: http://codeforces.com/contest/4/problem/C
//	PROBLEM RESTATEMENT
//		Given a stream of strings.
//		If string has not been seen before, output "OK".
//		If string has been seen before, output name of string with occurrence.
//	APPROACH
//		Naive implementation problem. Just follow instructions.
//	NOTE
//		Scan is bad - too slow! Use bufio instead.

package main

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

func main() {
	var n int
	var name string
	reader, writer := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	fmt.Fscanf(reader, "%d\n", &n)
	m := make(map[string]int)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%s\n", &name)
		val := m[name]
		if val == 0 {
			fmt.Fprintf(writer, "OK\n")
		} else {
			fmt.Fprintf(writer, "%s%d\n", name, m[name])
		}
		m[name] += 1
	}
}

package main

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

func main() {
	var n int
	fmt.Scanln(&n)
	scanner := bufio.NewScanner(os.Stdin)

	userList := make(map[string]int)
	for scanner.Scan() {
		username := scanner.Text()
		v, ok := userList[username]
		if ok {
			userList[username] += 1
			username = username + strconv.Itoa(v)
			userList[username] = 1
			fmt.Println(username)
		} else {
			userList[username] = 1
			fmt.Println("OK")
		}
	}
}

package main

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

func main() {
	var n int
	var name string

	// Faster Input
	in := bufio.NewReader(os.Stdin)

	db := make(map[string]int, 100005)

	//fmt.Scanf("%d", &n)
	fmt.Fscanf(in, "%d\n", &n)

	for i := 0; i < n; i++ {
		// Individual name
		fmt.Fscanln(in, &name)
		// Add it to the db
		//fmt.Println(name)

		count, exists := db[name]

		if !exists {
			//fmt.Println("Adding new")
			//db[name] = 0
			fmt.Println("OK")
		} else {
			//fmt.Println(name, "Found. Occurences: ", count)
			fmt.Printf("%s%d\n", name, count)
		}

		db[name]++
	}

	//fmt.Println(db)
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var count int
	fmt.Fscanf(r, "%d\n", &count)
	dic := make(map[string]int, count)
	for i := 0; i < count; i++ {
		var str string
		fmt.Fscanf(r, "%s\n", &str)
		if _, has := dic[str]; has {
			fmt.Printf("%s%d\n", str, dic[str])
			dic[str]++
		} else {
			dic[str] = 1
			fmt.Println("OK")
		}
	}
}

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
)

type login struct {
	name  []byte
	count int
}

func bytesEqual(a, b []byte) bool {
	l := len(a)
	if l != len(b) {
		return false
	}
	for i := 0; i < l; i += 1 {
		if a[i] != b[i] {
			return false
		}
	}
	return true
}

func updateLogins(list []login, l []byte) ([]login, int) {
	for i := 0; i < len(list); i += 1 {
		if bytesEqual(list[i].name, l) {
			list[i].count += 1
			return list, list[i].count
		}
	}
	list = append(list, login{name: l, count: 0})
	return list, 0
}

// https://codeforces.com/problemset/problem/4/C
// комментарии к решению
// Задача хорошо ложиться на go'шный map, но при попытке использования map[string]int
// мы падаем по времени, а для []byte map не работает, поэтому реализуем на основе списков
func taskSolution(a [][]byte) string {
	count := 0
	seen := []login{}
	ans := []byte{}
	for i := 0; i < len(a); i += 1 {
		line := bytes.TrimSpace(a[i])
		seen, count = updateLogins(seen, line)
		if count == 0 {
			ans = append(ans, []byte("OK")...)
		} else {
			intStr := fmt.Sprint(count)
			//contest failed w/o trim spaces
			cleanedNum := bytes.TrimSpace([]byte(intStr))
			ans = append(ans, line...)
			ans = append(ans, cleanedNum...)
		}
		ans = append(ans, byte('\n'))
	}
	return string(ans)
}

func main() {
	var n int
	if _, err := fmt.Scan(&n); err != nil {
		panic(err)
	}

	inRaw, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		panic(err)
	}
	inRawArr := bytes.Split(bytes.TrimSpace(inRaw), []byte("\n"))

	fmt.Println(taskSolution(inRawArr))
}

package main

import (
	"fmt"
	"io/ioutil"
	"os"
)

type line struct {
	start int
	end   int
}

// https://codeforces.com/problemset/problem/4/C
// комментарии к решению
// При попытке считывания string через fmt.Scan мы падаем по времени, поэтому
// парсим входные данные самостоятельно, приводя строки к string только в крайнем случае
func taskSolution(in []byte) string {
	names := map[string]int{}
	ans := []byte{}
	next := line{start: 0, end: 0}
	// iterate lines
	for next.end < len(in) {
		next.start = next.end
		// skip spaces
		for next.start < len(in) && !(in[next.start] >= 'a' && in[next.start] <= 'z') {
			next.start += 1
		}
		// find end of word
		next.end = next.start
		for next.end < len(in) && in[next.end] >= 'a' && in[next.end] <= 'z' {
			next.end += 1
		}
		// break at EOF
		if next.end == len(in) {
			break
		}
		// check logins
		loginStr := string(in[next.start:next.end])
		if _, ok := names[loginStr]; ok {
			ans = append(ans, []byte(fmt.Sprintf("%s%d", loginStr, names[loginStr]))...)
			names[loginStr] += 1
		} else {
			ans = append(ans, []byte("OK")...)
			names[loginStr] = 1
		}
		ans = append(ans, byte('\n'))
	}
	return string(ans)
}

func main() {
	var n int
	if _, err := fmt.Scan(&n); err != nil {
		panic(err)
	}

	inRaw, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		panic(err)
	}

	fmt.Println(taskSolution(inRaw))
}

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
)

type login struct {
	name  []byte
	count int
}

func bytesEqual(a, b []byte) bool {
	l := len(a)
	if l != len(b) {
		return false
	}
	for i := 0; i < l; i += 1 {
		if a[i] != b[i] {
			return false
		}
	}
	return true
}

func updateLogins(list []login, l []byte) ([]login, int) {
	for i := 0; i < len(list); i += 1 {
		if bytesEqual(list[i].name, l) {
			list[i].count += 1
			return list, list[i].count
		}
	}
	list = append(list, login{name: l, count: 0})
	return list, 0
}

// https://codeforces.com/problemset/problem/4/C
// комментарии к решению
// Задача хорошо ложиться на go'шный map, но при попытке использования map[string]int
// мы падаем по времени, а для []byte map не работает, поэтому реализуем на основе списков
func taskSolution(a [][]byte) string {
	count := 0
	seen := []login{}
	ans := []byte{}
	for i := 0; i < len(a); i += 1 {
		line := bytes.TrimSpace(a[i])
		seen, count = updateLogins(seen, line)
		if count == 0 {
			ans = append(ans, []byte("OK")...)
		} else {
			intStr := fmt.Sprint(count)
			//contest failed w/o trim spaces
			//cleanedNum := bytes.TrimSpace([]byte(intStr))
			ans = append(ans, line...)
			//ans = append(ans, cleanedNum...)
			ans = append(ans, intStr...)
		}
		ans = append(ans, byte('\n'))
	}
	return string(ans)
}

func main() {
	var n int
	if _, err := fmt.Scan(&n); err != nil {
		panic(err)
	}

	inRaw, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		panic(err)
	}
	inRawArr := bytes.Split(bytes.TrimSpace(inRaw), []byte("\n"))

	fmt.Println(taskSolution(inRawArr))
}

package main

import (
	"fmt"
	"io/ioutil"
	"os"
)

type line struct {
	start int
	end   int
}

// https://codeforces.com/problemset/problem/4/C
// комментарии к решению
// Задача хорошо ложиться на go'шный map, но при попытке использования map[string]int
// мы падаем по времени, а для []byte map не работает, поэтому реализуем на основе списков
func taskSolution(in []byte) string {
	names := map[string]int{}
	ans := []byte{}
	next := line{start: 0, end: 0}
	// iterate lines
	for next.end < len(in) {
		next.start = next.end
		// skip spaces
		for next.start < len(in) && !(in[next.start] >= 'a' && in[next.start] <= 'z') {
			next.start += 1
		}

		// find end of word
		next.end = next.start
		for next.end < len(in) && in[next.end] >= 'a' && in[next.end] <= 'z' {
			next.end += 1
		}
		if next.end == len(in) {
			break
		}

		// check
		loginStr := string(in[next.start:next.end])
		if _, ok := names[loginStr]; ok {
			ans = append(ans, []byte(fmt.Sprintf("%s%d", loginStr, names[loginStr]))...)
			names[loginStr] += 1
		} else {
			ans = append(ans, []byte("OK")...)
			names[loginStr] = 1
		}
		ans = append(ans, byte('\n'))
	}
	return string(ans)
}

func main() {
	var n int
	if _, err := fmt.Scan(&n); err != nil {
		panic(err)
	}

	inRaw, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		panic(err)
	}

	fmt.Println(taskSolution(inRaw))
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var n int
	scanner.Scan()
	t := scanner.Text()
	n, _ = strconv.Atoi(t)
	names := make(map[string]int)
	for i := 0; i < n; i++ {
		scanner.Scan()
		name := scanner.Text()
		if val, ok := names[name]; ok {
			names[name] = val + 1
			fmt.Println(name + strconv.Itoa(val))
		} else {
			names[name] = 1
			fmt.Println("OK")
		}
	}
}

// https://codeforces.com/contest/4/problem/C
package main

import (
	"fmt"
	"strconv"
	"runtime/debug"
	"bufio"
	"os"
)

type Users map[string]*User
type User struct {
	Max int64
}

func main() {
	debug.SetGCPercent(-1)

	var newUserCount = 0
	_, err := fmt.Scanf("%d\n", &newUserCount)
	if err != nil {
		panic(err)
	}

	reader := bufio.NewReader(os.Stdin)
	db := make(Users, newUserCount)
	for i := 0; i < newUserCount; i++ {
		userNameBytes, _, err := reader.ReadLine()
		if err != nil {
			panic(err)
		}
		userName := string(userNameBytes)

		user, ok := db[userName]
		if !ok {
			db[userName] = &User{}
			fmt.Println("OK")
			continue
		}

		user.Max++
		newUserName := userName + strconv.FormatInt(user.Max, 10)
		db[newUserName] = &User{}
		fmt.Println(newUserName)
	}

	return
}

package main

import (
	"fmt"
)

func main() {
	name := map[string]int{}
	var n int
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		var s string
		fmt.Scanf("%s\n", &s)
		count, ok := name[s]
		if !ok {
			fmt.Printf("OK\n")
			name[s] = 0
		} else {
			fmt.Printf("%s%d\n", s, count+1)
			name[s] = count + 1
		}
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	db := make(map[string]int)

	var n int
	fmt.Scan(&n)

	for i := 0; i < n; i++ {
		scanner.Scan()

		if db[scanner.Text()] != 0 {
			fmt.Fprintf(writer, "%v%v\n", scanner.Text(), db[scanner.Text()])
		} else {
			writer.WriteString("OK\n")
		}
		db[scanner.Text()]++
	}

	writer.Flush()
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(r, "%d\n", &n)
	ds := make(map[string]int, n)
	for i:= 0; i<n; i++{
		var s string
		fmt.Fscanf(r, "%d\n", &s)
		if _, ok := ds[s]; ok {
			ds[s]++
			fmt.Printf("%s%d\n", s, ds[s])
			continue
		}
		fmt.Println("OK")
		ds[s] = 0
	}
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

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

func main() {
	defer writer.Flush()

	var n int
	scanf("%d\n", &n)

	names := make(map[string]int)
	for i := 0; i < n; i++ {
		nameb, err := reader.ReadBytes('\n')
		if err != nil {
			log.Fatal(err)
		}

		name := string(nameb[0 : len(nameb)-1])
		if len(name) == 0 {
			continue
		}

		if count, ok := names[name]; ok {
			printf("%s%dx\n", name, count)
			names[name]++
		} else {
			printf("OK\n")
			names[name] = 1
		}
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}
func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	defer writer.Flush()

	var n int
	scanf("%d\n", &n)
	names := make(map[string]int)
	for i := 0; i < n; i++ {
		name, err := reader.ReadString('\n')
		if err != nil {
			log.Fatal(err)
		}

		name = strings.TrimSuffix(name, "\n")
		if len(name) == 0 {
			continue
		}

		if count, ok := names[name]; ok {
			printf("%s%d\n", name, count)
			names[name]++
		} else {
			printf("OK\n")
			names[name] = 1
		}
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func close() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	var n int
	scanf("%d\n", &n)
	names := make(map[string]int)
	for i := 0; i < n; i++ {
		name, err := reader.ReadString('\n')
		if err != nil {
			log.Fatal(err)
		}

		name = strings.TrimSuffix(name, "\n")
		if len(name) == 0 {
			continue
		}

		if count, ok := names[name]; ok {
			printf("x%s%d\n", name, count)
			writer.Flush()
			names[name]++
		} else {
			printf("OK\n")
			names[name] = 1
		}
	}
	close()
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

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

//func scanf(format string, args ...interface{}) {
//	_, err := fmt.Scanf(format, args...)
//	if err != nil {
//		fmt.Printf("%v\n", err)
//		log.Fatal(err)
//	}
//}

func main() {
	defer writer.Flush()

	var n int
	scanf("%d\n", &n)

	names := make(map[string]int)
	for i := 0; i < n; i++ {
		nameb, err := reader.ReadBytes('\n')
		if err != nil {
			log.Fatal(err)
		}

		name := string(nameb[0 : len(nameb)-1])
		if len(name) == 0 {
			continue
		}

		if count, ok := names[name]; ok {
			printf("%s%d\n", name, count)
			names[name]++
		} else {
			printf("OK\n")
			names[name] = 1
		}
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func close() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	var n int
	scanf("%d\n", &n)
	names := make(map[string]int)
	for i := 0; i < n; i++ {
		name, err := reader.ReadString('\n')
		if err != nil {
			log.Fatal(err)
		}

		name = strings.TrimSuffix(name, "\n")
		if len(name) == 0 {
			continue
		}

		if count, ok := names[name]; ok {
			printf("x%s%d\n", name, count)
			names[name]++
		} else {
			printf("OK\n")
			names[name] = 1
		}
	}
	close()
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func close() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	var n int
	scanf("%d\n", &n)
	names := make(map[string]int)
	for i := 0; i < n; i++ {
		name, err := reader.ReadString('\n')
		if err != nil {
			log.Fatal(err)
		}

		name = strings.TrimSuffix(name, "\n")
		if len(name) == 0 {
			continue
		}

		if count, ok := names[name]; ok {
			for i := 0; i < len(name); i++ {
				fmt.Fprintf(writer, "[%d=%d,%c]", i, int(name[i]), name[i])
			}
			fmt.Fprintf(writer, "%s%d\n", name[0:7], count)
			names[name]++
		} else {
			printf("OK\n")
			names[name] = 1
		}
	}
	close()
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}
func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	defer writer.Flush()

	var n int
	scanf("%d\n", &n)
	names := make(map[string]int)
	for i := 0; i < n; i++ {
		name, err := reader.ReadString('\n')
		if err != nil {
			log.Fatal(err)
		}

		name = strings.TrimSuffix(name, "\n")
		if len(name) == 0 {
			continue
		}

		if count, ok := names[name]; ok {
			printf("%s%d\n", name, count*2)
			names[name]++
		} else {
			printf("OK\n")
			names[name] = 1
		}
	}
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

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

func main() {
	defer writer.Flush()

	var n int
	scanf("%d\n", &n)

	names := make(map[string]int)
	for i := 0; i < n; i++ {
		nameb, err := reader.ReadBytes('\n')
		if err != nil {
			log.Fatal(err)
		}

		name := string(nameb[0 : len(nameb)-1])
		if len(name) == 0 {
			continue
		}

		if count, ok := names[name]; ok {
			printf("%s%d\n", name, count)
			names[name]++
		} else {
			printf("OK\n")
			names[name] = 1
		}
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func close() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	var n int
	scanf("%d\n", &n)
	names := make(map[string]int)
	for i := 0; i < n; i++ {
		name, err := reader.ReadString('\n')
		if err != nil {
			log.Fatal(err)
		}

		name = strings.TrimSuffix(name, "\n")
		if len(name) == 0 {
			continue
		}

		if count, ok := names[name]; ok {
			printf("%s%d\n", name, count)
			names[name]++
		} else {
			printf("OK\n")
			names[name] = 1
		}
	}
	close()
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func close() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	var n int
	scanf("%d\n", &n)
	names := make(map[string]int)
	for i := 0; i < n; i++ {
		name, err := reader.ReadString('\n')
		if err != nil {
			log.Fatal(err)
		}

		name = strings.TrimSuffix(name, "\n")
		if len(name) == 0 {
			continue
		}

		if count, ok := names[name]; ok {
			//printf("%s%d\n", name, count)
			printf("%s", name)
			printf("%d", count)
			writer.Flush()
			names[name]++
		} else {
			printf("OK\n")
			names[name] = 1
		}
	}
	close()
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func close() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	var n int
	scanf("%d\n", &n)
	names := make(map[string]int)
	for i := 0; i < n; i++ {
		name, err := reader.ReadString('\n')
		if err != nil {
			log.Fatal(err)
		}

		name = strings.TrimSuffix(name, "\n")
		if len(name) == 0 {
			continue
		}

		if _, ok := names[name]; ok {
			//printf("x%s%d\n", name, count)
			names[name]++
		} else {
			printf("OK\n")
			names[name] = 1
		}
	}
	close()
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func close() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	var n int
	scanf("%d\n", &n)
	names := make(map[string]int)
	for i := 0; i < n; i++ {
		name, err := reader.ReadString('\n')
		if err != nil {
			log.Fatal(err)
		}

		name = strings.TrimSuffix(name, "\n")
		if len(name) == 0 {
			continue
		}

		if count, ok := names[name]; ok {
			fmt.Fprintf(writer, "%s%d\n", name[0:], count)
			names[name]++
		} else {
			printf("OK\n")
			names[name] = 1
		}
	}
	close()
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func close() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	var n int
	scanf("%d\n", &n)
	names := make(map[string]int)
	for i := 0; i < n; i++ {
		name, err := reader.ReadString('\n')
		for i := 0; i < len(name); i++ {
			fmt.Fprintf(writer, "[%d=%d,%c]", i, int(name[i]), name[i])
		}
		if err != nil {
			log.Fatal(err)
		}

		name = strings.TrimSuffix(name, "\n")
		if len(name) == 0 {
			continue
		}

		if count, ok := names[name]; ok {
			for i := 0; i < len(name); i++ {
				fmt.Fprintf(writer, "[%d=%d,%c]", i, int(name[i]), name[i])
			}
			fmt.Fprintf(writer, "%s%d\n", name[0:7], count)
			names[name]++
		} else {
			printf("OK\n")
			names[name] = 1
		}
	}
	close()
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}
func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	defer writer.Flush()

	var n int
	scanf("%d\n", &n)
	names := make(map[string]int)
	for i := 0; i < n; i++ {
		name, err := reader.ReadString('\n')
		if err != nil {
			log.Fatal(err)
		}

		name = strings.TrimSuffix(name, "\n")
		if len(name) == 0 {
			continue
		}

		if count, ok := names[name]; ok {
			fmt.Printf("%s%d\n", name, count)
			names[name]++
		} else {
			fmt.Printf("OK\n")
			names[name] = 1
		}
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func close() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	var n int
	scanf("%d\n", &n)
	names := make(map[string]int)
	for i := 0; i < n; i++ {
		name, err := reader.ReadString('\n')
		if err != nil {
			log.Fatal(err)
		}

		name = strings.TrimSuffix(name, "\n")
		if len(name) == 0 {
			continue
		}

		if count, ok := names[name]; ok {
			fmt.Fprintf(writer, "%s%d\n", name[0:len(name)], count)
			names[name]++
		} else {
			printf("OK\n")
			names[name] = 1
		}
	}
	close()
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func close() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	var n int
	scanf("%d\n", &n)
	names := make(map[string]int)
	for i := 0; i < n; i++ {
		name, err := reader.ReadString('\n')
		if err != nil {
			log.Fatal(err)
		}

		name = strings.TrimSuffix(name, "\n")
		if len(name) == 0 {
			continue
		}

		if count, ok := names[name]; ok {
			fmt.Fprintf(writer, "%s%d\n", name, count)
			names[name]++
		} else {
			printf("OK\n")
			names[name] = 1
		}
	}
	close()
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func close() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	var n int
	scanf("%d\n", &n)
	names := make(map[string]int)
	for i := 0; i < n; i++ {
		name, err := reader.ReadString('\n')
		if err != nil {
			log.Fatal(err)
		}

		name = strings.TrimSuffix(name, "\n")
		if len(name) == 0 {
			continue
		}

		if count, ok := names[name]; ok {
			printf("%s%d\n", name, count)
			writer.Flush()
			names[name]++
		} else {
			printf("OK\n")
			names[name] = 1
		}
	}
	close()
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func close() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	var n int
	scanf("%d\n", &n)
	names := make(map[string]int)
	for i := 0; i < n; i++ {
		name, err := reader.ReadString('\n')
		if err != nil {
			log.Fatal(err)
		}

		name = strings.TrimSuffix(name, "\n")
		if len(name) == 0 {
			continue
		}

		if count, ok := names[name]; ok {
			fmt.Fprintf(writer, "%s%d\n", name[0:6], count)
			names[name]++
		} else {
			printf("OK\n")
			names[name] = 1
		}
	}
	close()
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func close() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	var n int
	scanf("%d\n", &n)
	names := make(map[string]int)
	for i := 0; i < n; i++ {
		name, err := reader.ReadString('\n')
		if err != nil {
			log.Fatal(err)
		}

		name = strings.TrimSuffix(name, "\n")
		if len(name) == 0 {
			continue
		}

		if count, ok := names[name]; ok {
			fmt.Fprintf(writer, "%s%d\n", name[0:2], count)
			names[name]++
		} else {
			printf("OK\n")
			names[name] = 1
		}
	}
	close()
}

package main

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

func main() {
	var n int
	fmt.Scanf("%d \n", &n)
	result := ""
	myMap := make(map[string]int)
	scanner := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		scanner.Scan()
		temp := scanner.Text()
		if myMap[temp] == 0 {
			fmt.Println("OK")
		} else {
			result += temp + strconv.Itoa(myMap[temp])
			fmt.Println(result)
			myMap[result]++
		}
		myMap[temp]++
	}
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    var n int
    m := make(map[string]int)
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        scanner.Scan()
        if m[scanner.Text()] == 0 {
            fmt.Println("OK")
            m[scanner.Text()]++
        } else {
            fmt.Println(scanner.Text()+strconv.Itoa(m[scanner.Text()]))
            m[scanner.Text()]++
        }
    }
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    writer := bufio.NewWriter(os.Stdout)
    var n int
    m := make(map[string]int)
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        scanner.Scan()
        if m[scanner.Text()] == 0 {
            writer.WriteString("OK"+"\n")
            m[scanner.Text()]++
        } else {
            writer.WriteString(scanner.Text()+strconv.Itoa(m[scanner.Text()])+"\n")
            m[scanner.Text()]++
        }
    }
    writer.Flush()
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func main() {

	defer writer.Flush()
	var t int
	scanf("%d\n", &t)

	db := make(map[string]*int)

	for i := 0; i < t; i++ {
		var name string
		scanf("%s \n", &name)

		names, ok := db[name]
		if !ok {
			var a = 0
			db[name] = &a
			fmt.Println("OK")
			continue
		}

		*names = *names + 1
		newName := name + strconv.Itoa(*names)
		printf("%s\n", newName)
	}
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func main() {

	defer writer.Flush()
	var t int
	scanf("%d\n", &t)

	db := make(map[string]*int)

	for i := 0; i < t; i++ {
		var name string
		scanf("%s \n", &name)

		names, ok := db[name]
		if !ok {
			var a = 0
			db[name] = &a
			fmt.Println("OK")
			continue
		}

		*names = *names + 1
		newName := name + strconv.Itoa(*names)
		println(newName)
	}
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func main() {
	var t int
	scanf("%d\n", &t)

	db := make(map[string]*int)

	for i := 0; i < t; i++ {
		var name string
		scanf("%s \n", &name)

		names, ok := db[name]
		if !ok {
			var a = 0
			db[name] = &a
			fmt.Println("OK")
			writer.Flush()
			continue
		}

		*names = *names + 1
		newName := name + strconv.Itoa(*names)
		println(newName)

		writer.Flush()
	}
}

package main

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

func main() {
	var t int
	fmt.Scanf("%d\n", &t)

	db := make(map[string]*int)

	reader := bufio.NewReader(os.Stdin)

	for i := 0; i < t; i++ {
		//var name string
		//fmt.Scanf("%s \n", &name)
		name, _ := reader.ReadString('\n')

		name = strings.Replace(name, "\n", "", -1)

		names, ok := db[name]
		if !ok {
			var a = 0
			db[name] = &a
			fmt.Println("OK")
			continue
		}

		*names = *names + 1
		newName := name + strconv.Itoa(*names)
		fmt.Println(newName)
	}
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func main() {

	defer writer.Flush()
	var t int
	scanf("%d\n", &t)

	db := make(map[string]*int)

	for i := 0; i < t; i++ {
		var name string
		scanf("%s \n", &name)

		names, ok := db[name]
		if !ok {
			var a = 0
			db[name] = &a
			fmt.Println("OK")
			continue
		}

		*names = *names + 1
		newName := name + strconv.Itoa(*names)
		printf(newName)
	}
}

package main

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

var reader *bufio.Reader

func init() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader = bufio.NewReaderSize(stdin, 1<<20)
}

var n int
var s string

func main() {
	fmt.Fscan(reader, &n)
	m := make(map[string]int)
	for ; n != 0; n-- {
		fmt.Fscan(reader, &s)
		if m[s] == 0 {
			fmt.Println("OK")
		} else {
			fmt.Print(s, m[s], "\n")
		}
		m[s]++
	}
	fmt.Println(n)
}

package main

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

func main() {
        m := make(map[string]int)
        var n int
        var s string
        r := bufio.NewReader(os.Stdin)
        fmt.Fscanf(r, "%d\n", &n)
        for i := 0; i < n; i++ {
                fmt.Scan(&s)//fmt.Fscanf(r, "%s\n", &s)
                v := m[s]
                if v == 0 {
                        fmt.Println("OK")
                } else {
                        fmt.Printf("%s%d\n", s, v)
                }
                v++
                m[s] = v
        }
}

package main

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

func main() {
        m := make(map[string]int)
        var n int
        r := bufio.NewReader(os.Stdin)
        fmt.Fscanf(r, "%d\n", &n)
        for i := 0; i < n; i++ {
                var s string
                fmt.Scan(&s)//fmt.Fscanf(r, "%s\n", &s)
                v := m[s]
                if v == 0 {
                        fmt.Println("OK")
                } else {
                        fmt.Printf("%s%d\n", s, v)
                }
                v++
                m[s] = v
        }
}

package main

import "fmt"

func main() {
	names := make(map[string]int)

	var n int
	fmt.Scanf("%d", &n)

	for i := 0; i < int(n); i++ {
		var name string
		fmt.Scanf("%s", &name)

		if indices, ok := names[name]; ok {
			names[name]++
			fmt.Printf("%s%d\n", name, indices)
		} else {
			names[name] = 1
			fmt.Println("OK")
		}
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	var dict StringSet
	for i := 0; i < n; i++ {
		scanner.Scan()
		name := scanner.Text()
		if(!dict.Has(name)) {
			dict.Add(name)
			fmt.Printf("%s\n", "OK")
		} else {
			fmt.Printf("%s\n", findNextAvailable(&dict, name))
		}
	}
}

func findNextAvailable(s *StringSet, candidate string) string {
	i := 1
	nextCandidate := candidate+strconv.Itoa(i)
	for s.Has(nextCandidate) {
		i += 1
		nextCandidate = candidate+strconv.Itoa(i)
	}
	return nextCandidate
}

type StringSet struct {
	items map[string]bool
}

func (s *StringSet) Add(t string) *StringSet {
	if s.items == nil {
		s.items = make(map[string]bool)
	}
	_, ok := s.items[t]
	if !ok {
		s.items[t] = true
	}
	return s
}

func (s *StringSet) Has(item string) bool {
	_, ok := s.items[item]
	return ok
}

package main

import "fmt"

func main() {
	var n int
	var name string

	db := make(map[string]int, 100005)

	fmt.Scanf("%d", &n)

	for i := 0; i < n; i++ {
		// Individual name
		fmt.Scanf("%s",&name)
		// Add it to the db
		count, ok := db[name]

		if !ok {
			// It does not exists yet, so lets 'create' it
			db[name] = 0
			fmt.Println("OK")
		} else {
			//Not ok. There are one or more users with
			//The same name.
			fmt.Printf("%s%d\n", name, count)
		}

		// At this point it is guaranteed to exist
		db[name]++
	}
}

package main

import "fmt"

func main() {
	var n int
	var name string

	db := make(map[string]int, 1000005)

	fmt.Scanf("%d", &n)

	for i := 0; i < n; i++ {
		// Individual name
		fmt.Scanln(&name)
		// Add it to the db
		//fmt.Println(name)

		count, exists := db[name]

		if !exists {
			//fmt.Println("Adding new")
			//db[name] = 0
			fmt.Println("OK")
		} else {
			//fmt.Println(name, "Found. Occurences: ", count)
			fmt.Printf("%s%d\n", name, count)
		}

		db[name]++
	}

	//fmt.Println(db)
}

package main

import "fmt"

func main() {
	var n int
	var name string

	db := make(map[string]int, 100005)

	fmt.Scanf("%d", &n)

	for i := 0; i < n; i++ {
		// Individual name
		fmt.Scanln(&name)
		// Add it to the db
		count, ok := db[name]

		if !ok {
			// It does not exists yet, so lets 'create' it
			db[name] = 0
			fmt.Println("Ok")
		} else {
			//Not ok. There are one or more users with
			//The same name.
			fmt.Printf("%s%d\n", name, count)
		}

		// At this point it is guaranteed to exist
		db[name]++
	}
}

package main

import (
	"fmt"
	"regexp"
)

var reg = regexp.MustCompile(`([1-9])`)

func main() {
	var count int
	fmt.Scanf("%d\n", &count)
	var strs []string
	for i := 0; i < count; i++ {
		var str string
		fmt.Scanf("%s\n", &str)
		strs = append(strs, str)
	}
	//dic := make(map[string]int)

	for _, str := range strs {
		if reg.FindStringSubmatch(str) != nil {
			fmt.Println("has number:", str)
		}
		// if count, has := dic[str]; !has {
		// 	dic[str] = 1
		// 	fmt.Println("OK")
		// } else {
		// 	fmt.Println(str + strconv.Itoa(count))
		// 	dic[str]++
		// }
	}
}

package main

import (
	"fmt"
	"strconv"
)

func main() {
	var count int
	fmt.Scanf("%d\n", &count)
	var strs []string
	for i := 0; i < count; i++ {
		var str string
		fmt.Scanf("%s\n", &str)
		strs = append(strs, str)
	}
	dic := make(map[string]bool)
	var ret string
	for _, str := range strs {
		if _, has := dic[str]; !has {
			dic[str] = true
			ret = ret + "OK" + "\n"
		} else {
			for i := 1; ; i++ {
				newName := str + strconv.Itoa(i)
				if _, has := dic[newName]; !has {
					dic[newName] = true
					ret = ret + newName + "\n"
					break
				}
			}
		}
	}
	for _, str := range ret {
		fmt.Println(str)
	}
}

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
)

type login struct {
	name  []byte
	count int
}

func bytesEqual(a, b []byte) bool {
	l := len(a)
	if l != len(b) {
		return false
	}
	for i := 0; i < l; i += 1 {
		if a[i] != b[i] {
			return false
		}
	}
	return true
}

func updateLogins(list []login, l []byte) ([]login, int) {
	for i := 0; i < len(list); i += 1 {
		if bytesEqual(list[i].name, l) {
			list[i].count += 1
			return list, list[i].count
		}
	}
	list = append(list, login{name: l, count: 0})
	return list, 0
}

// https://codeforces.com/problemset/problem/4/C
// комментарии к решению
// Задача хорошо ложиться на go'шный map, но при попытке использования map[string]int
// мы падаем по времени, а для []byte map не работает, поэтому реализуем на основе списков
func taskSolution(a [][]byte) string {
	seen := []login{}
	count := 0
	ans := []byte{}
	for i := 0; i < len(a); i += 1 {
		seen, count = updateLogins(seen, bytes.TrimSpace(a[i]))
		if count == 0 {
			ans = append(ans, []byte("OK\n")...)
		} else {
			strInt := []byte(fmt.Sprintln(count))
			ans = append(ans, a[i]...)
			ans = append(ans, strInt...)
		}
	}
	return string(ans[:len(ans)-1])
}

func main() {
	var n int
	if _, err := fmt.Scan(&n); err != nil {
		panic(err)
	}

	inRaw, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		panic(err)
	}
	inRawArr := bytes.Split(bytes.TrimSpace(inRaw), []byte("\n"))

	fmt.Println(taskSolution(inRawArr))
}

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
)

type login struct {
	name  []byte
	count int
}

func bytesEqual(a, b []byte) bool {
	l := len(a)
	if l != len(b) {
		return false
	}
	for i := 0; i < l; i += 1 {
		if a[i] != b[i] {
			return false
		}
	}
	return true
}

func updateLogins(list []login, l []byte) ([]login, int) {
	for i := 0; i < len(list); i += 1 {
		if bytesEqual(list[i].name, l) {
			list[i].count += 1
			return list, list[i].count
		}
	}
	list = append(list, login{name: l, count: 0})
	return list, 0
}

// https://codeforces.com/problemset/problem/4/C
// комментарии к решению
// Задача хорошо ложиться на go'шный map, но при попытке использования map[string]int
// мы падаем по времени, а для []byte map не работает, поэтому реализуем на основе списков
func taskSolution(a [][]byte) string {
	seen := []login{}
	count := 0
	ans := []byte{}
	for i := 0; i < len(a); i += 1 {
		seen, count = updateLogins(seen, bytes.TrimSpace(a[i]))
		if count == 0 {
			ans = append(ans, []byte("OK\n")...)
		} else {
			strInt := []byte(fmt.Sprintln(count))
			ans = append(ans, a[i]...)
			ans = append(ans, strInt...)
		}
	}
	return string(ans)
}

func main() {
	var n int
	if _, err := fmt.Scan(&n); err != nil {
		panic(err)
	}

	inRaw, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		panic(err)
	}
	inRawArr := bytes.Split(bytes.TrimSpace(inRaw), []byte("\n"))

	fmt.Println(taskSolution(inRawArr))
}


As you might remember from our previous rounds, Vova really likes computer games. Now he is playing a strategy game known as Rage of Empires.In the game Vova can hire n different warriors; ith warrior has the type ai. Vova wants to create a balanced army hiring some subset of warriors. An army is called balanced if for each type of warrior present in the game there are not more than k warriors of this type in the army. Of course, Vova wants his army to be as large as possible.To make things more complicated, Vova has to consider q different plans of creating his army. ith plan allows him to hire only warriors whose numbers are not less than li and not greater than ri.Help Vova to determine the largest size of a balanced army for each plan.Be aware that the plans are given in a modified way. See input section for details.

The first line contains two integers n and k (1 ≤ n, k ≤ 100000). The second line contains n integers a1, a2, ... an (1 ≤ ai ≤ 100000). The third line contains one integer q (1 ≤ q ≤ 100000). Then q lines follow. ith line contains two numbers xi and yi which represent ith plan (1 ≤ xi, yi ≤ n). You have to keep track of the answer to the last plan (let's call it last). In the beginning last = 0. Then to restore values of li and ri for the ith plan, you have to do the following:   li = ((xi + last) mod n) + 1;  ri = ((yi + last) mod n) + 1;  If li > ri, swap li and ri.

Print q numbers. ith number must be equal to the maximum size of a balanced army when considering ith plan.

NoteIn the first example the real plans are:   1 2  1 6  6 6  2 4  4 6

package main

import (
	"bufio"
	. "fmt"
	"math/bits"
	"os"
)

type pstNode struct {
	l, r   int
	lo, ro *pstNode
	sum    int
}
type pst struct {
	nodes        []pstNode
	versionRoots []*pstNode
}

func (t *pst) _build(l, r int) *pstNode {
	t.nodes = append(t.nodes, pstNode{l: l, r: r})
	o := &t.nodes[len(t.nodes)-1]
	if l == r {
		return o
	}
	mid := (l + r) >> 1
	o.lo = t._build(l, mid)
	o.ro = t._build(mid+1, r)
	return o
}

func (t *pst) _update(o *pstNode, idx int, val int) *pstNode {
	t.nodes = append(t.nodes, *o)
	o = &t.nodes[len(t.nodes)-1]
	if o.l == o.r {
		o.sum += val
		return o
	}
	if mid := o.lo.r; idx <= mid {
		o.lo = t._update(o.lo, idx, val)
	} else {
		o.ro = t._update(o.ro, idx, val)
	}
	o.sum = o.lo.sum + o.ro.sum
	return o
}

func (t *pst) _query(o *pstNode, l, r int) (res int) {
	if l <= o.l && o.r <= r {
		return o.sum
	}
	mid := o.lo.r
	if l <= mid {
		res += t._query(o.lo, l, r)
	}
	if mid < r {
		res += t._query(o.ro, l, r)
	}
	return
}

func (t *pst) init(n int) {
	t.versionRoots[0] = t._build(1, n)
}

func (t *pst) update(dstVersion, srcVersion int, idx int, val int) {
	t.versionRoots[dstVersion] = t._update(t.versionRoots[srcVersion], idx, val)
}

func (t *pst) query(version int, l, r int) (sum int) {
	return t._query(t.versionRoots[version], l, r)
}

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var n, k, v, q, l, r int
	Fscan(in, &n, &k)
	t := &pst{
		make([]pstNode, 0, (bits.Len(uint(n))+2)*2*n),
		make([]*pstNode, n+1),
	}
	t.init(n)
	idx := [100001][]int{}
	for i := 1; i <= n; i++ {
		Fscan(in, &v)
		t.update(i, i-1, i, 1)
		idx[v] = append(idx[v], i)
		if sz := len(idx[v]); sz > k {
			t.update(i, i, idx[v][sz-k-1], -1)
		}
	}

	last := 0
	for Fscan(in, &q); q > 0; q-- {
		Fscan(in, &l, &r)
		l = (l+last)%n + 1
		r = (r+last)%n + 1
		if l > r {
			l, r = r, l
		}
		last = t.query(r, l, r)
		Fprintln(out, last)
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"os"
)

type pstNode struct {
	l, r   int
	lo, ro *pstNode
	sum    int
}
type pst struct {
	nodes        []pstNode
	versionRoots []*pstNode
}

func (t *pst) _build(l, r int) *pstNode {
	t.nodes = append(t.nodes, pstNode{l: l, r: r})
	o := &t.nodes[len(t.nodes)-1]
	if l == r {
		return o
	}
	mid := (l + r) >> 1
	o.lo = t._build(l, mid)
	o.ro = t._build(mid+1, r)
	return o
}

func (t *pst) _update(o *pstNode, idx int, val int) *pstNode {
	t.nodes = append(t.nodes, *o)
	o = &t.nodes[len(t.nodes)-1]
	if o.l == o.r {
		o.sum += val
		return o
	}
	if mid := o.lo.r; idx <= mid {
		o.lo = t._update(o.lo, idx, val)
	} else {
		o.ro = t._update(o.ro, idx, val)
	}
	o.sum = o.lo.sum + o.ro.sum
	return o
}

func (t *pst) _query(o *pstNode, l, r int) (res int) {
	if l <= o.l && o.r <= r {
		return o.sum
	}
	mid := o.lo.r
	if l <= mid {
		res += t._query(o.lo, l, r)
	}
	if mid < r {
		res += t._query(o.ro, l, r)
	}
	return
}

func (t *pst) init(n int) {
	t.versionRoots[0] = t._build(1, n)
}

func (t *pst) update(dstVersion, srcVersion int, idx int, val int) {
	t.versionRoots[dstVersion] = t._update(t.versionRoots[srcVersion], idx, val)
}

func (t *pst) query(version int, l, r int) (sum int) {
	return t._query(t.versionRoots[version], l, r)
}

// github.com/EndlessCheng/codeforces-go
func Sol813E(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var n, k, v, q, l, r int
	Fscan(in, &n, &k)
	t := &pst{
		make([]pstNode, 0, (bits.Len(uint(n))+2)*2*n),
		make([]*pstNode, n+1),
	}
	t.init(n)
	idx := [100001][]int{}
	for i := 1; i <= n; i++ {
		Fscan(in, &v)
		t.update(i, i-1, i, 1)
		idx[v] = append(idx[v], i)
		if sz := len(idx[v]); sz > k {
			t.update(i, i, idx[v][sz-k-1], -1)
		}
	}

	last := 0
	for Fscan(in, &q); q > 0; q-- {
		Fscan(in, &l, &r)
		l = (l+last)%n + 1
		r = (r+last)%n + 1
		if l > r {
			l, r = r, l
		}
		last = t.query(r, l, r)
		Fprintln(out, last)
	}
}

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


It's Petya's birthday party and his friends have presented him a brand new "Electrician-$$$n$$$" construction set, which they are sure he will enjoy as he always does with weird puzzles they give him.Construction set "Electrician-$$$n$$$" consists of $$$2n - 1$$$ wires and $$$2n$$$ light bulbs. Each bulb has its own unique index that is an integer from $$$1$$$ to $$$2n$$$, while all wires look the same and are indistinguishable. In order to complete this construction set one has to use each of the wires to connect two distinct bulbs. We define a chain in a completed construction set as a sequence of distinct bulbs of length at least two, such that every two consecutive bulbs in this sequence are directly connected by a wire. Completed construction set configuration is said to be correct if a resulting network of bulbs and wires has a tree structure, i.e. any two distinct bulbs are the endpoints of some chain.Petya was assembling different configurations for several days, and he noticed that sometimes some of the bulbs turn on. After a series of experiments he came up with a conclusion that bulbs indexed $$$2i$$$ and $$$2i - 1$$$ turn on if the chain connecting them consists of exactly $$$d_i$$$ wires. Moreover, the following important condition holds: the value of $$$d_i$$$ is never greater than $$$n$$$.Petya did his best but was not able to find a configuration that makes all bulbs to turn on, so he seeks your assistance. Please, find out a configuration that makes all bulbs shine. It is guaranteed that such configuration always exists.

The first line of the input contains a single integer $$$n$$$ ($$$1 \leq n \leq 100\,000$$$) — the parameter of a construction set that defines the number of bulbs and the number of wires. Next line contains $$$n$$$ integers $$$d_1, d_2, \ldots, d_n$$$ ($$$1 \leq d_i \leq n$$$), where $$$d_i$$$ stands for the number of wires the chain between bulbs $$$2i$$$ and $$$2i - 1$$$ should consist of.

Print $$$2n - 1$$$ lines. The $$$i$$$-th of them should contain two distinct integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \leq a_i, b_i \leq 2n$$$, $$$a_i \ne b_i$$$) — indices of bulbs connected by a wire. If there are several possible valid answer you can print any of them.

Note    Answer for the first sample test.      Answer for the second sample test.

package main

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

type pair struct {
	first  int
	second int
}
type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Less(i, j int) bool {
	if p[i].first == p[j].first {
		return p[i].second < p[j].second
	}
	return p[i].first < p[j].first
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

var n int
var d pairs
var ans pairs

func main() {
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	fmt.Fscanf(reader, "%d\n", &n)
	for i := 0; i < n; i++ {
		var p pair
		fmt.Fscanf(reader, "%d", &p.first)
		p.second = i*2 + 1
		d = append(d, p)
	}
	sort.Sort(sort.Reverse(d))
	for i := 1; i < n; i++ {
		ans = append(ans, pair{d[i-1].second, d[i].second})
	}

	for i := 0; i < n; i++ {
		ans = append(ans, pair{d[i+d[i].first-1].second, d[i].second + 1})
		if d[i].first == len(d)-i {
			d = append(d, pair{0, d[i].second + 1})
		}
	}
	// fmt.Println(d)

	for i := 0; i < len(ans); i++ {
		fmt.Println(ans[i].first, ans[i].second)
	}
}

package main

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

type pair struct {
	first  int
	second int
}
type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Less(i, j int) bool {
	if p[i].first == p[j].first {
		return p[i].second < p[j].second
	}
	return p[i].first < p[j].first
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

var n int
var d pairs
var ans pairs

func main() {
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	fmt.Fscanf(reader, "%d\n", &n)
	for i := 0; i < n; i++ {
		var p pair
		fmt.Fscanf(reader, "%d", &p.first)
		p.second = i*2 + 1
		d = append(d, p)
	}
	sort.Sort(sort.Reverse(d))
	for i := 1; i < n; i++ {
		ans = append(ans, pair{d[i-1].second, d[i].second})
	}
	// fmt.Println(d)

	for i := 0; i < n; i++ {
		ans = append(ans, pair{d[i+d[i].first].second, d[i].second + 1})
		if d[i].first == len(d)-1-i {
			d = append(d, pair{0, d[i].second + 1})
		}
	}

	for i := 0; i < len(ans); i++ {
		fmt.Println(ans[i].first, ans[i].second)
	}
}

package main

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

type pair struct {
	first  int
	second int
}
type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Less(i, j int) bool {
	if p[i].first == p[j].first {
		return p[i].second < p[j].second
	}
	return p[i].first < p[j].first
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

var n int
var d pairs
var ans pairs

func main() {
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	fmt.Fscanf(reader, "%d\n", &n)
	for i := 0; i < n; i++ {
		var p pair
		fmt.Fscanf(reader, "%d", &p.first)
		p.second = i*2 + 1
		d = append(d, p)
	}
	sort.Sort(sort.Reverse(d))
	for i := 1; i < n; i++ {
		ans = append(ans, pair{d[i-1].second, d[i].second})
	}
	// fmt.Println(d)

	for i := 0; i < n; i++ {
		ans = append(ans, pair{d[i+d[i].first-1].second, d[i].second + 1})
		if d[i].first == len(d)-1-i {
			d = append(d, pair{0, d[i].second + 1})
		}
	}

	for i := 0; i < len(ans); i++ {
		fmt.Println(ans[i].first, ans[i].second)
	}
}


Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.

The first line contains integer n (1 ≤ n ≤ 100) — the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai, bi (1 ≤ ai, bi ≤ 1000) — the description of the i-th bottle.

In a single line print a single integer — the answer to the problem.

//http://codeforces.com/problemset/problem/315/A
//A. Sereja and Bottles
// van befoka masfelebol legalabb ket
// 1 1
// 2 1
// a hurokeleket is nezni kell

package main

import (
	"fmt"
)

func main() {
	var (
		n, i, a, b, max, min int32
		self, aux, frek      [1008]int32
	)

	fmt.Scan(&n)
	min = 1008
	for i = 0; i < n; i++ {
		fmt.Scan(&a)
		if a > max {
			max = a
		}
		if a < min {
			min = a
		}
		frek[a]++
		fmt.Scan(&b)
		if a != b {
			aux[b]++
		} else {
			self[a]++
		}
	}

	n = 0
	for i = min; i <= max; i++ {
		if frek[i] > 0 {
			if aux[i] > 0 || self[i] > 1 {
				continue
			}
			if 0 == self[i] {
				n += frek[i]
				continue
			}
			// self[i] itt 1, csak onmagat nem tudja kinyitni
			// az osszes tobbi azonos tipusut igen
			n++
		}
	}

	fmt.Println(n)
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func max(nums ...int64) int64 {
	var m int64
	for i, v := range nums{
		if i == 0 || v > m {
			m = v
		}
	}
	return m
}

func main() {
	var n, res int;
	scanf("%d\n", &n)
	a := make([]int, n)
	b := make([]int, n)
	types := make(map[int]int)
	for i := range a {
		scanf("%d %d\n", &a[i], &b[i])
		types[b[i]]++
	}

	for i := range a {
		types[b[i]]--
		if types[a[i]] == 0 {
			res++
		}
		types[b[i]]++
	}

	fmt.Println(res)
}

package main

import (
  "bufio"
  "os"
  "strconv"
)

var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func ni() int {
  sc.Scan()
  ans, _ := strconv.Atoi(sc.Text())
  return ans
}

func next() string {
  sc.Scan()
  return sc.Text()
}

func pri(n int)    { w.WriteString(strconv.Itoa(n)) }
func prll(n int64) { w.WriteString(strconv.FormatInt(n, 10)) }
func sp()          { w.WriteByte(' ') }
func endl()        { w.WriteByte('\n') }

func main() {
  sc.Split(bufio.ScanWords)
  n := ni()
  cnt, can := make([]int, 1000), make([]int, 1000)
  for i := 0; i < n; i++ {
    a, b := ni()-1, ni()-1
    cnt[a] += 1
    if a == b {
      can[b] += 1
    } else {
      can[b] += 2
    }
  }
  ans := 0
  for i := 0; i < 1000; i++ {
    if can[i] < 1 {
      ans += cnt[i]
    } else if can[i] < 2 {
      ans += 1
    }
  }
  pri(ans)
  w.Flush()
}

package main
import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

func main() {
	var n,i,j,k int
	k=0
	var a,b,t [105]int
	fmt.Scan(&n)
	input:= bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	for i=1;i<=n; i++{
		input.Scan()
		aa,_:=strconv.Atoi(input.Text())
		a[i]=aa
		input.Scan()
		bb,_:=strconv.Atoi(input.Text())
		b[i]=bb
	}
	for i=1;i<=n; i++{
		for j=1;j<=n;j++ {
			if a[i]==b[j] && i!=j && t[i]==0 {
				k++
				t[i]=1
			}
		}
	}
	fmt.Println(n-k)

}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

type Bottle struct {
  Brand, Opens int
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n := getI()
  bottles := make([]*Bottle, n)
  for i := 0; i < n; i++ {
    bottles[i] = &Bottle{ getI(), getI() }
  }
  result := n
  for i := 0; i < n; i++ {
    bottle := bottles[i]
    for j := 0; j < n; j++ {
      if j == i {
        continue
      }
      other := bottles[j]
      if other.Opens == bottle.Brand {
        result--
        break
      }
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n", result))
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func max(nums ...int64) int64 {
	var m int64
	for i, v := range nums{
		if i == 0 || v > m {
			m = v
		}
	}
	return m
}

func main() {
	var n, res int;
	scanf("%d\n", &n)
	a := make([]int, n)
	b := make([]int, n)
	for i := range a {
		scanf("%d %d\n", &a[i], &b[i])
	}
	opened := make(map[int]bool)

	for i := range a {
		if a[i] != b[i] {
			opened[b[i]] = true
		}
	}

	for i := range a {
		if !opened[a[i]] {
			res++
		}
	}

	fmt.Println(res)
}

package main

import (
  "bufio"
  "os"
  "strconv"
)

var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func ni() int {
  sc.Scan()
  ans, _ := strconv.Atoi(sc.Text())
  return ans
}

func next() string {
  sc.Scan()
  return sc.Text()
}

func pri(n int)    { w.WriteString(strconv.Itoa(n)) }
func prll(n int64) { w.WriteString(strconv.FormatInt(n, 10)) }
func sp()          { w.WriteByte(' ') }
func endl()        { w.WriteByte('\n') }

func main() {
  sc.Split(bufio.ScanWords)
  n := ni()
  cnt, can := make([]int, 1000), make([]int, 1000)
  for i := 0; i < n; i++ {
    a, b := ni()-1, ni()-1
    cnt[a] += 1
    if a == b {
      can[b] += 1
    } else {
      can[b] += 2
    }
  }
  ans := 0
  for i := 0; i < 1000; i++ {
    if can[i] < 2 {
      ans += cnt[i]
    }
  }
  pri(ans)
  w.Flush()
}

package main

import (
  "bufio"
  "os"
  "strconv"
)

var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func ni() int {
  sc.Scan()
  ans, _ := strconv.Atoi(sc.Text())
  return ans
}

func next() string {
  sc.Scan()
  return sc.Text()
}

func pri(n int)    { w.WriteString(strconv.Itoa(n)) }
func prll(n int64) { w.WriteString(strconv.FormatInt(n, 10)) }
func sp()          { w.WriteByte(' ') }
func endl()        { w.WriteByte('\n') }

func main() {
  sc.Split(bufio.ScanWords)
  n := ni()
  cnt, can := make([]int, 1000), make([]int, 1000)
  for i := 0; i < n; i++ {
    a, b := ni()-1, ni()-1
    cnt[a] += 1
    if a == b {
      can[b] += 1
    } else {
      can[b] += 2
    }
  }
  ans := 0
  for i := 0; i < 1000; i++ {
    if cnt[i] > 0 && can[i] < 2 {
      ans += 1
    }
  }
  pri(ans)
  w.Flush()
}

package main

import (
  "bufio"
  "os"
  "strconv"
)

var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func ni() int {
  sc.Scan()
  ans, _ := strconv.Atoi(sc.Text())
  return ans
}

func next() string {
  sc.Scan()
  return sc.Text()
}

func pri(n int)    { w.WriteString(strconv.Itoa(n)) }
func prll(n int64) { w.WriteString(strconv.FormatInt(n, 10)) }
func sp()          { w.WriteByte(' ') }
func endl()        { w.WriteByte('\n') }

func main() {
  sc.Split(bufio.ScanWords)
  n := ni()
  a, b := make([]int, n), make([]int, n)
  for i := 0; i < n; i++ {
    a[i], b[i] = ni()-1, ni()-1
  }
  cnt := make([]int, 1000)
  for i := 0; i < n; i++ {
    cnt[a[i]] += 1
  }
  state := make([]int, 1000)
  for i := 0; i < n; i++ {
    if a[i] != b[i] || cnt[a[i]] > 1 {
      state[b[i]] = 1
    }
  }
  ans := 0
  for i := 0; i < 1000; i++ {
    if cnt[i] > 0 && state[i] == 0 {
      ans += 1
    }
  }
  pri(ans)
  w.Flush()
}

//http://codeforces.com/problemset/problem/315/A
//A. Sereja and Bottles
// van befoka masfelebol legalabb ket
// 1 1
// 2 1
// a hurokeleket is nezni kell

package main

import (
	"fmt"
)

func main() {
	var (
		n, i, a, b, max int32
		self, aux, frek [1008]int32
	)

	fmt.Scan(&n)
	for i = 0; i < n; i++ {
		fmt.Scan(&a)
		if a > max {
			max = a
		}
		frek[a]++
		fmt.Scan(&b)
		if a != b {
			aux[b]++
		} else {
			self[a]++
		}
	}

	n = 0
	for i = 1; i <= max; i++ {
		if frek[i] > 0 {
			if !(aux[i] > 0 || self[i] > 1) {
				n += frek[i]
			}
		}
	}

	fmt.Println(n)
}


You are given an integer m as a product of integers a1, a2, ... an . Your task is to find the number of distinct decompositions of number m into the product of n ordered positive integers.Decomposition into n products, given in the input, must also be considered in the answer. As the answer can be very large, print it modulo 1000000007 (109 + 7).

The first line contains positive integer n (1 ≤ n ≤ 500). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).

In a single line print a single number k — the number of distinct decompositions of number m into n ordered multipliers modulo 1000000007 (109 + 7).

NoteIn the second sample, the get a decomposition of number 2, you need any one number out of three to equal 2, and the rest to equal 1.In the third sample, the possible ways of decomposing into ordered multipliers are [7,5], [5,7], [1,35], [35,1].A decomposition of positive integer m into n ordered multipliers is a cortege of positive integers b = {b1, b2, ... bn} such that . Two decompositions b and c are considered different, if there exists index i such that bi ≠ ci.

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"math"
	"os"
)

var mod uint64 = 1000000007

func mi(a, x uint64) uint64 {
	if x == 1 {
		return a
	} else if x%2 == 0 {
		ans := mi(a, x/2)
		return (ans * ans) % mod
	} else {
		ans := mi(a, x/2)
		return ((ans * ans) % mod * a) % mod
	}
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	primeMap := map[int]uint64{}
	var n uint64
	fmt.Fscanf(reader, "%d\n", &n)

	for i := uint64(0); i < n; i++ {
		var a int
		fmt.Fscanf(reader, "%d ", &a)
		for j := 2; j <= int(math.Sqrt(float64(a))); j++ {
			for ; a%j == 0; a /= j {
				primeMap[j]++
			}
		}
		if a != 1 {
			primeMap[a]++
		}
	}

	var ans uint64 = 1

	var inv uint64 = 1

	for i := uint64(1); i < n; i++ {
		inv = (inv * i) % mod
	}
	inv = mi(inv, mod-2)

	for _, count := range primeMap {
		for i := count + 1; i < count+n; i++ {
			ans = (ans * i) % mod
		}
		ans = (ans * inv) % mod
	}
	fmt.Printf("%d", ans)

}