language
stringclasses 5
values | dataset
stringclasses 1
value | code
stringlengths 26
25k
| id
stringlengths 10
10
| test_IO
listlengths 1
1
|
---|---|---|---|---|
Go | codenet | package main
import (
"fmt"
"sort"
)
func main() {
in := make([]int, 3)
fmt.Scan(&in[0], &in[1], &in[2])
sort.Ints(in)
fmt.Println(in[2]*10 + in[1] + in[0])
}
| s635143344 | [
{
"input": "1 5 2\n",
"output": "53\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
var stdin = bufio.NewScanner(os.Stdin)
func main() {
arr := scanArrayInt()
a, b := arr[0], arr[1]
tap := 0
consent := 1
for consent < b {
consent = consent + a - 1
tap++
}
fmt.Println(tap)
}
func scanArrayInt() []int {
var ret = []int{}
stdin.Scan()
for _, s := range strings.Split(stdin.Text(), " ") {
i, _ := strconv.Atoi(s)
ret = append(ret, i)
}
return ret
}
| s217679680 | [
{
"input": "4 10\n",
"output": "3\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func out(x ...interface{}) {
fmt.Println(x...)
}
var sc = bufio.NewScanner(os.Stdin)
func getInt() int {
sc.Scan()
i, e := strconv.Atoi(sc.Text())
if e != nil {
panic(e)
}
return i
}
func getString() string {
sc.Scan()
return sc.Text()
}
func main() {
sc.Split(bufio.ScanWords)
sc.Buffer([]byte{}, 1000000)
n, q := getInt(), getInt()
fw := FenwickTree(n)
for i := 0; i < n; i++ {
a := getInt()
fw.Add(i, a)
}
for i := 0; i < q; i++ {
t := getInt()
if t == 0 {
p, x := getInt(), getInt()
fw.Add(p, x)
} else {
l, r := getInt(), getInt()
out(fw.Sum(l, r))
}
}
}
type BIT struct {
n int
data []int
}
func FenwickTree(n int) *BIT {
var ret BIT
ret.n = n
ret.data = make([]int, n)
return &ret
}
func (b *BIT) Add(p, x int) {
p++
for p <= b.n {
b.data[p-1] += x
p += p & -p
}
}
func (b *BIT) Sum(l, r int) int {
return b.sum(r) - b.sum(l)
}
func (b *BIT) sum(r int) int {
s := 0
for r > 0 {
s += b.data[r-1]
r -= r & -r
}
return s
}
| s480530100 | [
{
"input": "5 5\n1 2 3 4 5\n1 0 5\n1 2 4\n0 3 10\n1 0 5\n1 0 3\n",
"output": "15\n7\n25\n6\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"sort"
"strconv"
)
var (
sc = bufio.NewScanner(os.Stdin)
wr = bufio.NewWriter(os.Stdout)
)
func scanInt() int {
sc.Scan()
a, _ := strconv.Atoi(sc.Text())
return a
}
func scanInt64() int64 {
sc.Scan()
a, _ := strconv.ParseInt(sc.Text(), 10, 64)
return a
}
func scanInts(n int) []int {
res := make([]int, n)
for i := 0; i < n; i++ {
res[i] = scanInt()
}
return res
}
func scanText() string {
sc.Scan()
return sc.Text()
}
func printInts(a ...int) {
for i, e := range a {
fmt.Fprint(wr, e)
if i != len(a)-1 {
fmt.Fprint(wr, " ")
}
}
fmt.Fprintln(wr)
wr.Flush()
}
func main() {
sc.Split(bufio.ScanWords)
n := scanInt()
c := scanInts(n)
ans := 0
sort.Ints(c)
for i := 0; i < n; i++ {
ans = (ans + (n+1-i)*c[i]%mod) % mod
}
fmt.Println(ans * modpow(4, n-1) % mod)
}
const mod = 1000000007
func modpow(a, n int) int {
res := 1
for n > 0 {
if n&1 == 1 {
res = res * a % mod
}
a = a * a % mod
n = n >> 1
}
return res
}
| s495252714 | [
{
"input": "1\n1000000000\n",
"output": "999999993\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var day int
fmt.Scan(&day)
switch day {
case 25:
fmt.Println("Christmas")
case 24:
fmt.Println("Christmas Eve")
case 23:
fmt.Println("Christmas Eve Eve")
case 22:
fmt.Println("Christmas Eve Eve Eve")
}
}
| s053342495 | [
{
"input": "25\n",
"output": "Christmas\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"sort"
"strconv"
)
func getScanner(fp *os.File) *bufio.Scanner {
scanner := bufio.NewScanner(fp)
scanner.Split(bufio.ScanWords)
scanner.Buffer(make([]byte, 500001), 500000)
return scanner
}
func getNextString(scanner *bufio.Scanner) string {
scanner.Scan()
return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
i, _ := strconv.Atoi(getNextString(scanner))
return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
return i
}
func getNextUint64(scanner *bufio.Scanner) uint64 {
i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
i, _ := strconv.ParseFloat(getNextString(scanner), 64)
return i
}
func main() {
fp := os.Stdin
wfp := os.Stdout
if len(os.Args) > 1 {
fp, _ = os.Open(os.Args[1])
if len(os.Args) > 2 {
wfp, _ = os.Create(os.Args[2])
}
}
scanner := getScanner(fp)
writer := bufio.NewWriter(wfp)
n := getNextInt(scanner)
ll := make([]int, n)
for i := 0; i < n; i++ {
ll[i] = getNextInt(scanner)
}
sort.Ints(ll)
ans := 0
for i := 0; i < n-2; i++ {
for j := i + 1; j < n-1; j++ {
l := j + 1
r := n
for l < r {
m := (l + r) >> 1
if ll[m] < ll[i]+ll[j] {
l = m + 1
continue
}
r = m
}
ans += l - (j + 1)
}
}
fmt.Fprintln(writer, ans)
writer.Flush()
}
| s228769347 | [
{
"input": "4\n3 4 2 1\n",
"output": "1\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var A, B, C int
fmt.Scanf("%d %d %d", &A, &B, &C)
if C >= A && C <= B {
fmt.Println("Yes")
} else {
fmt.Println("No")
}
}
| s407800036 | [
{
"input": "1 3 2\n",
"output": "Yes\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"io"
"os"
"strconv"
)
var in = NewScanner(os.Stdin, 0)
func main() {
n, k := in.Int(), in.Int()
if n%k == 0 {
Pln(0)
} else {
Pln(1)
}
}
type Scanner struct {
*bufio.Scanner
}
func NewScanner(r io.Reader, max int) *Scanner {
s := bufio.NewScanner(r)
s.Split(scanWords)
if max <= 0 {
max = 1048576
}
s.Buffer([]byte{}, max)
return &Scanner{s}
}
func (s *Scanner) Int() int {
s.Scan()
i, e := strconv.ParseInt(s.Text(), 10, 64)
if e != nil {
panic(e)
}
return int(i)
}
func isSpace(b byte) bool {
return b == ' ' || b == '\n' || b == '\r' || b == '\t'
}
func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
start := 0
for start < len(data) && isSpace(data[start]) {
start++
}
for i := start; i < len(data); i++ {
if isSpace(data[i]) {
return i + 1, data[start:i], nil
}
}
if atEOF && len(data) > start {
return len(data), data[start:], nil
}
return start, nil, nil
}
func Pln(s ...interface{}) {
fmt.Println(s...)
}
| s791445247 | [
{
"input": "7 3\n",
"output": "1\n"
}
] |
Go | codenet | package main
import (
"fmt"
"strings"
)
func main() {
var a string
fmt.Scan(&a)
tmp := strings.Replace(a, "1", "0", -1)
b := strings.Replace(tmp, "9", "1", -1)
ans := strings.Replace(b, "0", "9", -1)
fmt.Println(ans)
}
| s278875041 | [
{
"input": "119\n",
"output": "991\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"sort"
"strconv"
)
const (
constMod = int(1e9) + 7
)
var (
sc = bufio.NewScanner(os.Stdin)
wr = bufio.NewWriter(os.Stdout)
)
func getInt() int {
sc.Scan()
i, e := strconv.Atoi(sc.Text())
if e != nil {
panic(e)
}
return i
}
func getIntSlice(n int) []int {
ns := []int{}
for i := 0; i < n; i++ {
ns = append(ns, getInt())
}
return ns
}
func getIntDoubleSlice(m int, n int) [][]int {
var nds [][]int
for i := 0; i < m; i++ {
ns := getIntSlice(n)
nds = append(nds, ns)
}
return nds
}
func getString() string {
sc.Scan()
return sc.Text()
}
func getStringSlice(n int) []string {
ss := []string{}
for i := 0; i < n; i++ {
ss = append(ss, getString())
}
return ss
}
func getStringDoubleSlice(m int, n int) [][]string {
sds := [][]string{}
for i := 0; i < m; i++ {
ss := getStringSlice(n)
sds = append(sds, ss)
}
return sds
}
func sortIntSlice(ns []int) []int {
sort.Sort(sort.IntSlice(ns))
return ns
}
func sortIntReverseSlice(ns []int) []int {
sort.Sort(sort.Reverse(sort.IntSlice(ns)))
return ns
}
func numAbs(x int) int {
if x < 0 {
return -x
}
return x
}
func numModPow(a int, n int, m int) int {
result := 1
for n > 0 {
if n%2 == 1 {
result = (result * a) % m
}
a = (a * a) % m
n >>= 1
}
return result
}
func numGcd(a int, b int) int {
if b == 0 {
return a
}
return numGcd(b, a%b)
}
func numLcm(a int, b int) int {
return a * b / numGcd(a, b)
}
func numModInv(a int, p int) int {
if a == 1 {
return 1
}
return p - numModInv(p%a, p)*(p/a)%p
}
func numModFrac(n int) []int {
frac := []int{1}
for i := 1; i <= n; i++ {
frac = append(frac, i*frac[i-1]%constMod)
}
return frac
}
func numModConb(n int, r int) int {
frac := numModFrac(n)
return (frac[n] / ((frac[n-r] * frac[r]) % constMod)) % constMod
}
func solve() {
n, m := getInt(), getInt()
a := getIntSlice(n)
sum := 0
for _, v := range a {
sum += v
}
count := 0
for _, v := range a {
rate := float64(sum) / float64(4*m)
if float64(v) >= rate {
count++
}
}
if count >= m {
fmt.Fprintln(wr, "Yes")
} else {
fmt.Fprintln(wr, "No")
}
}
func main() {
maxBufSize := int(1e8)
sc.Buffer(make([]byte, 4096), maxBufSize)
sc.Split(bufio.ScanWords)
solve()
wr.Flush()
}
| s819591647 | [
{
"input": "4 1\n5 4 2 1\n",
"output": "Yes\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
type Pair struct {
p1, p2 interface{}
}
const (
initialBufSize = 1e4
maxBufSize = 1e8
)
var (
scanner = bufio.NewScanner(os.Stdin)
writer = bufio.NewWriter(os.Stdout)
)
func main() {
buf := make([]byte, initialBufSize)
scanner.Buffer(buf, maxBufSize)
scanner.Split(bufio.ScanWords)
N, K := readInt(), readInt()
s := TenToN(N, K)
fmt.Println(len(s))
}
func TenToN(number int, n int) string {
var s string
tmp := number
for {
s = i2s(tmp%n) + s
if tmp < n {
break
}
tmp /= n
}
return s
}
func write(s string) {
writer.WriteString(s)
}
func print() {
writer.Flush()
}
func readLine() (s string) {
if scanner.Scan() {
s = scanner.Text()
}
return s
}
func readInt() (read int) {
scanner.Scan()
read, err := strconv.Atoi(scanner.Text())
if err != nil {
panic(err)
}
return
}
func readFloat() (read float64) {
scanner.Scan()
read, err := strconv.ParseFloat(scanner.Text(), 64)
if err != nil {
panic(err)
}
return
}
func readRunes() (read []rune) {
scanner.Scan()
for _, v := range scanner.Text() {
read = append(read, v)
}
return
}
func readString() (read string) {
scanner.Scan()
read = scanner.Text()
return
}
func readStrings() (read []string) {
scanner.Scan()
for _, v := range scanner.Text() {
read = append(read, string(v))
}
return
}
func s2i(s string) int {
var intVal, e = strconv.Atoi(s)
if e != nil {
panic(e)
}
return intVal
}
func i2s(i int) string {
var strVal = strconv.Itoa(i)
return strVal
}
func s2f(s string) float64 {
var floatVal, e = strconv.ParseFloat(s, 64)
if e != nil {
panic(e)
}
return floatVal
}
func sum(i []int) int {
sum := 0
for _, val := range i {
sum += val
}
return sum
}
func split(s string) []string {
return strings.Fields(s)
}
func strAry2intAry(strs []string) []int {
var ret = make([]int, 0, len(strs))
for _, str := range strs {
var intVal, e = strconv.Atoi(string(str))
if e != nil {
panic(e)
}
ret = append(ret, intVal)
}
return ret
}
func intAry2strAry(nums []int) []string {
var ret = make([]string, 0, len(nums))
for _, num := range nums {
var strVal = strconv.Itoa(num)
ret = append(ret, strVal)
}
return ret
}
func ary2str(strs []string) string {
return strings.Join(strs, " ")
}
func reverse(res []int) []int {
for i, j := 0, len(res)-1; i < j; i, j = i+1, j-1 {
res[i], res[j] = res[j], res[i]
}
return res
}
func initalize(res []int, init int) {
if len(res) == 0 {
return
}
res[0] = init
for i := 0; i < len(res); i++ {
copy(res[i:], res[:i])
}
}
| s583952795 | [
{
"input": "11 2\n",
"output": "4\n"
}
] |
Go | codenet | package main
import (
"fmt"
"strings"
)
func main() {
var s string
fmt.Scan(&s)
s = strings.Replace(s, "dream", "D", -1)
s = strings.Replace(s, "erase", "E", -1)
s = strings.Replace(s, "Der", "", -1)
s = strings.Replace(s, "Er", "", -1)
s = strings.Replace(s, "D", "", -1)
s = strings.Replace(s, "E", "", -1)
s = strings.TrimSpace(s)
if s == "" {
fmt.Println("YES")
} else {
fmt.Println("NO")
}
}
| s876834921 | [
{
"input": "erasedream\n",
"output": "YES\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"math"
"os"
"strconv"
)
func nextStr() string {
sc.Scan()
return sc.Text()
}
func nextInt() int {
sc.Scan()
i, e := strconv.Atoi(sc.Text())
if e != nil {
panic(e)
}
return i
}
func maxInt(a, b int) int {
if a > b {
return a
} else {
return b
}
}
func minInt(a, b int) int {
if a > b {
return b
} else {
return a
}
}
func absInt(a int) int {
if a >= 0 {
return a
} else {
return -a
}
}
func absFloat64(a float64) float64 {
if a >= 0 {
return a
} else {
return -a
}
}
func maxFloat64(a, b float64) float64 {
if a > b {
return a
} else {
return b
}
}
func minFloat64(a, b float64) float64 {
if a > b {
return b
} else {
return a
}
}
func str2Int(s string) int {
n, _ := strconv.Atoi(s)
return n
}
func reverse(s string) string {
runes := []rune(s)
for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
runes[i], runes[j] = runes[j], runes[i]
}
return string(runes)
}
func powInt(p, q int) int {
return int(math.Pow(float64(p), float64(q)))
}
func isPrime(x int) bool {
if x == 1 {
return false
}
if x == 2 {
return true
}
if x%2 == 0 {
return false
}
b := true
rootx := int(math.Sqrt(float64(x)))
i := 3
for i <= rootx {
if x%i == 0 {
b = false
break
}
i += 2
}
return b
}
func PrimeFactors(n int) (pfs []int) {
for n%2 == 0 {
pfs = append(pfs, 2)
n = n / 2
}
for i := 3; i*i <= n; i = i + 2 {
for n%i == 0 {
pfs = append(pfs, i)
n = n / i
}
}
if n > 2 {
pfs = append(pfs, n)
}
return
}
func PrimeFactorsMap(n int) map[int]int {
pfs := map[int]int{}
for n%2 == 0 {
if _, ok := pfs[2]; ok {
pfs[2]++
} else {
pfs[2] = 1
}
n = n / 2
}
for i := 3; i*i <= n; i = i + 2 {
for n%i == 0 {
if _, ok := pfs[i]; ok {
pfs[i]++
} else {
pfs[i] = 1
}
n = n / i
}
}
if n > 2 {
if _, ok := pfs[n]; ok {
pfs[n]++
} else {
pfs[n] = 1
}
}
return pfs
}
func sumInts(x []int) int {
total := 0
for _, v := range x {
total += v
}
return total
}
func gcd(a, b int) int {
if b == 0 {
return a
}
return gcd(b, a%b)
}
func lcm(x, y int) int {
return x * y / gcd(x, y)
}
const (
initialBufSize = 10000
maxBufSize = 1000000
mod = 1e9 + 7
)
var (
sc *bufio.Scanner = func() *bufio.Scanner {
sc := bufio.NewScanner(os.Stdin)
buf := make([]byte, initialBufSize)
sc.Buffer(buf, maxBufSize)
return sc
}()
)
func main() {
sc.Split(bufio.ScanWords)
N, M := nextInt(), nextInt()
tmp := minInt(N, M/2)
ans := 0
ans += tmp
N -= tmp
M -= tmp * 2
fmt.Println(ans + M/4)
}
| s493522692 | [
{
"input": "1 6\n",
"output": "2\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"math"
"os"
"strconv"
)
const (
initialBufSize = 10000
maxBufSize = 1000000
)
var (
sc *bufio.Scanner = func() *bufio.Scanner {
sc := bufio.NewScanner(os.Stdin)
buf := make([]byte, initialBufSize)
sc.Buffer(buf, maxBufSize)
sc.Split(bufio.ScanWords)
return sc
}()
mod int = 1e9 + 7
)
func main() {
week := []string{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}
s := getString()
index := -1
for i, day := range week {
if s == day {
index = i
break
}
}
fmt.Println(7 - index)
}
func getInt() int {
sc.Scan()
i, e := strconv.Atoi(sc.Text())
if e != nil {
panic(e)
}
return i
}
func getString() string {
sc.Scan()
return sc.Text()
}
func abs(a int) int {
return int(math.Abs(float64(a)))
}
func pow(p, q int) int {
return int(math.Pow(float64(p), float64(q)))
}
func min(nums ...int) int {
if len(nums) == 0 {
panic("funciton min() requires at least one argument.")
}
res := nums[0]
for i := 0; i < len(nums); i++ {
res = int(math.Min(float64(res), float64(nums[i])))
}
return res
}
func max(nums ...int) int {
if len(nums) == 0 {
panic("funciton max() requires at least one argument.")
}
res := nums[0]
for i := 0; i < len(nums); i++ {
res = int(math.Max(float64(res), float64(nums[i])))
}
return res
}
func strSearch(a []string, b string) bool {
for i := 0; i < len(a); i++ {
if a[i] == b {
return true
}
}
return false
}
func printIntArray(array []int) {
strArray := fmt.Sprint(array)
fmt.Println(strArray[1 : len(strArray)-1])
}
func calcMod(x int) int {
return x % mod
}
| s554610878 | [
{
"input": "SAT\n",
"output": "1\n"
}
] |
Go | codenet | package main
import (
"fmt"
)
func group(n int) string {
if n == 4 || n == 6 || n == 9 || n == 11 {
return "B"
} else {
return "A"
}
}
func main() {
var x, y int
fmt.Scan(&x, &y)
if x == 2 || y == 2 {
fmt.Println("No")
return
}
xg := group(x)
yg := group(y)
if xg == yg {
fmt.Println("Yes")
} else {
fmt.Println("No")
}
}
| s032855181 | [
{
"input": "1 3\n",
"output": "Yes\n"
}
] |
Go | codenet | package main
import (
"bufio"
"errors"
"fmt"
"io"
"math"
"os"
"strconv"
)
const (
MOD = 1000000000 + 7
ALPHABET_NUM = 26
INF_INT64 = math.MaxInt64
INF_BIT60 = 1 << 60
INF_INT32 = math.MaxInt32
INF_BIT30 = 1 << 30
NIL = -1
WHITE = 0
GRAY = 1
BLACK = 2
)
func init() {
ReadString = newReadString(os.Stdin, bufio.ScanWords)
stdout = bufio.NewWriter(os.Stdout)
}
var (
a, b, c int
k int
)
func main() {
a, b, c = ReadInt3()
k = ReadInt()
patterns := DuplicatePatterns([]int{0, 1, 2, 3}, k)
for _, P := range patterns {
r, g, b := a, b, c
for i := 0; i < len(P); i++ {
if P[i] == 0 {
continue
} else if P[i] == 1 {
r *= 2
} else if P[i] == 2 {
g *= 2
} else if P[i] == 3 {
b *= 2
}
}
if g > r && b > g {
fmt.Println("Yes")
return
}
}
fmt.Println("No")
}
func DuplicatePatterns(elems []int, k int) [][]int {
return dupliRec([]int{}, elems, k)
}
func dupliRec(pattern, elems []int, k int) [][]int {
if len(pattern) == k {
return [][]int{pattern}
}
res := [][]int{}
for _, e := range elems {
newPattern := make([]int, len(pattern))
copy(newPattern, pattern)
newPattern = append(newPattern, e)
res = append(res, dupliRec(newPattern, elems, k)...)
}
return res
}
var (
ReadString func() string
stdout *bufio.Writer
)
func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
r := bufio.NewScanner(ior)
r.Buffer(make([]byte, 1024), int(1e+9))
r.Split(sf)
return func() string {
if !r.Scan() {
panic("Scan failed")
}
return r.Text()
}
}
func ReadInt() int {
return int(readInt64())
}
func ReadInt2() (int, int) {
return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt64() int64 {
return readInt64()
}
func ReadInt64_2() (int64, int64) {
return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
return readInt64(), readInt64(), readInt64(), readInt64()
}
func readInt64() int64 {
i, err := strconv.ParseInt(ReadString(), 0, 64)
if err != nil {
panic(err.Error())
}
return i
}
func ReadIntSlice(n int) []int {
b := make([]int, n)
for i := 0; i < n; i++ {
b[i] = ReadInt()
}
return b
}
func ReadInt64Slice(n int) []int64 {
b := make([]int64, n)
for i := 0; i < n; i++ {
b[i] = ReadInt64()
}
return b
}
func ReadFloat64() float64 {
return float64(readFloat64())
}
func readFloat64() float64 {
f, err := strconv.ParseFloat(ReadString(), 64)
if err != nil {
panic(err.Error())
}
return f
}
func ReadFloat64Slice(n int) []float64 {
b := make([]float64, n)
for i := 0; i < n; i++ {
b[i] = ReadFloat64()
}
return b
}
func ReadRuneSlice() []rune {
return []rune(ReadString())
}
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
sn := fmt.Sprintf("%b", n)
residualLength := digitsNum - len(sn)
if residualLength <= 0 {
return []rune(sn)
}
zeros := make([]rune, residualLength)
for i := 0; i < len(zeros); i++ {
zeros[i] = '0'
}
res := []rune{}
res = append(res, zeros...)
res = append(res, []rune(sn)...)
return res
}
func Strtoi(s string) int {
if i, err := strconv.Atoi(s); err != nil {
panic(errors.New("[argument error]: Strtoi only accepts integer string"))
} else {
return i
}
}
func PrintIntsLine(A ...int) string {
res := []rune{}
for i := 0; i < len(A); i++ {
str := strconv.Itoa(A[i])
res = append(res, []rune(str)...)
if i != len(A)-1 {
res = append(res, ' ')
}
}
return string(res)
}
func PrintInts64Line(A ...int64) string {
res := []rune{}
for i := 0; i < len(A); i++ {
str := strconv.FormatInt(A[i], 10)
res = append(res, []rune(str)...)
if i != len(A)-1 {
res = append(res, ' ')
}
}
return string(res)
}
func PrintfDebug(format string, a ...interface{}) {
fmt.Fprintf(os.Stderr, format, a...)
}
func PrintfBufStdout(format string, a ...interface{}) {
fmt.Fprintf(stdout, format, a...)
}
| s557024716 | [
{
"input": "7 2 5\n3\n",
"output": "Yes\n"
}
] |
Go | codenet | package main
import (
"fmt"
)
func main() {
var n, x int
for {
fmt.Scan(&n, &x)
if n == 0 && x == 0 {
break
}
c := 0
for i := 1; i <= n-2; i++ {
for j := i + 1; j <= n-1; j++ {
for k := j + 1; k <= n; k++ {
if i+j+k == x {
c++
}
}
}
}
fmt.Println(c)
}
}
| s273611899 | [
{
"input": "5 9\n0 0\n",
"output": "2\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func getScanner(fp *os.File) *bufio.Scanner {
scanner := bufio.NewScanner(fp)
scanner.Split(bufio.ScanWords)
scanner.Buffer(make([]byte, 500001), 500000)
return scanner
}
func getNextString(scanner *bufio.Scanner) string {
scanner.Scan()
return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
i, _ := strconv.Atoi(getNextString(scanner))
return i
}
func main() {
fp := os.Stdin
if len(os.Args) > 1 {
fp, _ = os.Open(os.Args[1])
}
scanner := getScanner(fp)
writer := bufio.NewWriter(os.Stdout)
n := getNextInt(scanner)
mm := make([]int, n+1)
dp := make([][]int, n+1)
for i := 0; i <= n; i++ {
dp[i] = make([]int, n+1)
}
for i := 0; i < n; i++ {
mm[i] = getNextInt(scanner)
mm[i+1] = getNextInt(scanner)
}
for l := 2; l <= n; l++ {
for i := 1; i <= n-l+1; i++ {
j := i + l - 1
for k := i; k <= j-1; k++ {
d := dp[i][k] + dp[k+1][j] + mm[i-1]*mm[k]*mm[j]
if dp[i][j] == 0 || dp[i][j] > d {
dp[i][j] = d
}
}
}
}
fmt.Fprintln(writer, dp[1][n])
writer.Flush()
}
| s482866535 | [
{
"input": "6\n30 35\n35 15\n15 5\n5 10\n10 20\n20 25\n",
"output": "15125\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var s string
fmt.Scan(&s)
if (s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3]) {
fmt.Println("Yes")
} else {
fmt.Println("No")
}
}
| s426245140 | [
{
"input": "1118\n",
"output": "Yes\n"
}
] |
Go | codenet | package main
import (
"fmt"
"sort"
)
func main() {
var N int
fmt.Scanf("%d", &N)
A := make([]int, N)
for i := 0; i < N; i++ {
fmt.Scanf("%d", &A[i])
}
sort.Sort(sort.IntSlice(A))
var ans int
for i := 1; i < N; i++ {
ans += A[i] - A[i-1]
}
fmt.Println(ans)
}
| s562422877 | [
{
"input": "4\n2 3 7 9\n",
"output": "7\n"
}
] |
Go | codenet | package main
import (
"fmt"
"strings"
)
func main() {
var s1, s2, s3 string
fmt.Scan(&s1, &s2, &s3)
s1s := strings.Split(s1, "")
s2s := strings.Split(s2, "")
s3s := strings.Split(s3, "")
fmt.Println(strings.ToUpper(s1s[0]) + strings.ToUpper(s2s[0]) + strings.ToUpper(s3s[0]))
}
| s503150457 | [
{
"input": "atcoder beginner contest\n",
"output": "ABC\n"
}
] |
Go | codenet | package main
import (
"fmt"
"strings"
)
func main() {
var s string
fmt.Scanf("%s", &s)
fmt.Println(strings.Replace(s, "2017", "2018", -1))
}
| s695286684 | [
{
"input": "2017/01/07\n",
"output": "2018/01/07\n"
}
] |
Go | codenet | package main
import "fmt"
func Abs(x int) int {
if x < 0 {
return -x
}
return x
}
func min(a, b int) int {
if a > b {
return b
}
return a
}
func main() {
var N, K int
fmt.Scan(&N, &K)
var x int
x = N % K
x = min(Abs(x-K), x)
fmt.Println(x)
}
| s206203202 | [
{
"input": "7 4\n",
"output": "1\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"math"
"os"
"strconv"
"strings"
)
type bufReader struct {
r *bufio.Reader
buf []byte
i int
}
var reader = &bufReader{
bufio.NewReader(os.Stdin),
make([]byte, 0),
0,
}
func (r *bufReader) readLine() {
if r.i < len(r.buf) {
return
}
r.buf = make([]byte, 0)
r.i = 0
for {
line, isPrefix, err := r.r.ReadLine()
if err != nil {
panic(err)
}
r.buf = append(r.buf, line...)
if !isPrefix {
break
}
}
}
func (r *bufReader) next() string {
r.readLine()
from := r.i
for ; r.i < len(r.buf); r.i++ {
if r.buf[r.i] == ' ' {
break
}
}
s := string(r.buf[from:r.i])
r.i++
return s
}
func (r *bufReader) nextLine() string {
r.readLine()
s := string(r.buf[r.i:])
r.i = len(r.buf)
return s
}
var writer = bufio.NewWriter(os.Stdout)
func next() string {
return reader.next()
}
func nextInt64() int64 {
i, err := strconv.ParseInt(reader.next(), 10, 64)
if err != nil {
panic(err)
}
return i
}
func nextInt() int {
return int(nextInt64())
}
func nextLine() string {
return reader.nextLine()
}
func out(a ...interface{}) {
fmt.Fprintln(writer, a...)
}
func max64(x, y int64) int64 {
if x > y {
return x
}
return y
}
func max(x, y int) int {
return int(max64(int64(x), int64(y)))
}
func min64(x, y int64) int64 {
if x < y {
return x
}
return y
}
func min(x, y int) int {
return int(min64(int64(x), int64(y)))
}
func abs64(x int64) int64 {
if x < 0 {
return -x
}
return x
}
func abs(x int) int {
return int(abs64(int64(x)))
}
func joinInt64s(a []int64, sep string) string {
b := make([]string, len(a))
for i, v := range a {
b[i] = strconv.FormatInt(v, 10)
}
return strings.Join(b, sep)
}
func joinInts(a []int, sep string) string {
b := make([]string, len(a))
for i, v := range a {
b[i] = strconv.Itoa(v)
}
return strings.Join(b, sep)
}
func divUp64(x, y int64) int64 {
return (x + y - 1) / y
}
func divUp(x, y int) int {
return int(divUp64(int64(x), int64(y)))
}
func gcd64(x, y int64) int64 {
if x < y {
x, y = y, x
}
for y != 0 {
x, y = y, x%y
}
return x
}
func gcd(x, y int) int {
return int(gcd64(int64(x), int64(y)))
}
func lcm64(x, y int64) int64 {
return x * y / gcd64(x, y)
}
func lcm(x, y int) int {
return int(lcm64(int64(x), int64(y)))
}
func pow64(x, y int64) int64 {
return int64(math.Pow(float64(x), float64(y)))
}
func pow(x, y int) int {
return int(pow64(int64(x), int64(y)))
}
func main() {
solve()
writer.Flush()
}
func solve() {
N, _ := nextInt(), nextInt()
A := make([]int, N)
for i := 0; i < N; i++ {
A[i] = nextInt()
}
maxProfit := 0
maxCnt := 0
maxA := A[N-1]
for i := N - 2; i >= 0; i-- {
profit := max(0, maxA-A[i])
if maxProfit < profit {
maxProfit = profit
maxCnt = 1
} else if maxProfit == profit {
maxCnt++
}
maxA = max(maxA, A[i])
}
out(maxCnt)
}
| s998080221 | [
{
"input": "3 2\n100 50 200\n",
"output": "1\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"sort"
"strconv"
)
var sc = bufio.NewScanner(os.Stdin)
func Scanner() string {
sc.Scan()
return sc.Text()
}
func intScanner() int {
n, _ := strconv.Atoi(Scanner())
return n
}
func floatScanner() float64 {
n, _ := strconv.ParseFloat(Scanner(), 64)
return n
}
func stringToInt(s string) int {
n, _ := strconv.Atoi(s)
return n
}
var mod int
func main() {
mod = 1000000007
buf := make([]byte, 0)
sc.Buffer(buf, mod)
sc.Split(bufio.ScanWords)
n := intScanner()
as := make([]int, n)
for i := 0; i < n; i++ {
as[i] = intScanner()
}
xs := []int{as[0]}
for j := 1; j < n; j++ {
idx := sort.Search(len(xs), func(i int) bool { return xs[i] < as[j] })
if idx == len(xs) {
xs = append(xs, as[j])
} else {
xs[idx] = as[j]
}
}
fmt.Println(len(xs))
}
| s963048401 | [
{
"input": "5\n2\n1\n4\n5\n3\n",
"output": "2\n"
}
] |
Go | codenet | package main
import "fmt"
var n, ans int
const arraySize = 101
var a = [arraySize][arraySize]int{}
func findAns(i, j, sum int) {
if i == 1 && j == n-1 && sum+a[i][j] > ans {
ans = sum + a[i][j]
return
}
if i == 0 {
findAns(i+1, j, sum+a[i][j])
}
if j+1 < n {
findAns(i, j+1, sum+a[i][j])
}
}
func main() {
fmt.Scanf("%d", &n)
for i := 0; i < 2; i++ {
for j := 0; j < n; j++ {
fmt.Scanf("%d", &a[i][j])
}
}
findAns(0, 0, 0)
fmt.Println(ans)
}
| s099670837 | [
{
"input": "5\n3 2 2 4 1\n1 2 2 2 1\n",
"output": "14\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"io"
"os"
"strconv"
)
var in = NewScanner(os.Stdin, 0)
func main() {
n, k := in.Int(), in.Int()
if n%k == 0 {
Pln(0)
} else {
Pln(1)
}
}
type Scanner struct {
*bufio.Scanner
}
func NewScanner(r io.Reader, max int) *Scanner {
s := bufio.NewScanner(r)
s.Split(scanWords)
if max <= 0 {
max = 1048576
}
s.Buffer([]byte{}, max)
return &Scanner{s}
}
func (s *Scanner) Int() int {
s.Scan()
i, e := strconv.ParseInt(s.Text(), 10, 64)
if e != nil {
panic(e)
}
return int(i)
}
func isSpace(b byte) bool {
return b == ' ' || b == '\n' || b == '\r' || b == '\t'
}
func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
start := 0
for start < len(data) && isSpace(data[start]) {
start++
}
for i := start; i < len(data); i++ {
if isSpace(data[i]) {
return i + 1, data[start:i], nil
}
}
if atEOF && len(data) > start {
return len(data), data[start:], nil
}
return start, nil, nil
}
func Pln(s ...interface{}) {
fmt.Println(s...)
}
| s376370885 | [
{
"input": "7 3\n",
"output": "1\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"sort"
"strconv"
)
func out(x ...interface{}) {
}
var sc = bufio.NewScanner(os.Stdin)
func nextInt() int {
sc.Scan()
i, e := strconv.Atoi(sc.Text())
if e != nil {
panic(e)
}
return i
}
func nextString() string {
sc.Scan()
return sc.Text()
}
type Data struct {
X string
}
type Datas []Data
func (p Datas) Len() int {
return len(p)
}
func (p Datas) Swap(i, j int) {
p[i], p[j] = p[j], p[i]
}
func (p Datas) Less(i, j int) bool {
return p[i].X < p[j].X
}
func main() {
sc.Split(bufio.ScanWords)
N := nextInt()
L := nextInt()
s := make(Datas, N)
for i := 0; i < N; i++ {
s[i].X = nextString()
}
out(N, L, s)
sort.Sort(s)
out(s)
ans := ""
for i := 0; i < N; i++ {
ans = ans + s[i].X
}
fmt.Println(ans)
}
| s330691347 | [
{
"input": "3 3\ndxx\naxx\ncxx\n",
"output": "axxcxxdxx\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var a [3]int
fmt.Scan(&a[0], &a[1], &a[2])
five := 0
seven := 0
for i := 0; i < 3; i++ {
if a[i] == 5 {
five++
}
if a[i] == 7 {
seven++
}
}
if five == 2 && seven == 1 {
fmt.Println("YES")
} else {
fmt.Println("NO")
}
}
| s984784526 | [
{
"input": "5 5 7\n",
"output": "YES\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
var sc = bufio.NewScanner(os.Stdin)
func main() {
scanInit()
s := nextStr()
c := 'a'
for j := 0; j < 26; j++ {
found := false
for i := 0; i < len(s); i++ {
if s[i] == byte(c) {
found = true
break
}
}
if found == false {
fmt.Println(string(c))
return
}
c++
}
fmt.Println("None")
}
func scanInit() {
const cap = 1000 * 1024
var buf = make([]byte, cap)
sc.Buffer(buf, cap)
sc.Split(bufio.ScanWords)
return
}
func nextInt() int {
sc.Scan()
i, e := strconv.Atoi(sc.Text())
if e != nil {
panic(e)
}
return i
}
func nextStr() string {
sc.Scan()
return sc.Text()
}
| s726858931 | [
{
"input": "atcoderregularcontest\n",
"output": "b\n"
}
] |
Go | codenet | package main
import (
"fmt"
)
func main() {
var s string
fmt.Scan(&s)
ans := 0
for _, c := range s {
if c == '1' {
ans++
}
}
fmt.Println(ans)
}
| s306917423 | [
{
"input": "111100\n",
"output": "4\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
var sc *bufio.Scanner
func nextStr() string {
sc.Scan()
return sc.Text()
}
func nextInt() int {
sc.Scan()
i, e := strconv.Atoi(sc.Text())
if e != nil {
panic(e)
}
return i
}
func main() {
sc = bufio.NewScanner(os.Stdin)
sc.Buffer(make([]byte, 0), 1000000001*3)
sc.Split(bufio.ScanWords)
n := nextInt()
ans := 0
aPrev := 0
for i := 0; i < n; i++ {
a := nextInt()
switch {
case a > i || a > aPrev+1:
fmt.Println(-1)
return
case a == aPrev+1:
ans++
default:
ans += a
}
aPrev = a
}
fmt.Println(ans)
}
| s476359676 | [
{
"input": "4\n0\n1\n1\n2\n",
"output": "3\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"sort"
"strconv"
)
var sc = bufio.NewScanner(os.Stdin)
func scanInt() int {
sc.Scan()
iv, _ := strconv.Atoi(sc.Text())
return iv
}
func init() {
sc.Split(bufio.ScanWords)
}
func main() {
n := scanInt()
type arm struct{ l, r int }
as := make([]arm, n)
for i := range as {
x, l := scanInt(), scanInt()
as[i].l = x - l
as[i].r = x + l
}
sort.Slice(as, func(i, j int) bool { return as[i].r < as[j].r })
ans := 1
r := as[0].r
for i := 1; i < n; i++ {
if as[i].l >= r {
ans++
r = as[i].r
}
}
fmt.Println(ans)
}
| s648707342 | [
{
"input": "4\n2 4\n4 3\n9 3\n100 5\n",
"output": "3\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"math"
"os"
"sort"
"strconv"
)
func main() {
INF := int(math.Pow10(11))
A := nextInt()
B := nextInt()
Q := nextInt()
s := make([]int, A+2)
s[0], s[A+1] = -INF, INF
for i := 1; i <= A; i++ {
s[i] = nextInt()
}
t := make([]int, B+2)
t[0], t[B+1] = -INF, INF
for i := 1; i <= B; i++ {
t[i] = nextInt()
}
for i := 0; i < Q; i++ {
x := nextInt()
b, d := sort.SearchInts(s, x), sort.SearchInts(t, x)
res := INF
for _, S := range []int{s[b-1], s[b]} {
for _, T := range []int{t[d-1], t[d]} {
d1, d2 := abs(S-x)+abs(T-S), abs(T-x)+abs(S-T)
res = min(res, min(d1, d2))
}
}
fmt.Println(res)
}
}
var sc = bufio.NewScanner(os.Stdin)
func init() {
sc.Buffer([]byte{}, math.MaxInt64)
sc.Split(bufio.ScanWords)
}
func nextInt() int {
sc.Scan()
i, err := strconv.Atoi(sc.Text())
if err != nil {
panic(err)
}
return i
}
func nextFloat() float64 {
sc.Scan()
f64, err := strconv.ParseFloat(sc.Text(), 64)
if err != nil {
panic(err)
}
return f64
}
func nextString() string {
sc.Scan()
if err := sc.Err(); err != nil {
panic(err)
}
return sc.Text()
}
func abs(x int) int {
return int(math.Abs(float64(x)))
}
func min(x, y int) int {
return int(math.Min(float64(x), float64(y)))
}
func max(x, y int) int {
return int(math.Max(float64(x), float64(y)))
}
| s219662687 | [
{
"input": "2 3 4\n100\n600\n400\n900\n1000\n150\n2000\n899\n799\n",
"output": "350\n1400\n301\n399\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"sort"
"strconv"
)
func main() {
N, K := ReadInt(), ReadInt()
As := ReadInts(N)
Fs := ReadInts(N)
sort.Ints(As)
sort.Sort(sort.Reverse(sort.IntSlice(Fs)))
scores := make([]int, N)
for i := 0; i < N; i++ {
scores[i] = As[i] * Fs[i]
}
sort.Sort(sort.Reverse(sort.IntSlice(scores)))
ok := scores[0]
ng := -1
for ok-ng > 1 {
mid := (ok + ng) / 2
isOK := true
k := K
for i := 0; isOK && i < N; i++ {
if As[i]*Fs[i] > mid {
k -= As[i] - mid/Fs[i]
}
if k < 0 {
isOK = false
}
}
if isOK {
ok = mid
} else {
ng = mid
}
}
fmt.Println(ok)
}
func ReadInts(n int) []int {
ret := make([]int, n)
for i := 0; i < n; i++ {
ret[i] = ReadInt()
}
return ret
}
var sc = bufio.NewScanner(os.Stdin)
func init() { sc.Buffer(make([]byte, 256), 1e9); sc.Split(bufio.ScanWords) }
func Read() string { sc.Scan(); return sc.Text() }
func ReadInt() int {
v, e := strconv.Atoi(Read())
if e != nil {
panic(e.Error())
}
return v
}
| s733602892 | [
{
"input": "3 5\n4 2 1\n2 3 1\n",
"output": "2\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var x int
fmt.Scan(&x)
fmt.Println(x * x * x)
}
| s178339312 | [
{
"input": "2\n",
"output": "8\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func main() {
var N int
fmt.Scan(&N)
scanner := bufio.NewScanner(os.Stdin)
scanner.Split(bufio.ScanWords)
v := make([]int, N)
var a int
for i := 1; i < N; i++ {
scanner.Scan()
a, _ = strconv.Atoi(scanner.Text())
v[a-1]++
}
w := bufio.NewWriter(os.Stdout)
for _, e := range v {
fmt.Fprintln(w, e)
}
w.Flush()
}
| s563519278 | [
{
"input": "5\n1 1 2 2\n",
"output": "2\n2\n0\n0\n0\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var r, D, x int
fmt.Scan(&r, &D, &x)
for i := 1; i <= 10; i++ {
fmt.Println(r*x - D)
x = r*x - D
}
}
| s400924672 | [
{
"input": "2 10 20\n",
"output": "30\n50\n90\n170\n330\n650\n1290\n2570\n5130\n10250\n"
}
] |
Go | codenet | package main
import (
"fmt"
"os"
"strings"
)
var (
s string
)
func main() {
fmt.Scan(&s)
for i := 0; i < len(s); i++ {
if strings.Contains(s[i+1:], string(s[i])) {
fmt.Println("no")
os.Exit(0)
}
}
fmt.Println("yes")
}
| s079891640 | [
{
"input": "uncopyrightable\n",
"output": "yes\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func genid(a, b int) int {
if b < a {
a, b = b, a
}
return a*100000 + b
}
func main() {
N := readInt()
ab := make([][2]int, N-1)
edges := make([][]int, N)
for i := 0; i < N-1; i++ {
a := readInt() - 1
b := readInt() - 1
ab[i][0], ab[i][1] = a, b
edges[a] = append(edges[a], b)
edges[b] = append(edges[b], a)
}
colors := make(map[int]int)
q := make([][3]int, 0)
q = append(q, [3]int{0, -1, -1})
for len(q) != 0 {
currentNode, usedColor, parentNode := q[len(q)-1][0], q[len(q)-1][1], q[len(q)-1][2]
q = q[:len(q)-1]
color := 1
for _, childNode := range edges[currentNode] {
if childNode == parentNode {
continue
}
if color == usedColor {
color++
}
colors[genid(currentNode, childNode)] = color
q = append(q, [3]int{childNode, color, currentNode})
color++
}
}
K := -1
for i := 0; i < N; i++ {
t := len(edges[i])
if t > K {
K = t
}
}
fmt.Println(K)
for i := 0; i < N-1; i++ {
fmt.Println(colors[genid(ab[i][0], ab[i][1])])
}
}
const (
ioBufferSize = 1 * 1024 * 1024
)
var stdinScanner = func() *bufio.Scanner {
result := bufio.NewScanner(os.Stdin)
result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
result.Split(bufio.ScanWords)
return result
}()
func readString() string {
stdinScanner.Scan()
return stdinScanner.Text()
}
func readInt() int {
result, err := strconv.Atoi(readString())
if err != nil {
panic(err)
}
return result
}
| s954015601 | [
{
"input": "3\n1 2\n2 3\n",
"output": "2\n1\n2\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var n int
fmt.Scan(&n)
ans := 0
for i := 1; i*i < n; i++ {
if n%i == 0 && n%(n/i-1) == i {
ans += n/i - 1
}
}
fmt.Println(ans)
}
| s283266035 | [
{
"input": "8\n",
"output": "10\n"
}
] |
Go | codenet | package main
import (
"bufio"
"errors"
"fmt"
"io"
"math"
"os"
"strconv"
)
const (
MOD = 1000000000 + 7
ALPHABET_NUM = 26
INF_INT64 = math.MaxInt64
INF_BIT60 = 1 << 60
INF_INT32 = math.MaxInt32
INF_BIT30 = 1 << 30
NIL = -1
WHITE = 0
GRAY = 1
BLACK = 2
)
func init() {
ReadString = newReadString(os.Stdin, bufio.ScanWords)
stdout = bufio.NewWriter(os.Stdout)
}
var (
n, m int
edges [][]int
)
func main() {
n, m = ReadInt2()
for i := 0; i < n-1; i++ {
x, y := ReadInt2()
x--
y--
e := []int{x, y}
edges = append(edges, e)
}
f := func(x, y T) T { return T(int(x) * int(y) % m) }
g := func(v T, p int) T { return v + 1 }
s := NewReRootingSolver(n, edges, 1, f, g)
for i := 0; i < n; i++ {
fmt.Println(s.Query(i) - 1)
}
}
type T int
type ReRootingSolver struct {
NodeCount int
Adjacents [][]int
IndexForAdjacents [][]int
Res []T
DP [][]T
Identity T
Operate func(l, r T) T
OperateNode func(v T, p int) T
}
func NewReRootingSolver(
nodeCount int, edges [][]int, identity T, operate func(l, r T) T, operateNode func(v T, p int) T,
) *ReRootingSolver {
s := new(ReRootingSolver)
s.NodeCount = nodeCount
s.Identity = identity
s.Operate = operate
s.OperateNode = operateNode
s.Adjacents = make([][]int, nodeCount)
s.IndexForAdjacents = make([][]int, nodeCount)
for _, e := range edges {
s.IndexForAdjacents[e[0]] = append(s.IndexForAdjacents[e[0]], len(s.Adjacents[e[1]]))
s.IndexForAdjacents[e[1]] = append(s.IndexForAdjacents[e[1]], len(s.Adjacents[e[0]]))
s.Adjacents[e[0]] = append(s.Adjacents[e[0]], e[1])
s.Adjacents[e[1]] = append(s.Adjacents[e[1]], e[0])
}
s.DP = make([][]T, len(s.Adjacents))
s.Res = make([]T, len(s.Adjacents))
for i := 0; i < len(s.Adjacents); i++ {
s.DP[i] = make([]T, len(s.Adjacents[i]))
}
if s.NodeCount > 1 {
s.Initialize()
} else {
s.Res[0] = s.OperateNode(s.Identity, 0)
}
return s
}
func (s *ReRootingSolver) Query(node int) T {
return s.Res[node]
}
func (s *ReRootingSolver) Initialize() {
parents, order := make([]int, s.NodeCount), make([]int, s.NodeCount)
index := 0
stack := []int{}
stack = append(stack, 0)
parents[0] = -1
for len(stack) > 0 {
node := stack[len(stack)-1]
stack = stack[:len(stack)-1]
order[index] = node
index++
for i := 0; i < len(s.Adjacents[node]); i++ {
adjacent := s.Adjacents[node][i]
if adjacent == parents[node] {
continue
}
stack = append(stack, adjacent)
parents[adjacent] = node
}
}
for i := len(order) - 1; i >= 1; i-- {
node := order[i]
parent := parents[node]
accum := s.Identity
parentIndex := -1
for j := 0; j < len(s.Adjacents[node]); j++ {
if s.Adjacents[node][j] == parent {
parentIndex = j
continue
}
accum = s.Operate(accum, s.DP[node][j])
}
s.DP[parent][s.IndexForAdjacents[node][parentIndex]] = s.OperateNode(accum, node)
}
for i := 0; i < len(order); i++ {
node := order[i]
accum := s.Identity
accumsFromTail := make([]T, len(s.Adjacents[node]))
accumsFromTail[len(accumsFromTail)-1] = s.Identity
for j := len(accumsFromTail) - 1; j >= 1; j-- {
accumsFromTail[j-1] = s.Operate(s.DP[node][j], accumsFromTail[j])
}
for j := 0; j < len(accumsFromTail); j++ {
s.DP[s.Adjacents[node][j]][s.IndexForAdjacents[node][j]] = s.OperateNode(s.Operate(accum, accumsFromTail[j]), node)
accum = s.Operate(accum, s.DP[node][j])
}
s.Res[node] = s.OperateNode(accum, node)
}
}
var (
ReadString func() string
stdout *bufio.Writer
)
func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
r := bufio.NewScanner(ior)
r.Buffer(make([]byte, 1024), int(1e+9))
r.Split(sf)
return func() string {
if !r.Scan() {
panic("Scan failed")
}
return r.Text()
}
}
func ReadInt() int {
return int(readInt64())
}
func ReadInt2() (int, int) {
return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt64() int64 {
return readInt64()
}
func ReadInt64_2() (int64, int64) {
return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
return readInt64(), readInt64(), readInt64(), readInt64()
}
func readInt64() int64 {
i, err := strconv.ParseInt(ReadString(), 0, 64)
if err != nil {
panic(err.Error())
}
return i
}
func ReadIntSlice(n int) []int {
b := make([]int, n)
for i := 0; i < n; i++ {
b[i] = ReadInt()
}
return b
}
func ReadInt64Slice(n int) []int64 {
b := make([]int64, n)
for i := 0; i < n; i++ {
b[i] = ReadInt64()
}
return b
}
func ReadFloat64() float64 {
return float64(readFloat64())
}
func readFloat64() float64 {
f, err := strconv.ParseFloat(ReadString(), 64)
if err != nil {
panic(err.Error())
}
return f
}
func ReadFloat64Slice(n int) []float64 {
b := make([]float64, n)
for i := 0; i < n; i++ {
b[i] = ReadFloat64()
}
return b
}
func ReadRuneSlice() []rune {
return []rune(ReadString())
}
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
sn := fmt.Sprintf("%b", n)
residualLength := digitsNum - len(sn)
if residualLength <= 0 {
return []rune(sn)
}
zeros := make([]rune, residualLength)
for i := 0; i < len(zeros); i++ {
zeros[i] = '0'
}
res := []rune{}
res = append(res, zeros...)
res = append(res, []rune(sn)...)
return res
}
func Strtoi(s string) int {
if i, err := strconv.Atoi(s); err != nil {
panic(errors.New("[argument error]: Strtoi only accepts integer string"))
} else {
return i
}
}
func PrintIntsLine(A ...int) string {
res := []rune{}
for i := 0; i < len(A); i++ {
str := strconv.Itoa(A[i])
res = append(res, []rune(str)...)
if i != len(A)-1 {
res = append(res, ' ')
}
}
return string(res)
}
func PrintInts64Line(A ...int64) string {
res := []rune{}
for i := 0; i < len(A); i++ {
str := strconv.FormatInt(A[i], 10)
res = append(res, []rune(str)...)
if i != len(A)-1 {
res = append(res, ' ')
}
}
return string(res)
}
func PrintfDebug(format string, a ...interface{}) {
fmt.Fprintf(os.Stderr, format, a...)
}
func PrintfBufStdout(format string, a ...interface{}) {
fmt.Fprintf(stdout, format, a...)
}
| s620841407 | [
{
"input": "3 100\n1 2\n2 3\n",
"output": "3\n4\n3\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"io"
"math"
"os"
"strconv"
"strings"
)
func Run(r io.Reader, w io.Writer) {
sc := NewScanner(r)
a := sc.ReadLine().Ints()
N, D := a[0], a[1]
lines := sc.ReadLines(N).Ints()
count := 0
for _, line := range lines {
d := math.Sqrt(float64(line[0]*line[0] + line[1]*line[1]))
if float64(D) >= d {
count++
}
}
fmt.Fprintln(w, count)
}
func main() {
Run(os.Stdin, os.Stdout)
}
type Scanner struct {
sc *bufio.Scanner
}
func NewScanner(r io.Reader) *Scanner {
return &Scanner{sc: bufio.NewScanner(r)}
}
func (s *Scanner) ReadLine() Value {
if s.sc.Scan() {
return Value(s.sc.Text())
}
panic("scan error")
}
func (s *Scanner) ReadLines(n int) Values {
var a Values
for i := 0; i < n; i++ {
a = append(a, s.ReadLine())
}
return a
}
type Value string
func (v Value) String() string {
return string(v)
}
func (v Value) Int() int {
n, err := strconv.Atoi(v.String())
if err != nil {
panic(err)
}
return n
}
func (v Value) Float64() float64 {
f, err := strconv.ParseFloat(v.String(), 64)
if err != nil {
panic(err)
}
return f
}
func (v Value) Strings() []string {
return strings.Split(v.String(), " ")
}
func (v Value) Ints() []int {
var a []int
for _, s := range v.Strings() {
n, err := strconv.Atoi(s)
if err != nil {
panic(err)
}
a = append(a, n)
}
return a
}
func (v Value) Float64s() []float64 {
var a []float64
for _, s := range v.Strings() {
f, err := strconv.ParseFloat(s, 64)
if err != nil {
panic(err)
}
a = append(a, f)
}
return a
}
func (v Value) Runes() []rune {
return []rune(v.String())
}
type Values []Value
func (v Values) Strings() [][]string {
var a [][]string
for _, value := range v {
a = append(a, value.Strings())
}
return a
}
func (v Values) Ints() [][]int {
var a [][]int
for _, value := range v {
a = append(a, value.Ints())
}
return a
}
func (v Values) Float64s() [][]float64 {
var a [][]float64
for _, value := range v {
a = append(a, value.Float64s())
}
return a
}
func (v Values) Runes() [][]rune {
var a [][]rune
for _, value := range v {
a = append(a, value.Runes())
}
return a
}
| s497491075 | [
{
"input": "4 5\n0 5\n-2 4\n3 4\n4 -4\n",
"output": "3\n"
}
] |
Go | codenet | package main
import "fmt"
var e [][]int
var n, m int
func printEdge(e [][]int) {
for i := 1; i < n+1; i++ {
fmt.Printf("%d: ", i)
for _, v := range e[i] {
fmt.Printf("%d ", v)
}
fmt.Println()
}
}
func dfs(v int, visited []bool) int {
comp := true
for i := 1; i < n+1; i++ {
if !visited[i] {
comp = false
}
}
if comp {
return 1
}
count := 0
for _, ne := range e[v] {
if visited[ne] {
continue
}
visited[ne] = true
rst := dfs(ne, visited)
count += rst
visited[ne] = false
}
return count
}
func main() {
fmt.Scan(&n, &m)
e = make([][]int, n+1)
for i := 1; i < n+1; i++ {
e[i] = make([]int, 0)
}
for i := 0; i < m; i++ {
var a, b int
fmt.Scan(&a, &b)
e[a] = append(e[a], b)
e[b] = append(e[b], a)
}
visited := make([]bool, n+1)
visited[1] = true
count := dfs(1, visited)
fmt.Println(count)
}
| s406008869 | [
{
"input": "3 3\n1 2\n1 3\n2 3\n",
"output": "2\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var S string
fmt.Scan(&S)
switch S {
case "Sunny":
fmt.Println("Cloudy")
case "Cloudy":
fmt.Println("Rainy")
case "Rainy":
fmt.Println("Sunny")
}
}
| s201004620 | [
{
"input": "Sunny\n",
"output": "Cloudy\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"log"
"os"
"strconv"
)
var inf int = 1e14
func main() {
log.SetFlags(log.Lshortfile)
next := newScanner()
n := next.Int()
x := next.Int()
a := make([]int, n)
for i := 0; i < n; i++ {
a[i] = next.Int()
}
v := make([]int, n)
copy(v, a)
ans := inf
for k := 0; k < n; k++ {
kans := 0
for i := 0; i < n; i++ {
if i-k < 0 {
v[i] = min(v[i], a[n+i-k])
} else {
v[i] = min(v[i], a[i-k])
}
kans += v[i]
}
ans = min(ans, kans+k*x)
}
fmt.Println(ans)
}
type Pair struct {
a, b int
}
type Pairs []Pair
func (p Pairs) Len() int {
return len(p)
}
func (p Pairs) Swap(i, j int) {
p[i], p[j] = p[j], p[i]
}
func (p Pairs) Less(i, j int) bool {
if p[i].a < p[j].a {
return true
} else if p[i].a == p[j].a {
return p[i].b < p[j].b
}
return false
}
func in(c, a, z int) bool {
return c >= a && c < z
}
func btoi(b bool) int {
if b {
return 1
}
return 0
}
func itob(a int) bool {
if a == 0 {
return false
}
return true
}
func max(a ...int) int {
r := a[0]
for i := 0; i < len(a); i++ {
if r < a[i] {
r = a[i]
}
}
return r
}
func min(a ...int) int {
r := a[0]
for i := 0; i < len(a); i++ {
if r > a[i] {
r = a[i]
}
}
return r
}
func minmax(a, b int) (int, int) {
if a > b {
return b, a
}
return a, b
}
func abs(a int) int {
if a < 0 {
return -a
}
return a
}
func sum(a ...int) int {
r := a[0]
if len(a) > 1 {
for i := 1; i < len(a); i++ {
r += a[i]
}
}
return r
}
type scanner struct {
r *bufio.Reader
buf []byte
p int
}
func newScanner() *scanner {
rdr := bufio.NewReaderSize(os.Stdin, 10000)
return &scanner{r: rdr}
}
func (s *scanner) next() string {
s.pre()
start := s.p
for ; s.p < len(s.buf); s.p++ {
if s.buf[s.p] == ' ' {
break
}
}
result := string(s.buf[start:s.p])
s.p++
return result
}
func (s *scanner) Line() string {
s.pre()
start := s.p
s.p = len(s.buf)
return string(s.buf[start:])
}
func (s *scanner) Int() int {
v, _ := strconv.Atoi(s.next())
return v
}
func (s *scanner) Int64() int64 {
v, _ := strconv.ParseInt(s.next(), 10, 64)
return v
}
func (s *scanner) pre() {
if s.p >= len(s.buf) {
s.readLine()
s.p = 0
}
}
func (s *scanner) readLine() {
s.buf = make([]byte, 0)
for {
l, p, e := s.r.ReadLine()
if e != nil {
panic(e)
}
s.buf = append(s.buf, l...)
if !p {
break
}
}
}
| s462906333 | [
{
"input": "2 10\n1 100\n",
"output": "12\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var a string
fmt.Scan(&a)
var ans = "Good"
for i := 0; i < 3; i++ {
if a[i] == a[i+1] {
ans = "Bad"
}
}
fmt.Println(ans)
}
| s879077700 | [
{
"input": "3776\n",
"output": "Bad\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func main() {
fsc := NewFastScanner()
A, B, C := fsc.NextInt(), fsc.NextInt(), fsc.NextInt()
if B-A == C-B {
fmt.Println("YES")
} else {
fmt.Println("NO")
}
}
type FastScanner struct {
r *bufio.Reader
buf []byte
p int
}
func NewFastScanner() *FastScanner {
rdr := bufio.NewReaderSize(os.Stdin, 1024)
return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
s.pre()
start := s.p
for ; s.p < len(s.buf); s.p++ {
if s.buf[s.p] == ' ' {
break
}
}
result := string(s.buf[start:s.p])
s.p++
return result
}
func (s *FastScanner) NextLine() string {
s.pre()
start := s.p
s.p = len(s.buf)
return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
v, _ := strconv.Atoi(s.Next())
return v
}
func (s *FastScanner) NextInt64() int64 {
v, _ := strconv.ParseInt(s.Next(), 10, 64)
return v
}
func (s *FastScanner) pre() {
if s.p >= len(s.buf) {
s.readLine()
s.p = 0
}
}
func (s *FastScanner) readLine() {
s.buf = make([]byte, 0)
for {
l, p, e := s.r.ReadLine()
if e != nil {
panic(e)
}
s.buf = append(s.buf, l...)
if !p {
break
}
}
}
func IntMax(a, b int) int {
if a < b {
return b
}
return a
}
func Int64Max(a, b int64) int64 {
if a < b {
return b
}
return a
}
func Float64Max(a, b float64) float64 {
if a < b {
return b
}
return a
}
func IntMin(a, b int) int {
if a > b {
return b
}
return a
}
func Int64Min(a, b int64) int64 {
if a > b {
return b
}
return a
}
func Float64Min(a, b float64) float64 {
if a > b {
return b
}
return a
}
func IntGcd(a, b int) int {
if a < b {
b, a = a, b
}
if b == 0 {
return a
}
return IntGcd(b, a%b)
}
func Int64Gcd(a, b int64) int64 {
if a < b {
b, a = a, b
}
if b == 0 {
return a
}
return Int64Gcd(b, a%b)
}
func IntAbs(a int) int {
if a < 0 {
a *= -1
}
return a
}
func Int64Abs(a int64) int64 {
if a < 0 {
a *= -1
}
return a
}
| s680776563 | [
{
"input": "2 4 6\n",
"output": "YES\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
)
type Block struct {
Value string
Len int
}
func main() {
var N, K, ans int
fmt.Scan(&N, &K)
var S string
s := bufio.NewScanner(os.Stdin)
b := make([]byte, 1000000)
s.Buffer(b, 1000000)
s.Scan()
S = s.Text()
blocks := RunLength(S)
sum, zero, l := 0, 0, 0
for r := 0; r < len(blocks); r++ {
sum += blocks[r].Len
if blocks[r].Value == "0" {
zero++
}
for K < zero {
sum -= blocks[l].Len
if blocks[l].Value == "0" {
zero--
}
l++
}
ans = Max(ans, sum)
}
fmt.Println(ans)
}
func RunLength(s string) []Block {
var r []Block
if len(s) == 0 {
return r
}
t := Block{Value: string(s[0]), Len: 1}
for _, v := range s[1:] {
if t.Value == string(v) {
t.Len++
} else {
r = append(r, t)
t = Block{Value: string(v), Len: 1}
}
}
r = append(r, t)
return r
}
func Max(a, b int) int {
if b > a {
return b
}
return a
}
| s712890349 | [
{
"input": "5 1\n00010\n",
"output": "4\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func main() {
sc := NewScanner()
n := sc.ReadInt()
k := sc.ReadInt()
total := int64(0)
for i := k; i <= n+1; i++ {
total += combi(n, i)
total = total % (Pow64(10, 9) + 7)
}
fmt.Println(total)
}
func combi(n int, k int) int64 {
min := int64(k-1) * int64(k) / 2
max := int64(2*n-k+1) * int64(k) / 2
return max - min + 1
}
func Abs(x int) int {
if x >= 0 {
return x
}
return -x
}
func Min(values ...int) int {
if len(values) == 0 {
panic("no values")
}
min := values[0]
for _, v := range values {
if v < min {
min = v
}
}
return min
}
func Max(values ...int) int {
if len(values) == 0 {
panic("no values")
}
max := values[0]
for _, v := range values {
if v > max {
max = v
}
}
return max
}
func Pow(base int, exponent uint) int {
answer := 1
for i := uint(0); i < exponent; i++ {
answer *= base
}
return answer
}
func Abs64(x int64) int64 {
if x >= 0 {
return x
}
return -x
}
func Min64(values ...int64) int64 {
if len(values) == 0 {
panic("no values")
}
min := values[0]
for _, v := range values {
if v < min {
min = v
}
}
return min
}
func Max64(values ...int64) int64 {
if len(values) == 0 {
panic("no values")
}
max := values[0]
for _, v := range values {
if v > max {
max = v
}
}
return max
}
func Pow64(base int64, exponent uint) int64 {
answer := int64(1)
for i := uint(0); i < exponent; i++ {
answer *= base
}
return answer
}
type Scanner struct {
bufScanner *bufio.Scanner
}
func NewScanner() *Scanner {
bufSc := bufio.NewScanner(os.Stdin)
bufSc.Split(bufio.ScanWords)
return &Scanner{bufSc}
}
func (sc *Scanner) ReadString() string {
bufSc := sc.bufScanner
bufSc.Scan()
return bufSc.Text()
}
func (sc *Scanner) ReadInt() int {
bufSc := sc.bufScanner
bufSc.Scan()
text := bufSc.Text()
num, err := strconv.Atoi(text)
if err != nil {
panic(err)
}
return num
}
func (sc *Scanner) ReadInt64() int64 {
bufSc := sc.bufScanner
bufSc.Scan()
text := bufSc.Text()
num, err := strconv.ParseInt(text, 10, 64)
if err != nil {
panic(err)
}
return num
}
| s684434772 | [
{
"input": "3 2\n",
"output": "10\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"io"
"os"
"strconv"
)
const mod = 998244353
const facNum = 300001
func main() {
sc := newScanner(os.Stdin)
N := sc.i()
sum := 0
for i := 1; i <= N; i++ {
if i%3 == 0 || i%5 == 0 {
continue
}
sum += i
}
fmt.Println(sum)
}
type scanner struct {
sc *bufio.Scanner
}
func newScanner(input io.Reader) *scanner {
sc := bufio.NewScanner(input)
sc.Split(bufio.ScanWords)
sc.Buffer(make([]byte, 1024), int(1e+9))
return &scanner{sc}
}
func (s *scanner) s() string {
s.sc.Scan()
return s.sc.Text()
}
func (s *scanner) i() int {
i, e := strconv.Atoi(s.s())
if e != nil {
panic(e)
}
return i
}
func (s *scanner) f() float64 {
f, e := strconv.ParseFloat(s.s(), 64)
if e != nil {
panic(e)
}
return f
}
func (s *scanner) bs() []byte {
return []byte(s.s())
}
func (s *scanner) is(n int) []int {
res := make([]int, n)
for i := 0; i < n; i++ {
res[i] = s.i()
}
return res
}
func (s *scanner) fs(n int) []float64 {
res := make([]float64, n)
for i := 0; i < n; i++ {
res[i] = s.f()
}
return res
}
func Pow(a, n int) int {
ans := 1
for n > 0 {
if (n & 1) == 1 {
ans = ans * a % mod
}
a = a * a % mod
n = n >> 1
}
return ans
}
func Gcd(a, b int) int {
if a < b {
return Gcd(b, a)
}
for b != 0 {
a, b = b, a%b
}
return a
}
func min(a, b int) int {
if a < b {
return a
}
return b
}
func combination(n, k int, fac, ifac []int) int {
if n < k || n < 0 {
return 0
}
if k == 0 {
return 1
}
ans := ifac[k] * ifac[n-k] % mod
return ans * fac[n] % mod
}
func factorial() (fac []int, ifac []int) {
fac = make([]int, facNum)
fac[0] = 1
ifac = make([]int, facNum)
ifac[0] = 1
for i := 1; i < facNum; i++ {
fac[i] = fac[i-1] * i % mod
ifac[i] = ifac[i-1] * Pow(i, mod-2) % mod
}
return
}
func lowerBound(vs []int, v int) (index int) {
n := len(vs) / 2
m := len(vs)
for m != n {
if vs[n] < v {
n = (m-n+1)/2 + n
} else {
m = n
n = n / 2
}
}
return n
}
func IntSlice(n, init int) []int {
r := make([]int, n)
for i := range r {
r[i] = init
}
return r
}
| s716019902 | [
{
"input": "15\n",
"output": "60\n"
}
] |
Go | codenet | package main
import (
"fmt"
"math"
)
func main() {
var n float64
var k float64
fmt.Scan(&n, &k)
var x float64 = 0.0
for {
under := math.Pow(k, x)
upper := math.Pow(k, x+1)
if under <= n && n < upper {
fmt.Println(x + 1)
return
}
x++
}
}
| s209996417 | [
{
"input": "11 2\n",
"output": "4\n"
}
] |
Go | codenet | package main
import (
"fmt"
)
func solution(n, m int) int {
n = n - 2
m = m - 2
if n < 0 {
n = 1
}
if m < 0 {
m = 1
}
return n * m
}
func main() {
var n, m int
fmt.Scan(&n, &m)
fmt.Println(solution(n, m))
}
| s060770256 | [
{
"input": "2 2\n",
"output": "0\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
type node struct {
key int
parent *node
left *node
right *node
}
type tree struct {
root *node
}
func (tree *tree) insert(key int) {
if tree.root == nil {
tree.root = &node{key: key}
return
}
var currentNode, prevNode *node
currentNode = tree.root
for currentNode != nil {
prevNode = currentNode
if currentNode.key < key {
currentNode = currentNode.right
} else {
currentNode = currentNode.left
}
}
newNode := &node{key: key}
newNode.parent = prevNode
if prevNode.key < key {
prevNode.right = newNode
} else {
prevNode.left = newNode
}
}
func (tree tree) print() {
var acc []int
if tree.root == nil {
fmt.Println("")
fmt.Println("")
} else {
fmt.Println(" " + strings.Join(isToAs(visitInorder(tree.root, acc)), " "))
fmt.Println(" " + strings.Join(isToAs(visitPreorder(tree.root, acc)), " "))
}
}
func visitPreorder(node *node, acc []int) []int {
if node == nil {
return acc
}
acc = append(acc, int(node.key))
if node.left != nil {
acc = visitPreorder(node.left, acc)
}
if node.right != nil {
acc = visitPreorder(node.right, acc)
}
return acc
}
func visitInorder(node *node, acc []int) []int {
if node == nil {
return acc
}
if node.left != nil {
acc = visitInorder(node.left, acc)
}
acc = append(acc, int(node.key))
if node.right != nil {
acc = visitInorder(node.right, acc)
}
return acc
}
func main() {
sc := bufio.NewScanner(os.Stdin)
sc.Split(bufio.ScanWords)
n, err := nextInt(sc)
if err != nil {
panic(err)
}
tree := &tree{}
for i := 0; i < n; i++ {
command := nextText(sc)
switch command {
case "insert":
key, err := nextInt(sc)
if err != nil {
panic(err)
}
tree.insert(key)
case "print":
tree.print()
default:
panic("unknown command: " + command)
}
}
}
func nextText(sc *bufio.Scanner) string {
sc.Scan()
return sc.Text()
}
func nextInt(sc *bufio.Scanner) (int, error) {
return strconv.Atoi(nextText(sc))
}
func isToAs(is []int) []string {
n := len(is)
as := make([]string, n)
for i := 0; i < n; i++ {
as[i] = strconv.Itoa(is[i])
}
return as
}
| s632215495 | [
{
"input": "8\ninsert 30\ninsert 88\ninsert 12\ninsert 1\ninsert 20\ninsert 17\ninsert 25\nprint\n",
"output": " 1 12 17 20 25 30 88\n 30 12 1 20 17 25 88\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"math"
"os"
"reflect"
"sort"
"strconv"
"strings"
)
type pair struct {
index int64
p1, p2 interface{}
}
type pairs []pair
func (slice pairs) Len() int {
return len(slice)
}
func (slice pairs) Less(i, j int) bool {
return slice[i].index < slice[j].index
}
func (slice pairs) Swap(i, j int) {
slice[i], slice[j] = slice[j], slice[i]
}
type Int64Slice []int64
func (slice Int64Slice) Len() int {
return len(slice)
}
func (slice Int64Slice) Less(i, j int) bool {
return slice[i] < slice[j]
}
func (slice Int64Slice) Swap(i, j int) {
slice[i], slice[j] = slice[j], slice[i]
}
func Int64s(a []int64) { sort.Sort(Int64Slice(a)) }
func Int64sSliceAreSorted(a []int64) bool { return sort.IsSorted(Int64Slice(a)) }
const (
initialBufSize = 1e4
maxBufSize = 1e8
INF = 1e8
)
var (
scanner = bufio.NewScanner(os.Stdin)
writer = bufio.NewWriter(os.Stdout)
di = []int64{-1, 0, 1, 0}
dj = []int64{0, -1, 0, 1}
)
func main() {
buf := make([]byte, initialBufSize)
scanner.Buffer(buf, maxBufSize)
scanner.Split(bufio.ScanWords)
A, B, C := readInt(), readInt(), readInt()
if C >= A && C <= B {
fmt.Println("Yes")
} else {
fmt.Println("No")
}
}
func NextPermutation(x sort.Interface) bool {
n := x.Len() - 1
if n < 1 {
return false
}
j := n - 1
for ; !x.Less(j, j+1); j-- {
if j == 0 {
return false
}
}
l := n
for !x.Less(j, l) {
l--
}
x.Swap(j, l)
for k, l := j+1, n; k < l; {
x.Swap(k, l)
k++
l--
}
return true
}
func doubleAry(h int64, w int64, init int64) (res [][]int64) {
res = make([][]int64, h)
for i := int64(0); i < h; i++ {
res[i] = make([]int64, w)
for j := int64(0); j < w; j++ {
res[i][j] = init
}
}
return
}
func aryEq(a []int64, b []int64) bool {
return reflect.DeepEqual(a, b)
}
func clone(n []int64) (r []int64) {
r = make([]int64, len(n))
for i := 0; i < len(n); i++ {
r[i] = n[i]
}
return
}
func write(s string) {
writer.WriteString(s)
}
func print() {
writer.Flush()
}
func readLine() (s string) {
if scanner.Scan() {
s = scanner.Text()
}
return s
}
func readInt() (read int64) {
scanner.Scan()
read, err := strconv.ParseInt(scanner.Text(), 10, 64)
if err != nil {
panic(err)
}
return
}
func readFloat() (read float64) {
scanner.Scan()
read, err := strconv.ParseFloat(scanner.Text(), 64)
if err != nil {
panic(err)
}
return
}
func readRunes() (read []rune) {
scanner.Scan()
for _, v := range scanner.Text() {
read = append(read, v)
}
return
}
func readString() (read string) {
scanner.Scan()
read = scanner.Text()
return
}
func readStrings() (read []string) {
scanner.Scan()
for _, v := range scanner.Text() {
read = append(read, string(v))
}
return
}
func s2i(s string) int64 {
var intVal, e = strconv.ParseInt(s, 10, 64)
if e != nil {
panic(e)
}
return intVal
}
func i2s(i int64) string {
var strVal = strconv.FormatInt(i, 10)
return strVal
}
func s2f(s string) float64 {
var floatVal, e = strconv.ParseFloat(s, 64)
if e != nil {
panic(e)
}
return floatVal
}
func abs(i int64) int64 {
return int64(math.Abs(float64(i)))
}
func max(a ...int64) int64 {
ans := int64(0)
for i, v := range a {
if i == 0 {
ans = v
}
if ans < v {
ans = v
}
}
return ans
}
func min(a ...int64) int64 {
ans := int64(0)
for i, v := range a {
if i == 0 {
ans = v
}
if ans > v {
ans = v
}
}
return ans
}
func sum(i []int64) int64 {
sum := int64(0)
for _, val := range i {
sum += val
}
return sum
}
func split(s string) []string {
return strings.Fields(s)
}
func strAry2intAry(strs []string) []int64 {
var ret = make([]int64, 0, len(strs))
for _, str := range strs {
var intVal = s2i(str)
ret = append(ret, intVal)
}
return ret
}
func intAry2strAry(nums []int64) []string {
var ret = make([]string, 0, len(nums))
for _, num := range nums {
var strVal = i2s(num)
ret = append(ret, strVal)
}
return ret
}
func ary2str(strs []string) string {
return strings.Join(strs, " ")
}
func reverse(res []int64) []int64 {
for i, j := 0, len(res)-1; i < j; i, j = i+1, j-1 {
res[i], res[j] = res[j], res[i]
}
return res
}
func reverseStr(res []string) []string {
for i, j := 0, len(res)-1; i < j; i, j = i+1, j-1 {
res[i], res[j] = res[j], res[i]
}
return res
}
func ini(res []int, init int) {
if len(res) == 0 {
return
}
res[0] = init
for i := 0; i < len(res); i++ {
copy(res[i:], res[:i])
}
}
| s684610901 | [
{
"input": "1 3 2\n",
"output": "Yes\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var a, b int
fmt.Scan(&a, &b)
if a*b%2 == 0 {
fmt.Println("Even")
} else {
fmt.Println("Odd")
}
}
| s824543330 | [
{
"input": "3 4\n",
"output": "Even\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
var line, buffer []byte
var isPrefix bool = true
var err error
for isPrefix {
line, isPrefix, err = reader.ReadLine()
if err != nil {
panic(err)
}
buffer = append(buffer, line...)
}
return string(buffer)
}
func NextInt() int {
var n int
n, _ = strconv.Atoi(NextLine())
return n
}
func Write(s interface{}) {
fmt.Fprintln(writer, s)
}
func Output() {
_ = writer.Flush()
}
func Bipartite(S *[]string) bool {
N := len((*S))
D := make([]int, N)
D[0] = 1
Q := make([]int, N)
ret := true
pos := 1
for i := 0; i < N; i++ {
if !ret {
break
}
q := Q[i]
for j, s := range (*S)[q] {
if s == '0' {
continue
}
if D[j] == 0 {
D[j] = D[q] + 1
Q[pos] = j
pos++
continue
}
if D[j]%2 == D[q]%2 {
ret = false
break
}
}
}
return ret
}
func WarshallFloyd(S *[]string) int {
N := len(*(S))
G := make([][]int, N)
for i := range G {
G[i] = make([]int, N)
for j := range G[i] {
if i == j {
continue
}
if (*S)[i][j] == '0' {
G[i][j] = N
} else {
G[i][j] = 1
}
}
}
for k := 0; k < N; k++ {
for i := 0; i < N; i++ {
for j := 0; j < N; j++ {
if G[i][k]+G[k][j] < G[i][j] {
G[i][j] = G[i][k] + G[k][j]
}
}
}
}
ans := 0
for i := 0; i < N; i++ {
for j := 0; j < N; j++ {
if ans < G[i][j] {
ans = G[i][j]
}
}
}
return ans + 1
}
func main() {
N := NextInt()
S := make([]string, N)
for i := range S {
S[i] = NextLine()
}
if !Bipartite(&S) {
Write(-1)
} else {
Write(WarshallFloyd(&S))
}
Output()
}
| s537465285 | [
{
"input": "2\n01\n10\n",
"output": "2\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
)
var in = bufio.NewReader(os.Stdin)
func solve(a, b, c int) int {
var temp_ int
if c == a+b {
temp_ = b + c
} else if c-1 > a+b {
temp := (c - 1) - (a + b)
temp_ = b + c - temp
} else {
temp_ = b + c
}
return temp_
}
func main() {
var a, b, c int
fmt.Fscanf(in, "%d %d %d¥n", &a, &b, &c)
ans := solve(a, b, c)
fmt.Println(ans)
}
| s336868078 | [
{
"input": "3 1 4\n",
"output": "5\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
"sort"
)
func main() {
sc := NewScanner()
n := sc.NextInt()
arr := make([]float64, n)
for i := 0; i < n; i++ {
arr[i] = float64(sc.NextInt())
}
sort.Float64s(arr)
prev := arr[0]
for i := 1; i < len(arr); i++ {
prev = (prev + arr[i]) / 2
}
fmt.Printf("%v\n", prev)
}
type Scanner struct {
r *bufio.Reader
buf []byte
p int
}
func NewScanner() *Scanner {
rdr := bufio.NewReaderSize(os.Stdin, 1000)
return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
s.pre()
start := s.p
for ; s.p < len(s.buf); s.p++ {
if s.buf[s.p] == ' ' {
break
}
}
result := string(s.buf[start:s.p])
s.p++
return result
}
func (s *Scanner) NextLine() string {
s.pre()
start := s.p
s.p = len(s.buf)
return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
v, _ := strconv.Atoi(s.Next())
return v
}
func (s *Scanner) NextIntArray() []int {
s.pre()
start := s.p
result := []int{}
for ; s.p < len(s.buf); s.p++ {
if s.buf[s.p] == ' ' {
v, _ := strconv.Atoi(string(s.buf[start:s.p]))
result = append(result, v)
start = s.p + 1
}
}
v, _ := strconv.Atoi(string(s.buf[start:s.p]))
result = append(result, v)
return result
}
func (s *Scanner) NextMap() map[int]bool {
s.pre()
start := s.p
mp := map[int]bool{}
for ; s.p < len(s.buf); s.p++ {
if s.buf[s.p] == ' ' {
v, _ := strconv.Atoi(string(s.buf[start:s.p]))
mp[v] = true
start = s.p + 1
}
}
v, _ := strconv.Atoi(string(s.buf[start:s.p]))
mp[v] = true
return mp
}
func (s *Scanner) pre() {
if s.p >= len(s.buf) {
s.readLine()
s.p = 0
}
}
func (s *Scanner) readLine() {
s.buf = make([]byte, 0)
for {
l, p, e := s.r.ReadLine()
if e != nil {
panic(e)
}
s.buf = append(s.buf, l...)
if !p {
break
}
}
}
| s479324991 | [
{
"input": "2\n3 4\n",
"output": "3.5\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"math"
"os"
"strconv"
"strings"
)
func main() {
io, flash := NewIO()
defer flash()
n, t, a := io.ScanInt(), io.ScanFloat64(), io.ScanFloat64()
heights := io.ScanFloat64s(n)
minDiff := AbsDiffFloat64(t-heights[0]*0.006, a)
minIdx := 0
for i, h := range heights[1:] {
diff := AbsDiffFloat64(t-h*0.006, a)
if diff < minDiff {
minDiff = diff
minIdx = i + 1
}
}
fmt.Println(minIdx + 1)
}
func AbsDiffFloat64(n1, n2 float64) float64 {
return math.Abs(n1 - n2)
}
type IO struct {
scanner *bufio.Scanner
writer *bufio.Writer
}
func NewIO() (*IO, func()) {
io := &IO{
scanner: newScanner(),
writer: newWriter(),
}
return io, func() { io.writer.Flush() }
}
func newScanner() *bufio.Scanner {
s := bufio.NewScanner(os.Stdin)
s.Buffer(make([]byte, 10000000), 10000000)
s.Split(bufio.ScanWords)
return s
}
func newWriter() *bufio.Writer {
return bufio.NewWriter(os.Stdout)
}
func (io *IO) ScanBytes() []byte {
if !io.scanner.Scan() {
panic("scan string failed")
}
return io.scanner.Bytes()
}
func (io *IO) ScanString() string {
if !io.scanner.Scan() {
panic("scan string failed")
}
return io.scanner.Text()
}
func (io *IO) ScanStrings(n int) []string {
strs := make([]string, n)
for i := 0; i < n; i++ {
strs[i] = io.ScanString()
}
return strs
}
func (io *IO) Scan2DStrings(y, x int) [][]string {
strings := make([][]string, y)
for i := 0; i < y; i++ {
strings[i] = io.ScanStrings(x)
}
return strings
}
func (io *IO) Scan2DGraph(y int) [][]string {
strs := make([][]string, y)
for i := 0; i < y; i++ {
strs[i] = strings.Split(io.ScanString(), "")
}
return strs
}
func (io *IO) ScanInt() int {
return int(io.ScanInt64())
}
func (io *IO) ScanInt2() (int, int) {
return int(io.ScanInt64()), int(io.ScanInt64())
}
func (io *IO) ScanInt3() (int, int, int) {
return int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64())
}
func (io *IO) ScanInt4() (int, int, int, int) {
return int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64())
}
func (io *IO) ScanInts(n int) []int {
ints := make([]int, n)
for i := 0; i < n; i++ {
ints[i] = io.ScanInt()
}
return ints
}
func (io *IO) Scan2DInts(y, x int) [][]int {
ints := make([][]int, y)
for i := 0; i < y; i++ {
ints[i] = io.ScanInts(x)
}
return ints
}
func (io *IO) ScanInt64() int64 {
i, err := strconv.ParseInt(io.ScanString(), 10, 64)
if err != nil {
panic(err)
}
return i
}
func (io *IO) ScanFloat64() float64 {
i, _ := strconv.ParseFloat(io.ScanString(), 64)
return i
}
func (io *IO) ScanFloat64s(n int) []float64 {
floats := make([]float64, n)
for i := 0; i < n; i++ {
floats[i] = io.ScanFloat64()
}
return floats
}
func (io *IO) Println(a ...interface{}) {
fmt.Fprintln(io.writer, a...)
}
| s753839476 | [
{
"input": "2\n12 5\n1000 2000\n",
"output": "1\n"
}
] |
Go | codenet | package main
import "fmt"
type Dice struct {
Nums []int
}
func (d *Dice) rotate(direction string, times int) {
times %= 4
switch direction {
case "W":
for i := 0; i < times; i++ {
d.Nums[0], d.Nums[2], d.Nums[5], d.Nums[3] = d.Nums[2], d.Nums[5], d.Nums[3], d.Nums[0]
}
case "E":
for i := 0; i < times; i++ {
d.Nums[0], d.Nums[2], d.Nums[5], d.Nums[3] = d.Nums[3], d.Nums[0], d.Nums[2], d.Nums[5]
}
case "N":
for i := 0; i < times; i++ {
d.Nums[0], d.Nums[4], d.Nums[5], d.Nums[1] = d.Nums[1], d.Nums[0], d.Nums[4], d.Nums[5]
}
case "S":
for i := 0; i < times; i++ {
d.Nums[5], d.Nums[1], d.Nums[0], d.Nums[4] = d.Nums[1], d.Nums[0], d.Nums[4], d.Nums[5]
}
}
}
func (d *Dice) roll(direction string, times int) {
times %= 4
switch direction {
case "R":
for i := 0; i < times; i++ {
d.Nums[3], d.Nums[1], d.Nums[2], d.Nums[4] = d.Nums[1], d.Nums[2], d.Nums[4], d.Nums[3]
}
case "L":
for i := 0; i < times; i++ {
d.Nums[3], d.Nums[1], d.Nums[2], d.Nums[4] = d.Nums[4], d.Nums[3], d.Nums[1], d.Nums[2]
}
}
}
func (d *Dice) printStatus() {
status :=
` _ _ _ _
_ _ _|_%3d_|_ _ _ _ _ _
|_%3d_|_%3d_|_%3d_|_%3d_|
|_%3d_|
`
fmt.Printf(status, d.Nums[0], d.Nums[3], d.Nums[1], d.Nums[2], d.Nums[4], d.Nums[5])
fmt.Println()
}
func getIndex(nums []int, target int) (index int) {
for i, v := range nums {
if target == v {
index = i
break
} else {
index = -1
}
}
return index
}
func (d *Dice) isEqual(other Dice) bool {
for i, v := range d.Nums {
if v != other.Nums[i] {
return false
}
}
return true
}
func main() {
dice1 := Dice{
make([]int, 6),
}
dice2 := Dice{
make([]int, 6),
}
for i := 0; i < 6; i++ {
var n int
fmt.Scan(&n)
dice1.Nums[i] = n
}
for i := 0; i < 6; i++ {
var n int
fmt.Scan(&n)
dice2.Nums[i] = n
}
directionOrder := []string{"N", "S", "W", "E"}
rollOrder := []string{"R", "L"}
flag := false
CHECK:
for i := 0; i <= 2; i++ {
for j := 0; j <= 2; j++ {
for _, direction := range directionOrder {
for _, roll := range rollOrder {
tmp := new(Dice)
tmp.Nums = append([]int{}, dice2.Nums...)
tmp.rotate(direction, i)
tmp.roll(roll, j)
if tmp.isEqual(dice1) {
flag = true
break CHECK
}
}
}
}
}
if flag {
fmt.Println("Yes")
} else {
fmt.Println("No")
}
}
| s446670437 | [
{
"input": "1 2 3 4 5 6\n6 2 4 3 5 1\n",
"output": "Yes\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
)
var mod = 1000000007
var INF = 1000000007
func main() {
r := bufio.NewReader(os.Stdin)
var n, m, R int
fmt.Fscan(r, &n)
fmt.Fscan(r, &m)
fmt.Fscan(r, &R)
rs := make([]int, R)
for i := 0; i < R; i++ {
fmt.Fscan(r, &rs[i])
rs[i]--
}
costs := make([][]int, n)
for i := 0; i < n; i++ {
costs[i] = make([]int, n)
for j := 0; j < n; j++ {
costs[i][j] = INF
}
costs[i][i] = 0
}
var a, b, c int
for i := 0; i < m; i++ {
fmt.Fscan(r, &a)
fmt.Fscan(r, &b)
fmt.Fscan(r, &c)
a--
b--
costs[a][b] = c
costs[b][a] = c
}
for k := 0; k < n; k++ {
for i := 0; i < n; i++ {
for j := 0; j < n; j++ {
costs[i][j] = min(costs[i][j], costs[i][k]+costs[k][j])
}
}
}
perms := permutations(rs)
ans := INF
for _, perm := range perms {
tmp := 0
for j := 1; j < len(perm); j++ {
from := perm[j-1]
to := perm[j]
tmp += costs[from][to]
}
ans = min(ans, tmp)
}
fmt.Println(ans)
}
func permutations(arr []int) [][]int {
var helper func([]int, int)
res := [][]int{}
helper = func(arr []int, n int) {
if n == 1 {
tmp := make([]int, len(arr))
copy(tmp, arr)
res = append(res, tmp)
} else {
for i := 0; i < n; i++ {
helper(arr, n-1)
if n%2 == 1 {
tmp := arr[i]
arr[i] = arr[n-1]
arr[n-1] = tmp
} else {
tmp := arr[0]
arr[0] = arr[n-1]
arr[n-1] = tmp
}
}
}
}
helper(arr, len(arr))
return res
}
type unionFind struct {
d []int
}
func newUnionFind(n int) *unionFind {
uf := new(unionFind)
uf.d = make([]int, n)
for i := 0; i < n; i++ {
uf.d[i] = -1
}
return uf
}
func (uf *unionFind) find(x int) int {
if uf.d[x] < 0 {
return x
}
uf.d[x] = uf.find(uf.d[x])
return uf.d[x]
}
func (uf *unionFind) unite(x, y int) bool {
rootX := uf.find(x)
rootY := uf.find(y)
if rootX == rootY {
return false
}
if uf.d[rootX] < uf.d[rootY] {
uf.d[rootX] += uf.d[rootY]
uf.d[rootY] = rootX
} else {
uf.d[rootY] += uf.d[rootX]
uf.d[rootX] = rootY
}
return true
}
func (uf *unionFind) same(x, y int) bool {
return uf.find(x) == uf.find(y)
}
func (uf *unionFind) size(x int) int {
return -uf.d[uf.find(x)]
}
func modpow(a, n, mod int) int {
res := 1
for n > 0 {
if n%2 != 0 {
res = res * a % mod
}
a = a * a % mod
n = n / 2
}
return res
}
func modinv(n, mod int) int {
return modpow(n, mod-2, mod)
}
func modcomb(n, a, mod int) int {
x := 1
y := 1
for i := 0; i < a; i++ {
x = x * (n - i)
x %= mod
y = y * (i + 1)
y %= mod
}
return x * modpow(y, mod-2, mod) % mod
}
func modfactorial(n, mod int) int {
result := 1
for i := 1; i <= n; i++ {
result = (result * i) % mod
}
return result
}
type Combination struct {
facts, invs []int
mod int
}
func NewCombination(n, mod int) Combination {
return Combination{
facts: make([]int, n+1),
invs: make([]int, n+1),
mod: mod,
}
}
func (cmb *Combination) calc(n, k int) int {
ret := cmb.facts[n] * cmb.invs[k]
ret %= cmb.mod
ret = ret * cmb.invs[n-k]
ret %= cmb.mod
return ret
}
func (cmb *Combination) init(n int) {
cmb.facts[0] = 1
for i := 1; i <= n; i++ {
cmb.facts[i] = cmb.facts[i-1] * i % cmb.mod
}
cmb.invs[n] = modinv(cmb.facts[n], cmb.mod)
for i := n - 1; i >= 0; i-- {
cmb.invs[i] = cmb.invs[i+1] * (i + 1) % cmb.mod
}
}
func min(x, y int) int {
if x < y {
return x
}
return y
}
func max(x, y int) int {
if x > y {
return x
}
return y
}
func abs(x int) int {
if x < 0 {
return -x
}
return x
}
func primeFactor(x int) map[int]int {
res := make(map[int]int)
for i := 2; i*i <= x; i++ {
for x%i == 0 {
res[i]++
x = x / i
}
}
if x != 1 {
res[x] = 1
}
return res
}
func divisor(x int) []int {
res := make([]int, 0)
for i := 1; i*i <= x; i++ {
if x%i == 0 {
res = append(res, i)
if i != x/i {
res = append(res, x/i)
}
}
}
return res
}
func gcd(x, y int) int {
if y == 0 {
return x
}
return gcd(y, x%y)
}
func lcm(x, y int) int {
return x / gcd(x, y) * y
}
func reverseString(s string) string {
r := []rune(s)
for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
r[i], r[j] = r[j], r[i]
}
return string(r)
}
func pow(a, n int) int {
ret := 1
for i := 1; i <= n; i++ {
ret *= a
}
return ret
}
type Queue []int
func (q *Queue) empty() bool {
return len(*q) == 0
}
func (q *Queue) push(i int) {
*q = append(*q, i)
}
func (q *Queue) pop() (int, bool) {
if q.empty() {
return 0, false
} else {
res := (*q)[0]
*q = (*q)[1:]
return res, true
}
}
type Stack []int
func (s *Stack) empty() bool {
return len(*s) == 0
}
func (s *Stack) push(i int) {
*s = append(*s, i)
}
func (s *Stack) pop() (int, bool) {
if s.empty() {
return 0, false
} else {
index := len(*s) - 1
res := (*s)[index]
*s = (*s)[:index]
return res, true
}
}
type intHeap []int
func (h intHeap) Len() int { return len(h) }
func (h intHeap) Less(i, j int) bool { return h[i] > h[j] }
func (h intHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
func (h *intHeap) Push(x interface{}) {
*h = append(*h, x.(int))
}
func (h *intHeap) Pop() interface{} {
old := *h
n := len(old)
x := old[n-1]
*h = old[0 : n-1]
return x
}
type point struct {
x int
y int
}
type points []point
func (p points) Len() int {
return len(p)
}
func (p points) Less(i, j int) bool {
return p[i].x < p[j].x
}
func (p points) Swap(i, j int) {
p[i], p[j] = p[j], p[i]
}
| s853386130 | [
{
"input": "3 3 3\n1 2 3\n1 2 1\n2 3 1\n3 1 4\n",
"output": "2\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
const size = 1000000
var reader = bufio.NewReaderSize(os.Stdin, size)
func NextLine() string {
var line, buffer []byte
var isPrefix bool = true
var err error
for isPrefix {
line, isPrefix, err = reader.ReadLine()
if err != nil {
panic(err)
}
buffer = append(buffer, line...)
}
return string(buffer)
}
func NextInts() (int, int) {
var x, y int
var s []string = strings.Split(NextLine(), " ")
x, _ = strconv.Atoi(s[0])
y, _ = strconv.Atoi(s[1])
return x, y
}
func NextIntArray() []int {
var s []string = strings.Split(NextLine(), " ")
var a []int = make([]int, len(s))
for i := 0; i < len(s); i++ {
a[i], _ = strconv.Atoi(s[i])
a[i]--
}
return a
}
var par, rank []int
func main() {
var n, m int = NextInts()
var p []int = NextIntArray()
var x, y int
initialize(n)
for i := 0; i < m; i++ {
x, y = NextInts()
unite(x-1, y-1)
}
var s int
for i := 0; i < n; i++ {
if same(i, p[i]) {
s++
}
}
fmt.Println(s)
}
func initialize(n int) {
par = make([]int, n)
rank = make([]int, n)
for i := 0; i < n; i++ {
par[i] = i
}
}
func root(i int) int {
if par[i] == i {
return i
}
par[i] = root(par[i])
return par[i]
}
func same(i, j int) bool {
return root(i) == root(j)
}
func unite(i, j int) {
i = root(i)
j = root(j)
if i == j {
return
}
if rank[i] < rank[j] {
par[i] = j
} else {
par[j] = i
if rank[i] == rank[j] {
rank[i]++
}
}
}
| s301190573 | [
{
"input": "5 2\n5 3 1 4 2\n1 3\n5 4\n",
"output": "2\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
var sc = bufio.NewScanner(os.Stdin)
func main() {
sc.Split(bufio.ScanWords)
n := nextInt()
m := nextInt()
h := make([]int, n)
good := make([]bool, n)
for i := 0; i < n; i++ {
h[i] = nextInt()
good[i] = true
}
for i := 0; i < m; i++ {
ai := nextInt() - 1
bi := nextInt() - 1
if h[ai] > h[bi] {
good[bi] = false
} else if h[ai] < h[bi] {
good[ai] = false
} else {
good[ai] = false
good[bi] = false
}
}
ans := 0
for i := 0; i < n; i++ {
if good[i] {
ans++
}
}
fmt.Println(ans)
}
func nextInt() int {
sc.Scan()
i, e := strconv.Atoi(sc.Text())
if e != nil {
panic(e)
}
return i
}
| s302163336 | [
{
"input": "4 3\n1 2 3 4\n1 3\n2 3\n2 4\n",
"output": "2\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var n, m int
fmt.Scanf("%d %d", &n, &m)
h := make([]int, n)
for i := 0; i < n; i++ {
fmt.Scan(&h[i])
}
var a, b int
counter := make(map[int]struct{})
for i := 0; i < m; i++ {
fmt.Scanf("%d %d", &a, &b)
if h[a-1] < h[b-1] {
counter[a] = struct{}{}
} else if h[a-1] > h[b-1] {
counter[b] = struct{}{}
} else if h[a-1] == h[b-1] {
counter[a] = struct{}{}
counter[b] = struct{}{}
}
}
fmt.Println(n - len(counter))
}
| s860368733 | [
{
"input": "4 3\n1 2 3 4\n1 3\n2 3\n2 4\n",
"output": "2\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var n int
fmt.Scan(&n)
as := make([]int, n+1)
bs := make([]int, n)
for i := range as {
fmt.Scan(&as[i])
}
for i := range bs {
fmt.Scan(&bs[i])
}
var sum int
for i := 0; i <= n-1; i++ {
a := as[i]
b := bs[i]
if a <= b {
sum += a
b -= a
if i+1 <= n {
an := as[i+1]
if an <= b {
sum += an
as[i+1] = 0
} else {
sum += b
as[i+1] -= b
}
}
} else {
sum += b
}
}
fmt.Println(sum)
}
| s451489327 | [
{
"input": "2\n3 5 2\n4 5\n",
"output": "9\n"
}
] |
Go | codenet | package main
import "fmt"
type problem struct {
number, bonus int
}
func min(a, b int) int {
if a >= b {
return b
}
return a
}
func main() {
var D, G int
fmt.Scan(&D, &G)
problems := make([]problem, D)
for i := range problems {
fmt.Scan(&problems[i].number)
fmt.Scan(&problems[i].bonus)
}
ans := 10000
for bit := 0; bit < (1 << uint(D)); bit++ {
score := 0
solved := 0
ok := false
for j := 0; j < D; j++ {
if bit&(1<<uint(j)) != 0 {
score += (j+1)*100*problems[j].number + problems[j].bonus
solved += problems[j].number
}
}
if score < G {
var j int
for j = D - 1; j >= 0; j-- {
if bit&(1<<uint(j)) == 0 {
break
}
}
for k := 0; k < problems[j].number; k++ {
score += (j + 1) * 100
solved++
if score >= G {
ok = true
break
}
}
if !ok {
score += problems[j].bonus
if score >= G {
ok = true
}
}
} else {
ok = true
}
if ok {
ans = min(ans, solved)
}
}
fmt.Println(ans)
}
| s699619001 | [
{
"input": "2 700\n3 500\n5 800\n",
"output": "3\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func getScanner(fp *os.File) *bufio.Scanner {
scanner := bufio.NewScanner(fp)
scanner.Split(bufio.ScanWords)
scanner.Buffer(make([]byte, 500001), 500000)
return scanner
}
func getNextString(scanner *bufio.Scanner) string {
scanner.Scan()
return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
i, _ := strconv.Atoi(getNextString(scanner))
return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
return i
}
func getNextUint64(scanner *bufio.Scanner) uint64 {
i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
i, _ := strconv.ParseFloat(getNextString(scanner), 64)
return i
}
func main() {
fp := os.Stdin
wfp := os.Stdout
cnt := 0
if os.Getenv("MASPY") == "ますピ" {
fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
cnt = 2
}
if os.Getenv("MASPYPY") == "ますピッピ" {
wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
}
scanner := getScanner(fp)
writer := bufio.NewWriter(wfp)
solve(scanner, writer)
for i := 0; i < cnt; i++ {
fmt.Fprintln(writer, "-----------------------------------")
solve(scanner, writer)
}
writer.Flush()
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
k := getNextInt(scanner)
x := getNextInt(scanner)
ans := "No"
if k*500 >= x {
ans = "Yes"
}
fmt.Fprintln(writer, ans)
}
| s033683118 | [
{
"input": "2 900\n",
"output": "Yes\n"
}
] |
Go | codenet | package main
import (
"bufio"
"errors"
"fmt"
"io"
"math"
"os"
"sort"
"strconv"
"strings"
)
var (
ReadString func() string
stdout *bufio.Writer
)
func init() {
ReadString = newReadString(os.Stdin)
stdout = bufio.NewWriter(os.Stdout)
}
func newReadString(ior io.Reader) func() string {
r := bufio.NewScanner(ior)
r.Buffer(make([]byte, 1024), int(1e+11))
r.Split(bufio.ScanWords)
return func() string {
if !r.Scan() {
panic("Scan failed")
}
return r.Text()
}
}
func ReadInt() int {
return int(readInt64())
}
func readInt64() int64 {
i, err := strconv.ParseInt(ReadString(), 0, 64)
if err != nil {
panic(err.Error())
}
return i
}
func ReadIntSlice(n int) []int {
b := make([]int, n)
for i := 0; i < n; i++ {
b[i] = ReadInt()
}
return b
}
func ReadRuneSlice() []rune {
return []rune(ReadString())
}
func ChMin(updatedValue *int, target int) bool {
if *updatedValue > target {
*updatedValue = target
return true
}
return false
}
func ChMax(updatedValue *int, target int) bool {
if *updatedValue < target {
*updatedValue = target
return true
}
return false
}
func GetNthBit(num, nth int) int {
return num >> uint(nth) & 1
}
func Max(integers ...int) int {
m := integers[0]
for i, integer := range integers {
if i == 0 {
continue
}
if m < integer {
m = integer
}
}
return m
}
func Min(integers ...int) int {
m := integers[0]
for i, integer := range integers {
if i == 0 {
continue
}
if m > integer {
m = integer
}
}
return m
}
func CeilInt(a, b int) int {
res := a / b
if a%b > 0 {
res++
}
return res
}
func FloorInt(a, b int) int {
res := a / b
return res
}
func PowInt(a, e int) int {
if a < 0 || e < 0 {
panic(errors.New("[argument error]: PowInt does not accept negative integers"))
}
if e == 0 {
return 1
}
if e%2 == 0 {
halfE := e / 2
half := PowInt(a, halfE)
return half * half
}
return a * PowInt(a, e-1)
}
func AbsInt(a int) int {
if a < 0 {
return -a
}
return a
}
func Gcd(a, b int) int {
if a <= 0 || b <= 0 {
panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
}
if a < b {
a, b = b, a
}
for b > 0 {
div := a % b
a, b = b, div
}
return a
}
func Lcm(a, b int) int {
if a <= 0 || b <= 0 {
panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
}
gcd := Gcd(a, b)
return (a / gcd) * b
}
func DeleteElement(s []int, i int) []int {
if i < 0 || len(s) <= i {
panic(errors.New("[index error]"))
}
n := make([]int, 0, len(s)-1)
n = append(n, s[:i]...)
n = append(n, s[i+1:]...)
return n
}
func Concat(s, t []rune) []rune {
n := make([]rune, 0, len(s)+len(t))
n = append(n, s...)
n = append(n, t...)
return n
}
func UpperRune(r rune) rune {
str := strings.ToUpper(string(r))
return []rune(str)[0]
}
func LowerRune(r rune) rune {
str := strings.ToLower(string(r))
return []rune(str)[0]
}
func ToggleRune(r rune) rune {
var str string
if 'a' <= r && r <= 'z' {
str = strings.ToUpper(string(r))
} else if 'A' <= r && r <= 'Z' {
str = strings.ToLower(string(r))
} else {
str = string(r)
}
return []rune(str)[0]
}
func ToggleString(s string) string {
inputRunes := []rune(s)
outputRunes := make([]rune, 0, len(inputRunes))
for _, r := range inputRunes {
outputRunes = append(outputRunes, ToggleRune(r))
}
return string(outputRunes)
}
func Strtoi(s string) int {
if i, err := strconv.Atoi(s); err != nil {
panic(errors.New("[argument error]: Strtoi only accepts integer string"))
} else {
return i
}
}
func CalcFactorialPatterns(elements []rune) [][]rune {
copiedResidual := make([]rune, len(elements))
copy(copiedResidual, elements)
return factorialRecursion([]rune{}, copiedResidual)
}
func factorialRecursion(interim, residual []rune) [][]rune {
if len(residual) == 0 {
return [][]rune{interim}
}
res := [][]rune{}
for idx, elem := range residual {
copiedInterim := make([]rune, len(interim))
copy(copiedInterim, interim)
copiedInterim = append(copiedInterim, elem)
copiedResidual := genDeletedSlice(idx, residual)
res = append(res, factorialRecursion(copiedInterim, copiedResidual)...)
}
return res
}
func genDeletedSlice(delId int, S []rune) []rune {
res := []rune{}
res = append(res, S[:delId]...)
res = append(res, S[delId+1:]...)
return res
}
func CalcDuplicatePatterns(elements []rune, digit int) [][]rune {
return duplicateRecursion([]rune{}, elements, digit)
}
func duplicateRecursion(interim, elements []rune, digit int) [][]rune {
if len(interim) == digit {
return [][]rune{interim}
}
res := [][]rune{}
for i := 0; i < len(elements); i++ {
copiedInterim := make([]rune, len(interim))
copy(copiedInterim, interim)
copiedInterim = append(copiedInterim, elements[i])
res = append(res, duplicateRecursion(copiedInterim, elements, digit)...)
}
return res
}
func GeneralLowerBound(s []int, key int) int {
isOK := func(index, key int) bool {
if s[index] >= key {
return true
}
return false
}
ng, ok := -1, len(s)
for int(math.Abs(float64(ok-ng))) > 1 {
mid := (ok + ng) / 2
if isOK(mid, key) {
ok = mid
} else {
ng = mid
}
}
return ok
}
func GeneralUpperBound(s []int, key int) int {
isOK := func(index, key int) bool {
if s[index] > key {
return true
}
return false
}
ng, ok := -1, len(s)
for int(math.Abs(float64(ok-ng))) > 1 {
mid := (ok + ng) / 2
if isOK(mid, key) {
ok = mid
} else {
ng = mid
}
}
return ok
}
func InitParents(parents []int, maxNodeId int) {
for i := 0; i <= maxNodeId; i++ {
parents[i] = i
}
}
func unite(x, y int, parents []int) {
xp, yp := root(x, parents), root(y, parents)
if xp == yp {
return
}
parents[xp] = yp
}
func same(x, y int, parents []int) bool {
return root(x, parents) == root(y, parents)
}
func root(x int, parents []int) int {
if parents[x] == x {
return x
}
parents[x] = root(parents[x], parents)
return parents[x]
}
func TrialDivision(n int) map[int]int {
if n <= 1 {
panic(errors.New("[argument error]: TrialDivision only accepts a NATURAL number"))
}
p := map[int]int{}
for i := 2; i*i <= n; i++ {
exp := 0
for n%i == 0 {
exp++
n /= i
}
if exp == 0 {
continue
}
p[i] = exp
}
if n > 1 {
p[n] = 1
}
return p
}
func IsPrime(n int) bool {
if n == 1 {
return false
}
for i := 2; i*i <= n; i++ {
if n%i == 0 {
return false
}
}
return true
}
func CalcNegativeMod(val, m int) int {
res := val % m
if res < 0 {
res += m
}
return res
}
func modpow(a, e, m int) int {
if e == 0 {
return 1
}
if e%2 == 0 {
halfE := e / 2
half := modpow(a, halfE, m)
return half * half % m
}
return a * modpow(a, e-1, m) % m
}
func CalcModInv(a, m int) int {
return modpow(a, m-2, m)
}
type IntHeap []int
func (h IntHeap) Len() int { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
func (h *IntHeap) Push(x interface{}) {
*h = append(*h, x.(int))
}
func (h *IntHeap) Pop() interface{} {
old := *h
n := len(old)
x := old[n-1]
*h = old[0 : n-1]
return x
}
type Mono struct {
key, value int
}
type MonoList []*Mono
func (ml MonoList) Len() int {
return len(ml)
}
func (ml MonoList) Swap(i, j int) {
ml[i], ml[j] = ml[j], ml[i]
}
func (ml MonoList) Less(i, j int) bool {
return ml[i].value < ml[j].value
}
const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
var n, x int
var A []int
func main() {
n, x = ReadInt(), ReadInt()
A = ReadIntSlice(n)
sort.Sort(sort.IntSlice(A))
ans := 0
for i := 0; i < n; i++ {
if x >= A[i] {
ans++
x -= A[i]
} else {
break
}
}
if ans == n && x > 0 {
ans--
}
fmt.Println(ans)
}
| s032857139 | [
{
"input": "3 70\n20 30 10\n",
"output": "2\n"
}
] |
Go | codenet | package main
import (
"fmt"
)
func searchRange(text *string, start, limit int) (int, int, int) {
middle := -1
for i := start; i < limit; i++ {
if (*text)[i] != 'R' {
middle = i
break
}
}
end := limit
for i := middle; i < limit; i++ {
if (*text)[i] != 'L' {
end = i
break
}
}
return start, middle, end
}
func answer() {
var text string
fmt.Scan(&text)
limit := len(text)
start := 0
middle := 0
end := 0
firstPrinted := false
for end < limit {
start, middle, end = searchRange(&text, start, limit)
len1 := middle - start
len2 := end - middle
for i := start; i < middle-1; i++ {
if firstPrinted {
fmt.Print(" ")
}
fmt.Print("0")
firstPrinted = true
}
count1 := (len1+1)/2 + len2/2
count2 := len1/2 + (len2+1)/2
if firstPrinted {
fmt.Print(" ")
}
fmt.Printf("%v %v", count1, count2)
firstPrinted = true
for i := middle + 1; i < end; i++ {
if firstPrinted {
fmt.Print(" ")
}
fmt.Print("0")
firstPrinted = true
}
start = end
firstPrinted = true
}
fmt.Println()
}
func main() {
answer()
}
| s134607050 | [
{
"input": "RRLRL\n",
"output": "0 1 2 1 1\n"
}
] |
Go | codenet | package main
import (
"fmt"
"sort"
"strings"
)
func main() {
var s string
fmt.Scan(&s)
count := 0
var counter []int
if s == "" {
return
}
counter = append(counter, 0)
li := strings.Split(s, "")
for _, s := range li {
if s == "A" || s == "C" || s == "G" || s == "T" {
count++
} else {
counter = append(counter, count)
count = 0
}
}
counter = append(counter, count)
sort.Ints(counter)
fmt.Println(counter[len(counter)-1])
}
| s120583500 | [
{
"input": "ATCODER\n",
"output": "3\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var a, b, c int
fmt.Scanf("%d %d %d", &a, &b, &c)
if a < b && b < c {
fmt.Println("Yes")
} else {
fmt.Println("No")
}
return
}
| s344381425 | [
{
"input": "1 3 8\n",
"output": "Yes\n"
}
] |
Go | codenet | package main
import (
"fmt"
"math"
)
const inf = 10000000000.0
func main() {
var n int
fmt.Scan(&n)
arrA := make([]int, n)
for i := 0; i < n; i++ {
fmt.Scan(&arrA[i])
}
cumSumA := make([]int, n+1)
cumSumA[0] = 0
for i, a := range arrA {
cumSumA[i+1] = cumSumA[i] + a
}
ans := inf
for i := 1; i < n; i++ {
if math.Abs(float64(cumSumA[n]-(cumSumA[i]*2))) < ans {
ans = math.Abs(float64(cumSumA[n] - cumSumA[i]*2))
}
}
fmt.Println(int(ans))
}
| s716011659 | [
{
"input": "6\n1 2 3 4 5 6\n",
"output": "1\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"sort"
"strconv"
)
func main() {
scanner := bufio.NewScanner(os.Stdin)
scanner.Split(bufio.ScanWords)
N := ScanInt(scanner)
X := make([]int, N)
Y := make([]int, N)
for i := 0; i < N; i++ {
X[i] = ScanInt(scanner)
Y[i] = X[i]
}
sort.Sort(sort.IntSlice(Y))
m1 := Y[N/2-1]
m2 := Y[N/2]
for i := 0; i < N; i++ {
if X[i] <= m1 {
fmt.Println(m2)
} else {
fmt.Println(m1)
}
}
}
func ScanInt(scanner *bufio.Scanner) int {
scanner.Scan()
i, e := strconv.Atoi(scanner.Text())
if e != nil {
panic(e)
}
return i
}
func ScanFloat64(scanner *bufio.Scanner) float64 {
scanner.Scan()
f, e := strconv.ParseFloat(scanner.Text(), 64)
if e != nil {
panic(e)
}
return f
}
func ScanText(scanner *bufio.Scanner) string {
scanner.Scan()
return scanner.Text()
}
func Max(a, b int) int {
if a < b {
return b
}
return a
}
func Min(a, b int) int {
if a > b {
return b
}
return a
}
func Abs(a int) int {
if a < 0 {
a *= -1
}
return a
}
| s841275808 | [
{
"input": "4\n2 4 4 3\n",
"output": "4\n3\n3\n4\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func main() {
scanner := bufio.NewScanner(os.Stdin)
scanner.Split(bufio.ScanWords)
var c [3][3]int
var a, b [3]int
for i := 0; i < 3; i++ {
for j := 0; j < 3; j++ {
scanner.Scan()
c[i][j], _ = strconv.Atoi(scanner.Text())
}
}
b[0] = c[0][0] - a[0]
b[1] = c[0][1] - a[0]
b[2] = c[0][2] - a[0]
a[1] = c[1][0] - c[0][0]
a[2] = c[2][0] - c[0][0]
if a[1] == c[1][1]-c[0][1] && a[1] == c[1][2]-c[0][2] &&
a[2] == c[2][1]-c[0][1] && a[2] == c[2][2]-c[0][2] {
fmt.Println("Yes")
} else {
fmt.Println("No")
}
}
| s394238127 | [
{
"input": "1 0 1\n2 1 2\n1 0 1\n",
"output": "Yes\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var n int
var s string
fmt.Scan(&n, &s)
max := 0
cnt := 0
for _, r := range s {
if r == 'I' {
cnt++
} else {
cnt--
}
if cnt > max {
max = cnt
}
}
fmt.Println(max)
}
| s414601790 | [
{
"input": "5\nIIDID\n",
"output": "2\n"
}
] |
Go | codenet | package main
import (
"fmt"
)
func main() {
var N, K, R, S, P int
var T string
fmt.Scan(&N, &K, &R, &S, &P)
fmt.Scan(&T)
dict := map[string]int{"r": 0, "s": 0, "p": 0}
char := ""
s := make([]bool, N)
for i := 0; i < N; i++ {
s[i] = true
}
r := make([]bool, N)
p := make([]bool, N)
copy(r, s)
copy(p, s)
for i := 0; i < len(T); i++ {
char = T[i : i+1]
if i >= K {
if char == T[i-K:i+1-K] {
switch char {
case "s":
if s[i%K] {
s[i%K] = false
continue
} else {
s[i%K] = true
}
case "r":
if r[i%K] {
r[i%K] = false
continue
} else {
r[i%K] = true
}
case "p":
if p[i%K] {
p[i%K] = false
continue
} else {
p[i%K] = true
}
}
} else {
switch char {
case "s":
s[i%K] = true
case "r":
r[i%K] = true
case "p":
p[i%K] = true
}
}
}
switch char {
case "s":
dict["s"] = dict["s"] + 1
case "r":
dict["r"] = dict["r"] + 1
case "p":
dict["p"] = dict["p"] + 1
}
}
res := P*dict["r"] + S*dict["p"] + R*dict["s"]
fmt.Println(res)
}
| s934374308 | [
{
"input": "5 2\n8 7 6\nrsrpr\n",
"output": "27\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
for i := 0; i < 5; i++ {
var a int
fmt.Scan(&a)
if a == 0 {
fmt.Println(i + 1)
}
}
}
| s760945395 | [
{
"input": "0 2 3 4 5\n",
"output": "1\n"
}
] |
Go | codenet | package main
import (
"fmt"
)
func main() {
var a, b, c int
fmt.Scan(&a, &b, &c)
if b-a == c-b {
fmt.Println("YES")
} else {
fmt.Println("NO")
}
}
| s783520158 | [
{
"input": "2 4 6\n",
"output": "YES\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var x int
fmt.Scan(&x)
ans := 0
if x >= 400 && x <= 599 {
ans = 8
}
if x >= 600 && x <= 799 {
ans = 7
}
if x >= 800 && x <= 999 {
ans = 6
}
if x >= 1000 && x <= 1199 {
ans = 5
}
if x >= 1200 && x <= 1399 {
ans = 4
}
if x >= 1400 && x <= 1599 {
ans = 3
}
if x >= 1600 && x <= 1799 {
ans = 2
}
if x >= 1800 && x <= 9999 {
ans = 1
}
fmt.Println(ans)
}
| s808499721 | [
{
"input": "725\n",
"output": "7\n"
}
] |
Go | codenet | package main
import (
"fmt"
"sort"
)
func main() {
var n int
fmt.Scan(&n)
a := make([]int, n)
for i := 0; i < n; i++ {
fmt.Scan(&a[i])
}
s := make([]int, n+1)
for i := 0; i < n; i++ {
s[i+1] = s[i] + a[i]
}
sort.Sort(sort.IntSlice(s))
ans := 0
count := 0
for i := 0; i < n; i++ {
if s[i] == s[i+1] {
count++
} else if count > 0 {
ans += combi(count+1, 2)
count = 0
}
}
if count > 0 {
ans += combi(count+1, 2)
}
fmt.Println(ans)
}
func combi(n, r int) int {
c := 1
for i := 1; i <= r; i++ {
c = c * (n - i + 1) / i
}
return c
}
| s443186486 | [
{
"input": "6\n1 3 -4 2 2 -2\n",
"output": "3\n"
}
] |
Go | codenet | package main
import (
"fmt"
"strings"
)
func main() {
var s string
fmt.Scan(&s)
n := strings.Count(s, "o")
fmt.Println(700 + n*100)
}
| s235491884 | [
{
"input": "oxo\n",
"output": "900\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"sort"
"strconv"
)
func out(x ...interface{}) {
fmt.Println(x...)
}
var sc = bufio.NewScanner(os.Stdin)
func getInt() int {
sc.Scan()
i, e := strconv.Atoi(sc.Text())
if e != nil {
panic(e)
}
return i
}
func getString() string {
sc.Scan()
return sc.Text()
}
func max(a, b int) int {
if a > b {
return a
}
return b
}
func min(a, b int) int {
if a < b {
return a
}
return b
}
func asub(a, b int) int {
if a > b {
return a - b
}
return b - a
}
func abs(a int) int {
if a >= 0 {
return a
}
return -a
}
func main() {
sc.Split(bufio.ScanWords)
N, C, K := getInt(), getInt(), getInt()
t := make([]int, N)
for i := 0; i < N; i++ {
t[i] = getInt()
}
sort.Ints(t)
ans := 1
cnt := 1
end := t[0] + K
for i := 1; i < N; i++ {
if cnt < C && t[i] <= end {
cnt++
} else {
cnt = 1
end = t[i] + K
ans++
}
}
out(ans)
}
| s390866994 | [
{
"input": "5 3 5\n1\n2\n3\n6\n12\n",
"output": "3\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var K, X int
fmt.Scan(&K, &X)
if 500*K >= X {
fmt.Println("Yes")
} else {
fmt.Println("No")
}
}
| s101529434 | [
{
"input": "2 900\n",
"output": "Yes\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func main() {
N := nextInt()
h := nextInts(N)
dp := make([]int, N)
for i := 0; i < N; i++ {
dp[i] = 0
}
dp[1] = Abs(h[0] - h[1])
for i := 2; i < N; i++ {
dp[i] = Min([]int{dp[i-1] + Abs(h[i]-h[i-1]),
dp[i-2] + Abs(h[i]-h[i-2])})
}
fmt.Println(dp[N-1])
}
func Max(a []int) int {
r := a[0]
for i := 0; i < len(a); i++ {
if r < a[i] {
r = a[i]
}
}
return r
}
func Min(a []int) int {
r := a[0]
for i := 0; i < len(a); i++ {
if r > a[i] {
r = a[i]
}
}
return r
}
func Sum(a []int) (r int) {
for i := range a {
r += a[i]
}
return r
}
func Abs(a int) int {
if a < 0 {
return -a
}
return a
}
type Pair struct {
a, b int
}
type Pairs []Pair
func (p Pairs) Len() int {
return len(p)
}
func (p Pairs) Swap(i, j int) {
p[i], p[j] = p[j], p[i]
}
func (p Pairs) Less(i, j int) bool {
return p[i].b < p[j].b
}
var nextReader func() string
func init() {
nextReader = NewScanner()
}
func NewScanner() func() string {
r := bufio.NewScanner(os.Stdin)
r.Buffer(make([]byte, 1024), int(1e+11))
r.Split(bufio.ScanWords)
return func() string {
r.Scan()
return r.Text()
}
}
func nextString() string {
return nextReader()
}
func nextInt64() int64 {
v, _ := strconv.ParseInt(nextReader(), 10, 64)
return v
}
func nextInt() int {
v, _ := strconv.Atoi(nextReader())
return v
}
func nextInts(n int) []int {
r := make([]int, n)
for i := 0; i < n; i++ {
r[i] = nextInt()
}
return r
}
func nextStrings(n int) []string {
r := make([]string, n)
for i := 0; i < n; i++ {
r[i] = nextString()
}
return r
}
func nextFloat64() float64 {
f, _ := strconv.ParseFloat(nextReader(), 64)
return f
}
| s114239323 | [
{
"input": "4\n10 30 40 20\n",
"output": "30\n"
}
] |
Go | codenet | package main
import (
"fmt"
"strings"
)
func main() {
var n int
var s string
fmt.Scanf("%d", &n)
fmt.Scanf("%s", &s)
fmt.Printf("%d\n", strings.Count(s, "ABC"))
}
| s894183124 | [
{
"input": "10\nZABCDBABCQ\n",
"output": "2\n"
}
] |
Go | codenet | package main
import (
"bufio"
"errors"
"fmt"
"io"
"math"
"os"
"strconv"
)
var (
ReadString func() string
stdout *bufio.Writer
)
func init() {
ReadString = newReadString(os.Stdin)
stdout = bufio.NewWriter(os.Stdout)
}
func newReadString(ior io.Reader) func() string {
r := bufio.NewScanner(ior)
r.Buffer(make([]byte, 1024), int(1e+9))
r.Split(bufio.ScanWords)
return func() string {
if !r.Scan() {
panic("Scan failed")
}
return r.Text()
}
}
func ReadInt() int {
return int(readInt64())
}
func ReadInt2() (int, int) {
return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt64() int64 {
return readInt64()
}
func ReadInt64_2() (int64, int64) {
return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
return readInt64(), readInt64(), readInt64(), readInt64()
}
func readInt64() int64 {
i, err := strconv.ParseInt(ReadString(), 0, 64)
if err != nil {
panic(err.Error())
}
return i
}
func ReadIntSlice(n int) []int {
b := make([]int, n)
for i := 0; i < n; i++ {
b[i] = ReadInt()
}
return b
}
func ReadInt64Slice(n int) []int64 {
b := make([]int64, n)
for i := 0; i < n; i++ {
b[i] = ReadInt64()
}
return b
}
func ReadFloat64() float64 {
return float64(readFloat64())
}
func readFloat64() float64 {
f, err := strconv.ParseFloat(ReadString(), 64)
if err != nil {
panic(err.Error())
}
return f
}
func ReadFloat64Slice(n int) []float64 {
b := make([]float64, n)
for i := 0; i < n; i++ {
b[i] = ReadFloat64()
}
return b
}
func ReadRuneSlice() []rune {
return []rune(ReadString())
}
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
sn := fmt.Sprintf("%b", n)
residualLength := digitsNum - len(sn)
if residualLength <= 0 {
return []rune(sn)
}
zeros := make([]rune, residualLength)
for i := 0; i < len(zeros); i++ {
zeros[i] = '0'
}
res := []rune{}
res = append(res, zeros...)
res = append(res, []rune(sn)...)
return res
}
func ChMin(updatedValue *int, target int) bool {
if *updatedValue > target {
*updatedValue = target
return true
}
return false
}
func ChMax(updatedValue *int, target int) bool {
if *updatedValue < target {
*updatedValue = target
return true
}
return false
}
func NthBit(num, nth int) int {
return num >> uint(nth) & 1
}
func OnBit(num, nth int) int {
return num | (1 << uint(nth))
}
func OffBit(num, nth int) int {
return num & ^(1 << uint(nth))
}
func PopCount(num int) int {
res := 0
for i := 0; i < 70; i++ {
if ((num >> uint(i)) & 1) == 1 {
res++
}
}
return res
}
func Max(integers ...int) int {
m := integers[0]
for i, integer := range integers {
if i == 0 {
continue
}
if m < integer {
m = integer
}
}
return m
}
func Min(integers ...int) int {
m := integers[0]
for i, integer := range integers {
if i == 0 {
continue
}
if m > integer {
m = integer
}
}
return m
}
func DigitSum(n int) int {
if n < 0 {
return -1
}
res := 0
for n > 0 {
res += n % 10
n /= 10
}
return res
}
func DigitNumOfDecimal(n int) int {
res := 0
for n > 0 {
n /= 10
res++
}
return res
}
func Sum(integers ...int) int {
s := 0
for _, i := range integers {
s += i
}
return s
}
func Kiriage(a, b int) int {
return (a + (b - 1)) / b
}
func PowInt(a, e int) int {
if a < 0 || e < 0 {
panic(errors.New("[argument error]: PowInt does not accept negative integers"))
}
if e == 0 {
return 1
}
if e%2 == 0 {
halfE := e / 2
half := PowInt(a, halfE)
return half * half
}
return a * PowInt(a, e-1)
}
func AbsInt(a int) int {
if a < 0 {
return -a
}
return a
}
func Gcd(a, b int) int {
if a <= 0 || b <= 0 {
panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
}
if a < b {
a, b = b, a
}
for b > 0 {
div := a % b
a, b = b, div
}
return a
}
func Lcm(a, b int) int {
if a <= 0 || b <= 0 {
panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
}
gcd := Gcd(a, b)
return (a / gcd) * b
}
func Strtoi(s string) int {
if i, err := strconv.Atoi(s); err != nil {
panic(errors.New("[argument error]: Strtoi only accepts integer string"))
} else {
return i
}
}
func PrintIntsLine(A ...int) string {
res := []rune{}
for i := 0; i < len(A); i++ {
str := strconv.Itoa(A[i])
res = append(res, []rune(str)...)
if i != len(A)-1 {
res = append(res, ' ')
}
}
return string(res)
}
const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60
var memo [ALPHABET_NUM]int
var str string
func main() {
var sc = bufio.NewScanner(os.Stdin)
for {
if sc.Scan() {
str = sc.Text()
S := []rune(str)
if len(S) == 0 {
break
}
for i := 0; i < len(S); i++ {
c := S[i]
if 'a' <= c && c <= 'z' {
memo[c-'a']++
} else if 'A' <= c && c <= 'Z' {
memo[c-'A']++
} else {
continue
}
}
} else {
break
}
}
for i := 0; i < ALPHABET_NUM; i++ {
fmt.Printf("%c : %d\n", rune(i)+'a', memo[i])
}
}
| s635098814 | [
{
"input": "This is a pen.\n",
"output": "a : 1\nb : 0\nc : 0\nd : 0\ne : 1\nf : 0\ng : 0\nh : 1\ni : 2\nj : 0\nk : 0\nl : 0\nm : 0\nn : 1\no : 0\np : 1\nq : 0\nr : 0\ns : 2\nt : 1\nu : 0\nv : 0\nw : 0\nx : 0\ny : 0\nz : 0\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var A, B, C int
fmt.Scan(&A, &B, &C)
if A+B >= C {
fmt.Println("Yes")
} else {
fmt.Println("No")
}
}
| s469293815 | [
{
"input": "50 100 120\n",
"output": "Yes\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
)
var sc = bufio.NewScanner(os.Stdin)
func ri() (n int) {
sc.Scan()
for _, v := range sc.Bytes() {
n = n*10 + int(v-48)
}
return
}
func ave(s []float64) float64 {
var sum float64
for _, v := range s {
sum += v
}
return float64(sum) / float64(len(s))
}
func diff(a, b float64) float64 {
if a > b {
return a - b
}
return b - a
}
func main() {
sc.Split(bufio.ScanWords)
n := ri()
a := make([]float64, n)
for i := 0; i < n; i++ {
a[i] = float64(ri())
}
ave := ave(a)
minDiff := 999999.9
ansIndex := -1
for i, v := range a {
diff := diff(v, ave)
if diff < minDiff {
minDiff = diff
ansIndex = i
}
}
fmt.Println(ansIndex)
}
| s108967797 | [
{
"input": "3\n1 2 3\n",
"output": "1\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var n, m, x int
fmt.Scan(&n, &m, &x)
a := make([][]int, n)
p := make([]int, n)
for i := 0; i < n; i++ {
fmt.Scan(&p[i])
a[i] = make([]int, m)
for j := 0; j < m; j++ {
fmt.Scan(&a[i][j])
}
}
ans := 1200001
var tot int
var ok bool
for bits := 0; bits < 1<<n; bits++ {
tot = 0
ok = true
skill := make([]int, m)
for i := 0; i < n; i++ {
if (bits>>i)&1 == 1 {
tot += p[i]
for j := 0; j < m; j++ {
skill[j] += a[i][j]
}
}
}
for _, v := range skill {
if v < x {
ok = false
break
}
}
if ok {
if ans > tot {
ans = tot
}
}
}
if ans != 1200001 {
fmt.Println(ans)
} else {
fmt.Println("-1")
}
}
| s006130616 | [
{
"input": "3 3 10\n60 2 2 4\n70 8 7 9\n50 2 3 9\n",
"output": "120\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func main() {
sc := newInputScanner(true, 256)
N, P, S := sc.nextInt(), sc.nextInt(), sc.nextStr()
answer := checkSubNumbers(N, P, S)
fmt.Println(answer)
}
func checkSubNumbers(N int, P int, S string) int {
switch P {
case 2, 5:
return checkTwoOrFive(N, P, S)
default:
return checkNotTwoNorFive(N, P, S)
}
}
func checkTwoOrFive(N int, P int, S string) int {
answer := 0
var n int
for i := N - 1; i >= 0; i-- {
n, _ = strconv.Atoi(S[i : i+1])
if n%P == 0 {
answer += i + 1
}
}
return answer
}
func checkNotTwoNorFive(N int, P int, S string) int {
multiplier := 1
answer := 0
remainderLookup := make([]int, P)
prevRemaider := -1
var digit, remainder, count int
for i := N - 1; i >= 0; i-- {
digit = int(S[i] - '0')
if prevRemaider == -1 {
remainder = digit % P
} else {
remainder = (((multiplier * digit) % P) + prevRemaider) % P
}
if remainder == 0 {
answer++
}
count = remainderLookup[remainder]
answer += count
count++
remainderLookup[remainder] = count
prevRemaider = remainder
multiplier = (multiplier * 10) % P
}
return answer
}
type inputScanner struct {
*bufio.Scanner
}
func newInputScanner(enabledScanWords bool, sizeInKB int) *inputScanner {
scanner := bufio.NewScanner(os.Stdin)
if enabledScanWords {
scanner.Split(bufio.ScanWords)
}
capacity := sizeInKB * 1024
buf := make([]byte, capacity)
scanner.Buffer(buf, capacity)
return &inputScanner{
Scanner: scanner,
}
}
func (inputSc *inputScanner) nextInt() int {
i, e := strconv.Atoi(inputSc.nextStr())
if e != nil {
panic(e)
}
return i
}
func (inputSc *inputScanner) nextUInt64() uint64 {
i, e := strconv.ParseUint(inputSc.nextStr(), 10, 64)
if e != nil {
panic(e)
}
return i
}
func (inputSc *inputScanner) nextStr() string {
inputSc.Scan()
return inputSc.Text()
}
| s832289582 | [
{
"input": "4 3\n3543\n",
"output": "6\n"
}
] |
Go | codenet | package main
import (
"fmt"
)
func main() {
var n int
var x int
var l []int
fmt.Scan(&n)
fmt.Scan(&x)
for i := 0; i < n; i++ {
var tmpL int
fmt.Scan(&tmpL)
l = append(l, tmpL)
}
var tmpSum int
var rs int
for i, v := range l {
tmpSum += v
if i >= n {
rs = n
break
}
if tmpSum <= x {
rs = i + 2
} else if tmpSum > x {
break
}
}
fmt.Println(rs)
}
| s201528373 | [
{
"input": "3 6\n3 4 5\n",
"output": "2\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
)
const (
initialBufSize = 1e4
maxBufSize = 1e8
)
var sc = bufio.NewScanner(os.Stdin)
func init() {
buf := make([]byte, initialBufSize)
sc.Buffer(buf, maxBufSize)
sc.Split(bufio.ScanWords)
}
func next() string {
sc.Scan()
return sc.Text()
}
func min(x, y int) int {
if x > y {
return y
} else {
return x
}
}
func main() {
S := next()
l0, l1 := 0, 0
for i := 0; i < len(S); i++ {
if S[i] == '0' {
l0++
} else {
l1++
}
}
fmt.Println(2 * min(l0, l1))
}
| s801212431 | [
{
"input": "0011\n",
"output": "4\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var a, b, c, d, e int
fmt.Scan(&a, &b, &c, &d, &e)
al := []int{a, b, c, d, e}
for n, i := range al {
if i == 0 {
fmt.Println(n + 1)
break
}
}
}
| s672628848 | [
{
"input": "0 2 3 4 5\n",
"output": "1\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"sort"
"strconv"
)
func mainFn() {
n := getInt()
ls := getIntSlice(n)
lsRev := make([]int, n)
copy(lsRev, ls)
sort.Ints(ls)
sort.Sort(sort.Reverse(sort.IntSlice(lsRev)))
ans := 0
for i := 0; i < n; i++ {
for j := i + 1; j < n; j++ {
p, q := min(ls[i], ls[j]), max(ls[i], ls[j])
x, y := q-p, q+p
l := sort.Search(len(ls), func(i int) bool { return ls[i] > x })
r := n - sort.Search(len(lsRev), func(i int) bool { return lsRev[i] < y })
sum := r - l
if (i >= l) && (i <= r) {
sum--
}
if (j >= l) && (j <= r) {
sum--
}
sum = max(0, sum)
ans += sum
}
}
ans /= 3
puts(ans)
}
func min(a, b int) int {
if a < b {
return a
}
return b
}
func max(a, b int) int {
if a > b {
return a
}
return b
}
var (
scanner = bufio.NewScanner(os.Stdin)
writer = bufio.NewWriter(os.Stdout)
)
func main() {
scanner.Split(bufio.ScanWords)
mainFn()
writer.Flush()
}
func getInt() int {
scanner.Scan()
i, err := strconv.Atoi(scanner.Text())
if err != nil {
panic(err)
}
return i
}
func getIntSlice(n int) []int {
is := make([]int, n)
for i := range is {
is[i] = getInt()
}
return is
}
func getString() string {
scanner.Scan()
s := scanner.Text()
return s
}
func puts(a ...interface{}) {
if _, err := fmt.Fprintln(writer, a...); err != nil {
panic(err)
}
}
| s068639994 | [
{
"input": "4\n3 4 2 1\n",
"output": "1\n"
}
] |
Go | codenet | package main
import "fmt"
type data struct {
n, m int
nImg, mImg []string
}
func main() {
d := newData()
if d.exist() {
fmt.Println("Yes")
} else {
fmt.Println("No")
}
}
func newData() data {
var n, m int
fmt.Scanf("%d %d", &n, &m)
nImg := load(n)
mImg := load(m)
return data{n: n, m: m, nImg: nImg, mImg: mImg}
}
func load(cnt int) []string {
ret := make([]string, cnt)
for i := 0; i < cnt; i++ {
fmt.Scanf("%s", &ret[i])
}
return ret
}
func (d data) exist() bool {
for i := 0; i <= d.n-d.m; i++ {
for j := 0; j <= d.n-d.m; j++ {
if d.match(i, j) {
return true
}
}
}
return false
}
func (d data) match(x, y int) bool {
for i := 0; i < d.m; i++ {
for j := 0; j < d.m; j++ {
if d.nImg[x+i][y+j] != d.mImg[i][j] {
return false
}
}
}
return true
}
| s864554008 | [
{
"input": "3 2\n#.#\n.#.\n#.#\n#.\n.#\n",
"output": "Yes\n"
}
] |
Go | codenet | package main
import (
"fmt"
)
func solution(n int, a []int) int {
var memo [1e5 + 2]int
for _, num := range a {
memo[num]++
memo[num+1]++
memo[num+2]++
}
out := 0
for _, num := range memo {
if num > 0 {
out = max(out, num)
}
}
return out
}
func max(x, y int) int {
if x > y {
return x
}
return y
}
func main() {
var n int
fmt.Scan(&n)
a := make([]int, n)
for i := range a {
fmt.Scan(&a[i])
}
fmt.Println(solution(n, a))
}
| s054878611 | [
{
"input": "7\n3 1 4 1 5 9 2\n",
"output": "4\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"math"
"os"
"strconv"
)
var sc = bufio.NewScanner(os.Stdin)
func nextInt() int {
sc.Scan()
t, err := strconv.Atoi(sc.Text())
if err != nil {
panic(err)
}
return t
}
func scanNums(len int) (nums []int) {
var num int
for i := 0; i < len; i++ {
fmt.Scan(&num)
nums = append(nums, num)
}
return
}
func pattern1(l []int) int {
n := (l[0] * l[3]) + (l[1] * l[4])
return n
}
func pattern2(l []int) int {
n := 2 * l[2] * max(l[3], l[4])
return n
}
func pattern3(l []int) int {
n := 2*l[2]*min(l[3], l[4]) + (doch(l))
return n
}
func min(nums ...int) int {
if len(nums) == 0 {
panic("funciton min() requires at least one argument.")
}
res := nums[0]
for i := 0; i < len(nums); i++ {
res = int(math.Min(float64(res), float64(nums[i])))
}
return res
}
func max(nums ...int) int {
if len(nums) == 0 {
panic("funciton max() requires at least one argument.")
}
res := nums[0]
for i := 0; i < len(nums); i++ {
res = int(math.Max(float64(res), float64(nums[i])))
}
return res
}
func doch(l []int) int {
if l[3] > l[4] {
return l[0] * (l[3] - l[4])
} else {
return l[1] * (l[4] - l[3])
}
}
func main() {
len := 5
l := scanNums(len)
fmt.Println(min(pattern1(l), pattern2(l), pattern3(l)))
}
| s356695182 | [
{
"input": "1500 2000 1600 3 2\n",
"output": "7900\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
type Scanner struct {
sc *bufio.Scanner
}
func NewScanner() *Scanner {
sc := bufio.NewScanner(os.Stdin)
sc.Split(bufio.ScanWords)
sc.Buffer(make([]byte, 1024), int(1e+9))
return &Scanner{sc}
}
func (s *Scanner) nextStr() string {
s.sc.Scan()
return s.sc.Text()
}
func (s *Scanner) nextInt() int {
i, e := strconv.Atoi(s.nextStr())
if e != nil {
panic(e)
}
return i
}
func (s *Scanner) nextFloat() float64 {
f, e := strconv.ParseFloat(s.nextStr(), 64)
if e != nil {
panic(e)
}
return f
}
func (s *Scanner) nextRuneSlice() []rune {
return []rune(s.nextStr())
}
func (s *Scanner) nextIntSlice(n int) []int {
res := make([]int, n)
for i := 0; i < n; i++ {
res[i] = s.nextInt()
}
return res
}
func (s *Scanner) nextFloatSlice(n int) []float64 {
res := make([]float64, n)
for i := 0; i < n; i++ {
res[i] = s.nextFloat()
}
return res
}
func max(nums ...int) int {
m := nums[0]
for _, i := range nums {
if m < i {
m = i
}
}
return m
}
func min(nums ...int) int {
m := nums[0]
for _, i := range nums {
if m > i {
m = i
}
}
return m
}
func abs(x int) int {
if x > 0 {
return x
}
return -x
}
func pow(x, y int) int {
res := 1
for i := 0; i < y; i++ {
res *= x
}
return res
}
type Val struct {
id, num int
}
type ByNum []Val
func (a ByNum) Len() int { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func main() {
sc := NewScanner()
wtr := bufio.NewWriter(os.Stdout)
A, B, C, K := sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt()
ma := max(A, B, C)
rest := 0
if ma == A {
rest += B + C
} else if ma == B {
rest += A + C
} else {
rest += A + B
}
for i := 1; i <= K; i++ {
ma *= 2
}
fmt.Fprintln(wtr, ma+rest)
wtr.Flush()
}
| s211556675 | [
{
"input": "5 3 11\n1\n",
"output": "30\n"
}
] |
Go | codenet | package main
import (
"fmt"
"math"
)
func main() {
var n, m int
fmt.Scan(&n, &m)
x := m*1900 + (n-m)*100
fmt.Println(x * int(math.Pow(2.0, float64(m))))
}
| s739018217 | [
{
"input": "1 1\n",
"output": "3800\n"
}
] |