Nuts & Bolts Problem(LintCode 399):

Problem