-- Database schema
| cars : id [ INTEGER ] primary_key , train_id [ INTEGER ] cars.train_id = trains.id , position [ INTEGER ] , shape [ TEXT ] , len [ TEXT ] , sides [ TEXT ] , roof [ TEXT ] , wheels [ INTEGER ] , load_shape [ TEXT ] , load_num [ INTEGER ] | trains : id [ INTEGER ] primary_key , direction [ TEXT ] |
-- -- How many cars running east have double-sided tail cars?

SELECT COUNT(T1.id) FROM trains AS T1 INNER JOIN cars AS T2 ON T1.id = T2.train_id INNER JOIN ( SELECT train_id, MAX(position) AS trailPosi FROM cars GROUP BY train_id ) AS T3 ON T1.id = T3.train_id WHERE T1.direction = 'east' AND T2.position = T3.trailPosi AND T2.sides = 'double';