<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def list( self, application_id, filter_hostname=None, filter_ids=None, page=None):
 """ This API endpoint returns a paginated list of instances associated with the given application. Application instances can be filtered by hostname, or the list of application instance IDs. :type application_id: int :param application_id: Application ID :type filter_hostname: str :param filter_hostname: Filter by server hostname :type filter_ids: list of ints :param filter_ids: Filter by application instance ids :type page: int :param page: Pagination index :rtype: dict :return: The JSON response of the API, with an additional 'pages' key if there are paginated results :: { "application_instances": [ { "id": "integer", "application_name": "string", "host": "string", "port": "integer", "language": "integer", "health_status": "string", "application_summary": { "response_time": "float", "throughput": "float", "error_rate": "float", "apdex_score": "float" }, "end_user_summary": { "response_time": "float", "throughput": "float", "apdex_score": "float" }, "links": { "application": "integer", "application_host": "integer", "server": "integer" } } ], "pages": { "last": { "url": "https://api.newrelic.com/v2/applications/{application_id}/instances.json?page=2", "rel": "last" }, "next": { "url": "https://api.newrelic.com/v2/applications/{application_id}/instances.json?page=2", "rel": "next" } } } """

        filters = [
            'filter[hostname]={0}'.format(filter_hostname) if filter_hostname else None,
            'filter[ids]={0}'.format(','.join([str(app_id) for app_id in filter_ids])) if filter_ids else None,
            'page={0}'.format(page) if page else None
        ]
        return self._get(
            url='{root}applications/{application_id}/instances.json'.format(
                root=self.URL,
                application_id=application_id
            ),
            headers=self.headers,
            params=self.build_param_string(filters)
        )