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"
)
func main() {
var A, B int
fmt.Scanln(&A, &B)
var ans int
if 6 <= A && A <= 12 {
ans = B / 2
} else if 12 < A {
ans = B
}
fmt.Println(ans)
}
| s909858822 | [
{
"input": "30 100\n",
"output": "100\n"
}
] |
Go | codenet | package main
import (
"fmt"
)
const d = 1000000007
func main() {
var n, p int
fmt.Scan(&n)
fmt.Scan(&p)
mdans := map[int64]int64{}
for index := 0; index < p; index++ {
var n1 int64
fmt.Scan(&n1)
mdans[n1] = n1
}
dp := make([]int64, n+1, n+1)
dp[0] = 1
dp[1] = 1
if _, ok := mdans[1]; ok {
dp[1] = 0
}
for i := 2; i <= n; i++ {
if _, ok := mdans[int64(i)]; ok {
continue
}
dp[i] = (dp[i-1] + dp[i-2]) % d
}
fmt.Printf("%#v\n", dp[n])
}
| s658739453 | [
{
"input": "6 1\n3\n",
"output": "4\n"
}
] |
Go | codenet | package main
import (
"fmt"
"sort"
)
func main() {
var N int
fmt.Scanf("%d", &N)
values := make([]float64, N)
for i := 0; i < N; i++ {
fmt.Scanf("%f", &values[i])
}
sort.Sort(sort.Float64Slice(values))
var generated float64
for i := 0; i < N-1; i++ {
generated = (values[i] + values[i+1]) / 2
values[i+1] = generated
}
fmt.Println(generated)
}
| s876981782 | [
{
"input": "2\n3 4\n",
"output": "3.5\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"sort"
)
func main() {
scanner := bufio.NewScanner(os.Stdin)
ns := make([]int, 4)
scanner.Scan()
fmt.Sscanf(scanner.Text(), "%d %d %d %d", &ns[0], &ns[1], &ns[2], &ns[3])
sort.Sort(sort.IntSlice(ns))
if ns[0] == 1 && ns[1] == 4 && ns[2] == 7 && ns[3] == 9 {
fmt.Println("YES")
} else {
fmt.Println("NO")
}
}
| s385901297 | [
{
"input": "1 7 9 4\n",
"output": "YES\n"
}
] |
Go | codenet | package main
import (
"fmt"
)
func main() {
var n int
fmt.Scan(&n)
as := make([]int, n)
ps := make(map[int]int)
for i := 0; i < n; i++ {
fmt.Scan(&as[i])
ns := primeFactorize(as[i])
for k, v := range ns {
ps[k] = max(ps[k], v)
}
}
x := 1
for k, v := range ps {
for i := 1; i <= v; i++ {
x = mul(x, k)
}
}
ans := 0
for i := 0; i < n; i++ {
ans = add(ans, div(x, as[i]))
}
fmt.Println(ans)
}
func max(a, b int) int {
if a > b {
return a
}
return b
}
func primeFactorize(n int) map[int]int {
res := make(map[int]int)
for i := 2; i*i <= n; i++ {
for n%i == 0 {
n /= i
res[i]++
}
}
if n != 1 {
res[n]++
}
return res
}
const mod int = 1000000007
func pow(n, k int) int {
if k == 0 {
return 1
} else if k%2 == 1 {
return pow(n, k-1) * n % mod
} else {
t := pow(n, k/2)
return t * t % mod
}
}
func add(a, b int) int {
return (a + b) % mod
}
func sub(a, b int) int {
return (a + mod - b) % mod
}
func mul(a, b int) int {
return a % mod * b % mod % mod
}
func div(a, b int) int {
return mul(a, pow(b, mod-2))
}
| s823623405 | [
{
"input": "3\n2 3 4\n",
"output": "13\n"
}
] |
Go | codenet | package main
import (
"fmt"
)
func gcd(a int, b int) int {
if b == 0 {
return a
}
return gcd(b, a%b)
}
func main() {
var k, a, b, c int
ans := 0
fmt.Scan(&k)
for a = 1; a <= k; a++ {
for b = 1; b <= k; b++ {
for c = 1; c <= k; c++ {
ans += gcd(a, gcd(b, c))
}
}
}
fmt.Println(ans)
}
| s513492399 | [
{
"input": "2\n",
"output": "9\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var s, t string
fmt.Scan(&s, &t)
fmt.Println(t + s)
}
| s430241485 | [
{
"input": "oder atc\n",
"output": "atcoder\n"
}
] |
Go | codenet | package main
import (
"fmt"
)
func min(n ...int) int {
if len(n) == 0 {
panic("len == 0")
}
r := n[0]
for i := 1; i < len(n); i++ {
if n[i] <= r {
r = n[i]
}
}
return r
}
func main() {
var H, N, A, B int
fmt.Scan(&H, &N)
dp := make([]int, H+10001)
for l := 1; l < H+10001; l++ {
dp[l] = 2100000000
}
amax := 0
for i := 0; i < N; i++ {
fmt.Scan(&A, &B)
if A >= amax {
amax = A
}
dp[A] = min(dp[A], B)
for j := A + 1; j <= H+A+1; j++ {
dp[j] = min(dp[j], dp[j-A]+B)
}
}
fmt.Println(min(dp[H : H+amax+1]...))
}
| s257493016 | [
{
"input": "9 3\n8 3\n4 2\n2 1\n",
"output": "4\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"sort"
"strconv"
)
func nextInt(sc *bufio.Scanner) int {
sc.Scan()
t, _ := strconv.Atoi(sc.Text())
return t
}
type point struct {
x, l, r int
}
type ps []point
func (p ps) Len() int {
return len(p)
}
func (p ps) Swap(i, j int) {
p[i], p[j] = p[j], p[i]
}
func (p ps) Less(i, j int) bool {
return p[i].r < p[j].r
}
func main() {
sc := bufio.NewScanner(os.Stdin)
sc.Split(bufio.ScanWords)
N := nextInt(sc)
points := make([]point, N)
for i := 0; i < N; i++ {
points[i].x = nextInt(sc)
L := nextInt(sc)
points[i].l = points[i].x - L
points[i].r = points[i].x + L
}
sort.Sort(ps(points))
start := points[0].r
ans := 1
for i := 0; i < len(points); i++ {
if points[i].l < start {
continue
}
start = points[i].r
ans++
}
fmt.Println(ans)
}
| s252511058 | [
{
"input": "4\n2 4\n4 3\n9 3\n100 5\n",
"output": "3\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"math"
"os"
"strconv"
"strings"
)
func main() {
n := nextInt()
rt := int(math.Sqrt(float64(n)))
minf := 100
for i := 1; i < rt+1; i++ {
if n%i == 0 {
b := n / i
ndigit := 0
for b > 0 {
b /= 10
ndigit++
}
minf = min(minf, ndigit)
}
}
fmt.Println(minf)
}
const size = 1000000
var reader = bufio.NewReaderSize(os.Stdin, size)
func nextLine() string {
var line, buffer []byte
isPrefix := true
var err error
for isPrefix {
line, isPrefix, err = reader.ReadLine()
if err != nil {
panic(err)
}
buffer = append(buffer, line...)
}
return string(buffer)
}
func nextStringArray() []string {
return strings.Split(nextLine(), " ")
}
func nextInt() int {
n, _ := strconv.Atoi(nextLine())
return n
}
func nextIntArray() []int {
s := strings.Split(nextLine(), " ")
n := len(s)
a := make([]int, n)
for i := 0; i < n; i++ {
a[i], _ = strconv.Atoi(s[i])
}
return a
}
func min(i, j int) int {
if i > j {
return j
}
return i
}
| s129617956 | [
{
"input": "10000\n",
"output": "3\n"
}
] |
Go | codenet | package main
import (
"fmt"
"sort"
)
func main() {
var n int
fmt.Scan(&n)
a := make([]float64, n)
for i := 0; i < n; i++ {
fmt.Scan(&a[i])
}
for i := 0; i+1 < n; i++ {
sort.Sort(sort.Float64Slice(a))
na := make([]float64, 0)
for j := 2; j < len(a); j++ {
na = append(na, a[j])
}
na = append(na, (a[0]+a[1])/2)
a = na
}
fmt.Println(a[0])
}
| s030204253 | [
{
"input": "2\n3 4\n",
"output": "3.5\n"
}
] |
Go | codenet | package main
import (
"fmt"
)
func main() {
var s string
fmt.Scan(&s)
max_tmp := 0
max := 0
for i := 0; i < len(s); i++ {
flag := false
switch string(s[i]) {
case "A", "C", "T", "G":
max_tmp++
default:
flag = true
}
if i == len(s)-1 {
flag = true
}
if flag == true {
if max < max_tmp {
max = max_tmp
}
max_tmp = 0
}
}
fmt.Println(max)
}
| s001472496 | [
{
"input": "ATCODER\n",
"output": "3\n"
}
] |
Go | codenet | package main
import (
"bufio"
"container/heap"
"fmt"
"os"
)
const Inf = 1 << 60
func main() {
H, W, K := ReadInt(), ReadInt(), ReadInt()
x1, y1, x2, y2 := ReadInt()-1, ReadInt()-1, ReadInt()-1, ReadInt()-1
x1, y1 = y1, x1
x2, y2 = y2, x2
c := make([]string, H)
for y := 0; y < H; y++ {
c[y] = ReadString()
}
var dx = []int{1, 0, -1, 0}
var dy = []int{0, 1, 0, -1}
toID := func(x, y, dir int) int {
return 4*(W*y+x) + dir
}
splatID := func(id int) (x, y, dir int) {
return id / 4 % W, id / 4 / W, id % 4
}
dist := make([]int, W*H*4)
for i := 0; i < W*H*4; i++ {
dist[i] = Inf
}
q := Heap{}
for i := 0; i < 4; i++ {
q = append(q, State{
Cost: 0,
ID: toID(x1, y1, i),
})
}
for len(q) > 0 {
now := q.pop()
x, y, dir := splatID(now.ID)
if c[y][x] == '@' {
continue
}
if dist[now.ID] <= now.Cost {
continue
}
dist[now.ID] = now.Cost
if x == x2 && y == y2 {
break
}
for i := 0; i < 4; i++ {
nCost := (now.Cost + K - 1) / K * K
nID := toID(x, y, i)
if dist[nID] <= nCost {
continue
}
q.push(State{
Cost: nCost,
ID: nID,
})
}
nx := x + dx[dir]
ny := y + dy[dir]
if 0 <= nx && nx < W && 0 <= ny && ny < H {
nCost := now.Cost + 1
nID := toID(nx, ny, dir)
if dist[nID] <= nCost {
continue
}
q.push(State{
Cost: nCost,
ID: nID,
})
}
}
ans := Inf
for i := 0; i < 4; i++ {
id := toID(x2, y2, i)
if dist[id] < ans {
d2 := (dist[id] + K - 1) / K
if d2 < ans {
ans = d2
}
}
}
if ans < Inf {
fmt.Println(ans)
} else {
fmt.Println(-1)
}
}
type State struct {
Cost, ID int
}
type HeapElement = State
type Heap []HeapElement
func (h Heap) Less(i, j int) bool { return h[i].Cost < h[j].Cost }
func (h Heap) Len() int { return len(h) }
func (h Heap) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
func (h *Heap) Push(x interface{}) { *h = append(*h, x.(HeapElement)) }
func (h *Heap) Pop() (x interface{}) { *h, x = (*h)[:len(*h)-1], (*h)[len(*h)-1]; return }
func (h *Heap) push(v HeapElement) { heap.Push(h, v) }
func (h *Heap) pop() HeapElement { return heap.Pop(h).(HeapElement) }
var reader = bufio.NewReader(os.Stdin)
func Scan(a ...interface{}) {
if _, err := fmt.Fscan(reader, a...); err != nil {
panic(err)
}
}
func ReadInt() (i int) { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
v := make([]int, n)
for i := 0; i < n; i++ {
Scan(&v[i])
}
return v
}
| s940441641 | [
{
"input": "3 5 2\n3 2 3 4\n.....\n.@..@\n..@..\n",
"output": "5\n"
}
] |
Go | codenet | package main
import (
"fmt"
"sort"
"strings"
)
type city struct {
prefecture int
position int
year int
}
type cities []*city
type cMap map[int]cities
func main() {
var (
n, m int
)
fmt.Scanf("%d %d\n", &n, &m)
h := make(cMap)
for i := 0; i < m; i++ {
var x, y int
fmt.Scanf("%d %d\n", &x, &y)
_, exists := h[x]
if !exists {
h[x] = cities{{prefecture: x, year: y, position: i}}
} else {
h[x] = append(h[x], &city{prefecture: x, year: y, position: i})
}
}
results := make([]string, m)
for _, v := range h {
sort.Sort(v)
for idx, ci := range v {
results[ci.position] = fmt.Sprintf("%06d%06d", ci.prefecture, idx+1)
}
}
fmt.Println(strings.Join(results, "\n"))
}
func (c cities) Len() int {
return len(c)
}
func (c cities) Swap(i, j int) {
c[i], c[j] = c[j], c[i]
}
func (c cities) Less(i, j int) bool {
return c[i].year < c[j].year
}
| s865387202 | [
{
"input": "2 3\n1 32\n2 63\n1 12\n",
"output": "000001000002\n000002000001\n000001000001\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func main() {
sc := NewScanner()
A, B := sc.NextInt(), sc.NextInt()
mx := max(A+B, A-B)
mx = max(mx, A*B)
fmt.Println(mx)
}
func max(a int, b int) int {
if a < b {
return b
}
return a
}
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) NextInt64() int64 {
v, _ := strconv.ParseInt(s.Next(), 10, 64)
return v
}
func (s *Scanner) NextFloat() float64 {
v, _ := strconv.ParseFloat(s.Next(), 64)
return v
}
func (s *Scanner) NextIntArray() []int {
s.pre()
start := s.p
result := []int{}
for ; s.p < len(s.buf)+1; s.p++ {
if s.p == len(s.buf) || s.buf[s.p] == ' ' {
v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
result = append(result, int(v))
start = s.p + 1
}
}
return result
}
func (s *Scanner) NextInt64Array() []int64 {
s.pre()
start := s.p
result := []int64{}
for ; s.p < len(s.buf)+1; s.p++ {
if s.p == len(s.buf) || s.buf[s.p] == ' ' {
v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
result = append(result, v)
start = s.p + 1
}
}
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
}
}
}
| s913685556 | [
{
"input": "-13 3\n",
"output": "-10\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
func main() {
sc := newScanner()
S := sc.next()
if strings.HasPrefix(S, "YAKI") {
fmt.Println("Yes")
} else {
fmt.Println("No")
}
}
func min(a, b int) int {
if a > b {
return b
}
return a
}
func max(a, b int) int {
if a > b {
return a
}
return b
}
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)+1; s.p++ {
if s.p == len(s.buf) || s.buf[s.p] == ' ' {
v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
result = append(result, int(v))
start = s.p + 1
}
}
return result
}
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
}
}
}
| s048939108 | [
{
"input": "YAKINIKU\n",
"output": "Yes\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"sort"
"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
}
func ceil(a, b int) int {
if a%b == 0 {
return a / b
} else {
return a/b + 1
}
}
type RuneSlice []rune
func (a RuneSlice) Len() int { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
const MOD = int(1e+9) + 7
const INF = 1 << 60
type Mon struct {
x, h int
}
type Mons []Mon
func (a Mons) Len() int { return len(a) }
func (a Mons) Less(i, j int) bool { return a[i].x < a[j].x }
func (a Mons) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
type Node struct {
x, h int
}
type Queue struct {
arr []Node
}
func (q *Queue) push(v Node) {
q.arr = append(q.arr, v)
}
func (q *Queue) first() Node {
return q.arr[0]
}
func (q *Queue) pop() Node {
res := q.arr[0]
q.arr = q.arr[1:]
return res
}
func (q *Queue) isEmpty() bool {
return len(q.arr) == 0
}
func main() {
sc := NewScanner()
wtr := bufio.NewWriter(os.Stdout)
N, D, A := sc.nextInt(), sc.nextInt(), sc.nextInt()
M := make([]Mon, N)
for i := 0; i < N; i++ {
M[i] = Mon{sc.nextInt(), sc.nextInt()}
}
sort.Sort(Mons(M))
var q Queue
ans := 0
total := 0
for i := 0; i < N; i++ {
m := M[i]
for !q.isEmpty() && q.first().x < m.x {
total -= q.pop().h
}
if total < m.h {
m.h -= total
count := ceil(m.h, A)
ans += count
damage := count * A
q.push(Node{m.x + 2*D, damage})
total += damage
}
}
fmt.Fprintln(wtr, ans)
wtr.Flush()
}
| s512742019 | [
{
"input": "3 3 2\n1 2\n5 4\n9 2\n",
"output": "2\n"
}
] |
Go | codenet | package main
import (
"fmt"
)
func main() {
var a, b int
fmt.Scan(&a, &b)
fmt.Println(a*b, (a+b)*2)
}
| s102334995 | [
{
"input": "3 5\n",
"output": "15 16\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
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 main() {
sc.Split(bufio.ScanWords)
appleNum := nextInt()
pieceNum := nextInt()
pieceNumMadeFromApples := appleNum * 3
totalPiece := pieceNumMadeFromApples + pieceNum
fmt.Println(totalPiece / 2)
}
| s822496038 | [
{
"input": "1 3\n",
"output": "3\n"
}
] |
Go | codenet | package main
import (
"fmt"
"math"
)
func walkOnMultiplicationTable(num int) int {
div := 0
for i := int(math.Sqrt(float64(num))); i > 1; i-- {
if num%i == 0 {
div = i
break
}
}
if div == 0 {
return num - 1
}
return div + num/div - 2
}
func main() {
var a int
fmt.Scan(&a)
fmt.Println(walkOnMultiplicationTable(a))
}
| s363337466 | [
{
"input": "10\n",
"output": "5\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var a, b int
fmt.Scan(&a, &b)
if product := a * b; product%2 == 0 {
fmt.Println("Even")
} else {
fmt.Println("Odd")
}
}
| s150867340 | [
{
"input": "3 4\n",
"output": "Even\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
var sc = bufio.NewScanner(os.Stdin)
func read() string {
sc.Scan()
return sc.Text()
}
func main() {
sc.Split(bufio.ScanWords)
a, _ := strconv.Atoi(read())
b, _ := strconv.Atoi(read())
ret := a + b
if ret < (a - b) {
ret = a - b
}
if ret < (a * b) {
ret = a * b
}
fmt.Println(ret)
}
| s577481826 | [
{
"input": "3 1\n",
"output": "4\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"log"
"os"
"strconv"
)
func check(e error) {
if e != nil {
log.Fatalf("error: %v", e)
}
}
func main() {
stdin := bufio.NewScanner(os.Stdin)
stdin.Scan()
sage := stdin.Text()
switch sage {
case "1":
fmt.Println("Hello World")
case "2":
var sum int
for i := 0; i < 2; i++ {
stdin.Scan()
num, err := strconv.Atoi(stdin.Text())
check(err)
sum += num
}
fmt.Println(sum)
}
}
| s141943854 | [
{
"input": "1\n",
"output": "Hello World\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var a, b, c int
fmt.Scan(&a, &b, &c)
if c >= a && c <= b {
fmt.Println("Yes")
} else {
fmt.Println("No")
}
}
| s870102598 | [
{
"input": "1 3 2\n",
"output": "Yes\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
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 os.Getenv("MASPY") == "ますピ" {
fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
}
if os.Getenv("MASPYPY") == "ますピッピ" {
wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
}
scanner := getScanner(fp)
writer := bufio.NewWriter(wfp)
s := getNextString(scanner)
t := getNextString(scanner)
ns := len(s)
nt := len(t)
ss := make([]string, (nt-1)/ns+1)
for i := 0; i < len(ss); i++ {
ss[i] = s
}
sss := fmt.Sprintf("%s%s", strings.Join(ss, ""), strings.Join(ss, ""))
ok := make([]bool, ns)
uni := make([]int, ns)
mp := MP{}
mp.init(t)
m := 0
for i := 0; i < ns; i++ {
uni[i] = i
}
var o bool
for i := 0; i < ns; i++ {
o = true
for m < nt {
if t[m] != sss[i+m] {
o = false
break
}
m++
}
ok[i] = o
if o {
i += nt - mp.table[m]
m = mp.table[m]
}
for m >= 0 && t[m] != sss[i+m] {
i += m - mp.table[m]
m = mp.table[m]
}
i--
m++
}
ans := 0
var r, rr int
for i := 0; i < ns; i++ {
if ok[i] == false {
continue
}
if ok[(i+nt)%ns] == false {
continue
}
r = root(i, uni)
rr = root((i+nt)%ns, uni)
if rr == r {
fmt.Println(-1)
return
}
uni[rr] = r
}
counter := make([]int, ns)
for i := 0; i < ns; i++ {
r = root(i, uni)
if ok[r] == false {
continue
}
counter[r]++
}
for i := 0; i < ns; i++ {
if ans < counter[i] {
ans = counter[i]
}
}
fmt.Println(ans)
writer.Flush()
}
func root(i int, uni []int) int {
if i == uni[i] {
return i
}
uni[i] = root(uni[i], uni)
return uni[i]
}
type MP struct {
s string
table []int
}
func (mp *MP) init(s string) {
mp.s = s
n := len(s)
table := make([]int, n+1)
table[0] = -1
j := -1
for i := 0; i < n; i++ {
for j >= 0 && s[i] != s[j] {
j = table[j]
}
j++
table[i+1] = j
}
mp.table = table
}
| s050367086 | [
{
"input": "abcabab\nab\n",
"output": "3\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
var sc = bufio.NewScanner(os.Stdin)
func next() string {
sc.Scan()
return sc.Text()
}
func nextInt() int {
sc.Scan()
i, _ := strconv.Atoi(sc.Text())
return i
}
func nextFloat64() float64 {
f, _ := strconv.ParseFloat(next(), 64)
return f
}
func nextInts(n int) []int {
slice := make([]int, n)
for i := 0; i < n; i++ {
slice[i] = nextInt()
}
return slice
}
func main() {
sc.Split(bufio.ScanWords)
if nextInt()+nextInt() >= nextInt() {
fmt.Println("Yes")
} else {
fmt.Println("No")
}
}
| s596502954 | [
{
"input": "50 100 120\n",
"output": "Yes\n"
}
] |
Go | codenet | package main
import (
"fmt"
"unicode"
)
func main() {
var s string
fmt.Scan(&s)
l := len(s)
ans := "AC"
if s[0] != 'A' {
ans = "WA"
}
cnt := 0
for i := 1; i < l; i++ {
if unicode.IsUpper(rune(s[i])) {
if i == 1 || i == l-1 || s[i] != 'C' {
ans = "WA"
}
cnt++
}
}
if cnt != 1 {
ans = "WA"
}
fmt.Println(ans)
}
| s192968897 | [
{
"input": "AtCoder\n",
"output": "AC\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
var sc = bufio.NewScanner(os.Stdin)
func nextLine() string {
sc.Scan()
return sc.Text()
}
func main() {
sc.Split(bufio.ScanWords)
var a, _ = strconv.Atoi(nextLine())
var b, _ = strconv.Atoi(nextLine())
if a*b%2 != 0 {
fmt.Println("Odd")
} else {
fmt.Println("Even")
}
}
| s255858499 | [
{
"input": "3 4\n",
"output": "Even\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var a, b int
fmt.Scan(&a, &b)
if b%a == 0 {
fmt.Println(a + b)
} else {
fmt.Println(b - a)
}
}
| s969060017 | [
{
"input": "4 12\n",
"output": "16\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
var sc = bufio.NewScanner(os.Stdin)
func scanInt() int {
num, _ := strconv.Atoi(scanString())
return num
}
func scanString() string {
sc.Scan()
return sc.Text()
}
func scanInts(n int) []int {
sl := make([]int, n)
for i := range sl {
sl[i] = scanInt()
}
return sl
}
func scanStrings(n int) []string {
sl := make([]string, n)
for i := range sl {
sl[i] = scanString()
}
return sl
}
func init() {
sc.Split(bufio.ScanWords)
}
func main() {
r, D, x := scanInt(), scanInt(), scanInt()
for i := 1; i <= 10; i++ {
x = r*x - D
fmt.Println(x)
}
}
| s187065108 | [
{
"input": "2 10 20\n",
"output": "30\n50\n90\n170\n330\n650\n1290\n2570\n5130\n10250\n"
}
] |
Go | codenet | package main
import (
"fmt"
)
func min(nums ...int) int {
min := nums[0]
for _, v := range nums {
if v < min {
min = v
}
}
return min
}
func main() {
var n, a, b int
fmt.Scan(&n, &a, &b)
fmt.Println(min(n*a, b))
}
| s984400335 | [
{
"input": "7 17 120\n",
"output": "119\n"
}
] |
Go | codenet | package main
import (
"fmt"
"strings"
)
func main() {
var n int
var s string
fmt.Scan(&n, &s)
fmt.Println(strings.Count(s, "ABC"))
}
| s695527706 | [
{
"input": "10\nZABCDBABCQ\n",
"output": "2\n"
}
] |
Go | codenet | package main
import (
"bufio"
"bytes"
"fmt"
"os"
"strconv"
"strings"
)
type node struct {
key int32
prev *node
next *node
}
func (n *node) rPrint(buf *bytes.Buffer) {
buf.WriteString(fmt.Sprint(n.key))
if n.next != nil {
buf.WriteString(" ")
n.next.rPrint(buf)
}
return
}
func (n *node) Delete(first, last *node) (*node, *node) {
if n.prev != nil && n.next != nil {
n.prev.next = n.next
n.next.prev = n.prev
return first, last
}
if n.next == nil && n.prev == nil {
return nil, nil
}
if n.prev == nil {
first = n.next
n.next.prev = nil
}
if n.next == nil {
last = n.prev
n.prev.next = nil
}
return first, last
}
func initNode(key int32) *node {
return &node{
key: key,
}
}
func main() {
stdin := bufio.NewScanner(os.Stdin)
var first, last *node
stdin.Scan()
for stdin.Scan() {
cmd := stdin.Text()
switch cmd {
case "deleteFirst":
first, last = first.Delete(first, last)
case "deleteLast":
first, last = last.Delete(first, last)
default:
xcmd := strings.Split(cmd, " ")
k, _ := strconv.Atoi(xcmd[1])
k32 := int32(k)
switch xcmd[0] {
case "delete":
for a := first; a != nil; a = a.next {
if a.key == k32 {
first, last = a.Delete(first, last)
break
}
}
case "insert":
n := initNode(k32)
n.next = first
if first != nil {
first.prev = n
}
first = n
if last == nil {
last = n
}
}
}
}
var buf bytes.Buffer
first.rPrint(&buf)
fmt.Println(buf.String())
}
| s269502139 | [
{
"input": "7\ninsert 5\ninsert 2\ninsert 3\ninsert 1\ndelete 3\ninsert 6\ndelete 5\n",
"output": "6 1 2\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
func main() {
input := Input{bufio.NewReaderSize(os.Stdin, 1000000)}
n := input.NextInt()
s := input.NextIntArray()
u := make([]bool, n)
var m, f int64
for c := 1; c < n-1; c++ {
f = 0
for k := 0; c < n-1-k*c; k++ {
u[k*c] = true
if u[n-1-k*c] {
break
}
f += s[n-1-k*c] + s[k*c]
if m < f {
m = f
}
}
for k := 0; k*c < n-1; k++ {
u[k*c] = false
}
}
fmt.Println(m)
}
type Input struct {
reader *bufio.Reader
}
func (i *Input) NextLine() string {
var buffer []byte
for {
line, isPrefix, err := i.reader.ReadLine()
if err != nil {
panic(err)
}
buffer = append(buffer, line...)
if !isPrefix {
break
}
}
return string(buffer)
}
func (i *Input) NextInt() int {
n, _ := strconv.Atoi(i.NextLine())
return n
}
func (i *Input) NextIntArray() []int64 {
s := strings.Split(i.NextLine(), " ")
a := make([]int64, len(s))
for i := 0; i < len(s); i++ {
a[i], _ = strconv.ParseInt(s[i], 10, 64)
}
return a
}
| s447509781 | [
{
"input": "5\n0 2 5 1 0\n",
"output": "3\n"
}
] |
Go | codenet | package main
import (
"fmt"
"math"
)
func main() {
var N, M int
var ans int
fmt.Scan(&N, &M)
if N == 1 && M == 1 {
ans += 1
} else if 1 < N && 1 < M {
ans += (N - 2) * (M - 2)
} else {
ans += (N * M) - 2
}
fmt.Println(ans)
}
func max(x ...int) int {
var res int = x[0]
for i := 1; i < len(x); i++ {
res = int(math.Max(float64(x[i]), float64(res)))
}
return res
}
func min(x ...int) int {
var res int = x[0]
for i := 1; i < len(x); i++ {
res = int(math.Min(float64(x[i]), float64(res)))
}
return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int { return int(math.Abs(float64(x))) }
func floor(x int) int { return int(math.Floor(float64(x))) }
type SortBy []int
func (a SortBy) Len() int { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return abs(a[i]) < abs(a[j]) }
| s870655271 | [
{
"input": "2 2\n",
"output": "0\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
)
type deque struct {
front, back []byte
}
func (deq *deque) isEmptyFront() bool {
return len(deq.front) == 0
}
func (deq *deque) isEmptyBack() bool {
return len(deq.back) == 0
}
func (deq *deque) pushBack(v byte) {
deq.back = append(deq.back, v)
}
func (deq *deque) pushFront(v byte) {
deq.front = append(deq.front, v)
}
func (deq *deque) popBack(v *byte) bool {
r := true
if !deq.isEmptyBack() {
*v = deq.back[len(deq.back)-1]
deq.back = deq.back[:len(deq.back)-1]
} else if !deq.isEmptyFront() {
*v = deq.front[0]
deq.front = deq.front[1:]
} else {
r = false
}
return r
}
func (deq *deque) popFront(v *byte) bool {
r := true
if !deq.isEmptyFront() {
*v = deq.front[len(deq.front)-1]
deq.front = deq.front[:len(deq.front)-1]
} else if !deq.isEmptyBack() {
*v = deq.back[0]
deq.back = deq.back[1:]
} else {
r = false
}
return r
}
func (deq *deque) get(idx int) byte {
tot := len(deq.front) + len(deq.back)
var v byte
if idx < tot {
if idx < len(deq.front) {
v = deq.front[len(deq.front)-1-idx]
} else {
v = deq.back[idx-len(deq.front)]
}
}
return v
}
type op struct {
rev, front bool
c byte
}
func rev(s string) string {
r := make([]byte, len(s))
i, j := len(s)-1, 0
for i >= 0 {
r[j] = s[i]
j++
i--
}
return string(r)
}
func main() {
var S string
fmt.Scan(&S)
var Q int
fmt.Scan(&Q)
ops := make([]op, Q)
for i := 0; i < Q; i++ {
var q int
fmt.Scan(&q)
if q == 1 {
ops[i].rev = true
} else {
var f int
fmt.Scanf("%d %c", &f, &ops[i].c)
if f == 1 {
ops[i].front = true
}
}
}
sum := make([]int, Q+1)
for i := Q - 1; i >= 1; i-- {
if ops[i].rev {
sum[i-1] = sum[i] + 1
} else {
sum[i-1] = sum[i]
}
}
if sum[0]%2 == 1 {
S = rev(S)
}
var deq deque
for i := 0; i < Q; i++ {
if !ops[i].rev {
if ops[i].front {
if sum[i]%2 == 1 {
deq.pushBack(ops[i].c)
} else {
deq.pushFront(ops[i].c)
}
} else {
if sum[i]%2 == 1 {
deq.pushFront(ops[i].c)
} else {
deq.pushBack(ops[i].c)
}
}
}
}
wtr := bufio.NewWriter(os.Stdout)
for i := len(deq.front) - 1; i >= 0; i-- {
fmt.Fprint(wtr, string(deq.front[i]))
}
for i := 0; i < len(S); i++ {
fmt.Fprint(wtr, string(S[i]))
}
for i := 0; i < len(deq.back); i++ {
fmt.Fprint(wtr, string(deq.back[i]))
}
fmt.Fprintln(wtr)
wtr.Flush()
}
| s323794848 | [
{
"input": "a\n4\n2 1 p\n1\n2 2 c\n1\n",
"output": "cpa\n"
}
] |
Go | codenet | package main
import (
"fmt"
)
func main() {
var data int
fmt.Scan(&data)
var result = data * data * data
fmt.Printf("%d\n", result)
}
| s136583229 | [
{
"input": "2\n",
"output": "8\n"
}
] |
Go | codenet | package main
import (
"fmt"
)
func main() {
var a, b, h int
fmt.Scan(&a, &b, &h)
fmt.Println((a + b) * h / 2)
}
| s589878052 | [
{
"input": "3\n4\n2\n",
"output": "7\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func getNextWord(scanner *bufio.Scanner) string {
scanner.Scan()
return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
i, _ := strconv.Atoi(getNextWord(scanner))
return i
}
func main() {
fp := os.Stdin
if len(os.Args) > 1 {
fp, _ = os.Open(os.Args[1])
}
scanner := bufio.NewScanner(fp)
scanner.Split(bufio.ScanWords)
writer := bufio.NewWriter(os.Stdout)
n := getNextInt(scanner)
m := getNextInt(scanner)
aa := make(map[int]int, 0)
for i := 0; i < m; i++ {
aa[getNextInt(scanner)] = 1
}
dp := make([]int, n+1)
dp[0] = 1
for i := 0; i < n; i++ {
for ii := 1; ii <= 2 && i+ii <= n; ii++ {
_, ok := aa[i+ii]
if ok {
continue
}
dp[i+ii] += dp[i]
dp[i+ii] %= 1000000007
}
}
fmt.Fprintln(writer, dp[n])
writer.Flush()
}
| s546282715 | [
{
"input": "6 1\n3\n",
"output": "4\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var s string
fmt.Scan(&s)
price := 700
for _, c := range s {
if c == 'o' {
price += 100
}
}
fmt.Println(price)
}
| s774791701 | [
{
"input": "oxo\n",
"output": "900\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
const mod = 1000000007
const ioBufferSize = 1 * 1024 * 1024
var sc = func() *bufio.Scanner {
sc := bufio.NewScanner(os.Stdin)
sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
sc.Split(bufio.ScanWords)
return sc
}()
func next() 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() {
h, n := nextInt(), nextInt()
a := 0
for i := 0; i < n; i++ {
a += nextInt()
}
if h > a {
fmt.Println("No")
} else {
fmt.Println("Yes")
}
}
| s464350089 | [
{
"input": "10 3\n4 5 6\n",
"output": "Yes\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var n, k int
fmt.Scanf("%d %d\n", &n, &k)
if k <= (n+n%2)/2 {
fmt.Println("YES")
} else {
fmt.Println("NO")
}
}
| s584033358 | [
{
"input": "3 2\n",
"output": "YES\n"
}
] |
Go | codenet | package main
import (
_ "bufio"
"fmt"
_ "os"
_ "strconv"
)
func main() {
var x, a, b int
fmt.Scan(&x, &a, &b)
switch {
case b-a <= 0:
fmt.Println("delicious")
break
case b-a <= x:
fmt.Println("safe")
break
default:
fmt.Println("dangerous")
break
}
}
| s693332680 | [
{
"input": "4 3 6\n",
"output": "safe\n"
}
] |
Go | codenet | package main
import (
"fmt"
)
func comp(x, a int) int {
if x < a {
return 0
}
return 10
}
func main() {
var x, a int
fmt.Scan(&x, &a)
fmt.Println(comp(x, a))
}
| s506882149 | [
{
"input": "3 5\n",
"output": "0\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"math"
"os"
"strconv"
)
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)
sc.Split(bufio.ScanWords)
return sc
}()
)
func main() {
N := getInt()
sqrtN := int(math.Sqrt(float64(N)))
min := N
for i := 1; i <= sqrtN; i++ {
if N%i != 0 {
continue
}
num := i + (N / i) - 2
if num < min {
min = num
}
}
fmt.Println(min)
}
type Graph struct {
n int
edges [][]int
}
func NewGraph(n int) *Graph {
g := &Graph{
n: n,
edges: make([][]int, n),
}
return g
}
func (g *Graph) AddEdge(u, v int) {
g.edges[v] = append(g.edges[v], u)
g.edges[u] = append(g.edges[u], v)
}
func dfs(c int, edges [][]int, visited map[int]struct{}) {
visited[c] = struct{}{}
for _, v := range edges[c] {
_, flag := visited[v]
if flag {
continue
}
dfs(v, edges, visited)
}
}
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 powMod(n, p int) int {
if p == 0 {
return 1
} else if p%2 == 0 {
t := powMod(n, p/2)
return calcMod(t * t)
} else {
return calcMod(n * powMod(n, p-1))
}
}
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
}
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 isPrime(n int) bool {
if n < 2 {
return false
} else if n == 2 {
return true
} else if n%2 == 0 {
return false
}
sqrtN := int(math.Sqrt(float64(n)))
for i := 3; i <= sqrtN; i += 2 {
if n%i == 0 {
return false
}
}
return true
}
| s824350268 | [
{
"input": "10\n",
"output": "5\n"
}
] |
Go | codenet | package main
import (
"bufio"
"container/heap"
"fmt"
"math"
"os"
"strconv"
)
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)
sc.Split(bufio.ScanWords)
return sc
}()
)
func main() {
N := getInt()
switch N % 10 {
case 2, 4, 5, 7, 9:
fmt.Println("hon")
case 0, 1, 6, 8:
fmt.Println("pon")
case 3:
fmt.Println("bon")
}
}
type Graph struct {
n int
edges [][]int
}
func NewGraph(n int) *Graph {
g := &Graph{
n: n,
edges: make([][]int, n),
}
return g
}
func (g *Graph) AddEdge(u, v int) {
g.edges[v] = append(g.edges[v], u)
g.edges[u] = append(g.edges[u], v)
}
func dfs(c int, edges [][]int, visited map[int]struct{}) {
visited[c] = struct{}{}
for _, v := range edges[c] {
_, flag := visited[v]
if flag {
continue
}
dfs(v, edges, visited)
}
}
func bfs(c int, graph *Graph) {
next := make([]int, 0)
next = append(next, c)
visited := make(map[int]struct{})
for len(next) != 0 {
u := next[0]
next = next[1:]
visited[u] = struct{}{}
for _, v := range graph.edges[u] {
_, flag := visited[v]
if flag {
continue
}
next = append(next, v)
}
}
}
func getInt() int {
sc.Scan()
i, e := strconv.Atoi(sc.Text())
if e != nil {
panic(e)
}
return i
}
func getIntArray(n int) []int {
array := make([]int, n)
for i := 0; i < n; i++ {
array[i] = getInt()
}
return array
}
func getString() string {
sc.Scan()
return sc.Text()
}
func getStringArray(n int) []string {
array := make([]string, n)
for i := 0; i < n; i++ {
array[i] = getString()
}
return array
}
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 powMod(n, p int) int {
if p == 0 {
return 1
} else if p%2 == 0 {
t := powMod(n, p/2)
return calcMod(t * t)
} else {
return calcMod(n * powMod(n, p-1))
}
}
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
}
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 isPrime(n int) bool {
if n < 2 {
return false
} else if n == 2 {
return true
} else if n%2 == 0 {
return false
}
sqrtN := int(math.Sqrt(float64(n)))
for i := 3; i <= sqrtN; i += 2 {
if n%i == 0 {
return false
}
}
return true
}
func contains(s []int, e int) bool {
for _, v := range s {
if e == v {
return true
}
}
return false
}
func makeRange(min, max int) []int {
a := make([]int, max-min+1)
for i := range a {
a[i] = min + i
}
return a
}
func powerset2(nums []int) [][]int {
length := int(math.Pow(2, float64(len(nums))))
result := make([][]int, length)
index := 0
result[index] = []int{}
index++
for _, n := range nums {
max := index
for i := 0; i < max; i++ {
result[index] = copyAndAppend(result[i], n)
index++
}
}
return result
}
func copyAndAppend(nums []int, n int) []int {
dst := make([]int, len(nums)+1)
copy(dst, nums)
dst[len(nums)] = n
return dst
}
func calcGcd(x, y int) int {
if y == 0 {
return x
} else if x >= y {
return calcGcd(y, x%y)
} else {
return calcGcd(x, y%x)
}
}
func getDivisor(n int) []int {
divisor := make(map[int]struct{})
divisor[1] = struct{}{}
if n != 1 {
divisor[n] = struct{}{}
}
sqrt := int(math.Sqrt(float64(n)))
for i := 2; i <= sqrt; i++ {
if n%i == 0 {
divisor[i] = struct{}{}
divisor[n/i] = struct{}{}
}
}
var divisorArray []int
for d := range divisor {
divisorArray = append(divisorArray, d)
}
return divisorArray
}
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
}
func initHeap() *intHeap {
ih := &intHeap{}
heap.Init(ih)
return ih
}
func (h *intHeap) pushHeap(n int) {
heap.Push(h, n)
}
func (h *intHeap) popHeap() int {
return heap.Pop(h).(int)
}
func factMod(n int) int {
value := 1
for ; n > 1; n-- {
value = calcMod(value * n)
}
return value
}
func combinationMod(n, k int) int {
factN := factMod(n)
factK := factMod(k)
factNK := factMod(n - k)
factKR := powMod(factK, mod-2)
factNKR := powMod(factNK, mod-2)
return calcMod(factN * calcMod(factKR*factNKR))
}
func primeFactors(n int) []int {
factors := make([]int, 0)
i := 2
for i*i <= n {
r := n % i
if r != 0 {
i += 1
} else if r == 0 {
n /= i
factors = append(factors, i)
}
}
if n > 1 {
factors = append(factors, n)
}
return factors
}
| s633919449 | [
{
"input": "16\n",
"output": "pon\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"math"
"os"
"strconv"
"strings"
"flag"
"runtime"
"runtime/pprof"
)
var magic = 1000000007
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
var memprofile = flag.String("memprofile", "", "write mem profile to file")
var N int
var p [200000]int
func find(n int) int {
for i := 0; i < N; i++ {
if n == p[i] {
return 0
}
}
return 1
}
func solve() {
io := NewIo()
defer io.Flush()
X := io.NextInt()
Logf("%v\n", X)
N = io.NextInt()
Logf("%v\n", N)
for i := 0; i < N; i++ {
p[i] = io.NextInt()
}
Logf("p %v\n", p[0:10])
for i := 0; i <= 100; i++ {
if find(X-i) == 1 {
fmt.Printf("%v\n", X-i)
os.Exit(0)
}
if find(X+i) == 1 {
fmt.Printf("%v\n", X+i)
os.Exit(0)
}
}
}
func main() {
flag.Parse()
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
Logf("%v\n", err)
os.Exit(1)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
solve()
if *memprofile != "" {
f, err := os.Create(*memprofile)
if err != nil {
Logf("could not create memory profile: ", err)
os.Exit(1)
}
defer f.Close()
runtime.GC()
if err := pprof.WriteHeapProfile(f); err != nil {
Logf("could not write memory profile: ", err)
os.Exit(1)
}
}
}
type Io struct {
reader *bufio.Reader
writer *bufio.Writer
tokens []string
nextToken int
}
func NewIo() *Io {
return &Io{
reader: bufio.NewReader(os.Stdin),
writer: bufio.NewWriter(os.Stdout),
}
}
func (io *Io) Flush() {
err := io.writer.Flush()
if err != nil {
panic(err)
}
}
func (io *Io) NextLine() string {
var buffer []byte
for {
line, isPrefix, err := io.reader.ReadLine()
if err != nil {
panic(err)
}
buffer = append(buffer, line...)
if !isPrefix {
break
}
}
return string(buffer)
}
func (io *Io) Next() string {
for io.nextToken >= len(io.tokens) {
line := io.NextLine()
io.tokens = strings.Fields(line)
io.nextToken = 0
}
r := io.tokens[io.nextToken]
io.nextToken++
return r
}
func (io *Io) NextInt() int {
i, err := strconv.Atoi(io.Next())
if err != nil {
panic(err)
}
return i
}
func (io *Io) NextFloat() float64 {
i, err := strconv.ParseFloat(io.Next(), 64)
if err != nil {
panic(err)
}
return i
}
func (io *Io) PrintLn(a ...interface{}) {
fmt.Fprintln(io.writer, a...)
}
func (io *Io) Printf(format string, a ...interface{}) {
fmt.Fprintf(io.writer, format, a...)
}
func (io *Io) PrintIntLn(a []int) {
b := []interface{}{}
for _, x := range a {
b = append(b, x)
}
io.PrintLn(b...)
}
func (io *Io) PrintStringLn(a []string) {
b := []interface{}{}
for _, x := range a {
b = append(b, x)
}
io.PrintLn(b...)
}
func Log(name string, value interface{}) {
fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}
func Logf(format string, a ...interface{}) {
fmt.Fprintf(os.Stderr, format, a...)
}
func intMin(a, b int) int {
if a < b {
return a
}
return b
}
func intMax(a, b int) int {
if a > b {
return a
}
return b
}
func combination(n, m int) int {
if m > n {
return 0
} else if m == n || m == 0 {
return 1
} else {
res := 1
for i := 0; i < m; i++ {
res *= (n - i)
}
for i := 1; i <= m; i++ {
res /= i
}
return res
}
}
func lucas(n, m, p int) int {
ntemp := n
mtemp := m
res := 1
for i := 0; i < 100; i++ {
nreminder := ntemp % p
ntemp = ntemp / p
mreminder := mtemp % p
mtemp = mtemp / p
res = res * (combination(nreminder, mreminder) % p)
if ntemp == 0 {
break
}
}
return res % p
}
func combMod(n, m, p int) int {
return lucas(n, m, p)
}
func bfs(start int, nodes map[int][]int, fn func(int)) {
frontier := []int{start}
visited := map[int]bool{}
for 0 < len(frontier) {
next := []int{}
for _, node := range frontier {
visited[node] = true
fn(node)
for _, n := range bfsFrontier(node, nodes, visited) {
next = append(next, n)
}
}
frontier = next
}
}
func bfsFrontier(node int, nodes map[int][]int, visited map[int]bool) []int {
next := []int{}
iter := func(n int) bool { _, ok := visited[n]; return !ok }
for _, n := range nodes[node] {
if iter(n) {
next = append(next, n)
}
}
return next
}
func dfs(node int, nodes map[int][]int, fn func(int)) {
dfsRecur(node, nodes, map[int]bool{}, fn)
}
func dfsRecur(node int, nodes map[int][]int, v map[int]bool, fn func(int)) {
v[node] = true
fn(node)
for _, n := range nodes[node] {
if _, ok := v[n]; !ok {
dfsRecur(n, nodes, v, fn)
}
}
}
func dfs2(node int, nodes map[int][]int, fn1, fn2 func(int, int)) {
dfs2Recur(node, -1, nodes, map[int]bool{}, fn1, fn2)
}
func dfs2Recur(node, parent int, nodes map[int][]int, v map[int]bool, fn1, fn2 func(int, int)) {
v[node] = true
if fn1 != nil {
fn1(node, parent)
}
for _, n := range nodes[node] {
if _, ok := v[n]; !ok {
dfs2Recur(n, node, nodes, v, fn1, fn2)
}
}
if fn2 != nil {
fn2(node, parent)
}
}
type Stack struct {
top *Element
size int
}
type Element struct {
value interface{}
next *Element
}
func (s *Stack) Len() int {
return s.size
}
func (s *Stack) Push(value interface{}) {
s.top = &Element{value, s.top}
s.size++
}
func (s *Stack) Pop() (value interface{}) {
if s.size > 0 {
value, s.top = s.top.value, s.top.next
s.size--
return
}
return nil
}
func powerInt(n, p int) int {
tmp := 1
for i := 0; i < n; i++ {
tmp *= p
}
return tmp
}
func findDivisors(n int, a *[]int) {
if n == 1 {
return
}
sqrt := int(math.Sqrt(float64(n)))
for i := 2; i <= sqrt; i++ {
if n%i == 0 {
*a = append(*a, i)
*a = append(*a, n/i)
}
}
*a = append(*a, n)
}
func removeDuplicate(a []int) []int {
m := make(map[int]bool)
for i := 0; i < len(a); i++ {
m[a[i]] = true
}
res := []int{}
for i := range m {
res = append(res, i)
}
return res
}
func abs(a int) int {
if a > 0 {
return a
}
return -a
}
func gcd(a, b int) int {
for a != 0 {
a, b = b%a, a
}
return b
}
func power2mod(n, mod int) int {
res, x := 1, 2
for ; n > 0; n >>= 1 {
if n&1 == 1 {
res = res * x % mod
}
x = x * x % mod
}
return res
}
func power2(n int) int {
return power2mod(n, magic)
}
| s601720340 | [
{
"input": "6 5\n4 7 10 6 5\n",
"output": "8\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])
}
b := make([]int, 0, n)
for _, v := range a {
x := sort.Search(len(b), func(i int) bool {
return b[i] < v
})
if x == len(b) {
b = append(b, v)
} else {
b[x] = v
}
}
fmt.Println(len(b))
}
| s558200435 | [
{
"input": "5\n2\n1\n4\n5\n3\n",
"output": "2\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var x1, y1, x2, y2 int
fmt.Scan(&x1, &y1, &x2, &y2)
a := x2 - x1
b := y2 - y1
x3 := x2 - b
y3 := y2 + a
x4 := x1 - b
y4 := y1 + a
fmt.Println(x3, y3, x4, y4)
}
| s554832295 | [
{
"input": "0 0 0 1\n",
"output": "-1 1 -1 0\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"math"
"os"
"strconv"
"strings"
"unsafe"
)
func main() {
AB := sc.nextInts()
A := AB[0]
B := AB[1]
if (A+B)%2 == 0 {
fmt.Println((A + B) / 2)
return
}
fmt.Println("IMPOSSIBLE")
}
var (
sc scanner
)
func init() {
sc = scanner{
buf: make([]string, 0, 0),
cur: 0,
r: bufio.NewReader(os.Stdin),
}
}
type scanner struct {
buf []string
cur int
r *bufio.Reader
}
func (s *scanner) readln() {
rbuf := make([]byte, 0, 0)
for {
line, prefix, err := s.r.ReadLine()
if err != nil {
panic(err)
}
rbuf = append(rbuf, line...)
if prefix == false {
break
}
}
s.cur = 0
s.buf = strings.Split(*(*string)(unsafe.Pointer(&rbuf)), " ")
}
func (s *scanner) isFull() bool {
if s.cur == len(s.buf) {
return true
}
return false
}
func (s *scanner) resetCur() {
s.cur = 0
}
func (s *scanner) next() string {
if s.cur == 0 {
s.readln()
}
res := s.buf[s.cur]
s.cur++
if s.isFull() {
s.resetCur()
}
return res
}
func (s *scanner) nexts() []string {
s.readln()
s.resetCur()
return s.buf
}
func (s *scanner) nextInt() int {
if s.cur == 0 {
s.readln()
}
res, _ := strconv.Atoi(s.buf[s.cur])
s.cur++
if s.isFull() {
s.resetCur()
}
return res
}
func (s *scanner) nextInts() []int {
s.readln()
res := make([]int, len(s.buf))
for i := range s.buf {
res[i], _ = strconv.Atoi(s.buf[i])
}
s.resetCur()
return res
}
func (s *scanner) nextFloat() float64 {
if s.cur == 0 {
s.readln()
}
res, _ := strconv.ParseFloat(s.buf[s.cur],
64)
s.cur++
if s.isFull() {
s.resetCur()
}
return res
}
func (s *scanner) nextFloats() []float64 {
s.readln()
res := make([]float64, len(s.buf))
for i := range s.buf {
res[i], _ = strconv.ParseFloat(s.buf[i],
64)
}
s.resetCur()
return res
}
func digits(x int) int {
return len(strconv.Itoa(x))
}
func powInt(x, p int) (result int) {
result = 1
for i := 0; i < p; i++ {
result *= x
}
return
}
func max(x, y int) int {
return int(math.Max(float64(x), float64(y)))
}
func min(x, y int) int {
return int(math.Min(float64(x), float64(y)))
}
func abs(x int) int {
return int(math.Abs(float64(x)))
}
func varDump(value ...interface{}) {
for _, v := range value {
fmt.Fprintf(os.Stderr, "%#v\n", v)
}
}
func yes() {
fmt.Println("Yes")
}
func no() {
fmt.Println("No")
}
type Pair struct {
first int
second int
}
type Queue struct {
v []Pair
}
func (q *Queue) Push(v Pair) {
q.v = append(q.v, v)
}
func (q *Queue) Pop() Pair {
r := q.v[0]
q.v = q.v[1:]
return r
}
func (q Queue) Front() Pair {
return q.v[0]
}
func (q Queue) Empty() bool {
return len(q.v) == 0
}
| s789498198 | [
{
"input": "2 16\n",
"output": "9\n"
}
] |
Go | codenet | package main
import (
"bufio"
"bytes"
"fmt"
"io"
"os"
"sort"
"strconv"
"strings"
)
func ReadLongLines(times int) ([]string, error) {
result := make([]string, times)
reader := bufio.NewReader(os.Stdin)
buffer := bytes.NewBuffer(make([]byte, 0))
readBytes := int64(2)
for i := 0; i < times; i++ {
for {
readBuf, isPrefix, err := reader.ReadLine()
readBytes += int64(len(readBuf) + 1)
if err != nil {
if err == io.EOF {
fmt.Println("EOF")
break
} else {
return result, err
}
}
_, err = buffer.Write(readBuf)
if err != nil {
return result, err
}
if !isPrefix {
result[i] = buffer.String()
buffer.Reset()
break
}
}
}
os.Stdin.Seek(-int64(reader.Buffered()), os.SEEK_CUR)
return result, nil
}
type Console struct {
writer *bufio.Writer
}
func NewConsole() Console {
return Console{bufio.NewWriter(os.Stdout)}
}
func (this *Console) Printf(format string, a ...interface{}) {
fmt.Fprintf(this.writer, format, a...)
}
func (this *Console) Println(s string) {
fmt.Fprintln(this.writer, s)
}
func (this *Console) Close() {
this.Flush()
}
func (this Console) Flush() {
this.writer.Flush()
}
func PrintList(list []int) {
con := NewConsole()
defer con.Flush()
for i := range list {
if i == 0 {
con.Printf("%d", list[i])
} else {
con.Printf(" %d", list[i])
}
}
con.Println("")
}
func main() {
con := NewConsole()
defer con.Flush()
m := make(map[int]struct{})
lines, _ := ReadLongLines(4)
a := strings.Split(lines[1], " ")
for i := range a {
n, _ := strconv.Atoi(a[i])
m[n] = struct{}{}
}
result := make([]int, 0, 200000)
b := strings.Split(lines[3], " ")
for i := range b {
n, _ := strconv.Atoi(b[i])
if _, ok := m[n]; ok {
delete(m, n)
} else {
m[n] = struct{}{}
}
}
for k, _ := range m {
result = append(result, k)
}
sort.Slice(result, func(lhs, rhs int) bool {
return result[lhs] < result[rhs]
})
for j := range result {
con.Printf("%d\n", result[j])
}
}
| s227655384 | [
{
"input": "7\n1 2 3 4 5 6 7\n4\n2 4 6 8\n",
"output": "1\n3\n5\n7\n8\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func main() {
sc.Split(bufio.ScanWords)
n := nextInt()
a := nextInts(n)
ans := 0
for i := 0; i < n; i++ {
l, r := i, i+1
for r+1 < n && (a[r]-a[l])*(a[r+1]-a[r]) >= 0 {
r++
}
ans++
i = r
}
puts(ans)
wt.Flush()
}
var (
sc = bufio.NewScanner(os.Stdin)
rdr = bufio.NewReaderSize(os.Stdin, 1000000)
wt = bufio.NewWriter(os.Stdout)
)
func next() string {
sc.Scan()
return sc.Text()
}
func nextInt() int {
i, _ := strconv.Atoi(next())
return i
}
func nextFloat64() float64 {
f, _ := strconv.ParseFloat(next(), 64)
return f
}
func nextInts(n int) []int {
slice := make([]int, n)
for i := 0; i < n; i++ {
slice[i] = nextInt()
}
return slice
}
func nextFloat64s(n int) []float64 {
slice := make([]float64, n)
for i := 0; i < n; i++ {
slice[i] = nextFloat64()
}
return slice
}
func nextMega() string {
buf := make([]byte, 0, 1000000)
for {
l, p, _ := rdr.ReadLine()
buf = append(buf, l...)
if !p {
break
}
}
return string(buf)
}
func putf(format string, a ...interface{}) {
fmt.Fprintf(wt, format, a...)
}
func puts(a ...interface{}) {
fmt.Fprintln(wt, a...)
}
| s240914668 | [
{
"input": "6\n1 2 3 2 2 1\n",
"output": "2\n"
}
] |
Go | codenet | package main
import "fmt"
const size = 100001
func main() {
var n, t int
var l, r int
var mem [size]int
fmt.Scan(&n)
fmt.Scan(&t)
for i := 0; i < n; i++ {
fmt.Scan(&l)
fmt.Scan(&r)
mem[l] += 1
mem[r] -= 1
}
ans := mem[0]
for i := 1; i < t+1; i++ {
mem[i] += mem[i-1]
if ans < mem[i] {
ans = mem[i]
}
}
fmt.Println(ans)
}
| s097554686 | [
{
"input": "6 10\n0 2\n1 3\n2 6\n3 8\n4 10\n5 10\n",
"output": "4\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
var sc = bufio.NewScanner(os.Stdin)
func next() string {
sc.Scan()
return sc.Text()
}
func nextInt() int {
sc.Scan()
i, _ := strconv.Atoi(sc.Text())
return i
}
func nextFloat64() float64 {
f, _ := strconv.ParseFloat(next(), 64)
return f
}
func nextInts(n int) []int {
slice := make([]int, n)
for i := 0; i < n; i++ {
slice[i] = nextInt()
}
return slice
}
func main() {
sc.Split(bufio.ScanWords)
n, k := nextInt(), nextInt()
a := nextInts(n)
a[0] = 0
sum := k
ans := 1
for sum < n {
sum = sum - 1 + k
ans++
}
fmt.Println(ans)
}
| s225883945 | [
{
"input": "4 3\n2 3 1 4\n",
"output": "2\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var r, d, x int
fmt.Scanf("%d %d %d", &r, &d, &x)
for i := 0; i < 10; i++ {
x = r*x - d
fmt.Println(x)
}
}
| s502485201 | [
{
"input": "2 10 20\n",
"output": "30\n50\n90\n170\n330\n650\n1290\n2570\n5130\n10250\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"sort"
)
func main() {
m := make(map[int]int)
N, M := ReadInt(), ReadInt()
for i := 0; i < N; i++ {
m[ReadInt()]++
}
for i := 0; i < M; i++ {
B, C := ReadInt(), ReadInt()
m[C] += B
}
ints := make([]int, len(m))
for i, _ := range m {
ints = append(ints, i)
}
sort.Sort(sort.Reverse(sort.IntSlice(ints)))
rest := N
sum := 0
for _, i := range ints {
num := m[i]
if num >= rest {
sum += rest * i
break
}
sum += num * i
rest -= num
}
fmt.Println(sum)
}
var reader = bufio.NewReader(os.Stdin)
func Scan(a ...interface{}) {
if _, err := fmt.Fscan(reader, a...); err != nil {
panic(err)
}
}
func ReadInt() (i int) { Scan(&i); return }
| s982630782 | [
{
"input": "3 2\n5 1 4\n2 3\n1 5\n",
"output": "14\n"
}
] |
Go | codenet | package main
import (
"fmt"
)
func main() {
var n int
fmt.Scan(&n)
var s []byte
fmt.Scan(&s)
ns := make([]int, n)
for i := range s {
switch s[i] {
case 'R':
ns[i] = 0
case 'G':
ns[i] = 1
case 'B':
ns[i] = 2
}
}
rgb := make([][]int, n+1)
rgb[0] = make([]int, 3)
for i := 1; i <= n; i++ {
rgb[i] = make([]int, 3)
for j := 0; j < 3; j++ {
rgb[i][j] = rgb[i-1][j]
}
rgb[i][ns[i-1]]++
}
var sum int
for i := 0; i < n-2; i++ {
for j := i + 1; j < n-1; j++ {
if ns[i] != ns[j] {
tn := 3 - ns[i] - ns[j]
sum += rgb[n][tn] - rgb[j+1][tn]
k := 2*j - i
if k < n && ns[k] == tn {
sum--
}
}
}
}
fmt.Println(sum)
}
| s724499011 | [
{
"input": "4\nRRGB\n",
"output": "1\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"math"
"os"
"sort"
"strconv"
"strings"
)
func main() {
io := NewIo()
defer io.Flush()
n := io.Int()
aa := make([]int, n)
for i := 0; i < n; i++ {
aa[i] = io.Int()
}
cumsum := CumSum(aa)
ans := 2020202020
for i := 1; i < len(cumsum)-1; i++ {
ans = Min(ans, Abs(cumsum[len(cumsum)-1]-cumsum[i]-(cumsum[i]-cumsum[0])))
}
fmt.Println(ans)
}
type Io struct {
reader *bufio.Reader
writer *bufio.Writer
tokens []string
nextToken int
}
func NewIo() *Io {
return &Io{
reader: bufio.NewReader(os.Stdin),
writer: bufio.NewWriter(os.Stdout),
}
}
func (io *Io) Flush() {
err := io.writer.Flush()
if err != nil {
panic(err)
}
}
func (io *Io) NextLine() string {
var buffer []byte
for {
line, isPrefix, err := io.reader.ReadLine()
if err != nil {
panic(err)
}
buffer = append(buffer, line...)
if !isPrefix {
break
}
}
return string(buffer)
}
func (io *Io) Next() string {
for io.nextToken >= len(io.tokens) {
line := io.NextLine()
io.tokens = strings.Fields(line)
io.nextToken = 0
}
r := io.tokens[io.nextToken]
io.nextToken++
return r
}
func (io *Io) Int() int {
i, err := strconv.Atoi(io.Next())
if err != nil {
panic(err)
}
return i
}
func (io *Io) Float() float64 {
i, err := strconv.ParseFloat(io.Next(), 64)
if err != nil {
panic(err)
}
return i
}
func (io *Io) PrintLn(a ...interface{}) {
fmt.Fprintln(io.writer, a...)
}
func (io *Io) Printf(format string, a ...interface{}) {
fmt.Fprintf(io.writer, format, a...)
}
func (io *Io) PrintIntLn(a []int) {
b := []interface{}{}
for _, x := range a {
b = append(b, x)
}
io.PrintLn(b...)
}
func (io *Io) PrintStringLn(a []string) {
b := []interface{}{}
for _, x := range a {
b = append(b, x)
}
io.PrintLn(b...)
}
func Log(name string, value interface{}) {
fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}
func Abs(a int) int {
if a >= 0 {
return a
} else {
return -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 SortAsc(a []int) []int {
sort.Ints(a)
return a
}
func SortDesc(a []int) []int {
sort.Sort(sort.Reverse(sort.IntSlice(a)))
return a
}
func GCD(a, b int) int {
if b == 0 {
return a
}
return GCD(b, a%b)
}
func LCM(a, b int) int {
if a == 0 && b == 0 {
return 0
}
return a * b / GCD(a, b)
}
func CumSum(nums []int) []int {
sums := []int{0}
for i := 0; i < len(nums); i++ {
sums = append(sums, sums[i]+nums[i])
}
return sums
}
func BisectLeft(nums []int, left, right int, target int) int {
if left == right {
if nums[left] == target {
return left
} else if nums[left] < target {
return left + 1
} else {
return left
}
}
mid := (left + right) / 2
if nums[mid] == target {
return mid
}
if nums[mid] > target {
return BisectLeft(nums, left, mid, target)
} else if nums[mid] < target {
return BisectLeft(nums, mid+1, right, target)
}
return 0
}
func Permutations(nums []int) [][]int {
n := len(nums)
if n == 0 {
return [][]int{}
}
ans := [][]int{}
for _, n := range nums {
rest := remove(nums, n)
lists := Permutations(rest)
if len(lists) == 0 {
lists = [][]int{nil}
}
for i := 0; i < len(lists); i++ {
lists[i] = append(lists[i], n)
ans = append(ans, lists[i])
}
}
return ans
}
func remove(nums []int, target int) []int {
result := []int{}
for i := 0; i < len(nums); i++ {
if nums[i] != target {
result = append(result, nums[i])
}
}
return result
}
func PowerSet(nums []int) [][]int {
size := Pow(2, len(nums))
result := make([][]int, size)
idx := 0
result[idx] = []int{}
idx++
for _, n := range nums {
max := idx
for i := 0; i < max; i++ {
result[idx] = copyAndAppend(result[i], n)
idx++
}
}
return result
}
func copyAndAppend(nums []int, n int) []int {
dst := make([]int, len(nums)+1)
copy(dst, nums)
dst[len(nums)] = n
return dst
}
func Combination(nums []int, k int) [][]int {
size := len(nums)
result := make([][]int, CombinationCount(int64(len(nums)), int64(k), 10e10))
bi := (1 << uint(k)) - 1
max := 1 << uint(size)
idx := 0
for bi < max {
flags := bi
s := []int{}
for _, n := range nums {
if flags%2 != 0 {
s = append(s, n)
}
flags /= 2
}
result[idx] = s
idx++
bi = Combination2NextIndex(bi)
}
return result
}
func Combination2NextIndex(n int) int {
smallest := n & -n
ripple := n + smallest
newSmallest := ripple & -ripple
ones := ((newSmallest / smallest) >> 1) - 1
return ripple | ones
}
func CombinationCount(n, m, maxInput int64) int64 {
memo := map[int64]map[int64]int64{}
for i := int64(1); i <= maxInput*maxInput; i++ {
memo[int64(i)] = map[int64]int64{}
}
return combinationCount(n, m, memo)
}
func combinationCount(n, m int64, memo map[int64]map[int64]int64) int64 {
if n == m || m == 0 {
return 1
}
left, lOK := memo[n-1][m-1]
right, rOK := memo[n-1][m]
if lOK && rOK {
return left + right
}
if lOK {
right = combinationCount(n-1, m, memo)
memo[n-1][m] = right
return left + right
}
if rOK {
left = combinationCount(n-1, m-1, memo)
memo[n-1][m-1] = left
return left + right
}
left = combinationCount(n-1, m-1, memo)
right = combinationCount(n-1, m, memo)
memo[n-1][m-1] = left
memo[n-1][m] = right
return left + right
}
func Fact(n int) int {
if n == 0 {
return 1
} else {
return n * Fact(n-1)
}
}
func Divisors(n int) []int {
divisors := map[int]bool{}
for i := 1; i < int(math.Sqrt(float64(n)))+1; i++ {
if n%i == 0 {
divisors[i] = true
if i != n {
divisors[n/i] = true
}
}
}
ans := []int{}
for k := range divisors {
ans = append(ans, k)
}
return ans
}
| s846000843 | [
{
"input": "3\n2 4 3\n",
"output": "3\n"
}
] |
Go | codenet | package main
import (
"bufio"
"errors"
"fmt"
"io"
"math"
"os"
"sort"
"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, q int
C []int
Q []Query
P [500000 + 50]int
Answers [500000 + 50]int
)
type Query struct {
idx, l, r int
}
func main() {
n, q = ReadInt2()
C = ReadIntSlice(n)
for i := 1; i <= n; i++ {
P[i] = -1
}
for i := 0; i < q; i++ {
l, r := ReadInt2()
query := Query{idx: i, l: l, r: r}
Q = append(Q, query)
}
sort.SliceStable(Q, func(i, j int) bool { return Q[i].r < Q[j].r })
ft := NewFenwickTree(500000 + 50)
k := 0
for _, query := range Q {
for k < query.r {
if P[C[k]] != -1 {
ft.Add(P[C[k]]+1, -1)
}
P[C[k]] = k
ft.Add(k+1, 1)
k++
}
Answers[query.idx] = ft.Sum(query.r) - ft.Sum(query.l-1)
}
for i := 0; i < q; i++ {
PrintfBufStdout("%d\n", Answers[i])
}
stdout.Flush()
}
type FenwickTree struct {
dat []int
n int
minPow2 int
}
func NewFenwickTree(n int) *FenwickTree {
ft := new(FenwickTree)
ft.dat = make([]int, n+1)
ft.n = n
ft.minPow2 = 1
for {
if (ft.minPow2 << 1) > n {
break
}
ft.minPow2 <<= 1
}
return ft
}
func (ft *FenwickTree) Sum(i int) int {
s := 0
for i > 0 {
s += ft.dat[i]
i -= i & (-i)
}
return s
}
func (ft *FenwickTree) Add(i, x int) {
for i <= ft.n {
ft.dat[i] += x
i += i & (-i)
}
}
func (ft *FenwickTree) LowerBound(w int) int {
if w <= 0 {
return 0
}
x := 0
for k := ft.minPow2; k > 0; k /= 2 {
if x+k <= ft.n && ft.dat[x+k] < w {
w -= ft.dat[x+k]
x += k
}
}
return x + 1
}
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...)
}
| s040219730 | [
{
"input": "4 3\n1 2 1 3\n1 3\n2 4\n3 3\n",
"output": "2\n3\n1\n"
}
] |
Go | codenet | package main
import (
"fmt"
)
func main() {
var a, b, c, x, sum int
fmt.Scan(&a, &b, &c, &x)
for i := 0; i <= a; i++ {
for j := 0; j <= b; j++ {
for k := 0; k <= c; k++ {
if 500*i+100*j+50*k == x {
sum++
}
}
}
}
fmt.Println(sum)
}
| s141561537 | [
{
"input": "2\n2\n2\n100\n",
"output": "2\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"sort"
"strconv"
"strings"
)
var sc = bufio.NewScanner(os.Stdin)
var wtr = bufio.NewWriter(os.Stdout)
var N, ss, ans, A, B, C int
func main() {
X := strings.Split(nextLine(), " ")
N, _ = strconv.Atoi(X[0])
A, _ = strconv.Atoi(X[1])
B, _ = strconv.Atoi(X[2])
C, _ = strconv.Atoi(X[3])
arr := make([]int, N)
dp := make([]int, N)
ans = 10000
ss = A + B + C
for i := 0; i < N; i++ {
Y := strings.Split(nextLine(), " ")
a, _ := strconv.Atoi(Y[0])
arr[i] = a
}
dfs(dp, 0, arr)
fmt.Fprintln(wtr, ans)
_ = wtr.Flush()
}
func dfs(dp []int, times int, arr []int) {
if times >= N {
ans = min(ans, calc(dp, arr))
return
}
for i := 0; i < 4; i++ {
dp[times] = i
dfs(dp, times+1, arr)
}
}
func calc(dp, arr []int) int {
var cost, AA, BB, CC int
memo := make([]int, 4)
for i := 0; i < len(dp); i++ {
memo[dp[i]]++
if dp[i] == 1 {
AA += arr[i]
} else if dp[i] == 2 {
BB += arr[i]
} else if dp[i] == 3 {
CC += arr[i]
}
}
cost += abs(A-AA) + abs(B-BB) + abs(C-CC)
for i := 1; i < 4; i++ {
a := memo[i]
if a < 1 {
cost += 10000
} else {
cost += (a - 1) * 10
}
}
return cost
}
type otosidama struct {
x float64
v string
}
func chmax(a *string, b string) {
if len(*a) < len(b) {
*a = b
} else if len(*a) == len(b) && *a < b {
*a = b
}
}
func gcd(a, b int) int {
if b == 0 {
return a
}
return gcd(b, a%b)
}
func nextLine() string {
sc.Scan()
return sc.Text()
}
func min(a, b int) int {
if a < b {
return a
}
return b
}
func max(a, b int64) int64 {
if a > b {
return a
}
return b
}
func com(a, b int) int {
if a > b {
return 0
}
return 0
}
func abs(a int) int {
if a < 0 {
return a * -1
}
return a
}
func sum(a []int) (sum int) {
for _, num := range a {
sum += num
}
return
}
type item struct {
x int
}
type que []item
func (p que) Len() int {
return len(p)
}
func (p que) Swap(i, j int) {
p[i], p[j] = p[j], p[i]
}
func (p que) Less(i, j int) bool {
return p[i].x < p[j].x
}
func (p que) Push(in int) {
p = append(p, item{x: in})
sort.Sort(p)
}
func (p que) Pop() int {
res := p[0].x
p = p[1:]
return res
}
func (p que) Peek() int {
return p[0].x
}
| s617271364 | [
{
"input": "5 100 90 80\n98\n40\n30\n21\n80\n",
"output": "23\n"
}
] |
Go | codenet | package main
import (
"fmt"
)
func main() {
var N, M int
fmt.Scan(&N, &M)
Inf := 1 << 62
a := make([]int, M)
b := make([]int, M)
c := make([]int, M)
for i := 0; i < M; i++ {
fmt.Scan(&a[i], &b[i], &c[i])
c[i] = -c[i]
}
dist := make([]int, N)
for i := 0; i < N; i++ {
dist[i] = Inf
}
dist[0] = 0
for loop := 0; loop < N; loop++ {
for i := 0; i < M; i++ {
if dist[a[i]-1] == Inf {
continue
}
if dist[b[i]-1] > dist[a[i]-1]+c[i] {
dist[b[i]-1] = dist[a[i]-1] + c[i]
}
}
}
ans := dist[N-1]
navigate := make([]bool, N)
for loop := 0; loop < N; loop++ {
for i := 0; i < M; i++ {
if dist[a[i]-1] == Inf {
continue
}
if dist[b[i]-1] > dist[a[i]-1]+c[i] {
dist[b[i]-1] = dist[a[i]-1] + c[i]
navigate[b[i]-1] = true
}
if navigate[a[i]-1] == true {
navigate[b[i]-1] = true
}
}
}
if navigate[N-1] {
fmt.Println("inf")
} else {
fmt.Println(-ans)
}
}
| s984936225 | [
{
"input": "3 3\n1 2 4\n2 3 3\n1 3 5\n",
"output": "7\n"
}
] |
Go | codenet | package main
import (
"fmt"
"strings"
)
func main() {
var s string
fmt.Scanf("%s", &s)
ans := "No"
if strings.Index(s, "C") < strings.LastIndex(s, "F") {
ans = "Yes"
}
if strings.Index(s, "C") < 0 {
ans = "No"
}
fmt.Printf("%s\n", ans)
}
| s494300734 | [
{
"input": "CODEFESTIVAL\n",
"output": "Yes\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+B < 0 {
fmt.Println("0")
} else {
fmt.Printf("%d\n", C-A+B)
}
}
| s452291224 | [
{
"input": "6 4 3\n",
"output": "1\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func main() {
sc := NewScanner()
n := sc.NextInt()
ans := 0.0
for i := 0; i < n; i++ {
tmp := 1 / float64(sc.NextInt())
ans += tmp
}
fmt.Printf("%v\n", 1/ans)
}
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
}
}
}
| s940795037 | [
{
"input": "2\n10 30\n",
"output": "7.5\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"sort"
"strconv"
"strings"
)
var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)
func scanString() string { sc.Scan(); return sc.Text() }
func scanRunes() []rune { return []rune(scanString()) }
func scanInt() int { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }
func scanInts(n int) []int {
res := make([]int, n)
for i := 0; i < n; i++ {
res[i] = scanInt()
}
return res
}
func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }
func abs(a int) int {
if a < 0 {
return -a
}
return a
}
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
}
func main() {
defer wr.Flush()
sc.Split(bufio.ScanWords)
sc.Buffer(make([]byte, 10000), 1001001)
s := scanRunes()
t := scanRunes()
ans := []string{}
for i := 0; i < len(s)-len(t)+1; i++ {
f := true
ss := make([]rune, len(s))
copy(ss, s)
for j := 0; j < len(t); j++ {
if s[i+j] != t[j] && s[i+j] != '?' {
f = false
break
} else {
ss[i+j] = t[j]
}
}
if f {
ans = append(ans, strings.Replace(string(ss), "?", "a", -1))
}
}
sort.Strings(ans)
if len(ans) == 0 {
fmt.Fprintln(wr, "UNRESTORABLE")
} else {
fmt.Fprintln(wr, ans[0])
}
}
| s436101574 | [
{
"input": "?tc????\ncoder\n",
"output": "atcoder\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var S string
fmt.Scan(&S)
for i := 2; i <= len(S); i = i + 2 {
if S[0:(len(S)-i)/2] == S[(len(S)-i)/2:len(S)-i] {
fmt.Println((len(S) - i))
break
}
}
}
| s225932846 | [
{
"input": "abaababaab\n",
"output": "6\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"io"
"os"
"strconv"
)
type Scanner struct {
sc *bufio.Scanner
}
func NewScanner() *Scanner {
sc := bufio.NewScanner(os.Stdin)
sc.Split(bufio.ScanWords)
sc.Buffer(make([]byte, 10240), 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() []byte {
return []byte(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 run(input io.Reader, output io.Writer) int {
sc := NewScanner()
N := sc.nextInt()
S := sc.nextStr()
if N == 0 {
}
if N < 4 {
fmt.Println(0)
return 0
}
var nr, nb, ng int
for _, c := range S {
if c == 'R' {
nr++
}
if c == 'B' {
nb++
}
if c == 'G' {
ng++
}
}
same := 0
for a := 1; a < N; a++ {
i := 0
j := 1 * a
k := 2 * a
if k >= N {
break
}
for k < N {
if S[i] != S[j] && S[i] != S[k] && S[j] != S[k] {
same++
}
i += 1
j += 1
k += 1
}
}
tot := nr * nb * ng
fmt.Println(tot - same)
return 0
}
func main() {
os.Exit(run(os.Stdin, os.Stdout))
}
| s731620136 | [
{
"input": "4\nRRGB\n",
"output": "1\n"
}
] |
Go | codenet | package main
import (
"fmt"
)
func main() {
var s string
fmt.Scan(&s)
if len(s) >= 4 && s[0:4] == "YAKI" {
fmt.Println("Yes")
} else {
fmt.Println("No")
}
}
| s861455616 | [
{
"input": "YAKINIKU\n",
"output": "Yes\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"sort"
"strconv"
)
func solve() {
n := getInt()
as := getIntSlice(n)
xs := make([]int, n)
for i, a := range as {
xs[i] = a - i + 1
}
sort.Ints(xs)
b := xs[n/2]
ans := 0
for _, x := range xs {
ans += abs(x - b)
}
fmt.Fprintln(wr, ans)
}
func abs(n int) int {
if n < 0 {
return -n
}
return n
}
const (
inf = 1 << 60
)
var (
sc = bufio.NewScanner(os.Stdin)
wr = bufio.NewWriter(os.Stdout)
)
func main() {
maxBufSize := int(1e8)
sc.Buffer(make([]byte, 4096), maxBufSize)
sc.Split(bufio.ScanWords)
solve()
wr.Flush()
}
func getInt() (ret int) {
sc.Scan()
ret, err := strconv.Atoi(sc.Text())
if err != nil {
panic(err)
}
return
}
func getIntSlice(n int) (ret []int) {
ret = make([]int, n)
for i := range ret {
ret[i] = getInt()
}
return
}
func getString() (ret string) {
sc.Scan()
ret = sc.Text()
return
}
func getRunes() (ret []rune) {
ret = []rune(getString())
return
}
| s521372598 | [
{
"input": "5\n2 2 3 5 5\n",
"output": "2\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 (
S []rune
x, y int
dpx, dpy [8000][20000]bool
)
func main() {
S = ReadRuneSlice()
x, y = ReadInt2()
F := []int{}
cur := 0
for i := 0; i < len(S); i++ {
if S[i] == 'F' {
cur++
} else {
F = append(F, cur)
cur = 0
}
}
F = append(F, cur)
PrintfDebug("%v\n", F)
evens, odds := []int{}, []int{}
for i := 0; i < len(F); i++ {
if i%2 == 0 {
evens = append(evens, F[i])
} else {
odds = append(odds, F[i])
}
}
dpx[0][10000], dpy[0][10000] = true, true
for i := 0; i < len(evens); i++ {
val := evens[i]
for j := 2000; j <= 18000; j++ {
if j+val <= 18000 {
dpx[i+1][j+val] = dpx[i+1][j+val] || dpx[i][j]
}
if j-val >= 2000 && i != 0 {
dpx[i+1][j-val] = dpx[i+1][j-val] || dpx[i][j]
}
}
}
for i := 0; i < len(odds); i++ {
val := odds[i]
for j := 2000; j <= 18000; j++ {
if j+val <= 18000 {
dpy[i+1][j+val] = dpy[i+1][j+val] || dpy[i][j]
}
if j-val >= 2000 {
dpy[i+1][j-val] = dpy[i+1][j-val] || dpy[i][j]
}
}
}
if dpx[len(evens)][x+10000] && dpy[len(odds)][y+10000] {
fmt.Println("Yes")
} else {
fmt.Println("No")
}
}
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...)
}
| s069675863 | [
{
"input": "FTFFTFFF\n4 2\n",
"output": "Yes\n"
}
] |
Go | codenet | package main
import "fmt"
import "math"
func max(lhs, rhs int) int {
return int(math.Max(float64(lhs), float64(rhs)))
}
func main() {
var (
N, M int
)
fmt.Scanf("%d %d", &N, &M)
values := make([]int, N)
weights := make([]int, N)
for i := 0; i < N; i++ {
fmt.Scanf("%d %d", &weights[i], &values[i])
}
dp := make([][]int, N+1)
for i := 0; i < N+1; i++ {
dp[i] = make([]int, M+1)
}
for i := 1; i <= N; i++ {
for j := 0; j <= M; j++ {
dp[i][j] = dp[i-1][j]
if j >= weights[i-1] {
dp[i][j] = max(dp[i][j], dp[i-1][j-weights[i-1]]+values[i-1])
}
}
}
fmt.Println(dp[N][M])
}
| s794438584 | [
{
"input": "3 8\n3 30\n4 50\n5 60\n",
"output": "90\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"io"
"math"
"os"
"strconv"
)
type scanner struct{ *bufio.Scanner }
func newScanner(r io.Reader) *scanner {
s := bufio.NewScanner(r)
s.Split(bufio.ScanWords)
s.Buffer(nil, 100000000)
return &scanner{s}
}
func (s *scanner) Int() int {
s.Scan()
n, _ := strconv.Atoi(s.Text())
return n
}
func (s *scanner) IntSlice(l int) []int {
if l == 0 {
return []int{}
}
sl := make([]int, l, l)
for i := range sl {
sl[i] = s.Int()
}
return sl
}
func iabs(x int) int {
if x < 0 {
return -x
}
return x
}
func solve(n int, heights []int) int {
t := make([]int, n+1, n+1)
for i := range t {
t[i] = math.MaxInt64
}
t[0] = 0
for i := 1; i < n; i++ {
if v := t[i-1] + iabs(heights[i]-heights[i-1]); v < t[i] {
t[i] = v
}
if 1 < i {
if v := t[i-2] + iabs(heights[i]-heights[i-2]); v < t[i] {
t[i] = v
}
}
}
return t[n-1]
}
func main() {
sc := newScanner(os.Stdin)
n := sc.Int()
heights := sc.IntSlice(n)
ans := solve(n, heights)
fmt.Println(ans)
}
| s458415155 | [
{
"input": "4\n10 30 40 20\n",
"output": "30\n"
}
] |
Go | codenet | package main
import (
"bufio"
"errors"
"fmt"
"math"
"os"
"strconv"
"strings"
)
var sc = bufio.NewScanner(os.Stdin)
func NextLine() string {
sc.Scan()
return sc.Text()
}
func NextIntsLine() []int {
ints := []int{}
intsStr := NextLine()
tmp := strings.Split(intsStr, " ")
for _, s := range tmp {
integer, _ := strconv.Atoi(s)
ints = append(ints, integer)
}
return ints
}
func NextStringsLine() []string {
strs := []string{}
stringsStr := NextLine()
tmp := strings.Split(stringsStr, " ")
for _, s := range tmp {
strs = append(strs, s)
}
return strs
}
func NextRunesLine() []rune {
return []rune(NextLine())
}
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 PowInt(a, e int) int {
if a < 0 || e < 0 {
panic(errors.New("[argument error]: PowInt does not accept negative integers"))
}
fa := float64(a)
fe := float64(e)
fanswer := math.Pow(fa, fe)
return int(fanswer)
}
func AbsInt(a int) int {
fa := float64(a)
fanswer := math.Abs(fa)
return int(fanswer)
}
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
}
var x int
func main() {
tmp := NextIntsLine()
x = tmp[0]
i := 1
sum := 0
for {
sum += i
if sum >= x {
break
}
i++
}
fmt.Println(i)
}
| s617302278 | [
{
"input": "6\n",
"output": "3\n"
}
] |
Go | codenet | package main
import (
"fmt"
)
func main() {
var a int
fmt.Scan(&a)
fmt.Println(a + a*a + a*a*a)
}
| s566920420 | [
{
"input": "2\n",
"output": "14\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"log"
"math"
"math/rand"
"os"
"strconv"
"time"
)
var dx = [...]int{0, 1, 1, 1, 0, -1, -1, -1, 0}
var dy = [...]int{1, 1, 0, -1, -1, -1, 0, 1, 0}
var inf = math.MaxInt64
var next = newScanner()
func init() {
log.SetFlags(log.Lshortfile)
rand.Seed(time.Now().UnixNano())
}
func main() {
N := next.String()
b := []byte(N)
n := 0
for i := 0; i < len(b); i++ {
n += int(b[i] - '0')
}
m, _ := strconv.Atoi(N)
if m%n == 0 {
fmt.Println("Yes")
} else {
fmt.Println("No")
}
}
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[i].b
}
func in(c, a, z int) bool {
return c >= a && c < z
}
func out(c, a, z int) bool {
return !in(c, a, z)
}
func btoi(b bool) int {
if b {
return 1
}
return 0
}
func itob(a int) bool {
return a != 0
}
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 pro(a []int) int {
r := a[0]
for i := 1; i < len(a); i++ {
r *= a[i]
}
return r
}
func fill(a []int, n int) []int {
for i := range a {
a[i] = n
}
return a
}
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 ceil(a, b int) int {
if a%b != 0 {
return 1
}
return 0
}
func printStrings(out []string) {
for i := range out {
fmt.Print(out[i])
if i != len(out)-1 {
fmt.Print(" ")
}
}
fmt.Print("\n")
}
func printInts(out []int) {
for i := range out {
fmt.Print(out[i])
if i != len(out)-1 {
fmt.Print(" ")
}
}
fmt.Print("\n")
}
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) String() string {
return s.next()
}
func (s *scanner) Int() int {
v, err := strconv.Atoi(s.next())
if err != nil {
log.Fatal(err)
}
return v
}
func (s *scanner) Ints(n int) []int {
r := make([]int, n)
for i := 0; i < n; i++ {
r[i] = s.Int()
}
return r
}
func (s *scanner) Int64() int64 {
v, err := strconv.ParseInt(s.next(), 10, 64)
if err != nil {
log.Fatal(err)
}
return v
}
func (s *scanner) Uint64() uint64 {
v, err := strconv.ParseUint(s.next(), 10, 64)
if err != nil {
log.Fatal(err)
}
return v
}
func (s *scanner) Float64() float64 {
v, err := strconv.ParseFloat(s.next(), 64)
if err != nil {
log.Fatal(err)
}
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, err := s.r.ReadLine()
if err != nil {
log.Fatal(err)
}
s.buf = append(s.buf, l...)
if !p {
break
}
}
}
| s940603045 | [
{
"input": "12\n",
"output": "Yes\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
var (
a []int
ans = 0
)
func dfs(left, i, res int) {
if left == 0 {
ans += res
return
}
for j := i; j < len(a); j++ {
dfs(left-1, j+1, res*a[j])
}
}
func main() {
io := newIo()
n := io.nextInt()
dic := map[rune]int{}
for range make([]struct{}, n) {
c := io.nextString()[0]
switch c {
case 'M', 'A', 'R', 'C', 'H':
dic[rune(c)]++
}
}
for _, v := range dic {
a = append(a, v)
}
dfs(3, 0, 1)
fmt.Println(ans)
}
type io struct {
reader *bufio.Reader
tokens []string
nextToken int
}
func newIo() *io {
return &io{reader: bufio.NewReader(os.Stdin)}
}
func (io *io) nextLine() string {
var buffer []byte
for {
line, isPrefix, _ := io.reader.ReadLine()
buffer = append(buffer, line...)
if !isPrefix {
break
}
}
return string(buffer)
}
func (io *io) nextString() string {
for io.nextToken >= len(io.tokens) {
line := io.nextLine()
io.tokens = strings.Fields(line)
io.nextToken = 0
}
r := io.tokens[io.nextToken]
io.nextToken++
return r
}
func (io *io) nextInt() int {
i, _ := strconv.Atoi(io.nextString())
return i
}
| s058450440 | [
{
"input": "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI\n",
"output": "2\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"sort"
"strconv"
)
var sc = bufio.NewScanner(os.Stdin)
func main() {
sc.Split(bufio.ScanWords)
n := nextInt()
ar := make([]int, 3*n)
for i := range ar {
ar[i] = nextInt()
}
sort.Ints(ar)
sum := 0
for i := 0; i < n; i++ {
sum += ar[3*n-(i+1)*2]
}
fmt.Println(sum)
}
func nextInt() int {
sc.Scan()
i, _ := strconv.Atoi(sc.Text())
return i
}
| s144285625 | [
{
"input": "2\n5 2 8 5 1 5\n",
"output": "10\n"
}
] |
Go | codenet | package main
import (
"fmt"
)
func main() {
var a int
fmt.Scan(&a)
fmt.Println(3 * a * a)
}
| s143950643 | [
{
"input": "4\n",
"output": "48\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var s string
fmt.Scan(&s)
for i := 0; i < len(s); i++ {
fmt.Print("x")
}
fmt.Println("")
}
| s682653189 | [
{
"input": "sardine\n",
"output": "xxxxxxx\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func nextInt(sc *bufio.Scanner) int {
sc.Scan()
t, _ := strconv.Atoi(sc.Text())
return t
}
func reva(b []int) {
for i := 0; i < len(b)/2; i++ {
b[i], b[len(b)-1-i] = b[len(b)-1-i], b[i]
}
}
func main() {
sc := bufio.NewScanner(os.Stdin)
sc.Split(bufio.ScanWords)
n := nextInt(sc)
a := make([]int, n)
for i := range a {
a[i] = nextInt(sc)
}
q := nextInt(sc)
for i := 0; i < q; i++ {
b := nextInt(sc)
e := nextInt(sc)
reva(a[b:e])
}
wtr := bufio.NewWriter(os.Stdout)
for i := 0; i < n; i++ {
if i > 0 {
fmt.Fprint(wtr, " ")
}
fmt.Fprint(wtr, a[i])
}
fmt.Fprintln(wtr)
wtr.Flush()
}
| s525290130 | [
{
"input": "8\n1 2 3 4 5 6 7 8\n2\n1 6\n3 8\n",
"output": "1 6 5 8 7 2 3 4\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var n string
fmt.Scan(&n)
for i := 0; i < 3; i++ {
if n[i] == '7' {
fmt.Println("Yes")
return
}
}
fmt.Println("No")
}
| s863302171 | [
{
"input": "117\n",
"output": "Yes\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 lowerBound(a []int, x int) int {
idx := sort.Search(len(a), func(i int) bool {
return a[i] >= x
})
return idx
}
func upperBound(a []int, x int) int {
idx := sort.Search(len(a), func(i int) bool {
return a[i] > x
})
return idx
}
type shop struct {
a, b int
}
type Datas []shop
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].a < p[j].a
}
func main() {
sc.Split(bufio.ScanWords)
N, M := getInt(), getInt()
s := make(Datas, N)
for i := 0; i < N; i++ {
a, b := getInt(), getInt()
s[i] = shop{a, b}
}
sort.Sort(s)
total := 0
for _, e := range s {
n := min(e.b, M)
total += n * e.a
M -= n
if M == 0 {
break
}
}
out(total)
}
| s725956217 | [
{
"input": "2 5\n4 9\n2 4\n",
"output": "12\n"
}
] |
Go | codenet | package main
import (
"fmt"
"sort"
)
func main() {
var n int
fmt.Scan(&n)
var ws works = make([]work, n)
for i := 0; i < n; i++ {
var a, n int
fmt.Scan(&a, &n)
ws[i] = work{a, n}
}
sort.Sort(ws)
sum := int64(0)
for _, w := range ws {
sum += int64(w.time)
if sum > int64(w.limit) {
fmt.Println("No")
return
}
}
fmt.Println("Yes")
}
type work struct{ time, limit int }
type works []work
func (w works) Len() int { return len(w) }
func (w works) Swap(i, j int) { w[i], w[j] = w[j], w[i] }
func (w works) Less(i, j int) bool { return w[i].limit < w[j].limit }
| s851255999 | [
{
"input": "5\n2 4\n1 9\n1 8\n4 9\n3 12\n",
"output": "Yes\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
if len(os.Args) > 1 {
fp, _ = os.Open(os.Args[1])
}
scanner := getScanner(fp)
writer := bufio.NewWriter(os.Stdout)
n := getNextInt(scanner)
m := getNextInt(scanner)
seg := Segment{}
seg.init(n)
for i := 0; i < n; i++ {
seg.maximize(i, getNextInt(scanner))
}
for i := 0; i < m; i++ {
seg.maximize(seg.top(), seg.bucket[seg.h-1][0]>>1)
}
var ans int64
for i := 0; i < n; i++ {
ans += int64(seg.bucket[0][i])
}
fmt.Fprintln(writer, ans)
writer.Flush()
}
type Segment struct {
n, h, i, chunk int
unit []int
bucket [][]int
}
func (seg *Segment) init(n int) {
seg.n = n
seg.unit = make([]int, 1)
seg.unit[0] = 1
seg.bucket = make([][]int, 1)
seg.bucket[0] = make([]int, n)
chunk := 8
for i := 0; n > 1; i++ {
n = (n-1)/chunk + 1
seg.bucket = append(seg.bucket, make([]int, n))
seg.unit = append(seg.unit, seg.unit[i]*chunk)
}
seg.h = len(seg.unit)
seg.chunk = chunk
}
func (seg *Segment) maximize(index, value int) {
seg.bucket[0][index] = value
for seg.i = 0; seg.i < seg.h-1; seg.i++ {
s := index - index%seg.chunk
t := s + seg.chunk
if t > len(seg.bucket[seg.i]) {
t = len(seg.bucket[seg.i])
}
parent := index / seg.chunk
max := 0
for i := s; i < t; i++ {
if max < seg.bucket[seg.i][i] {
max = seg.bucket[seg.i][i]
}
}
seg.bucket[seg.i+1][parent] = max
index /= seg.chunk
}
}
func (seg *Segment) top() int {
index := 0
for seg.i = seg.h - 2; seg.i >= 0; seg.i-- {
s := index * seg.chunk
t := s + seg.chunk
if t > len(seg.bucket[seg.i]) {
t = len(seg.bucket[seg.i])
}
for i := s; i < t; i++ {
if seg.bucket[seg.i][i] == seg.bucket[seg.i+1][index] {
index = i
break
}
}
}
return index
}
| s129530281 | [
{
"input": "3 3\n2 13 8\n",
"output": "9\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
)
func main() {
S, T := ReadString(), ReadString()
max := 0
for i := 0; i <= len(S)-len(T); i++ {
c := 0
for j := 0; j < len(T); j++ {
if S[i+j] == T[j] {
c++
}
}
if max < c {
max = c
}
}
fmt.Println(len(T) - max)
}
var reader = bufio.NewReader(os.Stdin)
func Scan(a ...interface{}) {
if _, err := fmt.Fscan(reader, a...); err != nil {
panic(err)
}
}
func ReadInt() (i int) { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
v := make([]int, n)
for i := 0; i < n; i++ {
Scan(&v[i])
}
return v
}
| s118500787 | [
{
"input": "cabacc\nabc\n",
"output": "1\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
func main() {
s := bufio.NewScanner(os.Stdin)
s.Scan()
s.Scan()
ds := s.Text()
dd := strings.Split(ds, " ")
dn := make([]int, len(dd))
for i, d := range dd {
dn[i], _ = strconv.Atoi(d)
}
sum := 0
for i := 0; i < len(dn); i++ {
for j := i + 1; j < len(dn); j++ {
sum += dn[i] * dn[j]
}
}
fmt.Println(sum)
}
| s692569558 | [
{
"input": "3\n3 1 2\n",
"output": "11\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
const MX = 10000
sieve := make([]int, MX)
primes := make([]int, 0, MX)
for i := 2; i < MX; i++ {
if sieve[i] != 0 {
continue
}
primes = append(primes, i)
for j := i + i; j < MX; j += i {
sieve[j] = i
}
}
var n int
fmt.Scan(&n)
ans := 0
for i := 0; i < n; i++ {
var x int
fmt.Scan(&x)
ans++
for j := 0; j < len(primes); j++ {
if x > primes[j] && x%primes[j] == 0 {
ans--
break
}
}
}
fmt.Println(ans)
}
| s803744887 | [
{
"input": "5\n2\n3\n4\n5\n6\n",
"output": "3\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"log"
"os"
"strconv"
)
func main() {
log.SetFlags(log.Lshortfile)
sc := newScanner()
x := sc.nextInt()
y := sc.nextInt()
var xt, yt int
a := [3][]int{{1, 3, 5, 7, 8, 10, 12}, {4, 6, 9, 11}, {2}}
for i, t := range a {
for _, n := range t {
if x == n {
xt = i
}
if y == n {
yt = i
}
}
}
if xt == yt {
fmt.Println("Yes")
} else {
fmt.Println("No")
}
}
func max(a, b int) int {
if a > b {
return a
}
return b
}
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) 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
}
}
}
| s554024899 | [
{
"input": "1 3\n",
"output": "Yes\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func main() {
sc := NewScanner()
H, W, N := sc.NextInt(), sc.NextInt(), sc.NextInt()
A := max(H, W)
fmt.Println((N + A - 1) / A)
}
func max(a int, b int) int {
if a < b {
return b
}
return a
}
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) NextInt64() int64 {
v, _ := strconv.ParseInt(s.Next(), 10, 64)
return v
}
func (s *Scanner) NextFloat() float64 {
v, _ := strconv.ParseFloat(s.Next(), 64)
return v
}
func (s *Scanner) NextIntArray() []int {
s.pre()
start := s.p
result := []int{}
for ; s.p < len(s.buf)+1; s.p++ {
if s.p == len(s.buf) || s.buf[s.p] == ' ' {
v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
result = append(result, int(v))
start = s.p + 1
}
}
return result
}
func (s *Scanner) NextInt64Array() []int64 {
s.pre()
start := s.p
result := []int64{}
for ; s.p < len(s.buf)+1; s.p++ {
if s.p == len(s.buf) || s.buf[s.p] == ' ' {
v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
result = append(result, v)
start = s.p + 1
}
}
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
}
}
}
| s918723842 | [
{
"input": "3\n7\n10\n",
"output": "2\n"
}
] |
Go | codenet | package main
import "fmt"
var N, K int
var d, a int
func main() {
fmt.Scan(&N, &K)
as := make(map[int]int)
for i := 1; i <= N; i++ {
as[i] = 0
}
for i := 0; i < K; i++ {
fmt.Scan(&d)
for j := 0; j < d; j++ {
fmt.Scan(&a)
as[a]++
}
}
ans := 0
for _, v := range as {
if v == 0 {
ans++
}
}
fmt.Println(ans)
}
| s382986061 | [
{
"input": "3 2\n2\n1 3\n1\n3\n",
"output": "1\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"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 nextInt() int64 {
i, err := strconv.ParseInt(reader.next(), 10, 64)
if err != nil {
panic(err)
}
return i
}
func nextLine() string {
return reader.nextLine()
}
func out(a ...interface{}) {
fmt.Fprintln(writer, a...)
}
func max(x, y int64) int64 {
if x > y {
return x
}
return y
}
func min(x, y int64) int64 {
if x < y {
return x
}
return y
}
func joinInts(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 divUp(x, y int64) int64 {
return (x + y - 1) / y
}
func main() {
solve()
writer.Flush()
}
func solve() {
N := nextInt()
T, A := make([]int64, N), make([]int64, N)
for i := 0; i < int(N); i++ {
T[i], A[i] = nextInt(), nextInt()
}
t, a := T[0], A[0]
for i := 1; i < int(N); i++ {
r := max(divUp(t, T[i]), divUp(a, A[i]))
t, a = T[i]*r, A[i]*r
}
out(t + a)
}
| s541050824 | [
{
"input": "3\n2 3\n1 1\n3 2\n",
"output": "10\n"
}
] |
Go | codenet | package main
import "fmt"
func main() {
var x, y int
fmt.Scan(&x, &y)
fmt.Println(x + y/2)
}
| s784695632 | [
{
"input": "81 58\n",
"output": "110\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
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)
ans := "second"
for i := 0; i < n; i++ {
a := getNextInt(scanner)
if a%2 == 1 {
ans = "first"
break
}
}
fmt.Fprintln(writer, ans)
writer.Flush()
}
| s168401731 | [
{
"input": "2\n1\n2\n",
"output": "first\n"
}
] |
Go | codenet | package main
import (
"bufio"
"bytes"
"fmt"
"io"
"os"
"strconv"
)
var DEBUG = false
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)
var OutputBuffer *bufio.Writer
var OutputWriter io.Writer
func SetInteractive(w io.Writer, r io.Reader) {
SetUnbufferedInput(r)
OutputBuffer = nil
OutputWriter = w
}
func SetOutput(w io.Writer) {
OutputBuffer = bufio.NewWriter(w)
OutputWriter = OutputBuffer
}
func Flush() {
if OutputBuffer != nil {
OutputBuffer.Flush()
}
}
func IsSpace(c byte) bool {
switch c {
case '\t', '\n', '\v', '\f', '\r', ' ':
return true
}
return false
}
func IsNewLine(c byte) bool {
switch c {
case '\n', '\r':
return true
}
return false
}
func SetInput(r io.Reader) {
buf := new(bytes.Buffer)
var b []byte
var i int
rest := func() ([]byte, error) {
for i < len(b) && IsSpace(b[i]) {
i++
}
if i == len(b) {
return nil, io.ErrUnexpectedEOF
}
j := i
for i < len(b) && !IsSpace(b[i]) {
i++
}
return b[j:i], nil
}
initial := func() ([]byte, error) {
io.Copy(buf, r)
b = buf.Bytes()
nextToken = rest
return rest()
}
nextToken = initial
restLn := func() ([]byte, error) {
for i < len(b) && IsNewLine(b[i]) {
i++
}
if i == len(b) {
return nil, io.ErrUnexpectedEOF
}
j := i
for i < len(b) && !IsNewLine(b[i]) {
i++
}
return b[j:i], nil
}
initialLn := func() ([]byte, error) {
io.Copy(buf, r)
b = buf.Bytes()
nextLine = restLn
return restLn()
}
nextLine = initialLn
}
func SetUnbufferedInput(r io.Reader) {
buf := bufio.NewReader(r)
var b []byte
var i int
nextToken = func() ([]byte, error) {
var err error
if i == len(b) {
b, err = buf.ReadBytes('\n')
if err != nil {
return nil, err
}
i = 0
j := len(b) - 1
for 0 <= j && IsSpace(b[j]) {
j--
}
b = b[0 : j+1]
}
for i < len(b) && IsSpace(b[i]) {
i++
}
j := i
for i < len(b) && !IsSpace(b[i]) {
i++
}
if i == j {
return nil, io.ErrUnexpectedEOF
}
return b[j:i], nil
}
}
func readb() []byte {
b, err := nextToken()
if err != nil {
panic(err)
}
return b[:len(b):len(b)]
}
func reads() string {
return string(readb())
}
func readbln() []byte {
b, err := nextLine()
if err != nil {
panic(err)
}
return b[:len(b):len(b)]
}
func readsln() string {
return string(readbln())
}
func readll() int64 {
i, err := strconv.ParseInt(reads(), 10, 64)
if err != nil {
panic(err.Error())
}
return i
}
func readi() int {
return int(readll())
}
func readf() float64 {
f, err := strconv.ParseFloat(reads(), 64)
if err != nil {
panic(err.Error())
}
return f
}
func printf(f string, args ...interface{}) (int, error) {
return fmt.Fprintf(OutputWriter, f, args...)
}
func println(args ...interface{}) (int, error) {
return fmt.Fprintln(OutputWriter, args...)
}
func eprintf(f string, args ...interface{}) (int, error) {
return fmt.Fprintf(os.Stderr, f, args...)
}
func eprintln(args ...interface{}) (int, error) {
return fmt.Fprintln(os.Stderr, args...)
}
func debugf(f string, args ...interface{}) {
if !DEBUG {
return
}
fmt.Fprintf(os.Stderr, f, args...)
}
func debug(args ...interface{}) {
if !DEBUG {
return
}
fmt.Fprintln(os.Stderr, args...)
}
func sumSlice(a []int) int {
var res int
for _, v := range a {
res += v
}
return res
}
func sumSlicell(a []int64) int64 {
var res int64
for _, v := range a {
res += v
}
return res
}
func readInts(N int) (int, []int) {
if N == 0 {
N = readi()
}
a := make([]int, N)
for i := range a {
a[i] = readi()
}
return N, a
}
func readIntsll(N int) (int, []int64) {
if N == 0 {
N = readi()
}
a := make([]int64, N)
for i := range a {
a[i] = readll()
}
return N, a
}
const (
INF = 1000000007
INF2 = 1000000009
INF3 = 998244353
)
func min(a, b int) int {
if a < b {
return a
}
return b
}
func minll(a, b int64) int64 {
if a < b {
return a
}
return b
}
func minf(a, b float64) float64 {
if a < b {
return a
}
return b
}
func max(a, b int) int {
if a < b {
return b
}
return a
}
func maxll(a, b int64) int64 {
if a < b {
return b
}
return a
}
func maxf(a, b float64) float64 {
if a < b {
return b
}
return a
}
func abs(a int) int {
if a < 0 {
return -a
}
return a
}
func absll(a int64) int64 {
if a < 0 {
return -a
}
return a
}
func absf(a float64) float64 {
if a < 0 {
return -a
}
return a
}
func egcd(a, b int) (int, int, int) {
if b == 0 {
return a, 1, 0
}
d, x, y := egcd(b, a%b)
return d, y, x - a/b*y
}
func egcdll(a, b int64) (int64, int64, int64) {
if b == 0 {
return a, 1, 0
}
d, x, y := egcdll(b, a%b)
return d, y, x - a/b*y
}
func gcd(a, b int) int {
d, _, _ := egcd(a, b)
return d
}
func gcdll(a, b int64) int64 {
d, _, _ := egcdll(a, b)
return d
}
func init() {
SetInput(os.Stdin)
SetOutput(os.Stdout)
SetInteractive(os.Stdout, os.Stdin)
}
func main() {
defer Flush()
h, w, k := readi(), readi(), readi()
m := make([][]int, h)
for i := 0; i < h; i++ {
m[i] = make([]int, w)
s := reads()
for j := 0; j < w; j++ {
m[i][j] = int(s[j])
}
}
answer := solve(h, w, k, m)
println(answer)
}
const Black int = 35
func countBlack(h, w int, m [][]int) int {
count := 0
debug("new table")
for i := 0; i < h; i++ {
for j := 0; j < w; j++ {
if m[i][j] == Black {
count++
}
}
debug(m[i])
}
debug("result : ", count)
return count
}
func solve(h, w, a int, m [][]int) int {
result := 0
for i := 0; i < 1<<h; i++ {
for k := 0; k < 1<<w; k++ {
tmp := make([][]int, h)
for j := 0; j < h; j++ {
tmp[j] = make([]int, w)
copy(tmp[j], m[j])
}
for j := 0; j < h; j++ {
hPainted := (1 << j & i)
if hPainted > 0 {
debug("painted ", j, 1<<j, i, hPainted)
for l := 0; l < w; l++ {
tmp[j][l] = 1
}
}
}
for j := 0; j < w; j++ {
wPainted := (1 << j & k)
if wPainted > 0 {
for l := 0; l < h; l++ {
tmp[l][j] = 1
}
}
}
debug("i", strconv.FormatInt(int64(i), 2))
debug("k", strconv.FormatInt(int64(k), 2))
if countBlack(h, w, tmp) == a {
result++
}
}
}
return result
}
| s294436820 | [
{
"input": "2 3 2\n..#\n###\n",
"output": "5\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"math"
"os"
"strconv"
)
func main() {
R := nextInt()
G := nextInt()
B := nextInt()
N := nextInt()
var ans int
for x := 0; x <= N; x++ {
for y := 0; y <= N; y++ {
tmp := N - R*x - G*y
if tmp >= 0 && tmp%B == 0 {
ans++
}
}
}
fmt.Println(ans)
}
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)))
}
| s497500962 | [
{
"input": "1 2 3 4\n",
"output": "4\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
)
func main() {
sc := bufio.NewScanner(os.Stdin)
sc.Scan()
s := sc.Text()
d := 'a' - 'A'
for _, r := range s {
rr := r
if 'A' <= r && r <= 'Z' {
rr = r + d
} else if 'a' <= r && r <= 'z' {
rr = r - d
}
fmt.Printf("%c", rr)
}
fmt.Println()
}
| s057401371 | [
{
"input": "fAIR, LATER, OCCASIONALLY CLOUDY.\n",
"output": "Fair, later, occasionally cloudy.\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()
}
type Node struct {
to []int
}
func main() {
sc.Split(bufio.ScanWords)
N, M := getInt(), getInt()
n := make([]Node, N)
for i := 0; i < M; i++ {
from, to := getInt()-1, getInt()-1
n[from].to = append(n[from].to, to)
n[to].to = append(n[to].to, from)
}
for i := 0; i < N; i++ {
out(len(n[i].to))
}
}
| s236040683 | [
{
"input": "4 3\n1 2\n2 3\n1 4\n",
"output": "2\n2\n1\n1\n"
}
] |
Go | codenet | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
var sc = bufio.NewScanner(os.Stdin)
func readInt() int {
sc.Scan()
i, err := strconv.Atoi(sc.Text())
if err != nil {
panic(err)
}
return i
}
func readFloat64() float64 {
sc.Scan()
f, err := strconv.ParseFloat(sc.Text(), 64)
if err != nil {
panic(err)
}
return f
}
func readString() string {
sc.Scan()
return sc.Text()
}
func main() {
sc.Split(bufio.ScanWords)
n, m := readInt(), readInt()
a := make([]int, n)
sum := 0
for i := 0; i < m; i++ {
a[i] = readInt()
sum += a[i]
}
if sum > n {
fmt.Println("-1")
return
}
fmt.Println(n - sum)
}
| s197768810 | [
{
"input": "41 2\n5 6\n",
"output": "30\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 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)
aa := make([]int, n+2)
sum := 0
for i := 0; i < n; i++ {
aa[i+1] = getNextInt(scanner)
sum += absint(aa[i+1] - aa[i])
}
sum += absint(aa[n+1] - aa[n])
for i := 1; i < n+1; i++ {
ans := sum - absint(aa[i+1]-aa[i]) - absint(aa[i]-aa[i-1]) + absint(aa[i+1]-aa[i-1])
fmt.Fprintln(writer, ans)
}
writer.Flush()
}
func absint(a int) int {
if a < 0 {
return -a
}
return a
}
| s953070177 | [
{
"input": "3\n3 5 -1\n",
"output": "12\n8\n10\n"
}
] |