prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Generating invalid cpf (brazillian ssn)
  Faker is generating invalid checksum digits for cpf (brazillian ssn).
  
  ### Steps to reproduce
  
  1. Create fake instance using localization "pt_BR"
  1. Call fake.cpf()
  
  ### Expected behavior
  
  It should generate a valid CPF.
  
  ### Actual behavior
  
  It is generating a CPF with invalid checksum digits, in some cases.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `faker/providers/ssn/pt_BR/__init__.py`
  Content:
  ```
  1 #  -*- coding: utf-8 -*-
  2 
  3 from __future__ import unicode_literals
  4 from .. import Provider as SsnProvider
  5 
  6 
  7 def checksum(digits):
  8     s = 0
  9     p = len(digits) + 1
  10     for i in range(0, len(digits)):
  11         s += digits[i] * p
  12         p -= 1
  13 
  14     reminder = s % 11
  15     if reminder == 0 or reminder == 1:
  16         return 1
  17     else:
  18         return 11 - reminder
  19 
  20 
  21 class Provider(SsnProvider):
  22     """
  23     Provider for Brazilian SSN also known in Brazil as CPF.
  24     There are two methods Provider.ssn and Provider.cpf
  25     The snn returns a valid number with numbers only
  26     The cpf return a valid number formatted with brazilian mask. eg nnn.nnn.nnn-nn
  27     """
  28 
  29     def ssn(self):
  30         digits = self.generator.random.sample(range(10), 9)
  31 
  32         dv = checksum(digits)
  33         digits.append(dv)
  34         digits.append(checksum(digits))
  35 
  36         return ''.join(map(str, digits))
  37 
  38     def cpf(self):
  39         c = self.ssn()
  40         return c[:3] + '.' + c[3:6] + '.' + c[6:9] + '-' + c[9:]
  41
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/faker/providers/ssn/pt_BR/__init__.py b/faker/providers/ssn/pt_BR/__init__.py
  --- a/faker/providers/ssn/pt_BR/__init__.py
  +++ b/faker/providers/ssn/pt_BR/__init__.py
  @@ -5,6 +5,12 @@
   
   
   def checksum(digits):
  +    """
  +    Returns the checksum of CPF digits.
  +    References to the algorithm:
  +    https://pt.wikipedia.org/wiki/Cadastro_de_pessoas_f%C3%ADsicas#Algoritmo
  +    https://metacpan.org/source/MAMAWE/Algorithm-CheckDigits-v1.3.0/lib/Algorithm/CheckDigits/M11_004.pm
  +    """
       s = 0
       p = len(digits) + 1
       for i in range(0, len(digits)):
  @@ -13,7 +19,7 @@
   
       reminder = s % 11
       if reminder == 0 or reminder == 1:
  -        return 1
  +        return 0
       else:
           return 11 - reminder
  
verification_info: {"golden_diff": "diff --git a/faker/providers/ssn/pt_BR/__init__.py b/faker/providers/ssn/pt_BR/__init__.py\n--- a/faker/providers/ssn/pt_BR/__init__.py\n+++ b/faker/providers/ssn/pt_BR/__init__.py\n@@ -5,6 +5,12 @@\n \n \n def checksum(digits):\n+    \"\"\"\n+    Returns the checksum of CPF digits.\n+    References to the algorithm:\n+    https://pt.wikipedia.org/wiki/Cadastro_de_pessoas_f%C3%ADsicas#Algoritmo\n+    https://metacpan.org/source/MAMAWE/Algorithm-CheckDigits-v1.3.0/lib/Algorithm/CheckDigits/M11_004.pm\n+    \"\"\"\n     s = 0\n     p = len(digits) + 1\n     for i in range(0, len(digits)):\n@@ -13,7 +19,7 @@\n \n     reminder = s % 11\n     if reminder == 0 or reminder == 1:\n-        return 1\n+        return 0\n     else:\n         return 11 - reminder\n", "issue": "Generating invalid cpf (brazillian ssn)\nFaker is generating invalid checksum digits for cpf (brazillian ssn).\r\n\r\n### Steps to reproduce\r\n\r\n1. Create fake instance using localization \"pt_BR\"\r\n1. Call fake.cpf()\r\n\r\n### Expected behavior\r\n\r\nIt should generate a valid CPF.\r\n\r\n### Actual behavior\r\n\r\nIt is generating a CPF with invalid checksum digits, in some cases.\r\n\n", "before_files": [{"content": "#  -*- coding: utf-8 -*-\n\nfrom __future__ import unicode_literals\nfrom .. import Provider as SsnProvider\n\n\ndef checksum(digits):\n    s = 0\n    p = len(digits) + 1\n    for i in range(0, len(digits)):\n        s += digits[i] * p\n        p -= 1\n\n    reminder = s % 11\n    if reminder == 0 or reminder == 1:\n        return 1\n    else:\n        return 11 - reminder\n\n\nclass Provider(SsnProvider):\n    \"\"\"\n    Provider for Brazilian SSN also known in Brazil as CPF.\n    There are two methods Provider.ssn and Provider.cpf\n    The snn returns a valid number with numbers only\n    The cpf return a valid number formatted with brazilian mask. eg nnn.nnn.nnn-nn\n    \"\"\"\n\n    def ssn(self):\n        digits = self.generator.random.sample(range(10), 9)\n\n        dv = checksum(digits)\n        digits.append(dv)\n        digits.append(checksum(digits))\n\n        return ''.join(map(str, digits))\n\n    def cpf(self):\n        c = self.ssn()\n        return c[:3] + '.' + c[3:6] + '.' + c[6:9] + '-' + c[9:]\n", "path": "faker/providers/ssn/pt_BR/__init__.py"}], "after_files": [{"content": "#  -*- coding: utf-8 -*-\n\nfrom __future__ import unicode_literals\nfrom .. import Provider as SsnProvider\n\n\ndef checksum(digits):\n    \"\"\"\n    Returns the checksum of CPF digits.\n    References to the algorithm:\n    https://pt.wikipedia.org/wiki/Cadastro_de_pessoas_f%C3%ADsicas#Algoritmo\n    https://metacpan.org/source/MAMAWE/Algorithm-CheckDigits-v1.3.0/lib/Algorithm/CheckDigits/M11_004.pm\n    \"\"\"\n    s = 0\n    p = len(digits) + 1\n    for i in range(0, len(digits)):\n        s += digits[i] * p\n        p -= 1\n\n    reminder = s % 11\n    if reminder == 0 or reminder == 1:\n        return 0\n    else:\n        return 11 - reminder\n\n\nclass Provider(SsnProvider):\n    \"\"\"\n    Provider for Brazilian SSN also known in Brazil as CPF.\n    There are two methods Provider.ssn and Provider.cpf\n    The snn returns a valid number with numbers only\n    The cpf return a valid number formatted with brazilian mask. eg nnn.nnn.nnn-nn\n    \"\"\"\n\n    def ssn(self):\n        digits = self.generator.random.sample(range(10), 9)\n\n        dv = checksum(digits)\n        digits.append(dv)\n        digits.append(checksum(digits))\n\n        return ''.join(map(str, digits))\n\n    def cpf(self):\n        c = self.ssn()\n        return c[:3] + '.' + c[3:6] + '.' + c[6:9] + '-' + c[9:]\n", "path": "faker/providers/ssn/pt_BR/__init__.py"}]}