var input = require("fs").readFileSync("input.txt").toString().split("\n").filter(a=>a); var sqs = input.map((a)=>(a.match(/#\d+ @ (\d+),(\d+): (\d+)x(\d+)/)).map(a=>(parseInt(a))).filter(a=>(a>=0))); var xa = Math.min.apply(null, sqs.map(a=>(a[0]))); var ya = Math.min.apply(null, sqs.map(a=>(a[1]))); var xb = Math.max.apply(null, sqs.map(a=>(a[0]+a[2]))); var yb = Math.max.apply(null, sqs.map(a=>(a[1]+a[3]))); var count = 0; for(var x = xa; x <= xb; x++){ for(var y = ya; y <= yb; y++){ if(sqs.filter(a=>( (a[0] <= x) && ((a[0] + a[2]) > x) && (a[1] <= y) && ((a[1]) + a[3]) > y)).length >= 2){ count++; } } } console.log(count);