The lyrics were written by BjÃ rnstjerne BjÃ rnson , and melody by his cousin , Rikard Nordraak . The lyrics were written by BjÃ rnstjerne BjÃ rnson between 1859 and 1868 , and the melody was written by his cousin Rikard Nordraak in 1864 .