<commit_before><commit_msg>[Kotlin] 14888 - 연산자 끼워넣기<commit_after>import java.io.BufferedReader
import java.io.BufferedWriter
import java.io.InputStreamReader
import java.io.OutputStreamWriter

var N = 0
var A = Array<Int>(0, {0})
var ops = Array<Int>(0, {0})
var min = 0x7fffffff
var max = -min

fun main(args: Array<String>){
	val br = BufferedReader(InputStreamReader(System.`in`))
	val bw = BufferedWriter(OutputStreamWriter(System.out))

	N = br.readLine().toInt()
	A = Array<Int>(N, {0})
	ops = Array<Int>(N-1, {0})
	var line = br.readLine().split(" ")
	for(i in 0 until N)
		A[i] = line[i].toInt()
	line = br.readLine().split(" ")
	var k = 0; var l = 0
	for(i in 0..3){
		l = line[i].toInt()
		for(j in 0 until l) ops[k++] = i
	}
	dfs("")
	bw.write("%d\n%d".format(max, min))

	bw.close()
	br.close()
}

fun dfs(op: String) {
	if(op.length == N-1){
		calc(op)
		return
	}
	var k = 0
	for(i in 0 until N-1){
		if(ops[i] == -1) continue
		k = ops[i]; ops[i] = -1
		if(k==0) dfs(op+'+')
		else if(k==1) dfs(op+'-')
		else if(k==2) dfs(op+'*')
		else dfs(op+'/')
		ops[i] = k;
	}
}

fun calc(op: String){
	var ch = '0'
	var a = A[0]
	var b = 0
	for(i in 0 until N-1){
		ch = op[i]; b = A[i+1]
		if(ch=='+') a+=b
		else if(ch=='-') a-=b
		else if(ch=='*') a*=b
		else a/=b
	}
	max = Math.max(max, a);
	min = Math.min(min, a);
}
{'fraction_non_alphanumeric': 0.22272385252069224, 'fraction_numerical': 0.02708803611738149, 'mean_word_length': 3.433333333333333, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1856796', 'n_tokens_mistral': 659, 'n_tokens_neox': 629, 'n_words': 151}