Dima took up the biology of bacteria, as a result of his experiments, he invented k types of bacteria. Overall, there are n bacteria at his laboratory right now, and the number of bacteria of type i equals ci. For convenience, we will assume that all the bacteria are numbered from 1 to n. The bacteria of type ci are numbered from  to .With the help of special equipment Dima can move energy from some bacteria into some other one. Of course, the use of such equipment is not free. Dima knows m ways to move energy from some bacteria to another one. The way with number i can be described with integers ui, vi and xi mean that this way allows moving energy from bacteria with number ui to bacteria with number vi or vice versa for xi dollars.Dima's Chef (Inna) calls the type-distribution correct if there is a way (may be non-direct) to move energy from any bacteria of the particular type to any other bacteria of the same type (between any two bacteria of the same type) for zero cost.As for correct type-distribution the cost of moving the energy depends only on the types of bacteria help Inna to determine is the type-distribution correct? If it is, print the matrix d with size k × k. Cell d[i][j] of this matrix must be equal to the minimal possible cost of energy-moving from bacteria with type i to bacteria with type j.

The first line contains three integers n, m, k (1 ≤ n ≤ 105; 0 ≤ m ≤ 105; 1 ≤ k ≤ 500). The next line contains k integers c1, c2, ..., ck (1 ≤ ci ≤ n). Each of the next m lines contains three integers ui, vi, xi (1 ≤ ui, vi ≤ 105; 0 ≤ xi ≤ 104). It is guaranteed that .

If Dima's type-distribution is correct, print string «Yes», and then k lines: in the i-th line print integers d[i][1], d[i][2], ..., d[i][k] (d[i][i] = 0). If there is no way to move energy from bacteria i to bacteria j appropriate d[i][j] must equal to -1. If the type-distribution isn't correct print «No».

/*********************************************************************************
*     File Name           :     D.go
*     Created By          :     YIMMON, yimmon.zhuang@gmail.com
*     Creation Date       :     [2014-03-07 20:25]
*     Last Modified       :     [2014-03-07 22:14]
*     Description         :
**********************************************************************************/

package main

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

const inf = 0x3fffffff

var (
    n, m, k        int
    c, grp, parent []int
    g              [][]int
    q              chan int
    inq            []bool
)

func AddEdge(a, b, c int) {
    g[a][b] = MyInt(g[a][b]).Min(c)
    g[b][a] = g[a][b]
}

func GetParent(x int) int {
    if x != parent[x] {
        parent[x] = GetParent(parent[x])
    }
    return parent[x]
}

func Union(a, b int) {
    pa, pb := GetParent(a), GetParent(b)
    if pa != pb {
        parent[pa] = pb
    }
}

func Check() bool {
    c[k] = n + 1
    for i := 0; i < k; i++ {
        p := GetParent(c[i])
        for j := c[i] + 1; j < c[i+1]; j++ {
            if p != GetParent(j) {
                return false
            }
        }
    }
    return true
}

func Spfa(s int, dst []int) {
    for i := 0; i < k; i++ {
        dst[i] = inf
    }
    q <- s
    inq[s] = true
    dst[s] = 0
    for len(q) != 0 {
        f := <-q
        inq[f] = false
        for i := 0; i < k; i++ {
            if dst[f]+g[f][i] < dst[i] {
                dst[i] = dst[f] + g[f][i]
                if !inq[i] {
                    q <- i
                    inq[i] = true
                }
            }
        }
    }
}

func SpfaAndPrint() {
    var d = make([][]int, k)
    for i := 0; i < k; i++ {
        d[i] = make([]int, k)
        Spfa(i, d[i][:])
        for j := 0; j < k; j++ {
            if j > 0 {
                fmt.Print(" ")
            }
            if d[i][j] >= inf {
                d[i][j] = -1
            }
            fmt.Print(d[i][j])
        }
        fmt.Println()
    }
}

func main() {
    scanner.Split(bufio.ScanWords)

    scanner.NextInts(&n, &m, &k)
    c, grp, parent = make([]int, k+1), make([]int, n+1), make([]int, n+1)
    g = make([][]int, k)
    q = make(chan int, k)
    inq = make([]bool, k)
    for i, j := 0, 1; i < k; i++ {
        c[i], j = j, scanner.NextInt()+j
        for l := c[i]; l < j; l++ {
            grp[l], parent[l] = i, l
        }
        g[i] = make([]int, k)
        for l := 0; l < k; l++ {
            g[i][l] = inf
        }
    }
    for i := 0; i < m; i++ {
        var u, v, x int
        scanner.NextInts(&u, &v, &x)
        AddEdge(grp[u], grp[v], x)
        if x == 0 {
            Union(u, v)
        }
    }
    if Check() {
        fmt.Println("Yes")
        SpfaAndPrint()
    } else {
        fmt.Println("No")
    }
}

type Scanner struct {
    *bufio.Scanner
}

var scanner = Scanner{bufio.NewScanner(os.Stdin)}

func (self *Scanner) Next() string {
    if !self.Scan() {
        panic(self.Err())
    }
    return self.Text()
}

func (self *Scanner) NextInt() int {
    x, err := strconv.Atoi(self.Next())
    if err != nil {
        panic(err)
    }
    return x
}

func (self *Scanner) NextInts(args ...*int) {
    for _, v := range args {
        *v = self.NextInt()
    }
}

type MyInt int

func (self MyInt) Min(x int) int {
    if int(self) < x {
        return int(self)
    }
    return x
}

/*********************************************************************************
*     File Name           :     D.go
*     Created By          :     YIMMON, yimmon.zhuang@gmail.com
*     Creation Date       :     [2014-03-07 20:25]
*     Last Modified       :     [2014-03-07 21:49]
*     Description         :
**********************************************************************************/

package main

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

const inf = 0x3fffffff

var (
    n, m, k        int
    c, grp, parent []int
    g              [][]int
)

func AddEdge(a, b, c int) {
    g[a][b] = MyInt(g[a][b]).Min(c)
    g[b][a] = MyInt(g[b][a]).Min(c)
}

func GetParent(x int) int {
    px := x
    for parent[px] != px {
        px = parent[px]
    }
    for parent[x] != x {
        x, parent[x] = parent[x], px
    }
    return px
}

func Union(a, b int) {
    pa, pb := GetParent(a), GetParent(b)
    if pa != pb {
        parent[pa] = pb
    }
}

func Check() bool {
    c[k] = n + 1
    for i := 0; i < k; i++ {
        p := GetParent(c[i])
        for j := c[i] + 1; j < c[i+1]; j++ {
            if p != GetParent(j) {
                return false
            }
        }
    }
    return true
}

func Spfa(s int, dst []int) {
    var q = make(chan int, k)
    var inq = make([]bool, k)
    for i := 0; i < k; i++ {
        dst[i] = inf
    }
    q <- s
    inq[s] = true
    dst[s] = 0
    for len(q) != 0 {
        f := <-q
        inq[f] = false
        for i := 0; i < k; i++ {
            if g[f][i] < inf && dst[f]+g[f][i] < dst[i] {
                dst[i] = dst[f] + g[f][i]
                if !inq[i] {
                    q <- i
                    inq[i] = true
                }
            }
        }
    }
}

func SpfaAndPrint() {
    var d = make([][]int, k)
    for i := 0; i < k; i++ {
        d[i] = make([]int, k)
        Spfa(i, d[i][:])
        for j := 0; j < k; j++ {
            if j > 0 {
                fmt.Print(" ")
            }
            if d[i][j] >= inf {
                d[i][j] = -1
            }
            fmt.Print(d[i][j])
        }
        fmt.Println()
    }
}

func main() {
    scanner.Split(bufio.ScanWords)

    scanner.NextInts(&n, &m, &k)
    c, grp, parent = make([]int, k+1), make([]int, n+1), make([]int, n+1)
    g = make([][]int, k)
    for i, j := 0, 1; i < k; i++ {
        c[i], j = j, scanner.NextInt()+j
        for l := c[i]; l < j; l++ {
            grp[l], parent[l] = i, l
        }
        g[i] = make([]int, k)
        for l := 0; l < k; l++ {
            g[i][l] = inf
        }
    }
    for i := 0; i < m; i++ {
        var u, v, x int
        scanner.NextInts(&u, &v, &x)
        AddEdge(grp[u], grp[v], x)
        if x == 0 {
            Union(u, v)
        }
    }
    if Check() {
        fmt.Println("Yes")
        SpfaAndPrint()
    } else {
        fmt.Println("No")
    }
}

type Scanner struct {
    *bufio.Scanner
}

var scanner = Scanner{bufio.NewScanner(os.Stdin)}

func (self *Scanner) Next() string {
    if !self.Scan() {
        panic(self.Err())
    }
    return self.Text()
}

func (self *Scanner) NextInt() int {
    x, err := strconv.Atoi(self.Next())
    if err != nil {
        panic(err)
    }
    return x
}

func (self *Scanner) NextInts(args ...*int) {
    for _, v := range args {
        *v = self.NextInt()
    }
}

type MyInt int

func (self MyInt) Min(x int) int {
    if int(self) < x {
        return int(self)
    }
    return x
}

/*********************************************************************************
*     File Name           :     D.go
*     Created By          :     YIMMON, yimmon.zhuang@gmail.com
*     Creation Date       :     [2014-03-07 20:25]
*     Last Modified       :     [2014-03-07 22:26]
*     Description         :
**********************************************************************************/

package main

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

const inf = 0x3fffffff

var (
    n, m, k        int
    c, grp, parent []int
    g              [][]int
)

func AddEdge(a, b, c int) {
    g[a][b] = MyInt(g[a][b]).Min(c)
    g[b][a] = g[a][b]
}

func GetParent(x int) int {
    if x != parent[x] {
        parent[x] = GetParent(parent[x])
    }
    return parent[x]
}

func Union(a, b int) {
    pa, pb := GetParent(a), GetParent(b)
    if pa != pb {
        parent[pa] = pb
    }
}

func Check() bool {
    c[k] = n + 1
    for i := 0; i < k; i++ {
        p := GetParent(c[i])
        for j := c[i] + 1; j < c[i+1]; j++ {
            if p != GetParent(j) {
                return false
            }
        }
    }
    return true
}

func GetD() {
    for l := 0; l < k; l++ {
        for i := 0; i < k; i++ {
            if g[i][l] < inf {
                for j := 0; j < k; j++ {
                    g[i][j] = MyInt(g[i][j]).Min(g[i][l] + g[l][j])
                }
            }
        }
    }
    for i := 0; i < k; i++ {
        for j := 0; j < k; j++ {
            if j > 0 {
                fmt.Print(" ")
            }
            if g[i][j] >= inf {
                g[i][j] = -1
            }
            fmt.Print(g[i][j])
        }
        fmt.Println()
    }
}

func main() {
    scanner.Split(bufio.ScanWords)

    scanner.NextInts(&n, &m, &k)
    c, grp, parent = make([]int, k+1), make([]int, n+1), make([]int, n+1)
    g = make([][]int, k)
    for i, j := 0, 1; i < k; i++ {
        c[i], j = j, scanner.NextInt()+j
        for l := c[i]; l < j; l++ {
            grp[l], parent[l] = i, l
        }
        g[i] = make([]int, k)
        for l := 0; l < k; l++ {
            g[i][l] = inf
        }
        g[i][i] = 0
    }
    for i := 0; i < m; i++ {
        var u, v, x int
        scanner.NextInts(&u, &v, &x)
        AddEdge(grp[u], grp[v], x)
        if x == 0 {
            Union(u, v)
        }
    }
    if Check() {
        fmt.Println("Yes")
        GetD()
    } else {
        fmt.Println("No")
    }
}

type Scanner struct {
    *bufio.Scanner
}

var scanner = Scanner{bufio.NewScanner(os.Stdin)}

func (self *Scanner) Next() string {
    if !self.Scan() {
        panic(self.Err())
    }
    return self.Text()
}

func (self *Scanner) NextInt() int {
    x, err := strconv.Atoi(self.Next())
    if err != nil {
        panic(err)
    }
    return x
}

func (self *Scanner) NextInts(args ...*int) {
    for _, v := range args {
        *v = self.NextInt()
    }
}

type MyInt int

func (self MyInt) Min(x int) int {
    if int(self) < x {
        return int(self)
    }
    return x
}

package main

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

const maxn = 100010
const maxk = 510
const inf = 0x3fffffff

var p [maxn]int
var pnt [maxn]int
var g [maxk][maxk]int

func find(x int) int {
    if x == pnt[x] {
        return x
    } else {
        pnt[x] = find(pnt[x])
        return pnt[x]
    }
}
func main() {
    scanner.Split(bufio.ScanWords)
    n := scanner.NextInt()
    m := scanner.NextInt()
    k := scanner.NextInt()
    now := 1
    for i := 1; i <= k; i++ {
        for sz := scanner.NextInt(); sz > 0; sz-- {
            p[now] = i
            now++
        }
    }
    for i := 1; i <= n; i++ {
        pnt[i] = i
    }
    for i := 1; i <= k; i++ {
        for j := 1; j <= k; j++ {
            g[i][j] = inf
            if i == j {
                g[i][j] = 0
            }
        }
    }
    for i := 0; i < m; i++ {
        x := scanner.NextInt()
        y := scanner.NextInt()
        z := scanner.NextInt()
        if z == 0 {
            pnt[find(x)] = find(y)
        }
        if g[p[x]][p[y]] > z {
            g[p[x]][p[y]] = z
            g[p[y]][p[x]] = z
        }
    }
    ok := true
    for i := 2; ok && i <= n; i++ {
        ok = p[i] != p[i-1] || find(i) == find(i-1)
    }
    if !ok {
        fmt.Println("No")
    } else {
        fmt.Println("Yes")
        for i := 1; i <= k; i++ {
            for j := 1; j <= k; j++ {
                for v := 1; v <= k; v++ {
                    if g[j][v] > g[j][i]+g[i][v] {
                        g[j][v] = g[j][i] + g[i][v]
                    }
                }
            }
        }
        for i := 1; i <= k; i++ {
            for j := 1; j <= k; j++ {
                if g[i][j] == inf {
                    fmt.Printf("-1 ")
                } else {
                    fmt.Printf("%d ", g[i][j])
                }
            }
            fmt.Println()
        }
    }

}

type Scanner struct {
    *bufio.Scanner
}

var scanner = Scanner{bufio.NewScanner(os.Stdin)}

func (self *Scanner) Next() string {
    if !self.Scan() {
        panic(self.Err())
    }
    return self.Text()
}

func (self *Scanner) NextInt() int {
    x, err := strconv.Atoi(self.Next())
    if err != nil {
        panic(err)
    }
    return x
}

func (self *Scanner) NextInt64() int64 {
    x, err := strconv.ParseInt(self.Next(), 10, 64)
    if err != nil {
        panic(err)
    }
    return x
}

func (self *Scanner) NextDouble() float64 {
    x, err := strconv.ParseFloat(self.Next(), 64)
    if err != nil {
        panic(err)
    }
    return x
}

/*********************************************************************************
*     File Name           :     D.go
*     Created By          :     YIMMON, yimmon.zhuang@gmail.com
*     Creation Date       :     [2014-03-07 20:25]
*     Last Modified       :     [2014-03-07 22:26]
*     Description         :
**********************************************************************************/

package main

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

const inf = 0x3fffffff

var (
    n, m, k        int
    c, grp, parent []int
    g              [][]int
)

func AddEdge(a, b, c int) {
    g[a][b] = MyInt(g[a][b]).Min(c)
    g[b][a] = g[a][b]
}

func GetParent(x int) int {
    if x != parent[x] {
        parent[x] = GetParent(parent[x])
    }
    return parent[x]
}

func Union(a, b int) {
    pa, pb := GetParent(a), GetParent(b)
    if pa != pb {
        parent[pa] = pb
    }
}

func Check() bool {
    c[k] = n + 1
    for i := 0; i < k; i++ {
        p := GetParent(c[i])
        for j := c[i] + 1; j < c[i+1]; j++ {
            if p != GetParent(j) {
                return false
            }
        }
    }
    return true
}

func GetD() {
    for l := 0; l < k; l++ {
        for i := 0; i < k; i++ {
            if g[i][l] < inf {
                for j := 0; j < k; j++ {
                    g[i][j] = MyInt(g[i][j]).Min(g[i][l] + g[l][j])
                }
            }
        }
    }
    for i := 0; i < k; i++ {
        for j := 0; j < k; j++ {
            if j > 0 {
                fmt.Print(" ")
            }
            if g[i][j] >= inf {
                g[i][j] = -1
            }
            fmt.Print(g[i][j])
        }
        fmt.Println()
    }
}

func main() {
    scanner.Split(bufio.ScanWords)

    scanner.NextInts(&n, &m, &k)
    c, grp, parent = make([]int, k+1), make([]int, n+1), make([]int, n+1)
    g = make([][]int, k)
    for i, j := 0, 1; i < k; i++ {
        c[i], j = j, scanner.NextInt()+j
        for l := c[i]; l < j; l++ {
            grp[l], parent[l] = i, l
        }
        g[i] = make([]int, k)
        for l := 0; l < k; l++ {
            g[i][l] = inf
        }
        g[i][i] = 0
    }
    for i := 0; i < m; i++ {
        var u, v, x int
        scanner.NextInts(&u, &v, &x)
        AddEdge(grp[u], grp[v], x)
        if x == 0 {
            Union(u, v)
        }
    }
    if Check() {
        fmt.Println("Yes")
        GetD()
    } else {
        fmt.Println("No")
    }
}

type Scanner struct {
    *bufio.Scanner
}

var scanner = Scanner{bufio.NewScanner(os.Stdin)}

func (self *Scanner) NextInt() int {
    x, _ := strconv.Atoi(self.Text())
    return x
}

func (self *Scanner) NextInts(args ...*int) {
    for _, v := range args {
        *v = self.NextInt()
    }
}

type MyInt int

func (self MyInt) Min(x int) int {
    if int(self) < x {
        return int(self)
    }
    return x
}

/*********************************************************************************
*     File Name           :     D.go
*     Created By          :     YIMMON, yimmon.zhuang@gmail.com
*     Creation Date       :     [2014-03-06 21:27]
*     Last Modified       :     [2014-03-06 22:48]
*     Description         :
**********************************************************************************/

package main

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

const (
    N   = 100005
    K   = 505
    INF = 0x3fffffff
)

type Pair struct {
    v, x int
}

var n, m, k, u, v, x int
var c [K]int
var d [K][K]int
var g [N][]Pair

func SpfaAndTest(kind, idx int) bool {
    var (
        q   = make(chan int, n)
        dst = make([]int, n+1)
        inq = make([]bool, n+1)
    )
    for i := 1; i <= n; i++ {
        dst[i], inq[i] = INF, false
    }
    for i, j := range c[:kind] {
        for k := j; k < c[i+1]; k++ {
            dst[k] = d[i][kind]
        }
    }
    q <- idx
    dst[idx] = 0
    inq[idx] = true
    for len(q) > 0 {
        f := <-q
        inq[f] = false
        for _, p := range g[f] {
            if dst[p.v] > dst[f]+p.x {
                dst[p.v] = dst[f] + p.x
                if !inq[p.v] {
                    q <- p.v
                    inq[p.v] = true
                }
            }
        }
    }
    //fmt.Println(kind, idx, dst)
    tmp := n + 1
    if kind < k-1 {
        tmp = c[kind+1]
    }
    for i := idx; i < tmp; i++ {
        if dst[i] > 0 {
            return false
        }
    }
    for i, j := range c[:k] {
        d[kind][i], d[i][kind] = dst[j], dst[j]
    }
    return true
}

func solve() bool {
    for i, v := range c[:k] {
        if SpfaAndTest(i, v) == false {
            return false
        }
    }
    return true
}

func main() {
    scanner.Split(bufio.ScanWords)

    scanner.nextInts(&n, &m, &k)
    for i := 1; i <= n; i++ {
        g[i] = make([]Pair, 0)
    }
    for i, j := 0, 1; i < k; i++ {
        j, c[i] = scanner.nextInt()+j, j
    }
    for i := 0; i < m; i++ {
        scanner.nextInts(&u, &v, &x)
        g[u] = append(g[u], Pair{v, x})
        g[v] = append(g[v], Pair{u, x})
    }
    if solve() {
        fmt.Println("Yes")
        for i := 0; i < k; i++ {
            for j := 0; j < k; j++ {
                if j != 0 {
                    fmt.Print(" ")
                }
                if d[i][j] >= INF {
                    d[i][j] = -1
                }
                fmt.Print(d[i][j])
            }
            fmt.Println()
        }
    } else {
        fmt.Println("No")
    }
}

type Scanner struct {
    *bufio.Scanner
}

var scanner = Scanner{bufio.NewScanner(os.Stdin)}

func (self *Scanner) next() string {
    if !self.Scan() {
        panic(self.Err())
    }
    return self.Text()
}

func (self *Scanner) nextInt() int {
    x, err := strconv.Atoi(self.next())
    if err != nil {
        panic(err)
    }
    return x
}

func (self *Scanner) nextInts(arg ...*int) {
    for _, p := range arg {
        *p = self.nextInt()
    }
}

/*********************************************************************************
*     File Name           :     D.go
*     Created By          :     YIMMON, yimmon.zhuang@gmail.com
*     Creation Date       :     [2014-03-07 20:25]
*     Last Modified       :     [2014-03-07 22:26]
*     Description         :
**********************************************************************************/

package main

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

const inf = 0x3fffffff

var (
    n, m, k        int
    c, grp, parent []int
    g              [][]int
)

func AddEdge(a, b, c int) {
    g[a][b] = MyInt(g[a][b]).Min(c)
    g[b][a] = g[a][b]
}

func GetParent(x int) int {
    if x != parent[x] {
        parent[x] = GetParent(parent[x])
    }
    return parent[x]
}

func Union(a, b int) {
    pa, pb := GetParent(a), GetParent(b)
    if pa != pb {
        parent[pa] = pb
    }
}

func Check() bool {
    c[k] = n + 1
    for i := 0; i < k; i++ {
        p := GetParent(c[i])
        for j := c[i] + 1; j < c[i+1]; j++ {
            if p != GetParent(j) {
                return false
            }
        }
    }
    return true
}

func GetD() {
    for l := 0; l < k; l++ {
        for i := 0; i < k; i++ {
            if g[i][l] < inf {
                for j := 0; j < k; j++ {
                    g[i][j] = MyInt(g[i][j]).Min(g[i][l] + g[l][j])
                }
            }
        }
    }
    for i := 0; i < k; i++ {
        for j := 0; j < k; j++ {
            if j > 0 {
                fmt.Print(" ")
            }
            if g[i][j] >= inf {
                g[i][j] = -1
            }
            fmt.Print(g[i][j])
        }
        fmt.Println()
    }
}

func main() {
    scanner.Split(bufio.ScanWords)

    scanner.NextInts(&n, &m, &k)
    c, grp, parent = make([]int, k+1), make([]int, n+1), make([]int, n+1)
    g = make([][]int, k)
    for i, j := 0, 1; i < k; i++ {
        c[i], j = j, scanner.NextInt()+j
        for l := c[i]; l < j; l++ {
            grp[l], parent[l] = i, l
        }
        g[i] = make([]int, k)
        for l := 0; l < k; l++ {
            g[i][l] = inf
        }
        g[i][i] = 0
    }
    for i := 0; i < m; i++ {
        var u, v, x int
        scanner.NextInts(&u, &v, &x)
        AddEdge(grp[u], grp[v], x)
        if x == 0 {
            Union(u, v)
        }
    }
    if Check() {
        fmt.Println("Yes")
        GetD()
    } else {
        fmt.Println("No")
    }
}

type Scanner struct {
    *bufio.Scanner
}

var scanner = Scanner{bufio.NewScanner(os.Stdin)}

func (self *Scanner) Next() string {
    return self.Text()
}

func (self *Scanner) NextInt() int {
    x, _ := strconv.Atoi(self.Text())
    return x
}

func (self *Scanner) NextInts(args ...*int) {
    for _, v := range args {
        *v = self.NextInt()
    }
}

type MyInt int

func (self MyInt) Min(x int) int {
    if int(self) < x {
        return int(self)
    }
    return x
}

package main

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

const maxn = 100010
const maxk = 510
const inf = 0x3fffffff

var p [maxn]int
var pnt [maxn]int
var g [maxk][maxk]int

func find(x int) int {
    if x == pnt[x] {
        return x
    } else {
        pnt[x] = find(pnt[x])
        return pnt[x]
    }
}
func main() {
    scanner.Split(bufio.ScanWords)
    n := scanner.NextInt()
    m := scanner.NextInt()
    k := scanner.NextInt()
    now := 1
    for i := 1; i <= k; i++ {
        for sz := scanner.NextInt(); sz > 0; sz-- {
            p[now] = i
            now++
        }
    }
    for i := 1; i <= n; i++ {
        pnt[i] = i
    }
    for i := 1; i <= k; i++ {
        for j := 1; j <= k; j++ {
            g[i][j] = inf
            if i == j {
                g[i][j] = 0
            }
        }
    }
    for i := 0; i < m; i++ {
        x := scanner.NextInt()
        y := scanner.NextInt()
        z := scanner.NextInt()
        pnt[find(x)] = find(y)
        if g[p[x]][p[y]] > z {
            g[p[x]][p[y]] = z
            g[p[y]][p[x]] = z
        }
    }
    ok := true
    for i := 2; ok && i <= n; i++ {
        ok = p[i] != p[i-1] || find(i) == find(i-1)
    }
    if !ok {
        fmt.Println("No")
    } else {
        fmt.Println("Yes")
        for i := 1; i <= k; i++ {
            for j := 1; j <= k; j++ {
                for v := 1; v <= k; v++ {
                    if g[j][v] > g[j][i]+g[i][v] {
                        g[j][v] = g[j][i] + g[i][v]
                    }
                }
            }
        }
        for i := 1; i <= k; i++ {
            for j := 1; j <= k; j++ {
                if g[i][j] == inf {
                    fmt.Printf("-1 ")
                } else {
                    fmt.Printf("%d ", g[i][j])
                }
            }
            fmt.Println()
        }
    }

}

type Scanner struct {
    *bufio.Scanner
}

var scanner = Scanner{bufio.NewScanner(os.Stdin)}

func (self *Scanner) Next() string {
    if !self.Scan() {
        panic(self.Err())
    }
    return self.Text()
}

func (self *Scanner) NextInt() int {
    x, err := strconv.Atoi(self.Next())
    if err != nil {
        panic(err)
    }
    return x
}

func (self *Scanner) NextInt64() int64 {
    x, err := strconv.ParseInt(self.Next(), 10, 64)
    if err != nil {
        panic(err)
    }
    return x
}

func (self *Scanner) NextDouble() float64 {
    x, err := strconv.ParseFloat(self.Next(), 64)
    if err != nil {
        panic(err)
    }
    return x
}

package main

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

const maxn = 100010
const maxk = 510
const inf = 0x3fffffff

var p [maxn]int
var pnt [maxn]int
var g [maxk][maxk]int

func find(x int) int {
    if x == pnt[x] {
        return x
    } else {
        pnt[x] = find(pnt[x])
        return pnt[x]
    }
}
func main() {
    scanner.Split(bufio.ScanWords)
    n := scanner.NextInt()
    m := scanner.NextInt()
    k := scanner.NextInt()
    now := 1
    for i := 1; i <= k; i++ {
        for sz := scanner.NextInt(); sz > 0; sz-- {
            p[now] = i
            now++
        }
    }
    for i := 1; i <= n; i++ {
        pnt[i] = i
    }
    for i := 1; i <= k; i++ {
        for j := 1; j <= k; j++ {
            g[i][j] = inf
            if i == j {
                g[i][j] = 0
            }
        }
    }
    for i := 0; i < m; i++ {
        x := scanner.NextInt()
        y := scanner.NextInt()
        z := scanner.NextInt()
        if z == 0 && p[x] == p[y] {
            pnt[find(x)] = find(y)
        }
        if g[p[x]][p[y]] > z {
            g[p[x]][p[y]] = z
            g[p[y]][p[x]] = z
        }
    }
    ok := true
    for i := 2; ok && i <= n; i++ {
        ok = p[i] != p[i-1] || find(i) == find(i-1)
    }
    if !ok {
        fmt.Println("No")
    } else {
        fmt.Println("Yes")
        for i := 1; i <= k; i++ {
            for j := 1; j <= k; j++ {
                for v := 1; v <= k; v++ {
                    if g[j][v] > g[j][i]+g[i][v] {
                        g[j][v] = g[j][i] + g[i][v]
                    }
                }
            }
        }
        for i := 1; i <= k; i++ {
            for j := 1; j <= k; j++ {
                if g[i][j] == inf {
                    fmt.Printf("-1 ")
                } else {
                    fmt.Printf("%d ", g[i][j])
                }
            }
            fmt.Println()
        }
    }

}

type Scanner struct {
    *bufio.Scanner
}

var scanner = Scanner{bufio.NewScanner(os.Stdin)}

func (self *Scanner) Next() string {
    if !self.Scan() {
        panic(self.Err())
    }
    return self.Text()
}

func (self *Scanner) NextInt() int {
    x, err := strconv.Atoi(self.Next())
    if err != nil {
        panic(err)
    }
    return x
}

func (self *Scanner) NextInt64() int64 {
    x, err := strconv.ParseInt(self.Next(), 10, 64)
    if err != nil {
        panic(err)
    }
    return x
}

func (self *Scanner) NextDouble() float64 {
    x, err := strconv.ParseFloat(self.Next(), 64)
    if err != nil {
        panic(err)
    }
    return x
}


William has two arrays $$$a$$$ and $$$b$$$, each consisting of $$$n$$$ items.For some segments $$$l..r$$$ of these arrays William wants to know if it is possible to equalize the values of items in these segments using a balancing operation. Formally, the values are equalized if for each $$$i$$$ from $$$l$$$ to $$$r$$$ holds $$$a_i = b_i$$$.To perform a balancing operation an even number of indices must be selected, such that $$$l \le pos_1 < pos_2 < \dots < pos_k \le r$$$. Next the items of array a at positions $$$pos_1, pos_3, pos_5, \dots$$$ get incremented by one and the items of array b at positions $$$pos_2, pos_4, pos_6, \dots$$$ get incremented by one.William wants to find out if it is possible to equalize the values of elements in two arrays for each segment using some number of balancing operations, and what is the minimal number of operations required for that. Note that for each segment the operations are performed independently.

The first line contains a two integers $$$n$$$ and $$$q$$$ ($$$2 \le n \le 10^5$$$, $$$1 \le q \le 10^5$$$), the size of arrays $$$a$$$ and $$$b$$$ and the number of segments. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(0 \le a_i \le 10^9)$$$. The third line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ $$$(0 \le b_i \le 10^9)$$$. Each of the next $$$q$$$ lines contains two integers $$$l_i$$$ and $$$r_i$$$ $$$(1 \le l_i < r_i \le n)$$$, the edges of segments.

For each segment output a single number — the minimal number of balancing operations needed or "-1" if it is impossible to equalize segments of arrays.

NoteFor the first segment from $$$2$$$ to $$$6$$$ you can do one operation with $$$pos = [2, 3, 5, 6]$$$, after this operation the arrays will be: $$$a = [0, 2, 2, 9, 4, 2, 7, 5]$$$, $$$b = [2, 2, 2, 9, 4, 2, 5, 8]$$$. Arrays are equal on a segment from $$$2$$$ to $$$6$$$ after this operation.For the second segment from $$$1$$$ to $$$7$$$ you can do three following operations:   $$$pos = [1, 3, 5, 6]$$$  $$$pos = [1, 7]$$$  $$$pos = [2, 7]$$$ After these operations, the arrays will be: $$$a = [2, 2, 2, 9, 4, 2, 7, 5]$$$, $$$b = [2, 2, 2, 9, 4, 2, 7, 8]$$$. Arrays are equal on a segment from $$$1$$$ to $$$7$$$ after these operations.For the third segment from $$$2$$$ to $$$4$$$ you can do one operation with $$$pos = [2, 3]$$$, after the operation arrays will be: $$$a = [0, 2, 2, 9, 3, 2, 7, 5]$$$, $$$b = [2, 2, 2, 9, 4, 1, 5, 8]$$$. Arrays are equal on a segment from $$$2$$$ to $$$4$$$ after this operation.It is impossible to equalize the fourth and the fifth segment.

package main

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

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

const MAX_LOG int = 17

type ISparseTable interface {
	build()
	get(int, int) int
}

type SparseTable struct {
	tableSize int
	log       []int
	table     [][]int
	compare   func(int, int) bool
}

func SparseTableFactory(size int, initFunc func(int, int) bool) *SparseTable {
	init := SparseTable{
		tableSize: size,
		table:     make([][]int, MAX_LOG+1),
		log:       make([]int, size+1),
		compare:   initFunc,
	}

	for i := 2; i <= size; i++ {
		init.log[i] = init.log[i>>1] + 1
	}

	for lev := 0; lev <= MAX_LOG; lev++ {
		init.table[lev] = make([]int, size+1)
	}

	return &init
}

func (self *SparseTable) build() {
	for i := 1; i <= self.tableSize; i++ {
		self.table[0][i] = i
	}

	for lev := 1; lev <= MAX_LOG; lev++ {
		for i := 1; i+(1<<lev)-1 <= self.tableSize; i++ {
			if self.compare(self.table[lev-1][i], self.table[lev-1][i+(1<<(lev-1))]) {
				self.table[lev][i] = self.table[lev-1][i]
			} else {
				self.table[lev][i] = self.table[lev-1][i+(1<<(lev-1))]
			}
		}
	}
}

func (self *SparseTable) get(l, r int) int {
	x := self.log[r-l+1]
	if self.compare(self.table[x][l], self.table[x][r-(1<<x)+1]) {
		return self.table[x][l]
	} else {
		return self.table[x][r-(1<<x)+1]
	}
}

func main() {
	defer writer.Flush()

	var n, q int
	fmt.Fscan(reader, &n, &q)

	a := make([]int, n+1)
	b := make([]int, n+1)

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

	for i := 1; i <= n; i++ {
		fmt.Fscan(reader, &b[i])
	}

	diff := make([]int64, n+1)
	for i := 1; i <= n; i++ {
		diff[i] = diff[i-1] + int64(b[i]-a[i])
	}

	maxTable := SparseTableFactory(n, func(i, j int) bool {
		return (diff[i] > diff[j])
	})

	minTable := SparseTableFactory(n, func(i, j int) bool {
		return (diff[i] < diff[j])
	})

	maxTable.build()
	minTable.build()

	for query := 1; query <= q; query++ {
		var l, r int
		fmt.Fscan(reader, &l, &r)

		minPos := minTable.get(l, r)
		maxPos := maxTable.get(l, r)

		if diff[r]-diff[l-1] != 0 || diff[minPos]-diff[l-1] < 0 {
			fmt.Fprintln(writer, "-1")
		} else {
			fmt.Fprintf(writer, "%v\n", diff[maxPos]-diff[l-1])
		}
	}
}


Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of d meters, and a throw is worth 3 points if the distance is larger than d meters, where d is some non-negative integer.Vasya would like the advantage of the points scored by the first team (the points of the first team minus the points of the second team) to be maximum. For that he can mentally choose the value of d. Help him to do that.

The first line contains integer n (1 ≤ n ≤ 2·105) — the number of throws of the first team. Then follow n integer numbers — the distances of throws ai (1 ≤ ai ≤ 2·109).  Then follows number m (1 ≤ m ≤ 2·105) — the number of the throws of the second team. Then follow m integer numbers — the distances of throws of bi (1 ≤ bi ≤ 2·109).

Print two numbers in the format a:b — the score that is possible considering the problem conditions where the result of subtraction a - b is maximum. If there are several such scores, find the one in which number a is maximum.

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

func getData(scanner *bufio.Scanner) ([]int, map[int]int) {
	n := scanInt(scanner)
	throws := make([]int, n)
	for i := range throws {
		throws[i] = scanInt(scanner)
	}
  sort.Ints(throws)
  unique_throws, counts := []int{}, map[int]int{}
  count, previous := 0, 0
  for i, throw := range throws {
    if throw == previous {
      count += 1
    } else {
      unique_throws = append(unique_throws, previous)
      counts[previous] = i
      count, previous = 1, throw
    }
  }
  unique_throws = append(unique_throws, throws[n-1])
  counts[throws[n-1]] = n
  return unique_throws, counts
}

func calculateScore(d int, unique_throws []int, counts map[int]int) int {
  low, high := 0, len(unique_throws)-1
  for low != high {
    mid := (low+high+1)/2
    if d < unique_throws[mid] {
      high = mid-1
    } else {
      low = mid
    }
  }
  twos := counts[unique_throws[low]]
  threes := counts[unique_throws[len(unique_throws)-1]] - twos
  score := 2*twos + 3*threes
  return score
}

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

  n_unique_throws, n_counts := getData(scanner)
  m_unique_throws, m_counts := getData(scanner)
  ds := []int{}
  for _, x := range n_unique_throws {
    ds = append(ds, x-1)
  }
  for _, x := range m_unique_throws {
    ds = append(ds, x-1)
  }
  n, m := len(n_unique_throws), len(m_unique_throws)
  ds = append(ds, n_unique_throws[n-1])
  ds = append(ds, m_unique_throws[m-1])

  best_a := calculateScore(0, n_unique_throws, n_counts)
  best_b := calculateScore(0, m_unique_throws, m_counts)
  for _, d := range ds {
    a := calculateScore(d, n_unique_throws, n_counts)
    b := calculateScore(d, m_unique_throws, m_counts)
    if a-b > best_a-best_b || (a-b == best_a-best_b && a > best_a) {
      best_a = a
      best_b = b
    }
  }

  writer.WriteString(fmt.Sprintf("%d:%d\n", best_a, best_b))
}

package main

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

func main() {
    n, m := 0, 0
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)

    ScanInts := func(a ...*int) {
        for i := 0; i < len(a); i++ {
            scanner.Scan()
            *(a[i]), _ = strconv.Atoi(scanner.Text())
        }
    }
    ScanInts(&n)
    fir := make([]int, n, n)
    for i := 0; i < n; i++ {
        ScanInts(&fir[i])
    }
    ScanInts(&m)
    sec := make([]int, m, m)
    for i := 0; i < m; i++ {
        ScanInts(&sec[i])
    }
    sort.Ints(fir)
    sort.Ints(sec)
    ans, a, b := 0, 0, 0
    if n*2-m*2 > n*3-m*3 {
        a, b = n*2, m*2
    } else {
        a, b = n*3, m*3
    }
    ans = a - b
    for i := 0; i < n; i++ {
        key := fir[i] - 1
        idx := lower_bound(0, m-1, key, sec)
        s, f := 0, i*2+(n-i)*3
        if sec[idx] > key {
            s = idx*2 + (m-idx)*3
        } else if sec[idx] == key {
            idx := lower_bound(0, m-1, key+1, sec)
            if sec[idx] <= key {
                s = m * 2
            } else {
                s = idx*2 + (m-idx)*3
            }
        } else {
            s = m * 2
        }
        if f-s > ans || (f-s == ans && f > a) {
            a, b = f, s
            ans = f - s
        }
    }
    fmt.Printf("%d:%d", a, b)
}

func lower_bound(l, r, key int, arr []int) int {
    for l < r {
        mid := (l + r) >> 1
        if arr[mid] < key {
            l = mid + 1
        } else {
            r = mid
        }
    }
    return l
}

package main

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

// Input & Output
var (
	input  = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

var (
	n      int
	m      int
	a      []int64
	b      []int64
	ra, rb int
)

type ByValue []int64

func (v ByValue) Len() int {
	return len(v)
}

func (v ByValue) Swap(i, j int) {
	v[i], v[j] = v[j], v[i]
}

func (v ByValue) Less(i, j int) bool {
	return v[i] < v[j]
}

func in() {
	fmt.Fscan(input, &n)
	a = make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &a[i])
	}
	fmt.Fscan(input, &m)
	b = make([]int64, m)
	for i := 0; i < m; i++ {
		fmt.Fscan(input, &b[i])
	}
}

func out() {
	fmt.Fprintf(output, "%d:%d\n", ra, rb)
	defer output.Flush()
}

func run() {
	sort.Sort(ByValue(a))
	sort.Sort(ByValue(b))
	sa := make([]int, m+1)
	sb := make([]int, m+1)
	sa[0] = 3 * n
	sb[0] = 3 * m
	pa, pb := 0, 0
	for ; pb < m; pb++ {
		if pb < m-1 && b[pb+1] == b[pb] {
			pb++
		}
		for pa < n && a[pa] <= b[pb] {
			pa++
		}
		sa[pb+1] = 2*pa + 3*(n-pa)
		sb[pb+1] = 2*(pb+1) + 3*(m-pb-1)
	}
	var adv int = math.MinInt32
	for i := 0; i < len(sa); i++ {
		if sa[i] > 0 && sa[i]-sb[i] > adv {
			adv = sa[i] - sb[i]
			ra = sa[i]
			rb = sb[i]
		}
	}
}

func main() {
	in()
	run()
	out()
}

package main

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

// import bufio, os, strconv
var sc *bufio.Scanner

func scInit() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
}

func scanOne() {
	if !sc.Scan() {
		panic("could not scan the reader")
	}
}

func nextInt() int {
	scanOne()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLong() int64 {
	scanOne()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	scInit()
	n := nextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}
	m := nextInt()
	b := make([]int, m)
	for i := 0; i < m; i++ {
		b[i] = nextInt()
	}
	sort.Ints(a)
	sort.Ints(b)
	c := append(a, b...)
	c = append(c, 1<<30)
	sort.Ints(c)
	var ma, mb int
	mb = 1 << 30
	for i, j, k := 0, 0, 0; k <= n+m; k++ {
		th := c[k] - 1
		for i < n && a[i] <= th {
			i++
		}
		for j < m && b[j] <= th {
			j++
		}
		pa := 2*i + 3*(n-i)
		pb := 2*j + 3*(m-j)
		if pa-pb > ma-mb {
			ma, mb = pa, pb
		}
	}
	fmt.Printf("%d:%d\n", ma, mb)
}

package main

import (
    "strconv"
    "bufio"
    "os"
    "fmt"
    "sort"
)
// var file, _ = os.Open("input.txt")
// var outfile, _ = os.Create("output.txt")
// var in = bufio.NewScanner(file)
// var out = bufio.NewWriter(outfile)
var in = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func next() string {
    if !in.Scan() {
        panic("Scan error")
    }
    return in.Text()
}

func nextInt() int {
    ret, _ := strconv.Atoi(next())
    return ret
}

func nextFloat() float64 {
    ret, _ := strconv.ParseFloat(next(), 64)
    return ret
}

func getPoints(a []int, d int) int {
    l := 0
    r := len(a) - 1
    for l < r {
        m := l + (r - l) / 2
        if a[m] <= d {
            l = m + 1
        } else {
            r = m
        }
    }
    // fmt.Fprintln(out, d)
    // fmt.Fprintln(out, l)
    // fmt.Fprintln(out, a)
    if a[r] > d { r-- }
    return (r + 1) * 2 + (len(a) - r - 1) * 3
}

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

func main() {
    defer out.Flush()
    in.Split(bufio.ScanWords)
    n := nextInt()
    a := make([]int, n)
    for i := 0; i < n; i++ {
        a[i] = nextInt()
    }
    m := nextInt()
    b := make([]int, m)
    for i := 0; i < m; i++ {
        b[i] = nextInt()
    }

    sort.Ints(a)
    sort.Ints(b)
    c := append(a, b...)
    c = append(c, 0)
    c = append(c, 2000000001)
    sort.Ints(c)
    aa := 0
    ab := 0
    max := -2000000001
    for i := 0; i < len(c); i++ {
        d := c[i]
        pa := getPoints(a, d)
        pb := getPoints(b, d)
        if max < pa - pb {
            max = pa - pb
            aa = pa
            ab = pb
        }
    }

    fmt.Fprintln(out, strconv.Itoa(aa) + ":" + strconv.Itoa(ab))
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

func getData(scanner *bufio.Scanner) ([]int, map[int]int) {
	n := scanInt(scanner)
	throws := make([]int, n)
	for i := range throws {
		throws[i] = scanInt(scanner)
	}
  sort.Ints(throws)
  unique_throws, counts := []int{}, map[int]int{}
  count, previous := 0, 0
  for i, throw := range throws {
    if throw == previous {
      count += 1
    } else {
      unique_throws = append(unique_throws, previous)
      counts[previous] = i
      count, previous = 1, throw
    }
  }
  unique_throws = append(unique_throws, throws[n-1])
  counts[throws[n-1]] = n
  return unique_throws, counts
}

func calculateScore(d int, unique_throws []int, counts map[int]int) int {
  low, high := 0, len(unique_throws)-1
  for low != high {
    //fmt.Printf("%d %d\n", low, high)
    mid := (low+high+1)/2
    if d < unique_throws[mid] {
      high = mid-1
    } else {
      low = mid
    }
  }
  twos := counts[low]
  threes := counts[unique_throws[len(unique_throws)-1]] - twos
  score := 2*twos + 3*threes
  //fmt.Printf("d = %d, low = %d, score = %d\n", d, low, score)
  return score
}

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

  n_unique_throws, n_counts := getData(scanner)
  m_unique_throws, m_counts := getData(scanner)
  ds := []int{}
  for _, x := range n_unique_throws {
    ds = append(ds, x-1)
  }
  for _, x := range m_unique_throws {
    ds = append(ds, x-1)
  }
  n, m := len(n_unique_throws), len(m_unique_throws)
  ds = append(ds, n_unique_throws[n-1])
  ds = append(ds, m_unique_throws[m-1])

  best_a := calculateScore(0, n_unique_throws, n_counts)
  best_b := calculateScore(0, m_unique_throws, m_counts)
  for _, d := range ds {
    a := calculateScore(d, n_unique_throws, n_counts)
    b := calculateScore(d, m_unique_throws, m_counts)
    if a-b > best_a-best_b || (a-b == best_a-best_b && a > best_a) {
      best_a = a
      best_b = b
    }
  }

  writer.WriteString(fmt.Sprintf("%d:%d\n", best_a, best_b))
}

package main

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

// import bufio, os, strconv
var sc *bufio.Scanner

func scInit() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
}

func scanOne() {
	if !sc.Scan() {
		panic("could not scan the reader")
	}
}

func nextInt() int {
	scanOne()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLong() int64 {
	scanOne()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	scInit()
	n := nextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}
	m := nextInt()
	b := make([]int, m)
	for i := 0; i < m; i++ {
		b[i] = nextInt()
	}
	var maxD, ma, mb int64
	for i, j := 0, 0; i < n; i++ {
		th := a[i] - 1
		for j < m && b[j] <= th {
			j++
		}
		pa := int64(2*i + 3*(n-i))
		pb := int64(2*j + 3*(m-j))
		if pa-pb > maxD {
			maxD = pa - pb
			ma, mb = pa, pb
		}
	}
	fmt.Printf("%d:%d\n", ma, mb)
}

package main

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

// import bufio, os, strconv
var sc *bufio.Scanner

func scInit() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
}

func scanOne() {
	if !sc.Scan() {
		panic("could not scan the reader")
	}
}

func nextInt() int {
	scanOne()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLong() int64 {
	scanOne()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	scInit()
	n := nextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}
	m := nextInt()
	b := make([]int, m)
	for i := 0; i < m; i++ {
		b[i] = nextInt()
	}
	var maxD, ma, mb int
	maxD = -1
	for i, j := 0, 0; i < n; i++ {
		th := a[i] - 1
		for j < m && b[j] <= th {
			j++
		}
		pa := 2*i + 3*(n-i)
		pb := 2*j + 3*(m-j)
		if pa-pb > maxD {
			maxD = pa - pb
			ma, mb = pa, pb
		}
	}
	fmt.Printf("%d:%d\n", ma, mb)
}

package main

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

// import bufio, os, strconv
var sc *bufio.Scanner

func scInit() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
}

func scanOne() {
	if !sc.Scan() {
		panic("could not scan the reader")
	}
}

func nextInt() int {
	scanOne()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLong() int64 {
	scanOne()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	scInit()
	n := nextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}
	m := nextInt()
	b := make([]int, m)
	for i := 0; i < m; i++ {
		b[i] = nextInt()
	}
	var maxD, ma, mb int
	maxD = -(1 << 30)
	for i, j := 0, 0; i < n; i++ {
		th := a[i] - 1
		for j < m && b[j] <= th {
			j++
		}
		pa := 2*i + 3*(n-i)
		pb := 2*j + 3*(m-j)
		if pa-pb > maxD {
			maxD = pa - pb
			ma, mb = pa, pb
		}
	}
	fmt.Printf("%d:%d\n", ma, mb)
}

package main

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

// import bufio, os, strconv
var sc *bufio.Scanner

func scInit() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
}

func scanOne() {
	if !sc.Scan() {
		panic("could not scan the reader")
	}
}

func nextInt() int {
	scanOne()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLong() int64 {
	scanOne()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	scInit()
	n := nextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}
	m := nextInt()
	b := make([]int, m)
	for i := 0; i < m; i++ {
		b[i] = nextInt()
	}
	sort.Ints(a)
	sort.Ints(b)
	var maxD, ma, mb int
	maxD = -(1 << 30)
	for i, j := 0, 0; i < n; i++ {
		th := a[i] - 1
		for j < m && b[j] <= th {
			j++
		}
		pa := 2*i + 3*(n-i)
		pb := 2*j + 3*(m-j)
		if pa-pb > maxD {
			maxD = pa - pb
			ma, mb = pa, pb
		}
	}
	fmt.Printf("%d:%d\n", ma, mb)
}

package main

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

// import bufio, os, strconv
var sc *bufio.Scanner

func scInit() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
}

func scanOne() {
	if !sc.Scan() {
		panic("could not scan the reader")
	}
}

func nextInt() int {
	scanOne()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLong() int64 {
	scanOne()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	scInit()
	n := nextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}
	m := nextInt()
	b := make([]int, m)
	for i := 0; i < m; i++ {
		b[i] = nextInt()
	}
	sort.Ints(a)
	sort.Ints(b)
	ma := 3 * n
	mb := 3 * m
	maxD := ma - mb
	for i, j := 0, 0; i < n; i++ {
		th := a[i] - 1
		for j < m && b[j] <= th {
			j++
		}
		pa := 2*i + 3*(n-i)
		pb := 2*j + 3*(m-j)
		if pa-pb > maxD {
			maxD = pa - pb
			ma, mb = pa, pb
		}
	}
	fmt.Printf("%d:%d\n", ma, mb)
}

package main

import (
    "strconv"
    "bufio"
    "os"
    "fmt"
    "sort"
)
// var file, _ = os.Open("input.txt")
// var outfile, _ = os.Create("output.txt")
// var in = bufio.NewScanner(file)
// var out = bufio.NewWriter(outfile)
var in = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func next() string {
    if !in.Scan() {
        panic("Scan error")
    }
    return in.Text()
}

func nextInt() int {
    ret, _ := strconv.Atoi(next())
    return ret
}

func nextFloat() float64 {
    ret, _ := strconv.ParseFloat(next(), 64)
    return ret
}

func getPoints(a []int, d int) int {
    l := 0
    r := len(a) - 1
    for l < r {
        m := l + (r - l) / 2
        if a[m] <= d {
            l = m + 1
        } else {
            r = m
        }
    }
    // fmt.Fprintln(out, d)
    // fmt.Fprintln(out, l)
    // fmt.Fprintln(out, a)
    if a[r] > d { r-- }
    return (r + 1) * 2 + (len(a) - r - 1) * 3
}

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

func main() {
    defer out.Flush()
    in.Split(bufio.ScanWords)
    n := nextInt()
    a := make([]int, n)
    for i := 0; i < n; i++ {
        a[i] = nextInt()
    }
    m := nextInt()
    b := make([]int, m)
    for i := 0; i < m; i++ {
        b[i] = nextInt()
    }

    sort.Ints(a)
    sort.Ints(b)
    c := append(a, b...)
    c = append(c, 0)
    c = append(c, 2000000001)
    sort.Ints(c)
    aa := 0
    ab := 0
    max := 0
    for i := 0; i < len(c); i++ {
        d := c[i]
        pa := getPoints(a, d)
        pb := getPoints(b, d)
        if max < abs(pa - pb) {
            max = abs(pa - pb)
            aa = pa
            ab = pb
        }
    }

    fmt.Fprintln(out, strconv.Itoa(aa) + ":" + strconv.Itoa(ab))
}

package main

import (
    "strconv"
    "bufio"
    "os"
    "fmt"
    "sort"
)
// var file, _ = os.Open("input.txt")
// var outfile, _ = os.Create("output.txt")
// var in = bufio.NewScanner(file)
// var out = bufio.NewWriter(outfile)
var in = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func next() string {
    if !in.Scan() {
        panic("Scan error")
    }
    return in.Text()
}

func nextInt() int {
    ret, _ := strconv.Atoi(next())
    return ret
}

func nextFloat() float64 {
    ret, _ := strconv.ParseFloat(next(), 64)
    return ret
}

func getPoints(a []int, d int) int {
    l := 0
    r := len(a) - 1
    for l < r {
        m := l + (r - l) / 2
        if a[m] <= d {
            l = m + 1
        } else {
            r = m
        }
    }
    // fmt.Fprintln(out, d)
    // fmt.Fprintln(out, l)
    // fmt.Fprintln(out, a)
    if a[r] > d { r-- }
    return (r + 1) * 2 + (len(a) - r - 1) * 3
}

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

func main() {
    defer out.Flush()
    in.Split(bufio.ScanWords)
    n := nextInt()
    a := make([]int, n)
    for i := 0; i < n; i++ {
        a[i] = nextInt()
    }
    m := nextInt()
    b := make([]int, m)
    for i := 0; i < m; i++ {
        b[i] = nextInt()
    }

    sort.Ints(a)
    sort.Ints(b)
    d := a[0] - 1
    pa := len(a) * 3
    pb := getPoints(b, d)
    aa := pa
    ab := pb
    max := pa - pb
    for i := 0; i < n; i++ {
        d := a[i]
        pa := (i + 1) * 2 + (len(a) - i - 1) * 3
        pb := getPoints(b, d)
        if max < pa - pb {
            max = pa - pb
            aa = pa
            ab = pb
        }
    }

    fmt.Fprintln(out, strconv.Itoa(aa) + ":" + strconv.Itoa(ab))
}

package main

import (
    "strconv"
    "bufio"
    "os"
    "fmt"
    "sort"
)
// var file, _ = os.Open("input.txt")
// var outfile, _ = os.Create("output.txt")
// var in = bufio.NewScanner(file)
// var out = bufio.NewWriter(outfile)
var in = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func next() string {
    if !in.Scan() {
        panic("Scan error")
    }
    return in.Text()
}

func nextInt() int {
    ret, _ := strconv.Atoi(next())
    return ret
}

func nextFloat() float64 {
    ret, _ := strconv.ParseFloat(next(), 64)
    return ret
}

func getPoints(a []int, d int) int {
    l := 0
    r := len(a) - 1
    for l < r {
        m := l + (r - l) / 2
        if a[m] <= d {
            l = m + 1
        } else {
            r = m
        }
    }
    // fmt.Fprintln(out, d)
    // fmt.Fprintln(out, l)
    // fmt.Fprintln(out, a)
    if a[r] > d { r-- }
    return (r + 1) * 2 + (len(a) - r - 1) * 3
}

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

func main() {
    defer out.Flush()
    in.Split(bufio.ScanWords)
    n := nextInt()
    a := make([]int, n)
    for i := 0; i < n; i++ {
        a[i] = nextInt()
    }
    m := nextInt()
    b := make([]int, m)
    for i := 0; i < m; i++ {
        b[i] = nextInt()
    }

    sort.Ints(a)
    sort.Ints(b)
    d := a[0] - 1
    pa := len(a) * 3
    pb := getPoints(b, d)
    aa := pa
    ab := pb
    max := abs(pa - pb)
    for i := 0; i < n; i++ {
        d := a[i]
        pa := (i + 1) * 2 + (len(a) - i - 1) * 3
        pb := getPoints(b, d)
        if max < abs(pa - pb) {
            max = abs(pa - pb)
            aa = pa
            ab = pb
        }
    }

    fmt.Fprintln(out, strconv.Itoa(aa) + ":" + strconv.Itoa(ab))
}


At the Byteland State University marks are strings of the same length. Mark x is considered better than y if string y is lexicographically smaller than x.Recently at the BSU was an important test work on which Vasya recived the mark a. It is very hard for the teacher to remember the exact mark of every student, but he knows the mark b, such that every student recieved mark strictly smaller than b.Vasya isn't satisfied with his mark so he decided to improve it. He can swap characters in the string corresponding to his mark as many times as he like. Now he want to know only the number of different ways to improve his mark so that his teacher didn't notice something suspicious.More formally: you are given two strings a, b of the same length and you need to figure out the number of different strings c such that:1) c can be obtained from a by swapping some characters, in other words c is a permutation of a.2) String a is lexicographically smaller than c.3) String c is lexicographically smaller than b.For two strings x and y of the same length it is true that x is lexicographically smaller than y if there exists such i, that x1 = y1, x2 = y2, ..., xi - 1 = yi - 1, xi < yi.Since the answer can be very large, you need to find answer modulo 109 + 7.

First line contains string a, second line contains string b. Strings a, b consist of lowercase English letters. Their lengths are equal and don't exceed 106. It is guaranteed that a is lexicographically smaller than b.

Print one integer  — the number of different strings satisfying the condition of the problem modulo 109 + 7.

NoteIn first sample from string abc can be obtained strings acb, bac, bca, cab, cba, all of them are larger than abc, but smaller than ddd. So the answer is 5.In second sample any string obtained from abcdef is larger than abcdeg. So the answer is 0.

package main

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

const M = 1000000007

func PowMod(a, x int32) int32 {
	if x == 0 {
		return 1
	}
	t := int64(PowMod(a, x>>1))
	t = t * t % M;
	if (x&1) != 0 {
		t = t * int64(a) % M
	}
	return int32(t)
}

type P struct {
	x [26]int32
	sum, val int32
}

var fact, invf, inv [1000001]int32

func NewP(x [26]int32) *P {
	ret := P{
		x: x,
		sum: 0,
	}

	for _, xi := range x {
		ret.sum = ret.sum + xi
	}

	ret.val = fact[ret.sum]
	for _, xi := range x {
		ret.val = int32(int64(ret.val) * int64(invf[xi]) % M)
	}

	return &ret
}

func (perm *P) PretendToMinus(k int32) int32 {
	return int32(int64(perm.val) * int64(inv[perm.sum]) % M *
		int64(perm.x[k]) % M)
}

func (perm *P) Minus(k int32) {
	perm.val = perm.PretendToMinus(k)
	perm.sum--
	perm.x[k]--
}

func main() {
	fact[0] = 1
	for i := 1; i <= 1000000; i++ {
		fact[i] = int32(int64(i) * int64(fact[i-1]) % M)
	}
	inv[1] = 1
	invf[0] = 1
	invf[1] = 1
	for i := int64(2); i <= 1000000; i++ {
		t := M / i
		invk := int64(inv[M % i])
		inv[i] = int32(i * t % M * t % M * invk % M * invk % M)
		invf[i] = int32(int64(invf[i-1]) * int64(inv[i]) % M)
	}

	in := bufio.NewReader(os.Stdin)
	a, _ := in.ReadString('\n')
	b, _ := in.ReadString('\n')
	a = strings.TrimSpace(a)
	b = strings.TrimSpace(b)

	xx := [26]int32{0}
	for _, ch := range a {
		xx[ch-'a']++
	}

	perm := NewP(xx)
	all := perm.val

	for _, ch0 := range b {
		for ch := ch0+1; ch <= 'z'; ch++ {
			all = (all - perm.PretendToMinus(ch-'a')) % M
		}
		perm.Minus(ch0-'a')
	}

	perm = NewP(xx)
	for _, ch0 := range a {
		for ch := 'a'; ch < ch0; ch++ {
			all = (all - perm.PretendToMinus(ch-'a')) % M
		}
		perm.Minus(ch0-'a')
	}

	yy := [26]int32{0}
	for _, ch := range b {
		yy[ch-'a']++
	}
	if xx == yy {
		all = (all - 1) % M
	}
	all = (all - 1) % M
	if all < 0 {
		all = all + M
	}
	fmt.Println(all)
}


Once upon a time DravDe, an outstanding person famous for his professional achievements (as you must remember, he works in a warehouse storing Ogudar-Olok, a magical but non-alcoholic drink) came home after a hard day. That day he had to drink 9875 boxes of the drink and, having come home, he went to bed at once.DravDe dreamt about managing a successful farm. He dreamt that every day one animal came to him and asked him to let it settle there. However, DravDe, being unimaginably kind, could send the animal away and it went, rejected. There were exactly n days in DravDe’s dream and the animal that came on the i-th day, ate exactly ci tons of food daily starting from day i. But if one day the animal could not get the food it needed, it got really sad. At the very beginning of the dream there were exactly X tons of food on the farm.DravDe woke up terrified...When he retold the dream to you, he couldn’t remember how many animals were on the farm by the end of the n-th day any more, but he did remember that nobody got sad (as it was a happy farm) and that there was the maximum possible amount of the animals. That’s the number he wants you to find out. It should be noticed that the animals arrived in the morning and DravDe only started to feed them in the afternoon, so that if an animal willing to join them is rejected, it can’t eat any farm food. But if the animal does join the farm, it eats daily from that day to the n-th.

The first input line contains integers n and X (1 ≤ n ≤ 100, 1 ≤ X ≤ 104) — amount of days in DravDe’s dream and the total amount of food (in tons) that was there initially. The second line contains integers ci (1 ≤ ci ≤ 300). Numbers in the second line are divided by a space.

Output the only number — the maximum possible amount of animals on the farm by the end of the n-th day given that the food was enough for everybody.

NoteNote to the first example: DravDe leaves the second and the third animal on the farm. The second animal will eat one ton of food on the second day and one ton on the third day. The third animal will eat one ton of food on the third day.

package main

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

// github.com/EndlessCheng/codeforces-go
func CF35D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}

	var n, maxW int
	Fscan(in, &n, &maxW)
	ws := make([]int, n)
	for i := range ws {
		Fscan(in, &ws[i])
		ws[i] *= n - i
	}
	dp := make([][]int, n+1)
	for i := range dp {
		dp[i] = make([]int, maxW+1)
	}
	for i, wi := range ws {
		for j, dpij := range dp[i] {
			if j < wi {
				dp[i+1][j] = dpij
			} else {
				dp[i+1][j] = max(dpij, dp[i][j-wi]+1)
			}
		}
	}
	Fprint(_w, dp[n][maxW])
}

func main() { r, _ := os.Open("input.txt"); w, _ := os.Create("output.txt"); CF35D(r, w) }

package main

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

// github.com/EndlessCheng/codeforces-go
func CF35D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}

	var n, maxW int
	Fscan(in, &n, &maxW)
	ws := make([]int, n)
	for i := range ws {
		Fscan(in, &ws[i])
		ws[i] *= n - i
	}
	dp := make([][]int, n+1)
	for i := range dp {
		dp[i] = make([]int, maxW+1)
	}
	for i, wi := range ws {
		for j, dpij := range dp[i] {
			if j < wi {
				dp[i+1][j] = dpij
			} else {
				dp[i+1][j] = max(dpij, dp[i][j-wi]+1)
			}
		}
	}
	Fprint(_w, dp[n][maxW])
}

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