Improving In-context Learning via Bidirectional Alignment