let N = 39
let rgbArray = Array(" RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB")
var count = 0

var rgbIndex = Array(repeating: Array(repeating: 0, count: 0), count: 3)

rgbArray.enumerated().forEach{
    if $0.1 == "R"{
        rgbIndex[0].append($0.0)
    }
    if $0.1 == "G"{
        rgbIndex[1].append($0.0)
    }
    if $0.1 == "B"{
        rgbIndex[2].append($0.0)
    }

    
}
var total = rgbIndex[2].count*rgbIndex[1].count*rgbIndex[0].count

for i in 1...(N-2) {
    for j in (i+1)...(N-1) {
        let x = j - i
        let k = j + x
        if k <= N && rgbArray[i] != rgbArray[j] && rgbArray[i] != rgbArray[k] && rgbArray[j] != rgbArray[k]{
            total -= 1
        }

    }
}

print(total)
