package main

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

func solve() {
    n := readInt()
    p := readInt64Array(n)
    a := make([][]int, n)
    for i := 0; i < n-1; i++ {
        v, u := readInt()-1, readInt()-1
        a[v] = append(a[v], u)
        a[u] = append(a[u], v)
    }
    sub, was := make([]int64, n), make([]bool, n)
    dp1, dp2, can := make([]int64, n), make([]int64, n), make([]bool, n)
    var calc func(k int)
    calc = func(k int) {
        sub[k], was[k] = p[k], true
        ch1, ch2 := Ints64{}, Ints64{}
        for _, v := range a[k] {
            if !was[v] {
                calc(v)
                sub[k] += sub[v]
                ch1 = append(ch1, dp1[v])
                if can[v] {
                    ch2 = append(ch2, dp2[v])
                }
            }
        }
        sort.Sort(sort.Reverse(ch1))
        dp1[k] = sub[k]
        if len(ch1) > 0 && ch1[0] > sub[k] {
            dp1[k] = ch1[0]
        }
        if len(ch1) > 1 {
            ch2 = append(ch2, ch1[0]+ch1[1])
        }
        sort.Sort(sort.Reverse(ch2))

        if len(ch2) > 0 {
            dp2[k] = ch2[0]
            can[k] = true
        }
    }
    calc(0)

    if can[0] {
        fmt.Println(dp2[0])
    } else {
        fmt.Println("Impossible")
    }
}

// Helpers

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

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

// Math

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

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

// IO

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
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

// Sort

type Ints64 []int64

func (a Ints64) Len() int           { return len(a) }
func (a Ints64) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Ints64) Less(i, j int) bool { return a[i] < a[j] }

/* Sort tempalte
func (a ) Len() int           { return len(a) }
func (a ) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ) Less(i, j int) bool { return  }
*/

package main

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

const minf int64 = -2000000000000000

func Max(a, b int64) int64{
	if a > b {
		return a
	} else{
		return b
	}
}

func Dfs(v int, vis []bool, price []int, dpOne, dpTwo, sum []int64, graph [][]int){
	vis[v]   = true
	sum[v]   = int64(price[v])
	dpOne[v] = minf
	dpTwo[v] = minf

	for _, x := range graph[v] {
		if vis[x] {
			continue
		}
		Dfs(x, vis, price, dpOne, dpTwo, sum, graph)
		sum[v]  += sum[x]
		dpOne[v] = Max(dpOne[v], dpOne[x])
		dpTwo[v] = Max(dpTwo[v], dpTwo[x])
	}

	second   := false
	secDpOne := minf

	for _, x :=range graph[v] {
		if dpOne[x] == dpOne[v] && !second {
			second = true
			continue
		}
		secDpOne = Max(dpOne[x], secDpOne)
	}

	dpTwo[v] = Max(dpTwo[v], dpOne[v] + secDpOne)
	dpOne[v] = Max(dpOne[v], sum[v])
}

func readInt() int{
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

func prepare(){
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
}

func main() {
	prepare()

	var n, a, b int
	var graph   [][]int

	n = readInt()

	price     := make([]int,    n)
	dpOne     := make([]int64,  n)
	dpTwo     := make([]int64,  n)
	sum       := make([]int64,  n)
	visited   := make([]bool,   n)

	for i := 0; i < n; i++ {
		price[i] = readInt()
		graph    = append(graph, make([]int, 0))
	}

	for i := 0; i < n - 1; i++ {
		a = readInt() - 1
		b = readInt() - 1
		graph[a] = append(graph[a], b)
		graph[b] = append(graph[b], a)
	}

	Dfs(0, visited, price, dpOne, dpTwo, sum, graph)
	if dpTwo[0] * 2 < minf {
		fmt.Println("Impossible")
	} else {
		fmt.Println(dpTwo[0])
	}
}

package main

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

const MAX = 200010

const INF = int64(200000000000000)

type Edge struct {
	x, y int
}

type Node struct {
	ans, maxn, sum int64
}

var a []int64
var d []Node
var vis []bool
var c []int

var first []int
var next []int
var edges []Edge

var cnt int

func addEdge(u, v int) {
	cnt++
	edges[cnt].x = u
	edges[cnt].y = v

	next[cnt] = first[u]
	first[u] = cnt
}

func max(x, y int64) int64 {
	if x > y {
		return x
	}
	return y

}

func dp(root int) Node {
	if vis[root] {
		return d[root]
	}

	d[root].ans = -INF
	d[root].maxn = -INF
	d[root].sum = a[root]
	vis[root] = true

	x := -INF
	y := -INF

	for i := first[root]; i != 0; i = next[i] {
		u := edges[i].y
		if !vis[u] {
			tmp := dp(u)
			d[root].maxn = max(d[root].maxn, tmp.maxn)
			d[root].sum += tmp.sum

			d[root].ans = max(d[root].ans, tmp.ans)

			//fmt.Printf("root1 = %d %d %d\n", root, x, y)

			if tmp.maxn > x {
				y = x
				x = tmp.maxn
			} else if tmp.maxn > y {
				y = tmp.maxn
			}

			//	fmt.Printf("root2 = %d %d %d\n", root, x, y)

		}
	}

	d[root].maxn = max(d[root].maxn, d[root].sum)
	if x > -INF && y > -INF {
		d[root].ans = max(d[root].ans, x+y)
	}

	return d[root]

}

func main() {

	var n int

	b, _ := ioutil.ReadAll(os.Stdin)
	r := bytes.NewReader(b)

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

	a = make([]int64, n+1)
	d = make([]Node, n+1)
	vis = make([]bool, n+1)
	c = make([]int, n+1)

	first = make([]int, n+1)
	next = make([]int, 2*n+1)
	edges = make([]Edge, 2*n+1)

	cnt = 0

	for i := 1; i < n; i++ {
		fmt.Fscanf(r, "%v ", &a[i])
	}
	fmt.Fscanf(r, "%v\n", &a[n])

	var u, v int
	for i := 1; i < n; i++ {
		fmt.Fscanf(r, "%d %d\n", &u, &v)
		c[u]++
		c[v]++

		addEdge(u, v)
		addEdge(v, u)
	}

	root := 1

	for c[root] == 1 {
		vis[root] = true

		for i := first[root]; i != 0; i = next[i] {
			u = edges[i].y

			if !vis[u] {
				c[u] = c[u] - 1
				root = u
				break
			}
		}
	}

	//fmt.Printf("root = %d\n", root)

	dp(root)
	/*
		for i := 1; i <= n; i++ {
			fmt.Printf("%d %d %d\n", d[i].maxn, d[i].sum, d[i].ans)
		}
	*/
	ans := d[root].ans

	if ans <= -INF {
		fmt.Printf("Impossible\n")
	} else {
		fmt.Printf("%v\n", ans)
	}

	return

}

package main

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

const MAX = 200010

const INF = int64(200000000000000)

type Edge struct {
	x, y int
}

type Node struct {
	ans, maxn, sum int64
}

var a []int64
var d []Node
var vis []bool
var c []int

var first []int
var next []int
var edges []Edge

var cnt int

func addEdge(u, v int) {
	cnt++
	edges[cnt].x = u
	edges[cnt].y = v

	next[cnt] = first[u]
	first[u] = cnt
}

func max(x, y int64) int64 {
	if x > y {
		return x
	}
	return y

}

func dp(root int) Node {
	if vis[root] {
		return d[root]
	}

	d[root].ans = -INF
	d[root].maxn = -INF
	d[root].sum = a[root]
	vis[root] = true

	x := -INF
	y := -INF

	for i := first[root]; i != 0; i = next[i] {
		u := edges[i].y
		if !vis[u] {
			tmp := dp(u)
			d[root].maxn = max(d[root].maxn, tmp.maxn)
			d[root].sum += tmp.sum

			d[root].ans = max(d[root].ans, tmp.ans)

			if tmp.maxn > x {
				y = x
				x = tmp.maxn
			} else if tmp.maxn > y {
				y = tmp.maxn
			}
		}
	}

	d[root].maxn = max(d[root].maxn, d[root].sum)
	if x > -INF && y > -INF {
		d[root].ans = max(d[root].ans, x+y)
	}

	return d[root]

}

func main() {

	var n int

	b, _ := ioutil.ReadAll(os.Stdin)
	r := bytes.NewReader(b)

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

	a = make([]int64, n+1)
	d = make([]Node, n+1)
	vis = make([]bool, n+1)
	c = make([]int, n+1)

	first = make([]int, n+1)
	next = make([]int, 2*n+1)
	edges = make([]Edge, 2*n+1)

	cnt = 0

	for i := 1; i < n; i++ {
		fmt.Fscanf(r, "%v ", &a[i])
	}
	fmt.Fscanf(r, "%v\n", &a[n])

	var u, v int
	for i := 1; i < n; i++ {
		fmt.Fscanf(r, "%d %d\n", &u, &v)
		c[u]++
		c[v]++

		addEdge(u, v)
		addEdge(v, u)
	}

	dp(1)
	ans := d[1].ans

	if ans <= -INF {
		fmt.Printf("Impossible\n")
	} else {
		fmt.Printf("%v\n", ans)
	}

	return

}

package main

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

const minf int64 = -2000000000000

func Max(a, b int64) int64{
	if a > b {
		return a
	} else{
		return b
	}
}

func Dfs(v int, vis []bool, price []int, dpOne, dpTwo, sum []int64, graph [][]int){
	vis[v]   = true
	sum[v]   = int64(price[v])
	dpOne[v] = minf
	dpTwo[v] = minf

	for _, x := range graph[v] {
		if vis[x] {
			continue
		}
		Dfs(x, vis, price, dpOne, dpTwo, sum, graph)
		sum[v]  += sum[x]
		dpOne[v] = Max(dpOne[v], dpOne[x])
		dpTwo[v] = Max(dpTwo[v], dpTwo[x])
	}

	second   := false
	secDpOne := minf

	for _, x :=range graph[v] {
		if dpOne[x] == dpOne[v] && !second {
			second = true
			continue
		}
		secDpOne = Max(dpOne[x], secDpOne)
	}

	dpTwo[v] = Max(dpTwo[v], dpOne[v] + secDpOne)
	dpOne[v] = Max(dpOne[v], sum[v])
}

func readInt() int{
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

func prepare(){
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
}

func main() {
	prepare()

	var n, a, b int
	var graph   [][]int

	n = readInt()

	price     := make([]int,    n)
	dpOne     := make([]int64,  n)
	dpTwo     := make([]int64,  n)
	sum       := make([]int64,  n)
	visited   := make([]bool,   n)

	for i := 0; i < n; i++ {
		price[i] = readInt()
		graph    = append(graph, make([]int, 0))
	}

	for i := 0; i < n - 1; i++ {
		a = readInt() - 1
		b = readInt() - 1
		graph[a] = append(graph[a], b)
		graph[b] = append(graph[b], a)
	}

	Dfs(0, visited, price, dpOne, dpTwo, sum, graph)
	if dpTwo[0] * 2 < minf {
		fmt.Println("Impossible")
	} else {
		fmt.Println(dpTwo[0])
	}
}

package main

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

const MAX = 200010

type Edge struct {
	x, y int
}

var a []int64
var d []int64
var vis []bool
var c []int

var first []int
var next []int
var edges []Edge
var fa []int

var cnt int

func addEdge(u, v int) {
	cnt++
	edges[cnt].x = u
	edges[cnt].y = v

	next[cnt] = first[u]
	first[u] = cnt
}

func judge(n int) bool {
	for i := 1; i <= n; i++ {
		if c[i] > 1 {
			return true
		}
	}

	return false

}

func dp(root int) int64 {

	if vis[root] {
		return d[root]
	}

	d[root] = a[root]
	vis[root] = true

	for i := first[root]; i != 0; i = next[i] {
		tmp := edges[i]

		if !vis[tmp.y] {
			fa[tmp.y] = root
			d[root] += dp(tmp.y)
		}

	}

	return d[root]

}

func main() {

	var n int

	b, _ := ioutil.ReadAll(os.Stdin)
	r := bytes.NewReader(b)
	fmt.Fscanf(r, "%d\n", &n)

	a = make([]int64, n+1)
	d = make([]int64, n+1)
	vis = make([]bool, n+1)
	c = make([]int, n+1)

	first = make([]int, n+1)
	next = make([]int, 2*n+1)
	edges = make([]Edge, 2*n+1)
	fa = make([]int, n+1)

	cnt = 0

	for i := 1; i < n; i++ {
		fmt.Fscanf(r, "%v ", &a[i])
	}
	fmt.Fscanf(r, "%v\n", &a[n])

	var u, v int
	for i := 1; i < n; i++ {
		fmt.Fscanf(r, "%d %d\n", &u, &v)
		c[u]++
		c[v]++

		addEdge(u, v)
		addEdge(v, u)
	}

	if !judge(n) {
		fmt.Println("Impossible")
		return
	}

	dp(1)
	/*
		for i := 1; i <= n; i++ {
			fmt.Printf("%v ", fa[i])
		}
		fmt.Printf("\n")
	*/
	res1 := a[2]
	index := 2

	for i := 3; i <= n; i++ {
		if d[i] > res1 {
			res1 = d[i]
			index = i
		}
	}

	for i := 1; i <= n; i++ {
		vis[i] = false
	}

	for i := index; i != 0; i = fa[i] {
		vis[i] = true
	}

	var res2 int64

	for i := 2; i <= n; i++ {
		if !vis[i] {
			res2 = d[i]
			break
		}
	}

	for i := 2; i <= n; i++ {
		if !vis[i] {
			if d[i] > res2 {
				res2 = d[i]
			}
		}
	}

	fmt.Printf("%v\n", res1+res2)

	return

}

package main

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

const MAX = 200010

const INF = int64(200000000000000)

type Edge struct {
	x, y int
}

type Node struct {
	ans, maxn, sum int64
}

var a []int64
var d []Node
var vis []bool
var c []int

var first []int
var next []int
var edges []Edge

var cnt int

func addEdge(u, v int) {
	cnt++
	edges[cnt].x = u
	edges[cnt].y = v

	next[cnt] = first[u]
	first[u] = cnt
}

func max(x, y int64) int64 {
	if x > y {
		return x
	}
	return y

}

func dp(root int) Node {
	if vis[root] {
		return d[root]
	}

	d[root].ans = -INF
	d[root].maxn = a[root]
	d[root].sum = a[root]
	vis[root] = true

	x := -INF
	y := -INF

	for i := first[root]; i != 0; i = next[i] {
		u := edges[i].y
		if !vis[u] {
			tmp := dp(u)
			d[root].maxn = max(d[root].maxn, tmp.maxn)
			d[root].sum += tmp.sum

			d[root].ans = max(d[root].ans, tmp.ans)

			//fmt.Printf("root1 = %d %d %d\n", root, x, y)

			if tmp.maxn > x {
				y = x
				x = tmp.maxn
			} else if tmp.maxn > y {
				y = tmp.maxn
			}

			//	fmt.Printf("root2 = %d %d %d\n", root, x, y)

		}
	}

	d[root].maxn = max(d[root].maxn, d[root].sum)
	if x > -INF && y > -INF {
		d[root].ans = max(d[root].ans, x+y)
	}

	return d[root]

}

func main() {

	var n int

	b, _ := ioutil.ReadAll(os.Stdin)
	r := bytes.NewReader(b)

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

	a = make([]int64, n+1)
	d = make([]Node, n+1)
	vis = make([]bool, n+1)
	c = make([]int, n+1)

	first = make([]int, n+1)
	next = make([]int, 2*n+1)
	edges = make([]Edge, 2*n+1)

	cnt = 0

	for i := 1; i < n; i++ {
		fmt.Fscanf(r, "%v ", &a[i])
	}
	fmt.Fscanf(r, "%v\n", &a[n])

	var u, v int
	for i := 1; i < n; i++ {
		fmt.Fscanf(r, "%d %d\n", &u, &v)
		c[u]++
		c[v]++

		addEdge(u, v)
		addEdge(v, u)
	}

	root := 1

	for c[root] == 1 {
		vis[root] = true

		for i := first[root]; i != 0; i = next[i] {
			u = edges[i].y

			if !vis[u] {
				c[u] = c[u] - 1
				root = u
				break
			}
		}
	}

	//fmt.Printf("root = %d\n", root)

	dp(root)
	/*
		for i := 1; i <= n; i++ {
			fmt.Printf("%d %d %d\n", d[i].maxn, d[i].sum, d[i].ans)
		}
	*/
	ans := d[root].ans

	if ans <= -INF {
		fmt.Printf("Impossible\n")
	} else {
		fmt.Printf("%v\n", ans)
	}

	return

}

package main

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

const MAX = 200010

const INF = int64(2000000000000000)

type Edge struct {
	x, y int
}

type Node struct {
	value, maxn int64
}

var a []int64
var d []Node
var vis []bool
var c []int

var first []int
var next []int
var edges []Edge

var cnt int

func addEdge(u, v int) {
	cnt++
	edges[cnt].x = u
	edges[cnt].y = v

	next[cnt] = first[u]
	first[u] = cnt
}

func max(x, y int64) int64 {
	if x > y {
		return x
	}
	return y

}

func dp(root int) Node {

	if vis[root] {
		return d[root]
	}

	d[root].maxn = -INF
	d[root].value = a[root]
	vis[root] = true

	for i := first[root]; i != 0; i = next[i] {
		u := edges[i].y

		if !vis[u] {
			tmp := dp(u)
			d[root].value += tmp.value
			d[root].maxn = max(d[root].maxn, tmp.maxn)
		}

	}

	d[root].maxn = max(d[root].maxn, d[root].value)

	return d[root]
}

func maxRes(root int) int64 {

	var index int

	res := -INF

	for i := first[root]; i != 0; i = next[i] {
		u := edges[i].y

		if !vis[u] {
			if d[u].maxn > res {
				res = d[u].maxn
				index = u
			}
		}
	}

	vis[index] = true
	return res

}

func main() {

	var n int

	b, _ := ioutil.ReadAll(os.Stdin)
	r := bytes.NewReader(b)

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

	a = make([]int64, n+1)
	d = make([]Node, n+1)
	vis = make([]bool, n+1)
	c = make([]int, n+1)

	first = make([]int, n+1)
	next = make([]int, 2*n+1)
	edges = make([]Edge, 2*n+1)

	cnt = 0

	for i := 1; i < n; i++ {
		fmt.Fscanf(r, "%v ", &a[i])
	}
	fmt.Fscanf(r, "%v\n", &a[n])

	var u, v int
	for i := 1; i < n; i++ {
		fmt.Fscanf(r, "%d %d\n", &u, &v)
		c[u]++
		c[v]++

		addEdge(u, v)
		addEdge(v, u)
	}

	dp(1)

	for i := 1; i <= n; i++ {
		vis[i] = false
	}

	root := 1

	for c[root] == 1 {
		vis[root] = true
		for i := first[root]; i != 0; i = next[i] {
			tmp := edges[i]

			if !vis[tmp.y] {
				c[tmp.y] = c[tmp.y] - 1
				root = tmp.y
				break
			}
		}
	}

	vis[root] = true

	ans := maxRes(root) + maxRes(root)

	if ans <= -INF {
		fmt.Printf("Impossible\n")
	} else {
		fmt.Printf("%v\n", ans)
	}

	return

}

package main

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

const MAX = 200010

const INF = int64(200000000000000)

type Edge struct {
	x, y int
}

type Node struct {
	value, maxn int64
}

var a []int64
var d []Node
var vis []bool
var c []int

var first []int
var next []int
var edges []Edge

var cnt int

func addEdge(u, v int) {
	cnt++
	edges[cnt].x = u
	edges[cnt].y = v

	next[cnt] = first[u]
	first[u] = cnt
}

func max(x, y int64) int64 {
	if x > y {
		return x
	}
	return y

}

func dp(root int) Node {

	if vis[root] {
		return d[root]
	}

	d[root].maxn = -INF
	d[root].value = a[root]
	vis[root] = true

	for i := first[root]; i != 0; i = next[i] {
		u := edges[i].y

		if !vis[u] {
			tmp := dp(u)
			d[root].value += tmp.value
			d[root].maxn = max(d[root].maxn, tmp.maxn)
		}

	}

	d[root].maxn = max(d[root].maxn, d[root].value)

	return d[root]
}

func maxRes(root int) int64 {

	var index int

	res := -INF

	for i := first[root]; i != 0; i = next[i] {
		u := edges[i].y

		if !vis[u] {
			if d[u].maxn > res {
				res = d[u].maxn
				index = u
			}
		}
	}

	vis[index] = true
	return res

}

func main() {

	var n int

	b, _ := ioutil.ReadAll(os.Stdin)
	r := bytes.NewReader(b)

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

	a = make([]int64, n+1)
	d = make([]Node, n+1)
	vis = make([]bool, n+1)
	c = make([]int, n+1)

	first = make([]int, n+1)
	next = make([]int, 2*n+1)
	edges = make([]Edge, 2*n+1)

	cnt = 0

	for i := 1; i < n; i++ {
		fmt.Fscanf(r, "%v ", &a[i])
	}
	fmt.Fscanf(r, "%v\n", &a[n])

	var u, v int
	for i := 1; i < n; i++ {
		fmt.Fscanf(r, "%d %d\n", &u, &v)
		c[u]++
		c[v]++

		addEdge(u, v)
		addEdge(v, u)
	}

	dp(1)

	for i := 1; i <= n; i++ {
		vis[i] = false
	}

	root := 1

	for c[root] == 1 {
		vis[root] = true
		for i := first[root]; i != 0; i = next[i] {
			tmp := edges[i]

			if !vis[tmp.y] {
				c[tmp.y] = c[tmp.y] - 1
				root = tmp.y
				break
			}
		}
	}

	vis[root] = true

	ans := maxRes(root) + maxRes(root)

	if ans <= -INF {
		fmt.Printf("Impossible\n")
	} else {
		fmt.Printf("%v\n", ans)
	}

	return

}

package main

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

const MAX = 200010

const INF = int64(200000000000000)

type Edge struct {
	x, y int
}

var a []int64
var d []int64
var vis []bool
var c []int

var first []int
var next []int
var edges []Edge
var fa []int

var cnt int

func addEdge(u, v int) {
	cnt++
	edges[cnt].x = u
	edges[cnt].y = v

	next[cnt] = first[u]
	first[u] = cnt
}

func judge(n int) bool {
	for i := 1; i <= n; i++ {
		if c[i] > 1 {
			return true
		}
	}

	return false

}

func dp(root int) int64 {

	if vis[root] {
		return d[root]
	}

	d[root] = a[root]
	vis[root] = true

	for i := first[root]; i != 0; i = next[i] {
		tmp := edges[i]

		if !vis[tmp.y] {
			fa[tmp.y] = root
			d[root] += dp(tmp.y)
		}

	}

	return d[root]

}

func main() {

	var n int

	b, _ := ioutil.ReadAll(os.Stdin)
	r := bytes.NewReader(b)
	fmt.Fscanf(r, "%d\n", &n)

	a = make([]int64, n+1)
	d = make([]int64, n+1)
	vis = make([]bool, n+1)
	c = make([]int, n+1)

	first = make([]int, n+1)
	next = make([]int, 2*n+1)
	edges = make([]Edge, 2*n+1)
	fa = make([]int, n+1)

	cnt = 0

	for i := 1; i < n; i++ {
		fmt.Fscanf(r, "%v ", &a[i])
	}
	fmt.Fscanf(r, "%v\n", &a[n])

	var u, v int
	for i := 1; i < n; i++ {
		fmt.Fscanf(r, "%d %d\n", &u, &v)
		c[u]++
		c[v]++

		addEdge(u, v)
		addEdge(v, u)
	}

	if !judge(n) {
		fmt.Println("Impossible")
		return
	}

	//fmt.Printf("root = %d\n", root)

	dp(1)

	for i := 1; i <= n; i++ {
		vis[i] = false
	}

	root := 1

	for c[root] == 1 {
		vis[root] = true
		for i := first[root]; i != 0; i = next[i] {
			tmp := edges[i]

			if !vis[tmp.y] {
				c[tmp.y] = c[tmp.y] - 1
				root = tmp.y
				//fmt.Printf("root = %d\n", root)
				break
			}
		}
	}

	vis[root] = true

	res1 := -INF

	var index int

	for i := 1; i <= n; i++ {
		if !vis[i] {
			if d[i] > res1 {
				res1 = d[i]
				index = i
			}
		}
	}

	for i := index; i != 0; i = fa[i] {
		vis[i] = true
	}

	res2 := -INF

	for i := 1; i <= n; i++ {
		if !vis[i] {
			if d[i] > res2 {
				res2 = d[i]
			}
		}
	}

	fmt.Printf("%v\n", res1+res2)

	return

}


package main

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

type Point struct {
	x     int
	y     int
	color int
	step  int
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n, m, p := 0, 0, 0
	fmt.Fscanf(in, "%d %d %d\n", &n, &m, &p)
	speed := make([]int, p)
	s := make([][]byte, n)
	for i := 0; i < p; i++ {
		fmt.Fscanf(in, "%d", &speed[i])
	}
	fmt.Fscanf(in, "\n")
	for i := 0; i < n; i++ {
		str := ""
		fmt.Fscanf(in, "%s\n", &str)
		s[i] = []byte(str)
		//fmt.Println(s[i])
	}
	potentials := make([][]Point, p)
	for i := 0; i < p; i++ {
		potentials[i] = make([]Point, 0)
	}
	for i := 0; i < p; i++ {
		for j := 0; j < n; j++ {
			for k := 0; k < m; k++ {
				if s[j][k] == '1'+byte(i) {
					newP := Point{j, k, i + 1, speed[i]}
					potentials[i] = append(potentials[i], newP)
				}
			}
		}
	}
	dx := []int{0, 1, 0, -1}
	dy := []int{1, 0, -1, 0}
	for true {
		end := true
		for i := 0; i < p; i++ {
			st := potentials[i]
			if len(st) != 0 {
				end = false
			}
			potentials[i] = make([]Point, 0)
			for len(st) > 0 {
				if st[0].step == 0 {
					potentials[i] = append(potentials[i], Point{st[0].x, st[0].y, st[0].color, speed[i]})
				} else {
					for j := 0; j < 4; j++ {
						nx := st[0].x + dx[j]
						ny := st[0].y + dy[j]
						if nx >= 0 && nx < n && ny >= 0 && ny < m && s[nx][ny] == '.' {
							s[nx][ny] = '1' + byte(i)
							st = append(st, Point{nx, ny, i, st[0].step - 1})
						}
					}
				}
				st = st[1:]
			}
		}
		if end {
			break
		}
	}
	ans := make([]int, p)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if s[i][j] >= '0' && s[i][j] <= '9' {
				ans[s[i][j]-'1']++
			}
		}
	}
	fmt.Fprintf(out, "%d", ans[0])
	for i := 1; i < p; i++ {
		fmt.Fprintf(out, " %d", ans[i])
	}
	fmt.Fprintf(out, "\n")
	return
}

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

package main

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

var in = bufio.NewReaderSize(os.Stdin, 2<<16)

type elem struct {
	r, c, dist int
}

func main() {
	var n, m, p int
	fmt.Fscan(in, &n, &m, &p)
	speed := make([]int, p)
	for i := range speed {
		fmt.Fscan(in, &speed[i])
	}
	grid := make([][]byte, n)
	for i := range grid {
		var s string
		fmt.Fscan(in, &s)
		grid[i] = []byte(s)
	}

	ans := make([]int, p)
	queues := make([][]elem, p)
	for i := range grid {
		for j := range grid[i] {
			pl := grid[i][j] - '1'
			if pl < 0 || pl > 9 {
				continue
			}
			queues[pl] = append(queues[pl], elem{i, j, 0})
			ans[pl]++
		}
	}

	moved := true
	for round := 1; moved; round++ {
		moved = false
		for pl, q := range queues {
			for len(q) > 0 && q[0].dist < round*speed[pl] {
				v := q[0]
				q = q[1:]
				move := func(r, c int) {
					if grid[r][c] == '.' {
						grid[r][c] = byte(pl) + '1'
						ans[pl]++
						q = append(q, elem{r, c, v.dist + 1})
						moved = true
					}
				}
				if v.r > 0 {
					move(v.r-1, v.c)
				}
				if v.r+1 < n {
					move(v.r+1, v.c)
				}
				if v.c > 0 {
					move(v.r, v.c-1)
				}
				if v.c+1 < m {
					move(v.r, v.c+1)
				}
			}
			queues[pl] = q
		}
	}
	for i := range ans[1:] {
		fmt.Print(ans[i], " ")
	}
	fmt.Println(ans[p-1])
}

package main

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

type pInfo struct {
	step     int
	boundary map[[2]int]struct{}
	land     int
}

func expandCell(pi *pInfo, grids [][]rune, x, y, xp, yp int, f *bool, b map[[2]int]struct{}) {
	pi.land++
	grids[x][y] = rune('#')
	b[[2]int{x, y}] = struct{}{}
	*f = true
}

func expand(pi *pInfo, grids [][]rune, n, m int) (c bool) {
	for i := 0; i < pi.step; i++ {
		if len(pi.boundary) == 0 {
			return
		}
		nb := make(map[[2]int]struct{})
		for k := range pi.boundary {
			if k[0]+1 < n && grids[k[0]+1][k[1]] == rune('.') {
				expandCell(pi, grids, k[0]+1, k[1], k[0], k[1], &c, nb)
			}
			if k[0]-1 >= 0 && grids[k[0]-1][k[1]] == rune('.') {
				expandCell(pi, grids, k[0]-1, k[1], k[0], k[1], &c, nb)
			}
			if k[1]+1 < m && grids[k[0]][k[1]+1] == rune('.') {
				expandCell(pi, grids, k[0], k[1]+1, k[0], k[1], &c, nb)
			}
			if k[1]-1 >= 0 && grids[k[0]][k[1]-1] == rune('.') {
				expandCell(pi, grids, k[0], k[1]-1, k[0], k[1], &c, nb)
			}
		}
		pi.boundary = nb
	}
	return
}

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

	var n, m, p int
	fmt.Fscanln(reader, &n, &m, &p)
	ps := make([]*pInfo, p)
	grids := make([][]rune, n)

	line, err := reader.ReadString('\n')
	if err != nil {
		fmt.Println("read 1 error", err)
		return
	}
	strs := strings.Split(line[:len(line)-2], " ")
	for i, str := range strs {
		ps[i] = &pInfo{boundary: make(map[[2]int]struct{})}
		if ps[i].step, err = strconv.Atoi(str); err != nil {
			fmt.Println("read 2 error", err)
			return
		}
	}

	for i := 0; i < n; i++ {
		line, err = reader.ReadString('\n')
		if err != nil {
			fmt.Println("read 3 error", err)
			return
		}
		grids[i] = []rune(line[:len(line)-2])
		for j := 0; j < m; j++ {
			if grids[i][j] != rune('#') && grids[i][j] != rune('.') {
				pn := int(grids[i][j]) - 48
				ps[pn-1].boundary[[2]int{i, j}] = struct{}{}
				ps[pn-1].land++
			}
		}
	}

	for {
		canExpand := false
		for _, pi := range ps {
			r := expand(pi, grids, n, m)
			if r {
				canExpand = true
			}
		}
		if !canExpand {
			break
		}
	}

	res := []int{}
	for _, pi := range ps {
		res = append(res, pi.land)
	}
	fmt.Println(strings.Trim(strings.Join(strings.Fields(fmt.Sprint(res)), " "), "[]") + " ")
}

package main

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

type pInfo struct {
	step     int
	boundary map[[2]int]struct{}
	land     int
}

func expandCell(pi *pInfo, grids [][]rune, x, y, xp, yp int, f *bool, b map[[2]int]struct{}) {
	pi.land++
	grids[x][y] = rune('#')
	b[[2]int{x, y}] = struct{}{}
	*f = true
}

func expand(pi *pInfo, grids [][]rune, n, m int) (c bool) {
	for i := 0; i < pi.step; i++ {
		if len(pi.boundary) == 0 {
			return
		}
		nb := make(map[[2]int]struct{})
		for k := range pi.boundary {
			if k[0]+1 < n && grids[k[0]+1][k[1]] == rune('.') {
				expandCell(pi, grids, k[0]+1, k[1], k[0], k[1], &c, nb)
			}
			if k[0]-1 >= 0 && grids[k[0]-1][k[1]] == rune('.') {
				expandCell(pi, grids, k[0]-1, k[1], k[0], k[1], &c, nb)
			}
			if k[1]+1 < m && grids[k[0]][k[1]+1] == rune('.') {
				expandCell(pi, grids, k[0], k[1]+1, k[0], k[1], &c, nb)
			}
			if k[1]-1 >= 0 && grids[k[0]][k[1]-1] == rune('.') {
				expandCell(pi, grids, k[0], k[1]-1, k[0], k[1], &c, nb)
			}
		}
		pi.boundary = nb
	}
	return
}

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

	var n, m, p int
	fmt.Fscanln(reader, &n, &m, &p)
	ps := make([]*pInfo, p)
	grids := make([][]rune, n)

	line, err := reader.ReadString('\n')
	if err != nil {
		return
	}
	strs := strings.Split(line[:len(line)-1], " ")
	for i, str := range strs {
		ps[i] = &pInfo{boundary: make(map[[2]int]struct{})}
		if ps[i].step, err = strconv.Atoi(str); err != nil {
			return
		}
	}

	for i := 0; i < n; i++ {
		line, err = reader.ReadString('\n')
		if err != nil {
			return
		}
		grids[i] = []rune(line[:len(line)-1])
		for j := 0; j < m; j++ {
			if grids[i][j] != rune('#') && grids[i][j] != rune('.') {
				pn := int(grids[i][j]) - 48
				ps[pn-1].boundary[[2]int{i, j}] = struct{}{}
				ps[pn-1].land++
			}
		}
	}

	for {
		canExpand := false
		for _, pi := range ps {
			r := expand(pi, grids, n, m)
			if r {
				canExpand = true
			}
		}
		if !canExpand {
			break
		}
	}

	res := []int{}
	for _, pi := range ps {
		res = append(res, pi.land)
	}
	fmt.Println(strings.Trim(strings.Join(strings.Fields(fmt.Sprint(res)), " "), "[]") + " ")
}

package main

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

type pInfo struct {
	step     int
	boundary map[[2]int]struct{}
	land     int
}

func expandCell(pi *pInfo, grids [][]rune, x, y, xp, yp int, f *bool, b map[[2]int]struct{}) {
	pi.land++
	grids[x][y] = rune('#')
	b[[2]int{x, y}] = struct{}{}
	*f = true
}

func expand(pi *pInfo, grids [][]rune, n, m int) (c bool) {
	for i := 0; i < pi.step; i++ {
		if len(pi.boundary) == 0 {
			return
		}
		nb := make(map[[2]int]struct{})
		for k := range pi.boundary {
			if k[0]+1 < n && grids[k[0]+1][k[1]] == rune('.') {
				expandCell(pi, grids, k[0]+1, k[1], k[0], k[1], &c, nb)
			}
			if k[0]-1 >= 0 && grids[k[0]-1][k[1]] == rune('.') {
				expandCell(pi, grids, k[0]-1, k[1], k[0], k[1], &c, nb)
			}
			if k[1]+1 < m && grids[k[0]][k[1]+1] == rune('.') {
				expandCell(pi, grids, k[0], k[1]+1, k[0], k[1], &c, nb)
			}
			if k[1]-1 >= 0 && grids[k[0]][k[1]-1] == rune('.') {
				expandCell(pi, grids, k[0], k[1]-1, k[0], k[1], &c, nb)
			}
		}
		pi.boundary = nb
	}
	return
}

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

	var n, m, p int
	fmt.Fscanln(reader, &n, &m, &p)
	ps := make([]*pInfo, p)
	grids := make([][]rune, n)

	line, err := reader.ReadString('\n')
	if err != nil {
		return
	}
	strs := strings.Split(line[:len(line)-1], " ")
	for i, str := range strs {
		ps[i] = &pInfo{boundary: make(map[[2]int]struct{})}
		if ps[i].step, err = strconv.Atoi(str); err != nil {
			return
		}
	}

	for i := 0; i < n; i++ {
		line, err = reader.ReadString('\n')
		if err != nil {
			return
		}
		grids[i] = []rune(line[:len(line)-1])
		for j := 0; j < m; j++ {
			if grids[i][j] != rune('#') && grids[i][j] != rune('.') {
				pn := int(grids[i][j]) - 48
				ps[pn-1].boundary[[2]int{i, j}] = struct{}{}
				ps[pn-1].land++
			}
		}
	}

	for {
		canExpand := false
		for _, pi := range ps {
			r := expand(pi, grids, n, m)
			if r {
				canExpand = true
			}
		}
		if !canExpand {
			break
		}
	}

	res := []int{}
	for _, pi := range ps {
		res = append(res, pi.land)
	}
	fmt.Println(strings.Trim(strings.Join(strings.Fields(fmt.Sprint(res)), " "), "[]"))
}

package main

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

type pInfo struct {
	step     int
	boundary map[[2]int]struct{}
	land     int
}

func expandCell(pi *pInfo, grids [][]rune, x, y, xp, yp int, f *bool, b map[[2]int]struct{}) {
	pi.land++
	grids[x][y] = rune('#')
	b[[2]int{x, y}] = struct{}{}
	*f = true
}

func expand(pi *pInfo, grids [][]rune, n, m int) (c bool) {
	for i := 0; i < pi.step; i++ {
		if len(pi.boundary) == 0 {
			return
		}
		nb := make(map[[2]int]struct{})
		for k := range pi.boundary {
			if k[0]+1 < n && grids[k[0]+1][k[1]] == rune('.') {
				expandCell(pi, grids, k[0]+1, k[1], k[0], k[1], &c, nb)
			}
			if k[0]-1 >= 0 && grids[k[0]-1][k[1]] == rune('.') {
				expandCell(pi, grids, k[0]-1, k[1], k[0], k[1], &c, nb)
			}
			if k[1]+1 < m && grids[k[0]][k[1]+1] == rune('.') {
				expandCell(pi, grids, k[0], k[1]+1, k[0], k[1], &c, nb)
			}
			if k[1]-1 >= 0 && grids[k[0]][k[1]-1] == rune('.') {
				expandCell(pi, grids, k[0], k[1]-1, k[0], k[1], &c, nb)
			}
		}
		pi.boundary = nb
	}
	return
}

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

	var n, m, p int
	fmt.Fscanln(reader, &n, &m, &p)
	ps := make([]*pInfo, p)
	grids := make([][]rune, n)

	line, err := reader.ReadString('\n')
	if err != nil {
		return
	}
	strs := strings.Split(line[:len(line)-1], " ")
	for i, str := range strs {
		ps[i] = &pInfo{boundary: make(map[[2]int]struct{})}
		if ps[i].step, err = strconv.Atoi(str); err != nil {
			return
		}
	}

	for i := 0; i < n; i++ {
		line, err = reader.ReadString('\n')
		if err != nil {
			return
		}
		grids[i] = []rune(line[:len(line)-1])
		for j := 0; j < m; j++ {
			if grids[i][j] != rune('#') && grids[i][j] != rune('.') {
				pn := int(grids[i][j]) - 48
				ps[pn-1].boundary[[2]int{i, j}] = struct{}{}
				ps[pn-1].land++
			}
		}
	}

	for {
		canExpand := false
		for _, pi := range ps {
			r := expand(pi, grids, n, m)
			if r {
				canExpand = true
			}
		}
		if !canExpand {
			break
		}
	}

	res := []int{}
	for _, pi := range ps {
		res = append(res, pi.land)
	}
	fmt.Printf("#%s#", strings.Trim(strings.Join(strings.Fields(fmt.Sprint(res)), " "), "[]")+" ")
}


package main

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

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

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}
	ch := true
	put := func(s string) {
		fmt.Fprint(writer, s)
	}
	step := func(i int) {
		if a[i] > 0 {
			a[i]--
			put("P")
			ch = true
		}
	}
	for ch {
		ch = false
		for i := 0; i < n-1; i++ {
			step(i)
			put("R")
		}
		for i := n-1; i > 0; i-- {
			step(i)
			put("L")
		}
	}
	fmt.Fprintln(writer)
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

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

	var f int = 0
	var p int = 0
	var b bool = true

	for f < n {
		var c byte
		switch {
		case p < f:
			c = 'R'
			p += 1
			b = true
		case p == f:
			if a[p] == 0 {
				f += 1
			}
			if b && a[p] > 0 {
				c = 'P'
				a[p] -= 1
				b = false
				if a[p] == 0 {
					f += 1
				}
			} else {
				if p != n - 1 {
					c = 'R'
					p += 1
				} else {
					c = 'L'
					p -= 1
				}
				b = true
			}
		case p > f:
			if b && a[p] > 0 {
				c = 'P'
				a[p] -= 1
				b = false
			} else {
				if p != 0 {
					c = 'L'
					p -= 1
				} else {
					// never reach
					c = 'R'
					p += 1
				}
				b = true
			}
		}
		fmt.Printf("%c", c)
	}
	fmt.Println("")
}

package main

import "fmt"

func main() {
    var n int
    var a [305]int
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
    }
    pos, length := 0, n-1
    for pos < length {
        if a[pos] > 0 {
            fmt.Print("P")
            a[pos]--
        }
        fmt.Print("R")
        if a[pos+1] > 0 {
            fmt.Print("P")
            a[pos+1]--
        }
        fmt.Print("L")
        for a[pos] == 0 {
            fmt.Print("R")
            pos++
            if pos == length { break }
        }
    }
    for a[length] > 0 {
        fmt.Print("P")
        a[length]--
        if a[length] > 0 { fmt.Print("LR") }
    }
    fmt.Println()
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	ans := make([]byte, 0, 1e6)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	for i := range a[1:] {
		if i > 0 {
			ans = append(ans, 'R')
		}
		for a[i] > 0 {
			ans = append(ans, 'P')
			a[i]--
			if a[i] != 0 {
				if a[i+1] != 0 {
					ans = append(ans, 'R', 'P', 'L')
					a[i+1]--
				} else {
					ans = append(ans, 'R', 'L')
				}
			}
		}
	}
	for a[n-1] != 0 {
		ans = append(ans, 'R', 'P', 'L')
		a[n-1]--
	}
	fmt.Printf("%s\n", ans)
}

package main

import (
	"bytes"
	"fmt"
)

func DistributeCoins(numWallet int, coinsQtyPerWallet []int) {
	actions := make([]string, numWallet)
	i := 0
	for {
		if coinsQtyPerWallet[i] != 0 {
			actions = append(actions, "P")
			coinsQtyPerWallet[i] -= 1
		}
		if coinsQtyPerWallet[i] != 0 {
			if i == (numWallet - 1) {
				actions = append(actions, "LR")
			} else {
				actions = append(actions, "RL")
			}
		} else if coinsQtyPerWallet[i] == 0 {
			if i < (numWallet - 1) {
				actions = append(actions, "R")
				i++
			} else {
				break
			}
		}
	}
	var buffer bytes.Buffer
	for i := 0; i < len(actions); i++ {
		buffer.WriteString(actions[i])
	}
	fmt.Println(buffer.String())
}

func main() {
	var numWallets int
	fmt.Scan(&numWallets)

	coinsQtyPerWallet := make([]int, numWallets)
	for i := 0; i < numWallets; i++ {
		fmt.Scan(&coinsQtyPerWallet[i])
	}

	DistributeCoins(numWallets, coinsQtyPerWallet)
}

package main
import (
	"fmt"
	"bufio"
	"os"
)
func main() {
	var n,nw int
	sum:=0
	fmt.Scan(&n)
	m := make([]int,500)
	out := bufio.NewWriter(os.Stdout)

	for i:=0;i<n;i++ {
		fmt.Scan(&m[i])
		sum += m[i]
	}
	for  {
		if m[nw]!=0 {
			out.WriteRune('P')
			m[nw]--
			sum--
			if sum==0 {
				break
			}
		}
		if nw==(n-1) || nw !=0 && m[nw-1]!=0 {
			out.WriteRune('L')
			nw--
		} else {
			out.WriteRune('R')
			nw++
		}
	}
	out.Flush()
	fmt.Println()
}

package main
import (
	"fmt"
)
func main() {
	var n int
	fmt.Scan(&n)
	fmt.Println((n*n+1)/2)
	for i:=0;i<n;i++ {
		for j:=0;j<n;j++ {
			if (i+j)%2==0 {
				fmt.Print(".")
			}else {fmt.Print("C")
			}

		}
		fmt.Println()
	}
}

package main
import (
	"fmt"
)
func main() {
	var n int
	fmt.Scan(&n)
	fmt.Println((n*n+1)/2)
	for i:=0;i<n;i++ {
		for j:=0;j<n;j++ {
			if (i+j)%2==0 {
				fmt.Print(".")
			}else {fmt.Print("C")
			}
			fmt.Println()
		}
	}
}

package main

import "fmt"

func main() {
    var n int
    var a [305]int
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
    }
    l, r, pos, dir := 0, n-1, 0, 1
    for l < r {
        if a[pos] > 0 {
            fmt.Print("P")
            a[pos]--
        } else if pos == l {
            l++
        } else if pos == r {
            r--
        }

        if dir == 1 { fmt.Print("R") } else { fmt.Print("L") }
        pos += dir
        if (pos == l) {
            dir = 1
        } else if (pos == r) {
            dir = -1
        }
    }
    fmt.Println()
}

package main

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

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

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}
	ans := ""
	ch := true
	put := func(s string) {
		fmt.Fprint(writer, s)
	}
	step := func(i int) {
		if a[i] > 0 {
			a[i]--
			put("P")
			ch = true
		}
	}
	for ch {
		ch = false
		for i := 0; i < n-1; i++ {
			step(i)
			put("R")
		}
		for i := n-1; i > 0; i-- {
			step(i)
			put("L")
		}
	}
	fmt.Println(ans)
}