

def       A_     (							a = 1_0_0     ):

      """simple docstring"""



      SCREAMING_SNAKE_CASE_ :     Any							=   (n * (n + 1) // 2) ** 2
      SCREAMING_SNAKE_CASE_ :     Optional[int]							=   n * (n + 1) * (2 * n + 1) // 6
      return sum_cubes - sum_squares


if __name__ == "__main__":
    print(F'{solution() = }')











"""simple docstring"""







import collections
import json
import math
import os
import re
import time
from fnmatch import fnmatch
from typing import Dict

import requests
from slack_sdk import WebClient


lowercase__		:				List[str]          =	WebClient(token=os.environ["""CI_SLACK_BOT_TOKEN"""])

def 				UpperCamelCase_    (    lowerCAmelCase__      :				Dict						)						->   Optional[Any]:

  """simple docstring"""




  lowerCAmelCase_   :				List[Any]								= test_results.split(' '						)

  lowerCAmelCase_   :				Tuple								= 0
  lowerCAmelCase_   :				Any								= 0

  # When the output is short enough, the output is surrounded by = signs: "== OUTPUT =="
  # When it is too long, those signs are not present.
  lowerCAmelCase_   :				Any								= expressions[-2] if '=' in expressions[-1] else expressions[-1]

  for i, expression in enumerate(lowerCAmelCase__						):
    if "failed" in expression:
      failed += int(expressions[i - 1]						)
    if "passed" in expression:
      success += int(expressions[i - 1]						)

  return failed, success, time_spent

def 				UpperCamelCase_    (    lowerCAmelCase__      :				Dict						)						->   str:

  """simple docstring"""




  lowerCAmelCase_   :				Optional[Any]								= {}
  lowerCAmelCase_   :				List[str]								= None
  lowerCAmelCase_   :				List[str]								= False
  for line in failures_short_lines.split('\n'						):
    if re.search(R'_ \[doctest\]'    ,   lowerCAmelCase__						):
      lowerCAmelCase_   :				Optional[Any]								= True
      lowerCAmelCase_   :				Union[str, Any]								= line.split(' '						)[2]
    elif in_error and not line.split(' '						)[0].isdigit():
      lowerCAmelCase_   :				Union[str, Any]								= line
      lowerCAmelCase_   :				int								= False

  return failures







class       UpperCamelCase__   :




      """simple docstring"""




      def __init__(      self				:      Optional[Any]    ,			SCREAMING_SNAKE_CASE_				:      str    ,			SCREAMING_SNAKE_CASE_				:      Dict       ):
        lowerCAmelCase_   :				str								= title

        lowerCAmelCase_   :				Optional[int]								= doc_test_results['time_spent'].split(','       )[0]
        lowerCAmelCase_   :				int								= doc_test_results['success']
        lowerCAmelCase_   :				Dict								= doc_test_results['failures']
        lowerCAmelCase_   :				Optional[int]								= self.n_success + self.n_failures

        # Failures and success of the modeling tests
        lowerCAmelCase_   :				Any								= doc_test_results



      @property
      def      SCREAMING_SNAKE_CASE__ (      self				:      List[str]       ):
        lowerCAmelCase_   :				int								= [self._time_spent]
        lowerCAmelCase_   :				Any								= 0

        for time in time_spent:
          lowerCAmelCase_   :				Optional[Any]								= time.split(':'       )

          # Time can be formatted as xx:xx:xx, as .xx, or as x.xx if the time spent was less than a minute.
          if len(SCREAMING_SNAKE_CASE_       ) == 1:
            lowerCAmelCase_   :				Any								= [0, 0, time_parts[0]]

          lowerCAmelCase_						,lowerCAmelCase_						,lowerCAmelCase_   :				List[str]								= int(time_parts[0]       ), int(time_parts[1]       ), float(time_parts[2]       )
          total_secs += hours * 3_6_0_0 + minutes * 6_0 + seconds

        lowerCAmelCase_						,lowerCAmelCase_						,lowerCAmelCase_   :				Union[str, Any]								= total_secs // 3_6_0_0, (total_secs % 3_6_0_0) // 6_0, total_secs % 6_0
        return F"{int(SCREAMING_SNAKE_CASE_       )}h{int(SCREAMING_SNAKE_CASE_       )}m{int(SCREAMING_SNAKE_CASE_       )}s"



      @property
      def      SCREAMING_SNAKE_CASE__ (      self				:      int       ):
        return {"type": "header", "text": {"type": "plain_text", "text": self.title}}



      @property
      def      SCREAMING_SNAKE_CASE__ (      self				:      str       ):
        return {
            "type": "section",
            "text": {
                "type": "plain_text",
                "text": F"🌞 There were no failures: all {self.n_tests} tests passed. The suite ran in {self.time}.",
                "emoji": True,
            },
            "accessory": {
                "type": "button",
                "text": {"type": "plain_text", "text": "Check Action results", "emoji": True},
                "url": F"https://github.com/huggingface/transformers/actions/runs/{os.environ['GITHUB_RUN_ID']}",
            },
        }



      @property
      def      SCREAMING_SNAKE_CASE__ (      self				:      List[Any]       ):
        return {
            "type": "section",
            "text": {
                "type": "plain_text",
                "text": (
                    F"There were {self.n_failures} failures, out of {self.n_tests} tests.\nThe suite ran in"
                    F" {self.time}."
                ),
                "emoji": True,
            },
            "accessory": {
                "type": "button",
                "text": {"type": "plain_text", "text": "Check Action results", "emoji": True},
                "url": F"https://github.com/huggingface/transformers/actions/runs/{os.environ['GITHUB_RUN_ID']}",
            },
        }



      @property
      def      SCREAMING_SNAKE_CASE__ (      self				:      Tuple       ):
        lowerCAmelCase_   :				int								= 4_0
        lowerCAmelCase_   :				List[Any]								= {k: v['failed'] for k, v in doc_test_results.items() if isinstance(SCREAMING_SNAKE_CASE_    ,			SCREAMING_SNAKE_CASE_       )}

        lowerCAmelCase_   :				List[str]								= ''
        for category, failures in category_failures.items():
          if len(SCREAMING_SNAKE_CASE_       ) == 0:
            continue

          if report != "":
            report += "\n\n"

          report += F"*{category} failures*:".ljust(line_length // 2       ).rjust(line_length // 2       ) + "\n"
          report += "`"
          report += "`\n`".join(SCREAMING_SNAKE_CASE_       )
          report += "`"

        return {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": F"The following examples had failures:\n\n\n{report}\n",
            },
        }



      @property
      def      SCREAMING_SNAKE_CASE__ (      self				:      int       ):
        lowerCAmelCase_   :				int								= [self.header]

        if self.n_failures > 0:
          blocks.append(self.failures       )

        if self.n_failures > 0:
          blocks.extend([self.category_failures]       )

        if self.n_failures == 0:
          blocks.append(self.no_failures       )

        return json.dumps(SCREAMING_SNAKE_CASE_       )



      @staticmethod
      def      SCREAMING_SNAKE_CASE__ (      ):
        lowerCAmelCase_   :				Tuple								= [
            {
                'type': 'section',
                'text': {
                    'type': 'plain_text',
                    'text': 'There was an issue running the tests.',
                },
                'accessory': {
                    'type': 'button',
                    'text': {'type': 'plain_text', 'text': 'Check Action results', 'emoji': True},
                    'url': F"https://github.com/huggingface/transformers/actions/runs/{os.environ['GITHUB_RUN_ID']}",
                },
            }
        ]

        print('Sending the following payload'       )
        print(json.dumps({'blocks': json.loads(SCREAMING_SNAKE_CASE_       )}       )       )

        client.chat_postMessage(
            channel=os.environ['CI_SLACK_CHANNEL_ID_DAILY']    ,			text='There was an issue running the tests.'    ,			blocks=SCREAMING_SNAKE_CASE_    ,			)



      def      SCREAMING_SNAKE_CASE__ (      self				:      Union[str, Any]       ):
        print('Sending the following payload'       )
        print(json.dumps({'blocks': json.loads(self.payload       )}       )       )

        lowerCAmelCase_   :				Any								= F"{self.n_failures} failures out of {self.n_tests} tests," if self.n_failures else 'All tests passed.'

        lowerCAmelCase_   :				str								= client.chat_postMessage(
            channel=os.environ['CI_SLACK_CHANNEL_ID_DAILY']    ,			blocks=self.payload    ,			text=SCREAMING_SNAKE_CASE_    ,			)



      def      SCREAMING_SNAKE_CASE__ (      self				:      str    ,			SCREAMING_SNAKE_CASE_				:      int    ,			SCREAMING_SNAKE_CASE_				:      Any    ,			SCREAMING_SNAKE_CASE_				:      Any    ,			SCREAMING_SNAKE_CASE_				:      Dict       ):
        lowerCAmelCase_   :				List[Any]								= ''
        for key, value in failures.items():
          lowerCAmelCase_   :				List[Any]								= value[:2_0_0] + ' [Truncated]' if len(SCREAMING_SNAKE_CASE_       ) > 2_5_0 else value
          failures_text += F"*{key}*\n_{value}_\n\n"

        lowerCAmelCase_   :				int								= job_name
        lowerCAmelCase_   :				Dict								= {'type': 'section', 'text': {'type': 'mrkdwn', 'text': text}}

        if job_link is not None:
          lowerCAmelCase_   :				str								= {
              'type': 'button',
              'text': {'type': 'plain_text', 'text': 'GitHub Action job', 'emoji': True},
              'url': job_link,
          }

        return [
            {"type": "header", "text": {"type": "plain_text", "text": title.upper(), "emoji": True}},
            content,
            {"type": "section", "text": {"type": "mrkdwn", "text": failures_text}},
        ]





      def      SCREAMING_SNAKE_CASE__ (      self				:      Union[str, Any]       ):
        if self.thread_ts is None:
          raise ValueError('Can only post reply if a post has been made.'       )

        lowerCAmelCase_   :				Dict								= self.doc_test_results.pop('job_link'       )
        self.doc_test_results.pop('failures'       )
        self.doc_test_results.pop('success'       )
        self.doc_test_results.pop('time_spent'       )

        lowerCAmelCase_   :				Dict								= sorted(self.doc_test_results.items()    ,			key=lambda SCREAMING_SNAKE_CASE_       : t[0]       )
        for job, job_result in sorted_dict:
          if len(job_result['failures']       ):
            lowerCAmelCase_   :				Tuple								= F"*Num failures* :{len(job_result['failed']       )} \n"
            lowerCAmelCase_   :				List[str]								= job_result['failures']
            lowerCAmelCase_   :				Union[str, Any]								= self.get_reply_blocks(SCREAMING_SNAKE_CASE_    ,			SCREAMING_SNAKE_CASE_    ,			SCREAMING_SNAKE_CASE_    ,			text=SCREAMING_SNAKE_CASE_       )

            print('Sending the following reply'       )
            print(json.dumps({'blocks': blocks}       )       )

            client.chat_postMessage(
                channel=os.environ['CI_SLACK_CHANNEL_ID_DAILY']    ,			text=F"Results for {job}"    ,			blocks=SCREAMING_SNAKE_CASE_    ,			thread_ts=self.thread_ts['ts']    ,			)

            time.sleep(1       )




def 				UpperCamelCase_    (    )						->   str:

  """simple docstring"""




  lowerCAmelCase_   :				Union[str, Any]								= os.environ['GITHUB_RUN_ID']
  lowerCAmelCase_   :				int								= f"https://api.github.com/repos/huggingface/transformers/actions/runs/{run_id}/jobs?per_page=100"
  lowerCAmelCase_   :				str								= requests.get(lowerCAmelCase__						).json()
  lowerCAmelCase_   :				List[str]								= {}

  try:
    jobs.update({job['name']: job['html_url'] for job in result['jobs']}						)
    lowerCAmelCase_   :				Optional[Any]								= math.ceil((result['total_count'] - 100) / 100						)

    for i in range(lowerCAmelCase__						):
      lowerCAmelCase_   :				int								= requests.get(url + f"&page={i + 2}"						).json()
      jobs.update({job['name']: job['html_url'] for job in result['jobs']}						)

    return jobs
  except Exception as e:
    print('Unknown error, could not fetch links.'    ,   lowerCAmelCase__						)

  return {}

def 				UpperCamelCase_    (    lowerCAmelCase__      :				str						)						->   List[Any]:

  """simple docstring"""




  lowerCAmelCase_   :				int								= {}

  if os.path.exists(lowerCAmelCase__						):
    lowerCAmelCase_   :				Tuple								= os.listdir(lowerCAmelCase__						)
    for file in files:
      try:
        with open(os.path.join(lowerCAmelCase__    ,   lowerCAmelCase__						)    ,   encoding='utf-8'						) as f:
          lowerCAmelCase_   :				List[str]								= f.read()
      except UnicodeDecodeError as e:
        raise ValueError(f"Could not open {os.path.join(lowerCAmelCase__    ,   lowerCAmelCase__						)}."						) from e

  return _artifact

def 				UpperCamelCase_    (    )						->   Dict:

  """simple docstring"""




  class       UpperCamelCase__   :




        """simple docstring"""




        def __init__(      self				:      Dict    ,			SCREAMING_SNAKE_CASE_				:      str       ):
          lowerCAmelCase_   :				List[Any]								= name
          lowerCAmelCase_   :				Tuple								= []



        def __str__(      self				:      Optional[Any]       ):
          return self.name





        def      SCREAMING_SNAKE_CASE__ (      self				:      List[Any]    ,			SCREAMING_SNAKE_CASE_				:      str       ):
          self.paths.append({'name': self.name, 'path': path}       )




  lowerCAmelCase_   :				Dict[str, Artifact]								= {}

  lowerCAmelCase_   :				Any								= filter(os.path.isdir    ,   os.listdir()						)
  for directory in directories:
    lowerCAmelCase_   :				int								= directory
    if artifact_name not in _available_artifacts:
      lowerCAmelCase_   :				Optional[Any]								= Artifact(lowerCAmelCase__						)

      _available_artifacts[artifact_name].add_path(lowerCAmelCase__						)

  return _available_artifacts


if __name__ == "__main__":
     lowercase__		:				Optional[int]          =	get_job_links()
     lowercase__		:				Any          =	retrieve_available_artifacts()

     lowercase__		:				str          =	collections.OrderedDict(
         [
             ("""*.py""", """API Examples"""),
             ("""*.md""", """MD Examples"""),
         ]
     )

     # This dict will contain all the information relative to each doc test category:
     # - failed: list of failed tests
     # - failures: dict in the format 'test': 'error_message'
     lowercase__		:				Dict          =	{
         v: {
             """failed""": [],
             """failures""": {},
         }
         for v in docs.values()
     }

     # Link to the GitHub Action job
     lowercase__		:				str          =	github_actions_job_links.get("""run_doctests""")

     lowercase__		:				int          =	available_artifacts["""doc_tests_gpu_test_reports"""].paths[0]
     lowercase__		:				List[str]          =	retrieve_artifact(artifact_path["""name"""])
     if "stats" in artifact:
          lowercase__    ,     lowercase__    ,     lowercase__		:				str          =	handle_test_results(artifact["""stats"""])
          lowercase__		:				Any          =	failed
          lowercase__		:				str          =	success
          lowercase__		:				int          =	time_spent[1:-1] + """, """

          lowercase__		:				Tuple          =	extract_first_line_failure(artifact["""failures_short"""])
          for line in artifact["summary_short"].split("""\n"""):
               if re.search("""FAILED""", line):
                    lowercase__		:				List[str]          =	line.replace("""FAILED """, """""")
                    lowercase__		:				Union[str, Any]          =	line.split()[0].replace("""\n""", """""")

                    if "::" in line:
                         lowercase__    ,     lowercase__		:				Optional[Any]          =	line.split("""::""")
                    else:
                         lowercase__    ,     lowercase__		:				int          =	line, line

                    for file_regex in docs.keys():
                         if fnmatch(file_path, file_regex):
                              lowercase__		:				str          =	docs[file_regex]
                              doc_test_results[category]["failed"].append(test)

                              lowercase__		:				List[Any]          =	all_failures[test] if test in all_failures else """N/A"""
                              lowercase__		:				List[Any]          =	failure
                              break

     lowercase__		:				Union[str, Any]          =	Message("""🤗 Results of the doc tests.""", doc_test_results)
     message.post()
     message.post_reply()





