import random

randomSub = [
{"question_id":266182,"source":"#include <bits/stdc++.h>\nusing namespace std;\nclass Node {\npublic:\n    int data;\n    Node *left, *right;\n};\nNode* newNode(int item)\n{\n    Node* temp = new Node();\n    temp->data = item;\n    temp->left = temp->right = NULL;\n    return temp;\n}\nNode* insert(Node* node, int data)\n{\n    if (node == NULL)\n        return newNode(data);\n    if (data <= node->data)\n        node->left = insert(node->left,\n                            data);\n    else\n        node->right = insert(node->right,\n                             data);\n    return node;\n}\n\nint sum=0;\nint sumofvalofgivenrange(Node *root,int start,int end)\n{\n        if(root==NULL)\n            return 0;\n        if(root->data>=start && root->data<=end)\n            sum+=root->data;\n        sumofvalofgivenrange(root->left,start,end);\n        sumofvalofgivenrange(root->right,start,end);\n        return sum;\n}\nint main()\n{\n    Node* root = NULL;\n    int n;\n    cin>>n;\n    int k;\n    cin>>k;\n    root=insert(root,k);\n    for(int i=1;i<n;i++)\n    {\n        cin>>k;\n        insert(root,k);\n    }\n    int start,end;\n    cin>>start>>end;\n    int ans=sumofvalofgivenrange(root,start,end);\n    cout<<ans;\n    return 0;\n}","lang":"2"},
{"question_id":266182,"source":"#include <bits/stdc++.h>\nusing namespace std;\nclass Node {\npublic:\n    int data;\n    Node *left, *right;\n};\nNode* newNode(int item)\n{\n    Node* temp = new Node();\n    temp->data = item;\n    temp->left = temp->right = NULL;\n    return temp;\n}\nNode* insert(Node* node, int data)\n{\n    if (node == NULL)\n        return newNode(data);\n    if (data <= node->data)\n        node->left = insert(node->left,\n                            data);\n    else\n        node->right = insert(node->right,\n                             data);\n    return node;\n}\n\nint sum=0;\nint sumofvalofgivenrange(Node *root,int start,int end)\n{\n        if(root==NULL)\n            return 0;\n        if(root->data>=start && root->data<=end)\n            sum+=root->data;\n        sumofvalofgivenrange(root->left,start,end);\n        sumofvalofgivenrange(root->right,start,end);\n        return sum;\n}\nint main()\n{\n    Node* root = NULL;\n    int n;\n    cin>>n;\n    int k;\n    cin>>k;\n    root=insert(root,k);\n    for(int i=1;i<n;i++)\n    {\n        cin>>k;\n        insert(root,k);\n    }\n    int start,end;\n    cin>>start>>end;\n    int ans=sumofvalofgivenrange(root,start,end);\n    cout<<ans;\n    return 0;\n}","lang":"2"},
{"question_id":266182,"source":"#include <bits/stdc++.h>\nusing namespace std;\nclass Node {\npublic:\n    int data;\n    Node *left, *right;\n};\nNode* newNode(int item)\n{\n    Node* temp = new Node();\n    temp->data = item;\n    temp->left = temp->right = NULL;\n    return temp;\n}\nNode* insert(Node* node, int data)\n{\n    if (node == NULL)\n        return newNode(data);\n    if (data <= node->data)\n        node->left = insert(node->left,\n                            data);\n    else\n        node->right = insert(node->right,\n                             data);\n    return node;\n}\n\nint sum=0;\nint sumofvalofgivenrange(Node *root,int start,int end)\n{\n        if(root==NULL)\n            return 0;\n        if(root->data>=start && root->data<=end)\n            sum+=root->data;\n        sumofvalofgivenrange(root->left,start,end);\n        sumofvalofgivenrange(root->right,start,end);\n        return sum;\n}\nint main()\n{\n    Node* root = NULL;\n    int n;\n    cin>>n;\n    int k;\n    cin>>k;\n    root=insert(root,k);\n    for(int i=1;i<n;i++)\n    {\n        cin>>k;\n        insert(root,k);\n    }\n    int start,end;\n    cin>>start>>end;\n    int ans=sumofvalofgivenrange(root,start,end);\n    cout<<ans;\n    return 0;\n}","lang":"2"},
{"question_id":266182,"source":"#include <bits/stdc++.h>\nusing namespace std;\nclass Node {\npublic:\n    int data;\n    Node *left, *right;\n};\nNode* newNode(int item)\n{\n    Node* temp = new Node();\n    temp->data = item;\n    temp->left = temp->right = NULL;\n    return temp;\n}\nNode* insert(Node* node, int data)\n{\n    if (node == NULL)\n        return newNode(data);\n    if (data <= node->data)\n        node->left = insert(node->left,\n                            data);\n    else\n        node->right = insert(node->right,\n                             data);\n    return node;\n}\n\nint sum=0;\nint sumofvalofgivenrange(Node *root,int start,int end)\n{\n        if(root==NULL)\n            return 0;\n        if(root->data>=start && root->data<=end)\n            sum+=root->data;\n        sumofvalofgivenrange(root->left,start,end);\n        sumofvalofgivenrange(root->right,start,end);\n        return sum;\n}\nint main()\n{\n    Node* root = NULL;\n    int n;\n    cin>>n;\n    int k;\n    cin>>k;\n    root=insert(root,k);\n    for(int i=1;i<n;i++)\n    {\n        cin>>k;\n        insert(root,k);\n    }\n    int start,end;\n    cin>>start>>end;\n    int ans=sumofvalofgivenrange(root,start,end);\n    cout<<ans;\n    return 0;\n}","lang":"2"},
{"question_id":266182,"source":"#include <bits/stdc++.h>\nusing namespace std;\nclass Node {\npublic:\n    int data;\n    Node *left, *right;\n};\nNode* newNode(int item)\n{\n    Node* temp = new Node();\n    temp->data = item;\n    temp->left = temp->right = NULL;\n    return temp;\n}\nNode* insert(Node* node, int data)\n{\n    if (node == NULL)\n        return newNode(data);\n    if (data <= node->data)\n        node->left = insert(node->left,\n                            data);\n    else\n        node->right = insert(node->right,\n                             data);\n    return node;\n}\n\nint sum=0;\nint sumofvalofgivenrange(Node *root,int start,int end)\n{\n        if(root==NULL)\n            return 0;\n        if(root->data>=start && root->data<=end)\n            sum+=root->data;\n        sumofvalofgivenrange(root->left,start,end);\n        sumofvalofgivenrange(root->right,start,end);\n        return sum;\n}\nint main()\n{\n    Node* root = NULL;\n    int n;\n    cin>>n;\n    int k;\n    cin>>k;\n    root=insert(root,k);\n    for(int i=1;i<n;i++)\n    {\n        cin>>k;\n        insert(root,k);\n    }\n    int start,end;\n    cin>>start>>end;\n    int ans=sumofvalofgivenrange(root,start,end);\n    cout<<ans;\n    return 0;\n}","lang":"2"},
{"question_id":266182,"source":"#include <bits/stdc++.h>\nusing namespace std;\nclass Node {\npublic:\n    int data;\n    Node *left, *right;\n};\nNode* newNode(int item)\n{\n    Node* temp = new Node();\n    temp->data = item;\n    temp->left = temp->right = NULL;\n    return temp;\n}\nNode* insert(Node* node, int data)\n{\n    if (node == NULL)\n        return newNode(data);\n    if (data <= node->data)\n        node->left = insert(node->left,\n                            data);\n    else\n        node->right = insert(node->right,\n                             data);\n    return node;\n}\n\nint sum=0;\nint sumofvalofgivenrange(Node *root,int start,int end)\n{\n        if(root==NULL)\n            return 0;\n        if(root->data>=start && root->data<=end)\n            sum+=root->data;\n        sumofvalofgivenrange(root->left,start,end);\n        sumofvalofgivenrange(root->right,start,end);\n        return sum;\n}\nint main()\n{\n    Node* root = NULL;\n    int n;\n    cin>>n;\n    int k;\n    cin>>k;\n    root=insert(root,k);\n    for(int i=1;i<n;i++)\n    {\n        cin>>k;\n        insert(root,k);\n    }\n    int start,end;\n    cin>>start>>end;\n    int ans=sumofvalofgivenrange(root,start,end);\n    cout<<ans;\n    return 0;\n}","lang":"2"},
{"question_id":266181,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n\n/* A binary tree Treenode has data,\npointer to left child and a\npointer to right child */\n struct TreeNode {\n      int val;\n      TreeNode *left;\n      TreeNode *right;\n      TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n };\n\n\n// Function to insert nodes in level order\nTreeNode* insertLevelOrder(vector<int>& arr, TreeNode* root,\n                    int i, int n)\n{\n    // Base case for recursion\n    if (i < n)\n    {\n        TreeNode* temp = new TreeNode(arr[i]);\n        root = temp;\n\n\n        // insert left child\n        root->left = insertLevelOrder(arr,\n                root->left, 2 * i + 1, n);\n\n\n        // insert right child\n        root->right = insertLevelOrder(arr,\n                root->right, 2 * i + 2, n);\n    }\n    return root;\n}\n\n\tint ans= 0;                                     // Global ans variable\n    void helper(TreeNode* root, int mx, int mn) {\n        if(!root)    return;                        // root == NULL\n            \n        mx= max(mx, root->val);\n        mn= min(mn, root->val);\n        ans= max(ans, abs(mx-mn));                  // calculation\n        \n        helper(root->left, mx, mn);                 // recursion call\n        helper(root->right, mx, mn);        \n    }\n    \n    \n    int maxAncestorDiff(TreeNode* root) {\n        int mx= INT_MIN;\n        int mn= INT_MAX;\n        \n        helper(root, mx, mn);\n        return ans;\n    }\n\n\n\n// Driver program to test above function\nint main()\n{\n    int n;\n    cin>>n;\n    vector<int>arr(n);\n    for(int i=0;i<n;i++){\n        cin>>arr[i];\n    }\n\n    sort(arr.begin(),arr.end());\n\n    TreeNode* root = insertLevelOrder(arr, root, 0, n);\n\n    int ans=maxAncestorDiff(root);\n\n    cout<<ans<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":266181,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n\n/* A binary tree Treenode has data,\npointer to left child and a\npointer to right child */\n struct TreeNode {\n      int val;\n      TreeNode *left;\n      TreeNode *right;\n      TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n };\n\n\n// Function to insert nodes in level order\nTreeNode* insertLevelOrder(vector<int>& arr, TreeNode* root,\n                    int i, int n)\n{\n    // Base case for recursion\n    if (i < n)\n    {\n        TreeNode* temp = new TreeNode(arr[i]);\n        root = temp;\n\n\n        // insert left child\n        root->left = insertLevelOrder(arr,\n                root->left, 2 * i + 1, n);\n\n\n        // insert right child\n        root->right = insertLevelOrder(arr,\n                root->right, 2 * i + 2, n);\n    }\n    return root;\n}\n\n\tint ans= 0;                                     // Global ans variable\n    void helper(TreeNode* root, int mx, int mn) {\n        if(!root)    return;                        // root == NULL\n            \n        mx= max(mx, root->val);\n        mn= min(mn, root->val);\n        ans= max(ans, abs(mx-mn));                  // calculation\n        \n        helper(root->left, mx, mn);                 // recursion call\n        helper(root->right, mx, mn);        \n    }\n    \n    \n    int maxAncestorDiff(TreeNode* root) {\n        int mx= INT_MIN;\n        int mn= INT_MAX;\n        \n        helper(root, mx, mn);\n        return ans;\n    }\n\n\n\n// Driver program to test above function\nint main()\n{\n    int n;\n    cin>>n;\n    vector<int>arr(n);\n    for(int i=0;i<n;i++){\n        cin>>arr[i];\n    }\n\n    sort(arr.begin(),arr.end());\n\n    TreeNode* root = insertLevelOrder(arr, root, 0, n);\n\n    int ans=maxAncestorDiff(root);\n\n    cout<<ans<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":266181,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n\n/* A binary tree Treenode has data,\npointer to left child and a\npointer to right child */\n struct TreeNode {\n      int val;\n      TreeNode *left;\n      TreeNode *right;\n      TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n };\n\n\n// Function to insert nodes in level order\nTreeNode* insertLevelOrder(vector<int>& arr, TreeNode* root,\n                    int i, int n)\n{\n    // Base case for recursion\n    if (i < n)\n    {\n        TreeNode* temp = new TreeNode(arr[i]);\n        root = temp;\n\n\n        // insert left child\n        root->left = insertLevelOrder(arr,\n                root->left, 2 * i + 1, n);\n\n\n        // insert right child\n        root->right = insertLevelOrder(arr,\n                root->right, 2 * i + 2, n);\n    }\n    return root;\n}\n\n\tint ans= 0;                                     // Global ans variable\n    void helper(TreeNode* root, int mx, int mn) {\n        if(!root)    return;                        // root == NULL\n            \n        mx= max(mx, root->val);\n        mn= min(mn, root->val);\n        ans= max(ans, abs(mx-mn));                  // calculation\n        \n        helper(root->left, mx, mn);                 // recursion call\n        helper(root->right, mx, mn);        \n    }\n    \n    \n    int maxAncestorDiff(TreeNode* root) {\n        int mx= INT_MIN;\n        int mn= INT_MAX;\n        \n        helper(root, mx, mn);\n        return ans;\n    }\n\n\n\n// Driver program to test above function\nint main()\n{\n    int n;\n    cin>>n;\n    vector<int>arr(n);\n    for(int i=0;i<n;i++){\n        cin>>arr[i];\n    }\n\n    sort(arr.begin(),arr.end());\n\n    TreeNode* root = insertLevelOrder(arr, root, 0, n);\n\n    int ans=maxAncestorDiff(root);\n\n    cout<<ans<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":266181,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n\n/* A binary tree Treenode has data,\npointer to left child and a\npointer to right child */\n struct TreeNode {\n      int val;\n      TreeNode *left;\n      TreeNode *right;\n      TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n };\n\n\n// Function to insert nodes in level order\nTreeNode* insertLevelOrder(vector<int>& arr, TreeNode* root,\n                    int i, int n)\n{\n    // Base case for recursion\n    if (i < n)\n    {\n        TreeNode* temp = new TreeNode(arr[i]);\n        root = temp;\n\n\n        // insert left child\n        root->left = insertLevelOrder(arr,\n                root->left, 2 * i + 1, n);\n\n\n        // insert right child\n        root->right = insertLevelOrder(arr,\n                root->right, 2 * i + 2, n);\n    }\n    return root;\n}\n\n\tint ans= 0;                                     // Global ans variable\n    void helper(TreeNode* root, int mx, int mn) {\n        if(!root)    return;                        // root == NULL\n            \n        mx= max(mx, root->val);\n        mn= min(mn, root->val);\n        ans= max(ans, abs(mx-mn));                  // calculation\n        \n        helper(root->left, mx, mn);                 // recursion call\n        helper(root->right, mx, mn);        \n    }\n    \n    \n    int maxAncestorDiff(TreeNode* root) {\n        int mx= INT_MIN;\n        int mn= INT_MAX;\n        \n        helper(root, mx, mn);\n        return ans;\n    }\n\n\n\n// Driver program to test above function\nint main()\n{\n    int n;\n    cin>>n;\n    vector<int>arr(n);\n    for(int i=0;i<n;i++){\n        cin>>arr[i];\n    }\n\n    sort(arr.begin(),arr.end());\n\n    TreeNode* root = insertLevelOrder(arr, root, 0, n);\n\n    int ans=maxAncestorDiff(root);\n\n    cout<<ans<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":266181,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n\n/* A binary tree Treenode has data,\npointer to left child and a\npointer to right child */\n struct TreeNode {\n      int val;\n      TreeNode *left;\n      TreeNode *right;\n      TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n };\n\n\n// Function to insert nodes in level order\nTreeNode* insertLevelOrder(vector<int>& arr, TreeNode* root,\n                    int i, int n)\n{\n    // Base case for recursion\n    if (i < n)\n    {\n        TreeNode* temp = new TreeNode(arr[i]);\n        root = temp;\n\n\n        // insert left child\n        root->left = insertLevelOrder(arr,\n                root->left, 2 * i + 1, n);\n\n\n        // insert right child\n        root->right = insertLevelOrder(arr,\n                root->right, 2 * i + 2, n);\n    }\n    return root;\n}\n\n\tint ans= 0;                                     // Global ans variable\n    void helper(TreeNode* root, int mx, int mn) {\n        if(!root)    return;                        // root == NULL\n            \n        mx= max(mx, root->val);\n        mn= min(mn, root->val);\n        ans= max(ans, abs(mx-mn));                  // calculation\n        \n        helper(root->left, mx, mn);                 // recursion call\n        helper(root->right, mx, mn);        \n    }\n    \n    \n    int maxAncestorDiff(TreeNode* root) {\n        int mx= INT_MIN;\n        int mn= INT_MAX;\n        \n        helper(root, mx, mn);\n        return ans;\n    }\n\n\n\n// Driver program to test above function\nint main()\n{\n    int n;\n    cin>>n;\n    vector<int>arr(n);\n    for(int i=0;i<n;i++){\n        cin>>arr[i];\n    }\n\n    sort(arr.begin(),arr.end());\n\n    TreeNode* root = insertLevelOrder(arr, root, 0, n);\n\n    int ans=maxAncestorDiff(root);\n\n    cout<<ans<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":266181,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n\n/* A binary tree Treenode has data,\npointer to left child and a\npointer to right child */\n struct TreeNode {\n      int val;\n      TreeNode *left;\n      TreeNode *right;\n      TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n };\n\n\n// Function to insert nodes in level order\nTreeNode* insertLevelOrder(vector<int>& arr, TreeNode* root,\n                    int i, int n)\n{\n    // Base case for recursion\n    if (i < n)\n    {\n        TreeNode* temp = new TreeNode(arr[i]);\n        root = temp;\n\n\n        // insert left child\n        root->left = insertLevelOrder(arr,\n                root->left, 2 * i + 1, n);\n\n\n        // insert right child\n        root->right = insertLevelOrder(arr,\n                root->right, 2 * i + 2, n);\n    }\n    return root;\n}\n\n\tint ans= 0;                                     // Global ans variable\n    void helper(TreeNode* root, int mx, int mn) {\n        if(!root)    return;                        // root == NULL\n            \n        mx= max(mx, root->val);\n        mn= min(mn, root->val);\n        ans= max(ans, abs(mx-mn));                  // calculation\n        \n        helper(root->left, mx, mn);                 // recursion call\n        helper(root->right, mx, mn);        \n    }\n    \n    \n    int maxAncestorDiff(TreeNode* root) {\n        int mx= INT_MIN;\n        int mn= INT_MAX;\n        \n        helper(root, mx, mn);\n        return ans;\n    }\n\n\n\n// Driver program to test above function\nint main()\n{\n    int n;\n    cin>>n;\n    vector<int>arr(n);\n    for(int i=0;i<n;i++){\n        cin>>arr[i];\n    }\n\n    sort(arr.begin(),arr.end());\n\n    TreeNode* root = insertLevelOrder(arr, root, 0, n);\n\n    int ans=maxAncestorDiff(root);\n\n    cout<<ans<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":266181,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n\n/* A binary tree Treenode has data,\npointer to left child and a\npointer to right child */\n struct TreeNode {\n      int val;\n      TreeNode *left;\n      TreeNode *right;\n      TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n };\n\n\n// Function to insert nodes in level order\nTreeNode* insertLevelOrder(vector<int>& arr, TreeNode* root,\n                    int i, int n)\n{\n    // Base case for recursion\n    if (i < n)\n    {\n        TreeNode* temp = new TreeNode(arr[i]);\n        root = temp;\n\n\n        // insert left child\n        root->left = insertLevelOrder(arr,\n                root->left, 2 * i + 1, n);\n\n\n        // insert right child\n        root->right = insertLevelOrder(arr,\n                root->right, 2 * i + 2, n);\n    }\n    return root;\n}\n\n\tint ans= 0;                                     // Global ans variable\n    void helper(TreeNode* root, int mx, int mn) {\n        if(!root)    return;                        // root == NULL\n            \n        mx= max(mx, root->val);\n        mn= min(mn, root->val);\n        ans= max(ans, abs(mx-mn));                  // calculation\n        \n        helper(root->left, mx, mn);                 // recursion call\n        helper(root->right, mx, mn);        \n    }\n    \n    \n    int maxAncestorDiff(TreeNode* root) {\n        int mx= INT_MIN;\n        int mn= INT_MAX;\n        \n        helper(root, mx, mn);\n        return ans;\n    }\n\n\n\n// Driver program to test above function\nint main()\n{\n    int n;\n    cin>>n;\n    vector<int>arr(n);\n    for(int i=0;i<n;i++){\n        cin>>arr[i];\n    }\n\n    sort(arr.begin(),arr.end());\n\n    TreeNode* root = insertLevelOrder(arr, root, 0, n);\n\n    int ans=maxAncestorDiff(root);\n\n    cout<<ans<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":266181,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n\n/* A binary tree Treenode has data,\npointer to left child and a\npointer to right child */\n struct TreeNode {\n      int val;\n      TreeNode *left;\n      TreeNode *right;\n      TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n };\n\n\n// Function to insert nodes in level order\nTreeNode* insertLevelOrder(vector<int>& arr, TreeNode* root,\n                    int i, int n)\n{\n    // Base case for recursion\n    if (i < n)\n    {\n        TreeNode* temp = new TreeNode(arr[i]);\n        root = temp;\n\n\n        // insert left child\n        root->left = insertLevelOrder(arr,\n                root->left, 2 * i + 1, n);\n\n\n        // insert right child\n        root->right = insertLevelOrder(arr,\n                root->right, 2 * i + 2, n);\n    }\n    return root;\n}\n\n\tint ans= 0;                                     // Global ans variable\n    void helper(TreeNode* root, int mx, int mn) {\n        if(!root)    return;                        // root == NULL\n            \n        mx= max(mx, root->val);\n        mn= min(mn, root->val);\n        ans= max(ans, abs(mx-mn));                  // calculation\n        \n        helper(root->left, mx, mn);                 // recursion call\n        helper(root->right, mx, mn);        \n    }\n    \n    \n    int maxAncestorDiff(TreeNode* root) {\n        int mx= INT_MIN;\n        int mn= INT_MAX;\n        \n        helper(root, mx, mn);\n        return ans;\n    }\n\n\n\n// Driver program to test above function\nint main()\n{\n    int n;\n    cin>>n;\n    vector<int>arr(n);\n    for(int i=0;i<n;i++){\n        cin>>arr[i];\n    }\n\n    sort(arr.begin(),arr.end());\n\n    TreeNode* root = insertLevelOrder(arr, root, 0, n);\n\n    int ans=maxAncestorDiff(root);\n\n    cout<<ans<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n\n\nint main() \n{\n     int n;\n     cin>>n;\n     vector<int>v(n);\n     for(int i=0;i<n;i++)\n     {\n         cin>>v[i];\n     }\n     priority_queue<int>pq;\n     for(int i=0;i<n;i++)\n     {\n         pq.push(-v[i]);\n     }\n     int cost=0;\n     while(pq.size()!=1)\n     {\n         int a=-pq.top();\n         pq.pop();\n         int b=-pq.top();\n         pq.pop();\n         cost+=a+b;\n         pq.push(-(a+b));\n\n     }\n     cout << cost << endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n#define int long long\n\nint32_t main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    int arr[n];\n    for(int i=0; i<n; i++) cin>>arr[i];\n    int ans=0;\n    multiset<int> st;\n    for(int i=0; i<n; i++){\n        st.insert(arr[i]);\n    }\n    while(st.size()>1){\n        auto itr=st.begin();\n        int a=*itr;\n        st.erase(itr);\n        itr=st.begin();\n        int b=*itr;\n        st.erase(itr);\n        ans+=a+b;\n        st.insert(a+b);\n    }\n    cout<<ans;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <queue>\nusing namespace std;\n\n\nint main() {\n    int n;\n    cin >> n;\n    long long int arr[n];\n    priority_queue<long long int,vector<long long int>,greater<long long int> >pq;\n    for(int i = 0; i < n; i++){\n        cin >> arr[i];\n        pq.push(arr[i]);\n    }\n    long long int sum = 0;\n    while(pq.size() != 1){\n        long long int a = pq.top();\n        pq.pop();\n        long long int b = pq.top();\n        pq.pop();\n        sum += (a + b);\n        pq.push(a + b);\n    }\n    cout << sum << endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\ntypedef long long ll;\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    ll n;\n    cin>>n;\n    ll a[n];\n    for(int i = 0;i<n;i++){\n        cin>>a[i];\n    }\n    priority_queue<ll,vector<ll>,greater<ll>>pq;\n    for(int i = 0 ;i<n;i++){\n        pq.push(a[i]);\n    }\n    ll ans = 0;\n    while(pq.size()>=2){\n        ll x = pq.top();\n        pq.pop();\n        ll y = pq.top();\n        pq.pop();\n        ans+= (x+y);\n        pq.push(x+y);\n    }\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<queue>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    priority_queue<int,vector<int>,greater<int>> gq;\n\n    int n;\n    cin>>n;\n    for(int i=0;i<n;i++)\n    {\n        int x;\n        cin>>x;\n        gq.push(x);\n    }\n    int cost =0;\n    while(gq.size()>1)\n    {\n        int a = gq.top();\n        gq.pop();\n        int b = gq.top();\n        gq.pop();\n        cost+=a+b;\n        gq.push(a+b);\n    }\n    cout<<cost;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include<bits/stdc++.h>\n#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin >> n;\n    vector<int> arr(n);\n    for(int i = 0; i < n; ++i) {\n        cin >> arr[i];\n        //priority_queue<int, vector<int>, greater<int>> minh;\n    }\n    priority_queue<int, vector<int>, greater<int>> pq;\n    for(int i = 0; i < n; ++i) {\n        pq.push(arr[i]);\n    }\n    int cost = 0;\n    while(pq.size() >= 2) {\n        int first = pq.top();\n        pq.pop();\n        int second = pq.top();\n        pq.pop();\n        cost += first + second;\n        pq.push(first + second);\n\n    }\n    cout << cost << endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n#include<bits/stdc++.h>\n# define int long long\n\n\nint32_t main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    int n;\n    cin>>n;\n    priority_queue<int,vector<int>,greater<int>>pq;\n    for(int i=0;i<n;i++){\n        int x;\n        cin>>x;\n        pq.push(x);\n    } \n    int ans=0;\n    while(pq.size()>1){\n        int a1=pq.top();\n        pq.pop();\n        int a2=pq.top();\n        pq.pop();\n        ans=ans+a1+a2;\n        pq.push(a1+a2);\n    } \n    cout<<ans<<endl;\n    return 0;\n    \n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n#define lint long long \n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n ; cin >> n ; vector < int > a(n); \n    multiset < lint> ms  ;\n\n    for(int i = 0; i < n; i++) {\n        cin >> a[i] ; \n        ms.insert(a[i]);\n    }\n\n    lint ans = 0 ; \n    while((int) ms.size() > 1) {\n        lint x = *ms.begin(); ms.erase(ms.find(x));\n        lint y = *ms.begin(); ms.erase(ms.find(y));\n        ans += (x + y); ms.insert(x + y); \n    }\n    cout << ans << endl ; \n    \n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n#include <bits/stdc++.h>\n#define ll long long\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    int n;\n    cin>>n;\n    vector<int> v(n,0);\n    priority_queue<ll,vector<ll>,greater<ll>> pq;\n    for(int i=0;i<n;i++)\n    {\n        cin>>v[i];\n        pq.push(v[i]);\n        \n    }\n    ll ans=0;\n    while(pq.size()>1)\n    {\n        ll a1=pq.top();\n        pq.pop();\n        ll a2=pq.top();\n        pq.pop();\n        ans+=a1+a2;\n        pq.push(a1+a2);\n    }\n    cout<<ans<<endl;\n    //priority_queue<  \n    return 0;\n    \n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <set>\n#include <bits/stdc++.h>\nusing namespace std;\n#define int long long \n\nsigned main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    int ans = 0;\n    vector<int> v;\n    // multiset<int> s;\n    // int ans = 0;\n    // for(int i=0;i<n;i++){\n    //     cin>>v[i];\n    //     s.insert(v[i]);\n    // }\n    // while(!s.empty()){\n    //     int t1 = 0,count = 0;\n    //     int t2 = 0;\n    //     for(auto i:s){\n    //         count++;\n    //         if(count == 3)break;\n    //         if(count == 2)t2 = i;\n    //         if(count == 1)t1 = i;\n    //     }\n    //     ans+=(t1+t2);\n    //     if(count!=3)break;\n\n    //     auto it  = s.begin();\n    //     int t1 = *it;\n    //     s.erase(it);\n    //     int t2 = 0;\n    //     if(s.size()!=0){\n    //         it = s.begin();\n    //         t2 = *it;\n    //         s.erase(it);\n    //     }\n    //     ans+=(t1+t2);\n    //     if(s.size()==0)continue;\n    //     s.insert(t1+t2);\n\n    // }\n    // cout<<ans<<endl;\n    priority_queue<int,vector<int>,greater<int>> pq;\n    for(int i=0;i<n;i++){\n        int k;\n        cin >> k;\n        pq.push(k);\n    }\n    while(pq.size() >1){\n        int a= pq.top();\n        pq.pop();\n        int b= pq.top();\n        pq.pop();\n        pq.push(a+b);\n        ans = (ans +a+b) %(1000000007);\n    }\n    cout << ans %(1000000007);\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include<bits/stdc++.h>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    int arr[n];\n    priority_queue<int,vector<int>,greater<int>>pq;\n    for (int i=0;i<n;i++){\n        cin>>arr[i];\n        pq.push(arr[i]);\n    }\n    long long sum=0;\n    while (pq.size()>1){\n        int a=pq.top();\n        pq.pop();\n        int b=pq.top();\n        pq.pop();\n        sum+=(a+b);\n        pq.push(a+b);\n    }\n    cout<<sum;\n    \n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\n#define int long long\nusing namespace std;\n\n\nint32_t main() {\n    /* Enter yo\n    ur code here. Read input from STDIN. Print output to STDOUT */   \n\n    int n;\n    cin>>n;\n\n    int a[n];\n    priority_queue<int, vector<int>, greater<int>> pq;\n\n    for(int i=0;i<n;i++){\n        cin>>a[i];\n\n        pq.push(a[i]);\n    }\n\n\n    int cost = 0;\n\n    while(pq.size()>1){\n        int x = pq.top();\n        pq.pop();\n        int y = pq.top();\n        pq.pop();\n\n        cost += (x+y);\n        pq.push(x+y);\n    }\n\n    cout<<cost;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    int n;\n    cin >> n;\n    multiset<int> st;\n    vector<int> a(n);\n    for(int i = 0; i < n; ++i){\n        cin >> a[i];\n        st.insert(a[i]);\n    }\n    int ans = 0;\n    while((int)st.size() > 1){\n        int val1 = *(st.begin());\n        st.erase(st.begin());\n        int val2 = *(st.begin());\n        st.erase(st.begin());\n        ans += val1 + val2;\n        st.insert(val1 + val2);\n    }\n    cout << ans;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\n\nusing namespace std;\n\n\nint main() {\n    long long i, n, ans;\n    cin >> n;\n    long long arr[n];\n    multimap<long long, long long> m;\n    for(int i = 0; i < n; i++) {\n        cin >> arr[i];\n        m.insert({arr[i], 1});\n    }\n\n    ans = 0;\n\n    while(m.size() > 1) {\n        auto i1 = m.begin();\n        auto i2 = i1;\n        i2++;\n        ans += ((*i1).first + (*i2).first);\n        m.erase(i1);\n        m.erase(i2);\n\n        m.insert({(*i1).first + (*i2).first, 1});\n    }\n    cout << ans  << endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\n#define int long long\nusing namespace std;\n\n\nint32_t main() {\n    /* Enter yo\n    ur code here. Read input from STDIN. Print output to STDOUT */   \n\n    int n;\n    cin>>n;\n\n    int a[n];\n    priority_queue<int, vector<int>, greater<int>> pq;\n\n    for(int i=0;i<n;i++){\n        cin>>a[i];\n\n        pq.push(a[i]);\n    }\n\n\n    int cost = 0;\n\n    while(pq.size()>1){\n        int x = pq.top();\n        pq.pop();\n        int y = pq.top();\n        pq.pop();\n\n        cost += (x+y);\n        pq.push(x+y);\n    }\n\n    cout<<cost;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <bits/stdc++.h>\nusing namespace std;\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    int n;\n    cin>>n;   \n    priority_queue<int,vector<int>,greater<int> >q;\n    int ans=0;\n    int count=0;\n    for(int i=0;i<n;i++)\n    {\n        count++;\n        int a;\n        cin>>a;\n        q.push(a);\n    }\n    if(count==1)\n    {\n        cout<<0;\n        return 0;\n    }\n    // cout<<matrix(n,a,1,n-1);\n    while(!q.empty())\n    {\n        if(q.size()==1)\n        break;\n        int a1=q.top();\n        q.pop();\n        int a2=q.top();\n        q.pop();\n        q.push(a1+a2);\n        ans+=a1+a2;\n    }\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\nlong long int n,a[100005];\npriority_queue<long long int> que;\nint main() {\n    long long int ans=0;\n    cin>>n;\n    for(int i=1;i<=n;i++){\n        cin>>a[i];\n        que.push(-a[i]);\n    }\n    while(que.size()>1){\n        long long int x=que.top();\n        que.pop();\n        long long int y=que.top();\n        que.pop();\n        ans+=x+y;\n        que.push(x+y);\n    }\n    cout<<-ans;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n#define int long long \n\n\nsigned main() {\n\n    int n;\n    cin >> n;\n    vector<int>a(n);\n    for(int i = 0;i<n;i++)cin >> a[i];\n\n    priority_queue<int,vector<int>,greater<int>>pq;\n    for(int i = 0;i<n;i++)pq.push(a[i]);\n    int res = 0;\n    while(pq.size()>1){\n        int t = pq.top();\n        pq.pop();\n        int s = pq.top();\n        pq.pop();\n        res += t+s;\n        pq.push(t+s);\n    }\n\n    cout << res << endl;\n      \n   \n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n/*#define N 401\n\nint dp[N][N];\nbool temp[N][N];\n\nint helper(int i,int j,int *arr){\n    if(i==j){\n        return 0;\n    }\n    if(temp[i][j]){\n        return dp[i][j];\n    }\n    temp[i][j]=1;\n    int &temp2=dp[i][j];\n\n    temp2=INT_MAX;\n    int sum=0;\n    for(int k=i;k<=j;k++){\n        sum+=arr[k];\n    }\n    for(int k=i+1;k<=j;k++){\n        temp2=min(temp2,sum+helper(i,k-1,arr)+helper(k,j,arr));\n    }\n    return temp2;\n}\n*/\nint solve(vector<int>&arr){\n    priority_queue<long long,vector<long long>,greater<long long>>pq;\n    for(int val:arr){\n        pq.push(val);\n    }\n    long long ans=0;\n    while(pq.size()>1){\n        int a=pq.top();\n        pq.pop();\n        int b=pq.top();\n        pq.pop();\n        ans+=a+b;\n        pq.push(a+b);\n    }\n    return ans;\n    \n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    //long long int arr[n];\n    vector<int>arr(n,0);\n    for(int i=0;i<n;i++){\n        int x;\n        cin>>x;\n        arr[i]=x;\n    }\n    //int x=sizeof(arr)/sizeof(int);\n    cout<<solve(arr)<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"# Enter your code here. Read input from STDIN. Print output to STDOUT\r\n\r\nN = int(input())\r\n\r\na = []\r\n\r\nt = input().split(\" \")\r\n\r\nfor i in t:\r\n    a.append(int(i))\r\n\r\nm = 0\r\n\r\nwhile(len(a) != 1):\r\n    min1 = min(a)\r\n    a.pop(a.index(min1))\r\n    min2 = min(a)\r\n    a.pop(a.index(min2))\r\n    m += min1 + min2\r\n    a.append(min1 + min2)\r\n\r\nprint(m)","lang":"30"},
{"question_id":41034,"source":"#include<bits/stdc++.h>\nusing namespace std;\n\nint func(vector<int>& a,int n){\n    priority_queue<int,vector<int>,greater<int> >pq;\n    for(int i=0;i<(int)a.size();i++) pq.push(a[i]);\n    int ans = 0;\n    while(pq.size()>1){\n        int cur = pq.top();\n        pq.pop();\n        int cur2 = pq.top();\n        pq.pop();\n\n        ans += cur + cur2;\n        pq.push(cur + cur2);\n    }\n\n    return ans;\n}\n\nint main() {\n\n    int n;\n    cin>>n;\n    vector<int>a(n);\n    for(int i=0;i<n;i++) cin>>a[i];\n\n    cout<<func(a,n);\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define ll long long int\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    ll n;cin>>n;\n    vector<ll>arr(n);\n    for(auto&x: arr) cin>>x;\n    priority_queue<int,vector<int>,greater<int>>pq;\n    for(auto&x:arr) pq.push(x);\n    ll ans =0;\n    while(pq.size()>1)\n    {\n        ll a = pq.top();\n        pq.pop();\n        ans+=a+pq.top();\n        a+=pq.top();\n        pq.pop();\n        pq.push(a);\n    }\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\nvoid solve(){\n    ll n;\n    cin>>n;\n    ll ans=0;\n    multiset<ll>mst;\n    ll x;\n    for(int i=1;i<=n;i++){\n        cin>>x;\n        mst.insert(x);\n    }\n    while(mst.size()>1){\n        ll z1=*mst.begin();\n        mst.erase(mst.begin());\n        ll z2=*mst.begin();\n        mst.erase(mst.begin());\n        \n        ans=(ans+z1+z2);\n        mst.insert(z1+z2);\n    }\n    cout<<ans;\n}\n\nint main() {\n    solve();\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\nlong long int find(vector<int> &res){\n    int n = res.size();\n\n    if(n == 1)return res[0];\n\n    priority_queue<int,vector<int>,greater<int>> pq;\n\n    for(auto it : res){\n        pq.push(it);\n    }\n\n    long long ans = 0;\n    ans += pq.top();\n\n    pq.pop();\n\n    ans += pq.top();\n    pq.pop();\n    pq.push(ans);\n\n    while(pq.size() > 1){\n        long long count = 0;\n        count += pq.top();\n        pq.pop();\n        count += pq.top();\n        ans += count;\n        pq.pop();\n        pq.push(count);\n    }\n\n    return ans;\n}\n\nint main() {\n    \n     int n;\n     cin>>n;\n\n     vector<int> res(n);\n\n     for(int i=0;i<n;i++){\n         cin>>res[i];\n     }\n\n     int x = find(res);\n     cout<<x<<endl;\n\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    priority_queue<int,vector<int>,greater<int>> pq;\n\n    int n;\n    cin>>n;\n    int arr[n];\n\n    for(int i=0;i<n;i++){\n        cin>>arr[i];\n        pq.push(arr[i]);\n    }\n\n    int ans=0;\n\n    while(pq.size()>1){\n        int e1=pq.top();\n        pq.pop();\n        int e2=pq.top();\n        pq.pop();\n\n        ans+=e1+e2;\n        pq.push(e1+e2);\n    }\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n#define ll long long\nll mod=1e9+7;\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    ll n;cin>>n;\n    multiset<ll> s;\n    for(ll i=0; i<n; i++)\n    {\n        int a; cin>>a;\n        s.insert(a);\n    }   \n    ll ans=0;\n    while(s.size()>=2)\n    {\n        ll it1=*s.begin();\n        ans+=it1;\n        s.erase(s.begin());\n        ll it2=*s.begin();\n        s.erase(s.begin());\n        ans+=it2;\n        s.insert(it1+it2);\n    }\n    cout<<ans;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n\n\nint main() \n{\n     int n;\n     cin>>n;\n     vector<int>v(n);\n     for(int i=0;i<n;i++)\n     {\n         cin>>v[i];\n     }\n     priority_queue<int>pq;\n     for(int i=0;i<n;i++)\n     {\n         pq.push(-v[i]);\n     }\n     int cost=0;\n     while(pq.size()!=1)\n     {\n         int a=-pq.top();\n         pq.pop();\n         int b=-pq.top();\n         pq.pop();\n         cost+=a+b;\n         pq.push(-(a+b));\n\n     }\n     cout << cost << endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include<bits/stdc++.h>\n#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin >> n;\n    vector<int> arr(n);\n    for(int i = 0; i < n; ++i) {\n        cin >> arr[i];\n        //priority_queue<int, vector<int>, greater<int>> minh;\n    }\n    for(int i = 0; i < 10009; ++i);\n    vector<int> v(1000);\n    priority_queue<int, vector<int>, greater<int>> pq;\n    for(int i = 0; i < n; ++i) {\n        pq.push(arr[i]);\n    }\n    int cost = 0;\n    while(pq.size() >= 2) {\n        int first = pq.top();\n        pq.pop();\n        int second = pq.top();\n        pq.pop();\n        cost += first + second;\n        pq.push(first + second);\n\n    }\n    cout << cost << endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint helper(vector<int> vt){\n    int n=vt.size();\n    priority_queue<int,vector<int>,greater<int>>pq;\n    for(auto t:vt){\n        pq.push(t);\n    }\n    int ans=0;\n    while(pq.size()>1){\n        auto top=pq.top();\n        pq.pop();\n        auto top2=pq.top();\n        pq.pop();\n        int x=top+top2;\n        ans+=x;\n        pq.push(x);\n    }\n    return ans;\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    vector<int> vt;\n    for(int i=0;i<n;i++){\n        int a;\n        cin>>a;\n        vt.push_back(a);\n    }\n    cout<<helper(vt);\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include<bits/stdc++.h>\n#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin >> n;\n    vector<int> arr(n);\n    for(int i = 0; i < n; ++i) {\n        cin >> arr[i];\n        //priority_queue<int, vector<int>, greater<int>> minh;\n    }\n    for(int i = 0; i < 10009; ++i);\n    vector<int> v(1000);\n    priority_queue<int, vector<int>, greater<int>> pq;\n    for(int i = 0; i < n; ++i) {\n        pq.push(arr[i]);\n    }\n    int cost = 0;\n    while(pq.size() >= 2) {\n        int first = pq.top();\n        pq.pop();\n        int second = pq.top();\n        pq.pop();\n        cost += first + second;\n        pq.push(first + second);\n\n    }\n    cout << cost << endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    long long n;\n    cin>>n;\n    vector<long long> v(n);\n    priority_queue<long long, vector<long long>, greater<long long>> q;\n\n    for(int i=0;i<n;i++)\n    {\n        cin>>v[i];\n        q.push(v[i]);\n    }\n    long long ans=0;\n    long long a, b;\n    while(q.size()!=1)\n    {\n        a=q.top();\n        q.pop();\n        b=q.top();\n        q.pop();\n        ans+=a+b;\n        q.push(a+b);\n    }\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    \n    int n;\n    cin>>n;\n    vector<int> a(n);\n    for(int i=0;i<n;i++) cin>>a[i];\n    priority_queue<long long,vector<long long>,greater<long long>> pq;\n    long long ans = 0;\n    for(int i=0;i<n;i++) pq.push(a[i]);\n\n    while(pq.size()>1){\n        long long top = pq.top();\n        pq.pop();\n        long long top2 = pq.top();      \n        pq.pop();\n        ans += (top + top2);\n        pq.push(top+top2);\n    }\n    cout<<ans<<\"\\n\";\n    \n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#define int long long\nusing namespace std;\n\n\nint32_t main() {\n    int n;cin>>n;\n    vector <int> v(n);\n    priority_queue <int,vector <int>,greater<int>> pq;\n    for(int i=0;i<n;i++){\n        cin>>v[i];\n        pq.push(v[i]);\n    }\n    if(n==1){\n        cout<<pq.top();\n        return 0;\n    }\n\n    int ans=0;\n    while(!pq.empty()){\n        int x=pq.top();\n        pq.pop();\n        if(pq.empty())break;\n        int y=pq.top();\n        pq.pop();\n        pq.push({x+y});\n        ans+=x+y;    \n    }\n    cout<<ans<<endl;\n    return 0;\n\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <bits/stdc++.h>\nusing namespace std;\n#define ll long long \n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    ll n;\n    cin>>n;\n    vector<ll> v(n);\n    priority_queue<ll,vector<ll> ,greater<ll> > pq;\n    for(int i=0;i<n;i++)\n    {\n        cin>>v[i];\n        pq.push(v[i]);\n    } \n    ll ans=0;\n    while(pq.size()>1)\n    {\n        ll a=pq.top();\n        pq.pop();\n        ll b=pq.top();\n        pq.pop();\n        ans+=a+b;\n        pq.push(a+b);\n        \n    }\n    cout<<ans;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\nvoid fun(vector<int>arr){\n    int n = arr.size();\n    priority_queue<long long int,vector<long long int>,greater<long long int>> que;\n    for(int i=0;i<n;i++){\n        que.push(arr[i]);\n    }\n    long long int cost = 0;\n    while(que.size() > 1){\n        int temp1 = que.top();\n        que.pop();\n        int temp2 = que.top();\n        que.pop();\n        cost += temp1+temp2;\n        que.push(temp1+temp2);\n\n    }\n    cout << cost << \"\\n\";\n}\n\nint main() {\n    int n;\n    cin >> n;\n    vector<int>arr(n);\n    for(int i=0;i<n;i++){\n        cin >> arr[i];\n    }\n    fun(arr);\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    int n;\n    cin>>n;\n    int a[n];\n    priority_queue<int, vector<int>, greater<int>> pq;\n    for(int i = 0;i<n;i++)\n    {\n        cin>>a[i];\n        pq.push(a[i]);\n    }  \n    long long sum = 0;\n    for(int i = 0;i<n-1;i++)\n    {\n        int a = pq.top();\n        pq.pop();\n        int b = pq.top();\n        pq.pop();\n        sum = sum + a + b;\n        pq.push(a+b);\n    }\n    cout<<sum<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n    long long n;\n    cin >> n;\n\n    priority_queue<long long, vector<long long>, greater<long long>> pq;\n\n    for(int i = 0; i < n; i++){\n        long long inp;\n        cin >> inp;\n        pq.push(inp);\n\n    }\n\n    long long ans = 0;\n    while(pq.size() >= 2){\n        long long a = pq.top();\n        pq.pop();\n        long long b = pq.top();\n        pq.pop();\n\n        pq.push(a + b);\n        ans += (a + b);\n\n\n    } \n\n    cout << ans << \"\\n\";\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include<bits/stdc++.h>\nusing namespace std;\n\nint func(vector<int>& a,int n){\n    priority_queue<int,vector<int>,greater<int> >pq;\n    for(int i=0;i<(int)a.size();i++) pq.push(a[i]);\n    int ans = 0;\n    while(pq.size()>1){\n        int cur = pq.top();\n        pq.pop();\n        int cur2 = pq.top();\n        pq.pop();\n\n        ans += cur + cur2;\n        pq.push(cur + cur2);\n    }\n\n    return ans;\n}\n\nint main() {\n\n    int n;\n    cin>>n;\n    vector<int>a(n);\n    for(int i=0;i<n;i++) cin>>a[i];\n\n    cout<<func(a,n);\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter yo\n    ur code here. Read input from STDIN. Print output to STDOUT */   \n\n    int n;\n    cin>>n;\n\n    int a[n];\n    priority_queue<int, vector<int>, greater<int>> pq;\n\n    for(int i=0;i<n;i++){\n        cin>>a[i];\n\n        pq.push(a[i]);\n    }\n\n\n    int cost = 0;\n\n    while(pq.size()>1){\n        int x = pq.top();\n        pq.pop();\n        int y = pq.top();\n        pq.pop();\n\n        cost += (x+y);\n        pq.push(x+y);\n    }\n\n    cout<<cost;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\n\nint main() {\n    ll n;cin>>n;\n    multiset<ll>s;\n    for(ll i=0;i<n;i++){\n        int a;cin>>a;\n        s.insert(a);\n    }\n    ll ans=0;\n    while(s.size()>=2){\n        ll it1=*s.begin();\n        ans+=it1;\n        s.erase(s.begin());\n        ll it2=*s.begin();\n        s.erase(s.begin());\n        ans+=it2;\n        s.insert(it1+it2);\n    }\n    cout<<ans;\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\nclass Solution {\n\n    public static void main(String[] args) {\n        Scanner scn = new Scanner(System.in);\n        int n = scn.nextInt();\n        ArrayList<Integer> a = new ArrayList<>();\n        for(int i=0;i<n;i++){\n            a.add(scn.nextInt());\n        }\n        ArrayList<Integer> results = new ArrayList<>();\n        while(a.size()!=1){\n            Collections.sort(a);\n            int x1 = a.remove(0);\n            int x2 = a.remove(0);\n            int k = x1+x2;\n            a.add(k);\n            results.add(k);\n        }\n        int answer = 0;\n        for(int i:results){\n            answer += i;\n        }\n        System.out.println(answer);\n    }\n}","lang":"43"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\n\nll dpmin(vector<ll>&arr,ll low,ll high,vector<vector<ll>>&dp)\n{\n    if(low==high) return 0;\n    if(dp[low][high]!=-1) return dp[low][high];\n    ll ans=1e18;\n    ll sum=0;\n    for(int i=low;i<=high;i++) sum+=arr[i];\n    ll curr=0;\n    for(int j=low;j<high;j++)\n    {\n\n        \n        ll x=dpmin(arr,low,j,dp);\n        ll y=dpmin(arr,j+1,high,dp);\n        ans=min(ans,x+y);\n\n\n    }\n    return (dp[low][high]=ans+sum);\n}\n\nint main() {\n    ll n;\n    cin>>n;\n    vector<ll>arr(n);\n    for(int i=0;i<n;i++) cin>>arr[i];\n    multiset<ll>st;\n    for(ll x:arr) st.insert(x);\n    ll ans=0;\n    while(st.size()>1){\n        auto it=st.begin();\n        ll a=*it;\n        st.erase(it);\n        it=st.begin();\n        ll b=*it;\n        st.erase(it);\n        ans+=(a+b);\n        st.insert(a+b);\n    }\n    cout<<ans<<\"\\n\";\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include<bits/stdc++.h>\nusing namespace std;\ntypedef long long int lli;\n\nlli solve( vector<lli>& a){\n    // int l, i,j,k;\n    // int n = a.size();\n    // if(n==0) return 0;\n    // vector<int> pre(n+1, 0);\n\n    // for(int i=1; i<=n; i++ ){\n    //     pre[i] = pre[i-1]+a[i-1];\n    // }\n\n    // vector<vector<int>> dp(n+1, vector<int>(n+1));\n\n    // for(int i=1; i<=n; i++ ){\n    //     dp[i][i] = 0;\n    // }\n\n    // for(l = 2; l<=n; l++ ){\n    //     for(i=1; i<=n-l+1; i++ ){\n    //         j = i+l-1;\n\n    //         int sum = pre[j]-pre[i-1];\n\n    //         dp[i][j] = INT_MAX;\n\n    //         for(k=i; k<j; k++){\n    //             dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j]+sum);\n    //         }\n    //     }\n    // }\n\n    // return dp[1][n];\n\n    priority_queue<lli, vector<lli>, greater<lli> > pq;\n\n    for(lli i=0; i<a.size(); i++ ){\n        pq.push(a[i]);\n    }\n\nlli sum = 0;\n    while(pq.size()!=1){\n        lli f = pq.top();\n        pq.pop();\n        lli s = pq.top();\n        pq.pop();\n        sum = sum + (f+s);\n        pq.push(f+s);\n    }\n    return sum;\n\n\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    vector<lli> a(n);\n    for(lli i=0; i<n; i++ ){\n        cin>>a[i];\n    }\n    cout<<solve(a);\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n#define f(a,n) for(int i=a;i<n;i++)\n\nint main() {\n\n\n    int t;cin>>t;\n    vector<int> arr(t);\n    multiset<int> ms;\n\n    f(0,t) cin>>arr[i];\n\n    f(0,t) ms.insert(arr[i]);\n    long long ans=0;\n    for(;ms.size()>1;) {\n        int v=*ms.begin();\n        ms.erase(ms.begin());\n        int x=*ms.begin();\n        ms.erase(ms.begin());\n        ans+=v+x;\n        ms.insert(v+x);\n    }\n\n    cout<<ans<<\"\\n\";\n\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define ll long long int\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    ll n;cin>>n;\n    vector<ll>arr(n);\n    for(auto&x: arr) cin>>x;\n    priority_queue<int,vector<int>,greater<int>>pq;\n    for(auto&x:arr) pq.push(x);\n    ll ans =0;\n    while(pq.size()>1)\n    {\n        ll a = pq.top();\n        pq.pop();\n        ans+=a+pq.top();\n        a+=pq.top();\n        pq.pop();\n        pq.push(a);\n    }\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    long long n;\n    cin>>n;\n    vector<long long> v(n);\n    priority_queue<long long, vector<long long>, greater<long long>> q;\n\n    for(int i=0;i<n;i++)\n    {\n        cin>>v[i];\n        q.push(v[i]);\n    }\n    long long ans=0;\n    long long a, b;\n    while(q.size()!=1)\n    {\n        a=q.top();\n        q.pop();\n        b=q.top();\n        q.pop();\n        ans+=a+b;\n        q.push(a+b);\n    }\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n\n    int n;\n    cin >> n;\n    vector<int>a(n);\n    for(int i = 0;i<n;i++)cin >> a[i];\n\n    priority_queue<int,vector<int>,greater<int>>pq;\n    for(int i = 0;i<n;i++)pq.push(a[i]);\n    int res = 0;\n    while(pq.size()>1){\n        int t = pq.top();\n        pq.pop();\n        int s = pq.top();\n        pq.pop();\n        res += t+s;\n        pq.push(t+s);\n    }\n\n    cout << res << endl;\n      \n   \n}","lang":"2"},
{"question_id":41034,"source":"#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\n\n\nint main() {\n    ll n; cin>>n;\n    vector<ll> v(n);\n    for(int i = 0; i < n; i++)cin>>v[i];\n    multiset<ll> s;\n    for(int i = 0; i < n; i++){\n        s.insert(v[i]);\n    }\n    ll sum = 0;\n    while(s.size() > 1){\n        ll x = *s.begin();\n        s.erase(s.begin());\n        ll y = *s.begin();\n        s.erase(s.begin());\n        sum += (x+y);\n        s.insert(x+y);\n    }\n    cout<<sum<<endl;    \n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define ll long long int\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    ll n;cin>>n;\n    vector<ll>arr(n);\n    for(auto&x: arr) cin>>x;\n    priority_queue<int,vector<int>,greater<int>>pq;\n    for(auto&x:arr) pq.push(x);\n    ll ans =0;\n    while(pq.size()>1)\n    {\n        ll a = pq.top();\n        pq.pop();\n        ans+=a+pq.top();\n        a+=pq.top();\n        pq.pop();\n        pq.push(a);\n    }\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n#define llint long long\n\nint main() {\n    llint n;\n    cin >> n;\n    priority_queue<llint,vector<llint>,greater<llint>> q;\n    for (int i = 0; i < n; i++) {\n        llint inp;\n        cin >> inp;\n        q.push(inp);\n    }\n    llint cost = 0;\n    while (q.size() > 1) {\n        llint a1 = q.top();\n        q.pop();\n        llint a2 = q.top();\n        q.pop();\n        cost += a1 + a2;\n        q.push(a1 + a2);\n    }\n    cout << cost << endl;\n\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    long long n;\n    cin >> n;\n\n    priority_queue<long long,vector<long long>, greater<long long>> pq;\n\n    for(long long i = 0; i < n; i++){\n        long long input;\n        cin >> input;\n        pq.push(input);\n    }\n\n    long long res = 0;\n    while(pq.size() > 1){\n        long long a = pq.top();\n        pq.pop();\n        long long b = pq.top();\n        pq.pop();\n\n        res += (a + b);\n        pq.push(a + b);\n    }\n\n    cout << res << \"\\n\";\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\nlong long int mod=1e9+7;\nint main() {\n    long long int n;\n    cin>>n;\n    if(n==0) {\n        cout<<0<<endl;\n        return 1;\n    }\n    vector<long long int>arr(n);\n    for(int i=0;i<n;i++) cin>>arr[i];\n    sort(arr.begin(),arr.end());\n    vector<vector<int>>dp(n+1,vector<int>(n+1));\n    vector<int>prefixSum(n+1,0);\n    for(int i=1;i<=n;i++) prefixSum[i]=prefixSum[i-1]+arr[i-1];\n    for(int i=0;i<=n;i++) dp[i][i]=0;\n    for(int length=2;length<=n;length++){\n        for(int i=1;i<=n-length+1;i++){\n            int j=i+length-1;\n            int sum=prefixSum[j]-prefixSum[i-1];\n            dp[i][j]=INT_MAX;\n            for(int k=i;k<j;k++) dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+sum);\n        }\n    }\n    cout<<dp[1][n];\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#define int long long\nusing namespace std;\n\n\nint32_t main() {\n    int n;cin>>n;\n    vector <int> v(n);\n    priority_queue <int,vector <int>,greater<int>> pq;\n    for(int i=0;i<n;i++){\n        cin>>v[i];\n        pq.push(v[i]);\n    }\n    if(n==1){\n        cout<<pq.top();\n        return 0;\n    }\n\n    int ans=0;\n    while(!pq.empty()){\n        int x=pq.top();\n        pq.pop();\n        if(pq.empty())break;\n        int y=pq.top();\n        pq.pop();\n        pq.push({x+y});\n        ans+=x+y;    \n    }\n    cout<<ans<<endl;\n    return 0;\n\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n#define f(a,n) for(int i=a;i<n;i++)\n\nint main() {\n\n\n    int t;cin>>t;\n    vector<long long> arr(t);\n    multiset<int> ms;\n\n    f(0,t) cin>>arr[i];\n\n    f(0,t) ms.insert(arr[i]);\n    long long ans=0;\n    for(;ms.size()>1;) {\n        int v=*ms.begin();\n        ms.erase(ms.begin());\n        int x=*ms.begin();\n        ms.erase(ms.begin());\n        ans+=v+x;\n        ms.insert(v+x);\n    }\n\n    cout<<ans<<\"\\n\";\n\n}","lang":"2"},
{"question_id":41034,"source":"#include<bits/stdc++.h>\n#define ll unsigned long long int\nusing namespace std;\n\nll func(vector<int>& a,int n){\n    priority_queue<ll,vector<ll>,greater<ll> >pq;\n    for(ll i=0;i<(ll)a.size();i++) pq.push(a[i]);\n    ll ans = 0;\n    while(pq.size()>1){\n        ll cur = pq.top();\n        pq.pop();\n        ll cur2 = pq.top();\n        pq.pop();\n\n        ans += cur + cur2;\n        pq.push(cur + cur2);\n    }\n\n    return ans;\n}\n\nint main() {\n\n    int n;\n    cin>>n;\n    vector<int>a(n);\n    for(int i=0;i<n;i++) cin>>a[i];\n\n    cout<<func(a,n);\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\nlong long int mod=1e9+7;\nint main() {\n    // long long int n;\n    // cin>>n;\n    // if(n==0) {\n    //     cout<<0<<endl;\n    //     return 1;\n    // }\n    // vector<long long int>arr(n);\n    // for(int i=0;i<n;i++) cin>>arr[i];\n    // sort(arr.begin(),arr.end());\n    // vector<vector<int>>dp(n+1,vector<int>(n+1));\n    // vector<int>prefixSum(n+1,0);\n    // for(int i=1;i<=n;i++) prefixSum[i]=prefixSum[i-1]+arr[i-1];\n    // for(int i=0;i<=n;i++) dp[i][i]=0;\n    // for(int length=2;length<=n;length++){\n    //     for(int i=1;i<=n-length+1;i++){\n    //         int j=i+length-1;\n    //         int sum=prefixSum[j]-prefixSum[i-1];\n    //         dp[i][j]=INT_MAX;\n    //         for(int k=i;k<j;k++) dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+sum);\n    //     }\n    // }\n    // cout<<dp[1][n];\n    // return 0;\n\n    long long n;\n    cin>>n;\n    vector<long long >arr(n);\n    for(int i=0;i<n;i++){\n        cin>>arr[i];\n    }\n    sort(arr.begin(),arr.end());\n    long long ans=0;\n    for(int i=0;i<n-1;i++){\n        ans+=(arr[1]+arr[0]);\n        arr[1]+=arr[0];\n        arr.erase(arr.begin());\n        sort(arr.begin(),arr.end());\n\n    }\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n#define int long long\n\nsigned main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    priority_queue<int,vector<int>,greater<int>> pq;\n    while(n--){\n        int x;\n        cin>>x;\n        pq.push(x);\n    }\n    int ans=0;\n    while(pq.size()>1){\n        int a=pq.top();pq.pop();\n        int b=pq.top();pq.pop();\n        ans+=a+b;\n        pq.push(a+b);\n    }\n    cout<<ans;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin >> n;\n\n    priority_queue<long long, vector<long long>,  greater<long long>> pq;\n    for(int i = 0; i < n; i++){\n        long long input;\n        cin >> input;\n        pq.push(input);\n    }\n\n    long long res = 0;\n    while(pq.size() > 1){\n        long long low = pq.top();\n        pq.pop();\n        long long high = pq.top();\n        pq.pop();\n\n        res += low + high;\n        pq.push(low + high);\n    }\n\n    cout << res << \"\\n\";\n\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define int long long\n\nint32_t main() {\n    int n;\n    cin>>n;\n    int a[n];\n    priority_queue<int, vector<int>, greater<int>> mn;\n    for(int i=0; i<n; i++){\n        cin>>a[i];\n        mn.push(a[i]);\n    }   \n    int score=0;\n    while(mn.size()> 1){\n        int x= mn.top();\n        mn.pop();\n        int y= mn.top();\n        mn.pop();\n\n        mn.push(abs(x+y));\n        score += abs(x+y);\n    }\n    cout<<score<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\nstruct Minheap{\n    unsigned size;\n    unsigned capacity;\n    int * harr;\n};\n\nstruct Minheap* createMinheap(unsigned capacity)\n{\n    struct Minheap* minheap= new Minheap;\n    minheap->size=0;\n    minheap->capacity=capacity;\n    minheap->harr= new int[capacity];\n    return minheap;\n}\n\nvoid swapMinheapnode(int* a, int* b)\n{\n    int temp=*a;\n    *a=*b;\n    *b=temp;\n}\n\nvoid minheapify(struct Minheap* minheap, int idx)\n{\n    int smallest=idx;\n    int left=2*idx+1;\n    int right=2*idx+2;\n    if(left<minheap->size && minheap->harr[left]<minheap->harr[smallest])\n    smallest=left;\n    if(right<minheap->size&&minheap->harr[right]<minheap->harr[smallest])\n    smallest=right;\n    if(smallest!=idx)\n    {\n        swapMinheapnode(&minheap->harr[smallest],&minheap->harr[idx]);\n        minheapify(minheap,smallest);\n    }\n}\nint issizeone(struct Minheap* minheap)\n{\n    return (minheap->size==1);\n}\nint extractmin(struct Minheap* minheap)\n{\n    int temp=minheap->harr[0];\n    minheap->harr[0]=minheap->harr[minheap->size-1];\n    --minheap->size;\n    minheapify(minheap,0);\n    return temp;\n}\nvoid insertminheap(struct Minheap* minheap,int val)\n{\n    ++minheap->size;\n    int i=minheap->size-1;\n    while(i&&(val<minheap->harr[(i-1)/2]))\n    {\n        minheap->harr[i]=minheap->harr[(i-1)/2];\n        i=(i-1)/2;\n    }\n    minheap->harr[i]=val;\n}\nvoid buildminheap(struct Minheap* minheap)\n{\n    int n=minheap->size-1,i;\n    for(i=(n-1)/2;i>=0;--i)\n    minheapify(minheap,i);\n}\nstruct Minheap* createAndbuildMinHeap(int len[],int size)\n{\n    struct Minheap* minheap=createMinheap(size);\n    for(int i=0;i<size;i++)\n    minheap->harr[i]=len[i];\n    minheap->size=size;\n    buildminheap(minheap);\n    return minheap;\n}\nint mincost(int len[],int n)\n{\n    int cost=0;\n    struct Minheap* minheap=createAndbuildMinHeap(len,n);\n    while(!issizeone(minheap))\n    {\n        int min=extractmin(minheap),sec_min=extractmin(minheap);\n        cost+=(min+sec_min);\n        insertminheap(minheap,min+sec_min);\n    }\n    return cost;\n}\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    int v[n];\n    for(int i=0;i<n;i++)\n    cin>>v[i];\n    cout<<mincost(v,n)<<\"\\n\";\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define ll long long int\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    ll n;cin>>n;\n    vector<ll>arr(n);\n    for(auto&x: arr) cin>>x;\n    priority_queue<ll,vector<ll>,greater<ll>>pq;\n    for(auto&x:arr) pq.push(x);\n    ll ans =0;\n    while(pq.size()>1)\n    {\n        ll a = pq.top();\n        pq.pop();\n        ans+=a+pq.top();\n        a+=pq.top();\n        pq.pop();\n        pq.push(a);\n    }\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include<bits/stdc++.h>\n#define ll long long int\nusing namespace std;\n\nll func(vector<int>& a,int n){\n    priority_queue<ll,vector<ll>,greater<ll> >pq;\n    for(ll i=0;i<(ll)a.size();i++) pq.push(a[i]);\n    ll ans = 0;\n    while(pq.size()>1){\n        ll cur = pq.top();\n        pq.pop();\n        ll cur2 = pq.top();\n        pq.pop();\n\n        ans += cur + cur2;\n        pq.push(cur + cur2);\n    }\n\n    return ans;\n}\n\nint main() {\n\n    int n;\n    cin>>n;\n    vector<int>a(n);\n    for(int i=0;i<n;i++) cin>>a[i];\n\n    cout<<func(a,n);\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define ll long long int\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    ll n;cin>>n;\n    vector<ll>arr(n);\n    for(auto&x: arr) cin>>x;\n    priority_queue<ll,vector<ll>,greater<ll>>pq;\n    for(auto&x:arr) pq.push(x);\n    ll ans =0;\n    while(pq.size()>1)\n    {\n        ll a = pq.top(); pq.pop();\n        ll b = pq.top(); pq.pop();\n        a+=b;\n        ans+=a;\n        pq.push(a);\n    }\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    int n;\n    cin >> n;\n    int arr[n];\n    for(int i = 0; i < n; i++){\n        cin >> arr[i];\n    }\n    priority_queue<int, vector<int>, greater<int>>pq(arr, arr + n);\n    int res = 0;\n    while(pq.size() > 1){\n        int f = pq.top();\n        pq.pop();\n        int s = pq.top();\n        pq.pop();\n        res += f + s;\n        pq.push(f + s);\n\n    }\n    cout << res << endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <stdio.h>\n#include <string.h>\n#include <math.h>\n#include <stdlib.h>\n#include<bits/stdc++.h>\n using namespace std;\n\nint mincost(int arr[], int n)\n{\n    priority_queue<int, vector<int>, greater <int>> pq(arr , arr+n);\n    int res =0;\n    while (pq.size() >1){\n        int first = pq.top();\n        pq.pop();\n        int second = pq.top();\n        pq.pop();\n\n        res += first+second;\n        pq.push (first+second);\n\n    }\n    return res;\n}\nint main() {\n\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n ;\n   \n    cin >> n;\n    int arr[n];\n    for(int i=0; i<n; i++){\n        cin >> arr[i];\n    }\n  cout << mincost(arr , n);\n    return 0;\n}","lang":"1"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\nint solve(vector<int>&v){\n    long long int n=v.size();\n    priority_queue<long long int,vector<long long int>,greater<long long int>> pq;\n    for(int i=0;i<n;i++){\n        pq.push(v[i]);\n    } \n    long long int sum=0;\n    long long int x,y;\n    while(pq.size()>1){\n\n        x=pq.top();\n        pq.pop();\n        \n        y=pq.top();\n        pq.pop();\n\n        sum+=(x+y);\n        pq.push(x+y);\n\n    }\n    return sum;\n}\n\nint main() {\n    int n,lol; cin>>n;\n    vector<int> a;\n    for(int i=0;i<n;i++){\n        cin>>lol;\n        a.push_back(lol);\n    }\n    cout<<solve(a)<<\"\\n\";\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n    long long n;\n    cin >> n;\n\n    priority_queue<long long, vector<long long>, greater<long long>> pq;\n\n    for(int i = 0; i < n; i++){\n        long long inp;\n        cin >> inp;\n        pq.push(inp);\n\n    }\n\n    long long ans = 0;\n    while(pq.size() >= 2){\n        long long a = pq.top();\n        pq.pop();\n        long long b = pq.top();\n        pq.pop();\n\n        pq.push(a + b);\n        ans += (a + b);\n\n\n    } \n\n    cout << ans << \"\\n\";\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\nimport java.util.*;\n\nclass Solution {\n\n    public static void main(String[] args) {\n        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n       long ans= (long)0;\n        PriorityQueue<Long> pq = new PriorityQueue<>((n1,n2)-> Long.compare(n1,n2));\n        for(int i=0 ; i<n ; i++){\n            pq.add(sc.nextLong());\n        }\n        while(pq.size()>1){\n            long a = pq.poll();\n            long b = pq.poll();\n            ans+=a+b;\n            pq.add(a+b);\n        }\n        System.out.println(ans);\n        \n    }\n}","lang":"3"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n    priority_queue<int, vector<int>, greater<int>>pq; \n    int n;\n    cin>>n;\n    for(int i=0;i<n;i++)\n    {\n        int a;\n        cin>>a;\n        pq.push(a);\n    }\n    long long cost= 0;\n     while(!pq.empty())\n     {\n         if(pq.size()==1)\n         {\n             break;\n         }\n          int a=pq.top();\n          pq.pop();\n          int b = pq.top();\n          pq.pop();\n          cost+=(a+b);\n          pq.push(a+b);\n         // cout<<a<<endl<<b<<endl;\n          \n    //     if(pq.size()==1) continue;\n    //     int b,c;\n    //     b = pq.top();\n    //     pq.pop();\n    //     c =pq.top();\n    //     pq.top();\n    //     cost+=b;\n    //     cost+=c;\n    //     pq.push(b+c)\n     }\n     //cost+=pq.top();\n    \n    cout<<cost<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\n#define ll long long int\nusing namespace std;\n\nvoid solve(){\n    ll n;\n    cin>>n;\n    priority_queue<ll,vector<ll>,greater<ll>> pq;\n    for(ll i=0;i<n;i++){\n        ll x;\n        cin>>x;\n        pq.push(x);\n    }\n    ll ans = 0;\n    while(pq.size()!=1){\n        ll a = pq.top();\n        pq.pop();\n        ll b = pq.top();\n        pq.pop();\n        ans+=(a+b);\n        pq.push(a+b);\n    }\n    cout<<ans<<endl;\n}\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    solve();\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    int n;cin>>n;\n    vector<int> a(n);\n    priority_queue<int,vector<int>,greater<int>> pq;\n    for(int i=0;i<n;i++){\n        cin>>a[i];\n        pq.push(a[i]);\n    }  \n    int cost = 0;\n    while(pq.size()>1){\n        int a = pq.top();pq.pop();\n        int b = pq.top();pq.pop();\n        cost+=(a+b);\n        pq.push(a+b);\n    }\n    cout<<cost<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n#include <bits/stdc++.h>\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    int n; cin>>n;\n    int a[n];\n    for(int i=0;i<n;i++){\n        cin>>a[i];\n    }\n    priority_queue<int, vector<int>, greater<int>> pq;\n    for(int i=0;i<n;i++){\n        pq.push(a[i]);\n    }\n    long long tot = 0;\n    while(pq.size()>1){\n        int x = pq.top();\n        pq.pop();\n        int y = pq.top();\n        pq.pop();\n        tot += x+y;\n        pq.push(x+y);\n    }\n    cout<<tot<<\"\\n\";\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define ll long long int\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    ll n;cin>>n;\n    vector<ll>arr(n);\n    for(auto&x: arr) cin>>x;\n    priority_queue<int,vector<int>,greater<int>>pq;\n    for(auto&x:arr) pq.push(x);\n    ll ans =0;\n    while(pq.size()>1)\n    {\n        ll a = pq.top();\n        pq.pop();\n        ans+=a+pq.top();\n        a+=pq.top();\n        pq.pop();\n        pq.push(a);\n    }\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <set>\n#include <bits/stdc++.h>\nusing namespace std;\n#define int long long \n\nsigned main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    int ans = 0;\n    vector<int> v;\n    // multiset<int> s;\n    // int ans = 0;\n    // for(int i=0;i<n;i++){\n    //     cin>>v[i];\n    //     s.insert(v[i]);\n    // }\n    // while(!s.empty()){\n    //     int t1 = 0,count = 0;\n    //     int t2 = 0;\n    //     for(auto i:s){\n    //         count++;\n    //         if(count == 3)break;\n    //         if(count == 2)t2 = i;\n    //         if(count == 1)t1 = i;\n    //     }\n    //     ans+=(t1+t2);\n    //     if(count!=3)break;\n\n    //     auto it  = s.begin();\n    //     int t1 = *it;\n    //     s.erase(it);\n    //     int t2 = 0;\n    //     if(s.size()!=0){\n    //         it = s.begin();\n    //         t2 = *it;\n    //         s.erase(it);\n    //     }\n    //     ans+=(t1+t2);\n    //     if(s.size()==0)continue;\n    //     s.insert(t1+t2);\n\n    // }\n    // cout<<ans<<endl;\n    priority_queue<int,vector<int>,greater<int>> pq;\n    for(int i=0;i<n;i++){\n        int k;\n        cin >> k;\n        pq.push(k);\n    }\n    while(pq.size() >1){\n        int a= pq.top();\n        pq.pop();\n        int b= pq.top();\n        pq.pop();\n        pq.push(a+b);\n        ans += (a+b);\n    }\n    cout << ans;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\nimport java.util.*;\n\nclass Solution {\n\n    public static void main(String[] args) {\n        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n       long ans= (long)0;\n        PriorityQueue<Long> pq = new PriorityQueue<>((n1,n2)-> Long.compare(n1,n2));\n        for(int i=0 ; i<n ; i++){\n            pq.add(sc.nextLong());\n        }\n        while(pq.size()>1){\n            long a = pq.poll();\n            long b = pq.poll();\n            ans+=a+b;\n            pq.add(a+b);\n        }\n        System.out.println(ans);\n        \n    }\n}","lang":"3"},
{"question_id":41034,"source":"#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    int n;\n    cin >> n;\n    // vector<int> arr(n);\n    // for(int i = 0 ; i < n ; i++){\n    //     cin >> arr[i];\n    // }\n    // int l = 0, ans = 0;\n    // sort(arr.begin(), arr.end());\n    // for(int i = 0 ; i < n ; i++){\n    //     l+=arr[i];\n    //     if(i>0)\n    //      ans+=l;\n    // }\n    // cout<<ans<<endl;\n    priority_queue<long long, vector<long long>, greater<long long>> pq;\n    for(int i = 0 ; i < n ; i++){\n        long long a;\n        cin >> a;\n        pq.push(a);\n    }\n    long long cost = 0;\n    while(pq.size() > 1){\n        long long a = pq.top();\n        pq.pop();\n        long long b = pq.top();\n        pq.pop();\n        pq.push(a+b);\n        cost += (a+b);\n    }\n    cout<<cost<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"def mincost(tetris):\r\n    if(len(tetris)<=1):\r\n        return 0\r\n    else:\r\n        mina = min(tetris)\r\n        tetris.remove(mina)\r\n        minb = min(tetris)\r\n        tetris.remove(minb)\r\n        tetris.append(mina + minb)\r\n\r\n        return mina + minb + mincost(tetris)\r\nn = int(input())\r\nlist1 = list(map(int,input().strip().split()))[:n]\r\nprint(mincost(list1))","lang":"30"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include<bits/stdc++.h>\n\n#define ll long long\n\nusing namespace std;\n\n\nint main() {\n    int n;\n    cin>>n;\n   \n   priority_queue<long long,vector<long long>,greater<long long>>pq;\n    for(int i=0;i<n;++i)\n    { \n        ll x;\n        cin>>x;\n        pq.push(x);\n      \n    }\n   \n    ll ans=0;\n    while(pq.size()>1)\n    {\n        ll a=pq.top();\n        pq.pop();\n        ll b=pq.top();\n        pq.pop();\n        ll t=a+b;\n        ans+=t;\n        pq.push(t);\n    }\n    cout<<ans<<endl;\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include<bits/stdc++.h>\nusing namespace std;\n#define int long long\n#define all(x) x.begin(),x.end()\nint32_t main() {\n\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n   int n;\n   cin>>n;\n   int arr[n];\n   for(int i=0;i<n;i++)cin>>arr[i];\n   priority_queue<int,vector<int>,greater<int>>q;\n   for(auto itr:arr)\n   {\n       q.push(itr);\n   }\n   int ans=0;\n   while(q.size()>1)\n   {\n       int a=q.top();\n       q.pop();\n       int b=q.top();\n       q.pop();\n       q.push(a+b);\n       ans+=a+b;\n   }\n   cout<<ans<<endl;\n    return 0;\n}","lang":"1"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint terisCost(int arr[] , int n){\n\n    priority_queue<int , vector<int> , greater<int>> pr(arr,arr+n);\n\n    int ans = 0 ; \n\n    while(pr.size() > 1){\n        int first = pr.top();\n        pr.pop();\n        int second = pr.top();\n        pr.pop();\n\n        ans += first + second ; \n        pr.push(first + second);\n    }\n\n    return ans;\n\n\n\n}\n\nint main() {\n    \n    int n ;\n    cin>>n;\n    int arr[n];\n\n    for(int i = 0 ; i<n ; i++){\n        cin>>arr[i];\n    }\n\n    cout<<terisCost(arr,n);\n\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n#define int long long int\n\nsigned main() {\n    int n;\n    cin>>n;\n    priority_queue<int, vector<int>, greater<int>> q;\n\n    for(int i=0;i<n;i++){\n        int x;\n        cin>>x;\n        q.push(x);\n    }\n\n    int s=0;\n    while(q.size()!=1){\n        int x=q.top();\n        q.pop();\n        int x2=q.top();\n        q.pop();\n        s+=x+x2;\n        q.push(x+x2);\n    }\n    cout<<s<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\n\nint main() {\n    \n    int n;\n    cin>>n;\n    vector<int> arr(n);\n    priority_queue<ll, vector<ll>, greater<ll>> pq;\n    for(int i=0;i<n;i++){\n        cin>>arr[i];\n        pq.push(arr[i]);\n    }\n    ll ans =0;\n    while(pq.size()>1){\n        ll tp1 = pq.top();\n        pq.pop();\n        ll tp2 = pq.top();\n        pq.pop();\n        ans += tp1 + tp2;\n        pq.push(tp1 + tp2);\n    }\n    cout<<ans;\n\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n\n#include<bits/stdc++.h>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;cin>>n;\n \n    priority_queue<long long ,vector<long long>,greater<long long>>pq;\n    for(int i=0;i<n;i++){\n        long long x;cin>>x;\n        pq.push(x);\n    }\n    long long ans=0;\n    while(pq.size()>1){\n        long long x=pq.top();\n        pq.pop();\n        long long y=pq.top();\n        pq.pop();\n        ans+=x+y;\n        pq.push(x+y);\n    }\n    cout <<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"# Enter your code here. Read input from STDIN. Print output to STDOUT\r\nimport heapq\r\n\r\ndef minCost(arr,n):\r\n\r\n    heapq.heapify(arr)\r\n    res=0\r\n    while(len(arr)>1):\r\n        first=heapq.heappop(arr)\r\n        second=heapq.heappop(arr)\r\n\r\n        res+=first+second\r\n        heapq.heappush(arr,first+second)\r\n    return res\r\n\r\nn=int(input())\r\narr=list(map(int,input().split()))\r\nprint(str(minCost(arr,len(arr))))","lang":"30"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    \n    int n;\n    cin>>n;\n    vector<long long> a(n);\n    for(int i=0;i<n;i++) cin>>a[i];\n    priority_queue<long long,vector<long long>,greater<long long>> pq;\n    long long ans = 0;\n    for(int i=0;i<n;i++) pq.push(a[i]);\n\n    while(pq.size()>1){\n        long long top = pq.top();\n        pq.pop();\n        long long top2 = pq.top();      \n        pq.pop();\n        ans += (top + top2);\n        pq.push(top+top2);\n    }\n    cout<<ans<<\"\\n\";\n    \n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    ll n;cin>>n;\n    multiset<ll> s;\n    for(ll i=0;i<n;i++)\n    {\n        int a;cin>>a;\n        s.insert(a);\n    }\n    ll ans=0;\n    while(s.size()>=2)\n    {\n        ll it1=*s.begin();\n        ans+=it1;\n        s.erase(s.begin());\n        ll it2=*s.begin();\n        s.erase(s.begin());\n        ans+=it2;\n        s.insert(it1+it2);\n    }\n    cout<<ans;\n\n\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\nint minCost(int arr[],int n)\n{\n    priority_queue<int,vector<int>,greater<int>>pq(arr,arr+n);\n        int res=0;\n        while(pq.size()>1){\n            int first=pq.top();\n            pq.pop();\n            int second=pq.top();\n            pq.pop();\n            res+=first+second;\n            pq.push(first+second);\n        }\n        return res;\n    }\nint main() {\n    int n;\n    cin>>n;\n    int len[n];\n    for(int i=0;i<n;i++){\n        cin>>len[i];\n    }\n    int size=sizeof(len)/sizeof(len[0]);\n    cout<<minCost(len,size);\n    \n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define ll long long\nvoid solve(){\n    ll n;\n    cin>>n;\n    ll x;\n    multiset<ll>mst;\n    for(int i=1;i<=n;i++){\n        cin>>x;\n        mst.insert(x);\n    }\n    ll ans=0;\n    while(mst.size()>1){\n        ll p1=*mst.begin();\n        mst.erase(mst.begin());\n        ll p2=*mst.begin();\n        mst.erase(mst.begin());\n        ans=(ans+p1+p2);\n        mst.insert(p1+p2);\n    }\n    cout<<ans;\n}\n\n\nint main() {\n    solve();\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n#define int long long\n\nint32_t main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    ios_base::sync_with_stdio(false);\n    cin.tie(NULL);\n    int n;\n    cin>>n;\n    vector<int> a(n);\n    priority_queue<int, vector<int>, greater<int>> pq;\n    for(auto &it: a){\n        cin>>it;\n        pq.push(it);\n    }  \n    int ans = 0;\n    while(pq.size() > 1){\n        int k = pq.top();\n        pq.pop();\n        int b = pq.top();\n        pq.pop();\n        ans += (k+b);\n        pq.push(k+b);\n    }\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <set>\n#include <bits/stdc++.h>\nusing namespace std;\n#define int long long \n\nsigned main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    int ans = 0;\n    vector<int> v;\n    // multiset<int> s;\n    // int ans = 0;\n    // for(int i=0;i<n;i++){\n    //     cin>>v[i];\n    //     s.insert(v[i]);\n    // }\n    // while(!s.empty()){\n    //     int t1 = 0,count = 0;\n    //     int t2 = 0;\n    //     for(auto i:s){\n    //         count++;\n    //         if(count == 3)break;\n    //         if(count == 2)t2 = i;\n    //         if(count == 1)t1 = i;\n    //     }\n    //     ans+=(t1+t2);\n    //     if(count!=3)break;\n\n    //     auto it  = s.begin();\n    //     int t1 = *it;\n    //     s.erase(it);\n    //     int t2 = 0;\n    //     if(s.size()!=0){\n    //         it = s.begin();\n    //         t2 = *it;\n    //         s.erase(it);\n    //     }\n    //     ans+=(t1+t2);\n    //     if(s.size()==0)continue;\n    //     s.insert(t1+t2);\n\n    // }\n    // cout<<ans<<endl;\n    priority_queue<int,vector<int>,greater<int>> pq;\n    for(int i=0;i<n;i++){\n        int k;\n        cin >> k;\n        pq.push(k);\n    }\n    while(pq.size() >1){\n        int a= pq.top();\n        pq.pop();\n        int b= pq.top();\n        pq.pop();\n        pq.push(a+b);\n        ans = (ans +a+b) %(1000000007);\n    }\n    cout << ans %(1000000007);\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include<bits/stdc++.h>\nusing namespace std;\nint main() {\n    int n , var; \n    cin >> n;\n    priority_queue<int, vector<int>, greater<int>> pq;\n\n    for(int i = 0; i<n; i++)\n    {\n        cin >> var;\n        pq.push(var);\n    }\n    int res =0;\n    while(pq.size() >1)\n    {\n        int val1 = pq.top(); pq.pop();\n        int val2 = pq.top(); pq.pop();\n        res += val1 + val2;\n        pq.push(val1 + val2);\n    }\n    cout << res;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\nvoid solve(){\n    ll n;\n    cin>>n;\n    ll ans=0;\n    multiset<ll>mst;\n    ll x;\n    for(int i=1;i<=n;i++){\n        cin>>x;\n        mst.insert(x);\n    }\n    while(mst.size()>1){\n        ll z1=*mst.begin();\n        mst.erase(mst.begin());\n        ll z2=*mst.begin();\n        mst.erase(mst.begin());\n        \n        ans=(ans+z1+z2);\n        mst.insert(z1+z2);\n    }\n    cout<<ans;\n}\n\nint main() {\n    solve();\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"# Enter your code here. Read input from STDIN. Print output to STDOUT\r\nimport heapq\r\n\r\ndef minCost(arr,n):\r\n    heapq.heapify(arr)\r\n    res=0\r\n    while(len(arr)>1):\r\n        first=heapq.heappop(arr)\r\n        second=heapq.heappop(arr)\r\n        res+=first+second\r\n        heapq.heappush(arr,first+second)\r\n    return res\r\n\r\nif __name__ == '__main__':\r\n    n=int(input())\r\n    arr=list(map(int,input().split()))\r\n    print(str(minCost(arr,n)))","lang":"30"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define ll long long int\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    ll n;cin>>n;\n    vector<ll>arr(n);\n    for(auto&x: arr) cin>>x;\n    priority_queue<ll,vector<ll>,greater<ll>>pq;\n    for(auto&x:arr) pq.push(x);\n    ll ans =0;\n    while(pq.size()>1)\n    {\n        ll a = pq.top(); pq.pop();\n        ll b = pq.top(); pq.pop();\n        a+=b;\n        ans+=a;\n        pq.push(a);\n    }\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include<bits/stdc++.h>\nusing namespace std;\n#define int long long\nint32_t main(){\n     ios::sync_with_stdio(false);\n     cin.tie(NULL);\n     cout.tie(NULL);\n    int n;cin>>n;\n    vector<int>arr(n);\n    for(auto &x:arr)cin>>x;\n    priority_queue<int,vector<int>,greater<int> >minheappq(arr.begin(),arr.end());\n    int valuestones=0;\n    while(minheappq.size()>1){\n        int u=minheappq.top();\n        minheappq.pop();\n        int v=minheappq.top();\n        minheappq.pop();\n        valuestones+=u+v;\n        minheappq.push(u+v);\n    }\n    cout<<valuestones;\n    return 0;\n}","lang":"1"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    int n; \n    cin>> n;\n    int a[n];\n    for(int i=0 ;i<n;i++){\n        cin>> a[i];\n    }   \n    long long res = 0;\n    multiset<int> pq;\n    for(int i=0; i<n; i++){\n        pq.insert(a[i]);\n    }\n\n    while(pq.size() > 1){\n        int x = *(pq.begin());\n        pq.erase(pq.begin());\n        \n        int y = *(pq.begin());\n        pq.erase(pq.begin());\n        \n        long long z = x+y;\n       pq.insert(z);\n       \n        res += z;\n        \n         \n        \n    }\n    cout<< res << endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\n\nusing namespace std;\nint solve(int arr[],int n)\n{\n    int finalcost=0;\n    priority_queue<int,vector<int>,greater<int>> minHeap;\n    for(int i=0;i<n;i++)\n    {\n        minHeap.push(arr[i]);\n    }\n    while(minHeap.size()>1)\n    {\n        int smallest=minHeap.top();\n        minHeap.pop();\n        int second=minHeap.top();\n        minHeap.pop();\n        finalcost+=(smallest+second);\n        minHeap.push(smallest+second);\n    }\n    return finalcost;\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n        priority_queue<int, vector<int>, greater<int>> pq;\n        int n;\n        cin>>n;\n        int arr[n];\n        for(int i=0;i<n;i++)\n        {\n            cin>>arr[i];\n        }\n        int ans=solve(arr,n);\n        cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"# Enter your code here. Read input from STDIN. Print output to STDOUT\r\n\r\nN = int(input())\r\n\r\na = []\r\n\r\nt = input().split(\" \")\r\n\r\nfor i in t:\r\n    a.append(int(i))\r\n\r\nm = 0\r\n\r\nwhile(len(a) != 1):\r\n    min1 = min(a)\r\n    a.pop(a.index(min1))\r\n    min2 = min(a)\r\n    a.pop(a.index(min2))\r\n    m += min1 + min2\r\n    a.append(min1 + min2)\r\n\r\nprint(m)","lang":"30"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n#define long long ll\n#define ll int\n\nint main() {\n    int n;\n    cin>>n;\n    priority_queue<int, vector<int>, greater<int>> q;\n\n    for(int i=0;i<n;i++){\n        int x;\n        cin>>x;\n        q.push(x);\n    }\n\n    int s=0;\n    while(q.size()!=1){\n        int x=q.top();\n        q.pop();\n        int x2=q.top();\n        q.pop();\n        s+=x+x2;\n        q.push(x+x2);\n    }\n    cout<<s<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    int n;\n    cin>>n;\n    priority_queue<int, vector<int>, greater<int>>pq;\n    for(int i=0; i<n; i++)\n    {\n        int a;\n        cin>>a;\n        pq.push(a);\n    }\n    long long sum=0;\n    while(pq.size()!=1)\n    {\n        int one = pq.top();\n        pq.pop();\n        int two = pq.top();\n        pq.pop();\n        sum+=one+two;\n        pq.push(one+two);\n    }\n    cout<<sum;\n\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\n#define int long long\nusing namespace std;\n\n\nint32_t main() {\n    /* Enter yo\n    ur code here. Read input from STDIN. Print output to STDOUT */   \n\n    int n;\n    cin>>n;\n\n    int a[n];\n    priority_queue<int, vector<int>, greater<int>> pq;\n\n    for(int i=0;i<n;i++){\n        cin>>a[i];\n\n        pq.push(a[i]);\n    }\n\n\n    int cost = 0;\n\n    while(pq.size()>1){\n        int x = pq.top();\n        pq.pop();\n        int y = pq.top();\n        pq.pop();\n\n        cost += (x+y);\n        pq.push(x+y);\n    }\n\n    cout<<cost;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    int n;\n    cin>>n;\n    priority_queue<int, vector<int>, greater<int>>pq;\n    for(int i=0; i<n; i++)\n    {\n        int a;\n        cin>>a;\n        pq.push(a);\n    }\n    long long sum=0;\n    while(pq.size()!=1)\n    {\n        int one = pq.top();\n        pq.pop();\n        int two = pq.top();\n        pq.pop();\n        sum+=one+two;\n        pq.push(one+two);\n    }\n    cout<<sum;\n\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n\n#include<bits/stdc++.h>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;cin>>n;\n \n    priority_queue<long long ,vector<long long>,greater<long long>>pq;\n    for(int i=0;i<n;i++){\n        long long x;cin>>x;\n        pq.push(x);\n    }\n    long long ans=0;\n    while(pq.size()>1){\n        long long x=pq.top();\n        pq.pop();\n        long long y=pq.top();\n        pq.pop();\n        ans+=x+y;\n        pq.push(x+y);\n    }\n    cout <<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n\n#include<bits/stdc++.h>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;cin>>n;\n \n    priority_queue<long long ,vector<long long>,greater<long long>>pq;\n    for(int i=0;i<n;i++){\n        long long x;cin>>x;\n        pq.push(x);\n    }\n    long long ans=0;\n    while(pq.size()>1){\n        long long x=pq.top();\n        pq.pop();\n        long long y=pq.top();\n        pq.pop();\n        ans+=x+y;\n        pq.push(x+y);\n    }\n    cout <<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include<bits/stdc++.h>\nusing namespace std;\n#define int long long\n#define all(x) x.begin(),x.end()\nvoid func(int x,int y)\n{\n    int s=0;\n    for(int i=0;i<2;i++)s+=i;\n    s-=x;\n    for(int i=0;i<5;i++)s-=i;\n    s+=y;\n}\nint32_t main() {\n\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n   int n;\n   cin>>n;\n   int arr[n];\n   for(int i=0;i<n;i++)cin>>arr[i];\n   func(10,10);\n   priority_queue<int,vector<int>,greater<int>>q;\n   for(auto itr:arr)\n   {\n       q.push(itr);\n   }\n   func(10,100);\n   int ans=0;\n   func(10,10);\n   while(q.size()>1)\n   {\n       int a=q.top();\n       q.pop();\n       int b=q.top();\n       q.pop();\n       q.push(a+b);\n       ans+=a+b;\n   }\n   func(100,10);\n   cout<<ans<<endl;\n    return 0;\n}","lang":"1"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    int n;\n    cin>>n;\n    priority_queue<int, vector<int>, greater<int>>pq;\n    for(int i=0; i<n; i++)\n    {\n        int a;\n        cin>>a;\n        pq.push(a);\n    }\n    long long sum=0;\n    while(pq.size()!=1)\n    {\n        int one = pq.top();\n        pq.pop();\n        int two = pq.top();\n        pq.pop();\n        sum+=one+two;\n        pq.push(one+two);\n    }\n    cout<<sum;\n\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"import heapq\nn=int(input())\na=list(map(int,input().split()))\nheapq.heapify(a)\ncost=0\nwhile len(a)>1:\n    x,y=heapq.heappop(a),heapq.heappop(a)\n    heapq.heappush(a,x+y)\n    cost+=x+y\nprint(cost)","lang":"30"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\nlong long int mod=1e9+7;\nint main() {\n    // long long int n;\n    // cin>>n;\n    // if(n==0) {\n    //     cout<<0<<endl;\n    //     return 1;\n    // }\n    // vector<long long int>arr(n);\n    // for(int i=0;i<n;i++) cin>>arr[i];\n    // sort(arr.begin(),arr.end());\n    // vector<vector<int>>dp(n+1,vector<int>(n+1));\n    // vector<int>prefixSum(n+1,0);\n    // for(int i=1;i<=n;i++) prefixSum[i]=prefixSum[i-1]+arr[i-1];\n    // for(int i=0;i<=n;i++) dp[i][i]=0;\n    // for(int length=2;length<=n;length++){\n    //     for(int i=1;i<=n-length+1;i++){\n    //         int j=i+length-1;\n    //         int sum=prefixSum[j]-prefixSum[i-1];\n    //         dp[i][j]=INT_MAX;\n    //         for(int k=i;k<j;k++) dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+sum);\n    //     }\n    // }\n    // cout<<dp[1][n];\n    // return 0;\n\n    long long n;\n    cin>>n;\n    vector<long long >arr(n);\n    for(int i=0;i<n;i++){\n        cin>>arr[i];\n    }\n    sort(arr.begin(),arr.end());\n    long long ans=0;\n    for(int i=0;i<n-1;i++){\n        ans+=(arr[1]+arr[0]);\n        arr[1]+=arr[0];\n        long long temp=arr[1];\n        arr.erase(arr.begin());\n        arr.erase(arr.begin());\n        arr.insert(upper_bound(arr.begin(),arr.end(),temp),temp);\n        //sort(arr.begin(),arr.end());\n\n    }\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n#define int long long int\n\nint32_t main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n    int n;\n    cin>>n;\n    priority_queue<int, vector<int>, greater<int>> q;\n    for (int i=0; i<n; i++){\n        int x;\n        cin>>x;\n        q.push(x);\n    } \n    int ans=0;\n    while((int)q.size()>1){\n        int x=q.top();\n        q.pop();\n        int y=q.top();\n        q.pop();\n        ans=ans+x+y;\n        q.push(x+y);\n    }\n    cout<<ans;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<queue>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    priority_queue<int,vector<int>,greater<int>> pq;\n    int n; cin >> n;\n    for(int i = 0; i < n; i++){\n        int x; cin >> x; pq.push(x);\n    }\n    int sum = 0;\n    while(pq.size() >= 2){\n        int a = pq.top(); pq.pop();\n        int b  = pq.top(); pq.pop();\n        pq.push(a + b);\n        sum += a + b;\n    }\n    cout << sum;\n    return 0;\n\n}","lang":"2"},
{"question_id":41034,"source":"#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long int\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n\n    ll n;\n    cin >> n;\n    ll a[n];\n    priority_queue<ll, vector<ll> , greater<ll>> q;\n\n    for(int i=0 ; i<n ; i++){\n        cin >> a[i];\n        q.push(a[i]);\n    }\n\n    ll ans = 0;\n    while(q.size() > 1){\n        ll x = q.top();\n        q.pop();\n        ll y = q.top();\n        q.pop();\n        ans += x+y;\n        q.push(x+y);\n    }\n\n    cout << ans;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n#include<bits/stdc++.h>\n\nint main() {\n\n    int n;cin>>n;\n    vector<long long>a(n);\n    priority_queue<long long, vector<long long>, greater<long long>> pq;\n\n    for(int i=0;i<n;i++){\n        cin>>a[i];\n        pq.push(a[i]);\n    }\n\n    long long answer = 0;\n\n    if(n==1){\n        cout<<a[0]<<endl;\n        return 0;\n    }\n\n    while(pq.size()!=1){\n        long long a = pq.top(); pq.pop();\n        long long b = pq.top(); pq.pop();\n\n        answer += (a+b);\n\n        pq.push(a+b);\n    }\n\n    cout<<answer<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\n#define ll long long int\nusing namespace std;\nll solve(ll arr[],ll n)\n{\n    ll finalcost=0;\n    priority_queue<ll,vector<ll>,greater<ll>> minHeap;\n    for(ll i=0;i<n;i++)\n    {\n        minHeap.push(arr[i]);\n    }\n    while(minHeap.size()>1)\n    {\n        ll smallest=minHeap.top();\n        minHeap.pop();\n        ll second=minHeap.top();\n        minHeap.pop();\n        finalcost+=(smallest+second);\n        minHeap.push(smallest+second);\n    }\n    return finalcost;\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n        priority_queue<ll, vector<ll>, greater<ll>> pq;\n        ll n;\n        cin>>n;\n        ll arr[n];\n        for(ll i=0;i<n;i++)\n        {\n            cin>>arr[i];\n        }\n        ll ans=solve(arr,n);\n        cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\nclass Solution {\n\n    public static void main(String[] args) {\n        \n        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        \n        PriorityQueue<Long> queue = new PriorityQueue<Long>();\n        long result =0;\n        for(int i=0;i<n;i++){\n            queue.add(sc.nextLong());\n        }\n        while(queue.size()>1){\n            long a1 = queue.poll();\n            long a2 = queue.poll();\n            result += a1+a2;\n            queue.add(a1+a2);\n        }\n        System.out.println(result);\n    }\n}","lang":"43"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    int n;\n    cin >> n;\n    int a[n];\n    for(int i = 0; i < n; i++){\n        cin >> a[i];\n    }\n    priority_queue<int, vector<int>, greater<int>> pq;\n    for(int i = 0; i < n; i++){\n        pq.push(a[i]);\n    }\n    int ans = 0;\n    while(!pq.empty()){\n        int x = pq.top();\n        pq.pop();\n        if(pq.empty()){\n            break;\n        }\n        int y = pq.top();\n        pq.pop();\n        ans += x+y;\n        pq.push(x+y);\n    }\n    cout << ans << endl;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\ntypedef long long ll;\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    ll n;\n    cin>>n;\n    ll a[n];\n    for(int i = 0;i<n;i++){\n        cin>>a[i];\n    }\n    priority_queue<ll,vector<ll>,greater<ll>>pq;\n    for(int i = 0 ;i<n;i++){\n        pq.push(a[i]);\n    }\n    ll ans = 0;\n    if(n==1){\n        cout<<a[0]<<endl;\n        return 0;\n    }\n    while(pq.size()>=2){\n        ll x = pq.top();\n        pq.pop();\n        ll y = pq.top();\n        pq.pop();\n        ans+= (x+y);\n        pq.push(x+y);\n    }\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include<bits/stdc++.h>\nusing namespace std;\n#define int long long\nint32_t main(){\n     ios::sync_with_stdio(false);\n     cin.tie(NULL);\n     cout.tie(NULL);\n    int n;cin>>n;\n    vector<int>arr(n);\n    for(auto &x:arr)cin>>x;\n    priority_queue<int>maxheappq;\n    priority_queue<int,vector<int>,greater<int> >minheappq(arr.begin(),arr.end());\n    int valuestones=0;\n    while(minheappq.size()>1){\n        int u=minheappq.top();\n        minheappq.pop();\n        int v=minheappq.top();\n        minheappq.pop();\n        valuestones+=u+v;\n        minheappq.push(u+v);\n        maxheappq.push(u+v);\n    }\n    cout<<valuestones;\n    return 0;\n}","lang":"1"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <bits/stdc++.h>\n#include <algorithm>\n#define int long long int\nusing namespace std;\n\n\nsigned main() {\n    priority_queue<int,vector<int>, greater<int>>q;\n    int n;\n    cin>>n;\n    while(n--){\n        int k;\n        cin>>k;\n        q.push(k);\n    }\n    int ans=0;\n    while(!q.empty()){\n        int a=q.top();\n        q.pop();\n        int b=q.top();\n        q.pop();\n        int c=a+b;\n        ans+=c;\n        if(q.empty())  break;\n        q.push(c);\n    }\n    cout<<ans<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\n#define ll long long\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    priority_queue<ll,vector<ll>,greater<ll>>pq;\n    for(int i=0;i<n;i++)\n    {\n        ll a;\n        cin>>a;\n        pq.push(a);\n    }\n    // sort(a.begin(),a.end());\n    ll ans=0;\n    while(pq.size()>1)\n    {\n        ll a=pq.top();\n        pq.pop();\n        ll b=pq.top();\n        pq.pop();\n        ans+=a+b;\n        pq.push(a+b);\n    }\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n#define int long long\n\nsigned main() {\n   int n;\n   cin>>n;\n   priority_queue<int,vector<int>,greater<int>>pq;\n   while(n--){\n       int x;\n       cin>>x;\n       pq.push(x);\n   }\n    int ans = 0;\n   while(pq.size() > 1){\n       int x = pq.top();\n       pq.pop();\n       int y = pq.top();\n       pq.pop();\n       ans+=(x+y);\n       pq.push(x+y);\n   }\n   cout<<ans;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\n\nll dpmin(vector<ll>&arr,ll low,ll high,vector<vector<ll>>&dp)\n{\n    if(low==high) return 0;\n    if(dp[low][high]!=-1) return dp[low][high];\n    ll ans=1e18;\n    ll sum=0;\n    for(int i=low;i<=high;i++) sum+=arr[i];\n    ll curr=0;\n    for(int j=low;j<high;j++)\n    {\n\n        \n        ll x=dpmin(arr,low,j,dp);\n        ll y=dpmin(arr,j+1,high,dp);\n        ans=min(ans,x+y);\n\n\n    }\n    return (dp[low][high]=ans+sum);\n}\n\nint main() {\n    ll n;\n    cin>>n;\n    vector<ll>arr(n);\n    for(int i=0;i<n;i++) cin>>arr[i];\n    multiset<ll>st;\n    for(ll x:arr) st.insert(x);\n    ll ans=0;\n    while(st.size()>1){\n        auto it=st.begin();\n        ll a=*it;\n        st.erase(it);\n        it=st.begin();\n        ll b=*it;\n        st.erase(it);\n        ans+=(a+b);\n        st.insert(a+b);\n    }\n    cout<<ans<<\"\\n\";\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\ntypedef long long ll;\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    ll n;\n    cin>>n;\n    ll a[n];\n    for(int i = 0;i<n;i++){\n        cin>>a[i];\n    }\n    priority_queue<ll,vector<ll>,greater<ll>>pq;\n    for(int i = 0 ;i<n;i++){\n        pq.push(a[i]);\n    }\n    ll ans = 0;\n    if(n==1){\n        cout<<0<<endl;\n        return 0;\n    }\n    while(pq.size()>=2){\n        ll x = pq.top();\n        pq.pop();\n        ll y = pq.top();\n        pq.pop();\n        ans+= (x+y);\n        pq.push(x+y);\n    }\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"# Enter your code here. Read input from STDIN. Print output to STDOUT\r\nimport heapq\r\n\r\ndef minCost(arr,n):\r\n    heapq.heapify(arr)\r\n    res=0\r\n    while(len(arr)>1):\r\n        first=heapq.heappop(arr)\r\n        second=heapq.heappop(arr)\r\n        res+=first+second\r\n        heapq.heappush(arr,first+second)\r\n    return res\r\n\r\nif __name__ == '__main__':\r\n    n=int(input())\r\n    arr=list(map(int,input().split()))\r\n    print(str(minCost(arr,n)))","lang":"30"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    long long n;\n    cin >> n;\n\n    priority_queue<long long, vector<long long>, greater<long long>> pq;\n    for(long long i = 0; i < n; i++){\n        long long input;\n        cin >> input;\n        pq.push(input);\n    }\n\n    long long res = 0;\n    while(pq.size() >= 2){\n        long long l = pq.top();\n        pq.pop();\n        long long r = pq.top();\n        pq.pop();\n\n        res += (l + r);\n        pq.push(l + r);\n    }\n\n    cout << res << \"\\n\";\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\n#define ll long long int\nusing namespace std;\n\nvoid solve(){\n    ll n;\n    cin>>n;\n    priority_queue<ll,vector<ll>,greater<ll>>pq;\n    for (ll i=0;i<n;i++){\n        ll x;\n        cin>>x;\n        pq.push(x);\n    }\n    ll ans=0;\n    while(pq.size()!=1){\n        ll a=pq.top();pq.pop();\n        ll b=pq.top();pq.pop();\n        ans+=(a+b);\n        pq.push(a+b);\n    }\n    cout<<ans<<endl;\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    solve();\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    long long n;\n    cin >> n;\n\n    priority_queue<long long,vector<long long>, greater<long long>> pq;\n\n    for(long long i = 0; i < n; i++){\n        long long input;\n        cin >> input;\n        pq.push(input);\n    }\n\n    long long res = 0;\n    while(pq.size() > 1){\n        long long a = pq.top();\n        pq.pop();\n        long long b = pq.top();\n        pq.pop();\n\n        res += (a + b);\n        pq.push(a + b);\n    }\n\n    cout << res << \"\\n\";\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\nvoid solve(){\n    ll n;\n    cin>>n;\n    ll ans=0;\n    multiset<ll>mst;\n    ll x;\n    for(int i=1;i<=n;i++){\n        cin>>x;\n        mst.insert(x);\n    }\n    while(mst.size()>1){\n        ll z1=*mst.begin();\n        mst.erase(mst.begin());\n        ll z2=*mst.begin();\n        mst.erase(mst.begin());\n        \n        ans=(ans+z1+z2);\n        mst.insert(z1+z2);\n    }\n    cout<<ans;\n}\n\nint main() {\n    solve();\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    priority_queue<int, vector<int>, greater<int> > qe;\n    int n;\n    cin>>n;\n    for(int i=0;i<n;i++){\n        int temp;\n        cin>>temp;\n        qe.push(temp);\n    }\n\n    int ans = 0 ;\n\n    while(qe.size()>=2){\n        int num1 = qe.top();\n        qe.pop();\n        int num2 = qe.top();\n        qe.pop();\n\n        ans += num1 + num2;\n\n        qe.push(num2+num1);\n    }\n\n\n    cout<<ans;\n\n    \n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <bits/stdc++.h>\nusing namespace std;\n#define ll long long \n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    ll n;\n    cin>>n;\n    vector<ll> v(n);\n    int sum=0;\n    priority_queue<ll,vector<ll> ,greater<ll> > pq;\n    for(int i=0;i<n;i++)\n    {\n        cin>>v[i];\n        sum+=v[i];\n        pq.push(v[i]);\n    } \n    sort(v.begin(),v.end()); \n    ll ans=0;\n    while(pq.size()>1)\n    {\n        int a=pq.top();\n        pq.pop();\n        int b=pq.top();\n        pq.pop();\n        ans+=a+b;\n        pq.push(a+b);\n        \n    }\n    cout<<ans;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\nlong long int mod=1e9+7;\nint main() {\n   \n\n    long long n;\n    cin>>n;\n    priority_queue<long long,vector<long long>,greater<long long>>arr;\n    for(int i=0;i<n;i++){\n        long long ai;\n        cin>>ai;\n        arr.push(ai);\n    }\n    long long ans=0;\n    while(arr.size()>1){\n        long long a0=arr.top();\n        arr.pop();\n        long long  a1=arr.top();\n        arr.pop();\n        long long temp=a0+a1;\n        ans+=temp;\n        arr.push(temp);\n    }\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include<bits/stdc++.h>\nusing namespace std;\n\nint func(vector<int>& a,int n){\n    priority_queue<int,vector<int>,greater<int> >pq(a.begin(),a.end());\n    int ans = 0;\n    while(pq.size()>1){\n        int cur = pq.top();\n        pq.pop();\n        int cur2 = pq.top();\n        pq.pop();\n\n        ans += cur + cur2;\n        pq.push(cur + cur2);\n    }\n\n    return ans;\n}\n\nint main() {\n\n    int n;\n    cin>>n;\n    vector<int>a(n);\n    for(int i=0;i<n;i++) cin>>a[i];\n\n    cout<<func(a,n);\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\nusing ll = long long;\n\nint main() {\n    int n;\n    cin>>n;\n    vector<ll> v(n);\n    ll ans=0;\n    priority_queue<ll, vector<ll>, greater<ll>> minH;\n    for(int i=0; i<n; i++)\n    {\n        cin>>v[i];\n        minH.push(v[i]);\n    }\n    while(minH.size()!=1)\n    {\n        ll a=minH.top();\n        minH.pop();\n        ll b=minH.top();\n        minH.pop();\n        minH.push(a+b);\n        ans+=(a+b);\n    }\n    cout<<ans;\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    int n;\n    cin>>n;\n    int a[n];\n    for(int i=0; i<n; i++){\n        cin>>a[i];\n    }\n    if (n==1){\n        cout<<a[0]<<endl;\n    }\n    else{\n        priority_queue<int, vector<int>, greater<int>> pq;\n        for(int i=0; i<n; i++){\n            pq.push(a[i]);\n        }\n        int sum=0;\n        while(pq.size()>1){\n            int x = pq.top();\n            pq.pop();\n            int y = pq.top();\n            pq.pop();\n            pq.push(x+y);\n            sum+=(x+y);\n        }\n        cout<<sum<<endl;\n\n    }\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\nint minCost(int arr[],int n)\n{\n    priority_queue<int,vector<int>,greater<int>>pq(arr,arr+n);\n        int res=0;\n        while(pq.size()>1){\n            int first=pq.top();\n            pq.pop();\n            int second=pq.top();\n            pq.pop();\n            res+=first+second;\n            pq.push(first+second);\n        }\n        return res;\n    }\nint main() {\n    int n;\n    cin>>n;\n    int len[n];\n    for(int i=0;i<n;i++){\n        cin>>len[i];\n    }\n    int size=sizeof(len)/sizeof(len[0]);\n    cout<<minCost(len,size);\n    \n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\n#define int long long\nusing namespace std;\n\n\nint32_t main() {\n    /* Enter yo\n    ur code here. Read input from STDIN. Print output to STDOUT */   \n\n    int n;\n    cin>>n;\n\n    int a[n];\n    priority_queue<int, vector<int>, greater<int>> pq;\n\n    for(int i=0;i<n;i++){\n        cin>>a[i];\n\n        pq.push(a[i]);\n    }\n\n\n    int cost = 0;\n\n    while(pq.size()>1){\n        int x = pq.top();\n        pq.pop();\n        int y = pq.top();\n        pq.pop();\n\n        cost += (x+y);\n        pq.push(x+y);\n    }\n\n    cout<<cost;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include<bits/stdc++.h>\n#define int long long\nusing namespace std;\n\n\nint32_t main() {\n   int n;\n    cin >> n;\n\n    vector<int> arr(n);\n    for(int i = 0; i < n; i++)\n    cin >> arr[i];\n\n   priority_queue<int , vector<int> , greater<int>> store;\n\n   for(auto x : arr)\n   store.push(x);\n\n   int ans = 0;\n\n   while(store.size() != 1){\n       int val = store.top();\n       store.pop();\n\n       int val2 = store.top();\n       store.pop();\n\n       val += val2;\n       ans += val;\n       store.push(val);\n   }\n\n   cout << ans << endl;\n\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint helper(vector<int> vt){\n    int n=vt.size();\n    priority_queue<int,vector<int>,greater<int>>pq;\n    for(auto t:vt){\n        pq.push(t);\n    }\n    int ans=0;\n    while(pq.size()>1){\n        auto top=pq.top();\n        pq.pop();\n        auto top2=pq.top();\n        pq.pop();\n        int x=top+top2;\n        ans+=x;\n        pq.push(x);\n    }\n    return ans;\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    vector<int> vt;\n    for(int i=0;i<n;i++){\n        int a;\n        cin>>a;\n        vt.push_back(a);\n    }\n    cout<<helper(vt);\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\nint solve(vector<long long int>&arr){\n    priority_queue<long long int,vector<long long int>,greater<long long int>>pq;\n    for(long long int val:arr){\n        pq.push(val);\n    }\n    long long int ans=0;\n    while(pq.size()>1){\n        long long int a=pq.top();\n        pq.pop();\n        long long int b=pq.top();\n        pq.pop();\n        ans+=a+b;\n        pq.push(a+b);\n    }\n    return ans;\n    \n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    long long int n;\n    cin>>n;\n\n    vector<long long int>arr(n,0);\n    for(long long int i=0;i<n;i++){\n        long long int x;\n        cin>>x;\n        arr[i]=x;\n    }\n    cout<<solve(arr)<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint helper(vector<int> vt){\n    int n=vt.size();\n    priority_queue<int,vector<int>,greater<int>>pq;\n    for(auto t:vt){\n        pq.push(t);\n    }\n    int ans=0;\n    while(pq.size()>1){\n        auto top=pq.top();\n        pq.pop();\n        auto top2=pq.top();\n        pq.pop();\n        int x=top+top2;\n        ans+=x;\n        pq.push(x);\n    }\n    return ans;\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    vector<int> vt;\n    for(int i=0;i<n;i++){\n        int a;\n        cin>>a;\n        vt.push_back(a);\n    }\n    cout<<helper(vt);\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n\n\n\nint minCost(int arr[],int n){\n    priority_queue<int,vector<int>,greater<int>>pq(arr,arr+n);\n    \n    int res=0;\n    while(pq.size()>1){\n        int first=pq.top();\n        pq.pop();\n        int second=pq.top();\n        pq.pop();\n\n        res +=first+second;\n        pq.push(first+second);\n    }\n    return res;\n}\n\nint main(){\n    int n;\n    cin>>n;\n    int arr[n];\n    for(int i=0;i<n;++i){\n        cin>>arr[i];\n    }\n    cout<<minCost(arr,n)<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\ntypedef long long ll;\nlong long int findSum(vector<int> &vi){\n\n   int n = vi.size();\n\n   if(n == 1)return vi[0];\n\n   priority_queue<int,vector<int>,greater<int>> pq;\n\n   for(auto i : vi){\n       pq.push(i);\n   }\n\n   ll ans = 0;\n\n   ans += pq.top();\n\n   pq.pop();\n\n   ans += pq.top();\n\n   pq.pop();\n   pq.push(ans);\n\n   while(pq.size()>1){\n\n      ll count = 0;\n\n      count += pq.top();\n\n      pq.pop();\n\n      count += pq.top();\n\n      ans += count;\n\n      pq.pop();\n\n      pq.push(count);\n\n   }\n\n   return ans;\n\n}\n\n\nint main() {\n    \n    int n;\n    cin>>n;\n\n    vector<int> vi(n);\n\n    for(int i=0;i<n;i++){\n        cin>>vi[i];\n    }\n\n    cout<<findSum(vi);\n\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include<bits/stdc++.h>\nusing namespace std;\n\n#define int long long\n\n\nint32_t main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n     int n ;\n     cin>>n ;\n    int a[n] ;\n    multiset<int> s ;\n    for(int i=0;i<n;i++){\n        cin>>a[i] ;\n        s.insert(a[i]) ;\n    }\n    int score=0 ;\n    while(s.size()!=1){\n        auto it1=s.begin() ;\n        s.erase(it1) ;\n        auto it2=s.begin() ;\n        s.erase(it2) ;\n        int x=*it1 ;\n        int y=*it2 ;\n        s.insert(x+y) ;\n        score+=(x+y) ;\n    }\n    cout<<score<<\"\\n\" ;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    ll n;cin>>n;\n    multiset<ll> s;\n    for(ll i=0;i<n;i++)\n    {\n        int a;cin>>a;\n        s.insert(a);\n    }\n    ll ans=0;\n    while(s.size()>=2)\n    {\n        ll it1=*s.begin();\n        ans+=it1;\n        s.erase(s.begin());\n        ll it2=*s.begin();\n        s.erase(s.begin());\n        ans+=it2;\n        s.insert(it1+it2);\n    }\n    cout<<ans;\n\n\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n/*#define N 401\n\nint dp[N][N];\nbool temp[N][N];\n\nint helper(int i,int j,int *arr){\n    if(i==j){\n        return 0;\n    }\n    if(temp[i][j]){\n        return dp[i][j];\n    }\n    temp[i][j]=1;\n    int &temp2=dp[i][j];\n\n    temp2=INT_MAX;\n    int sum=0;\n    for(int k=i;k<=j;k++){\n        sum+=arr[k];\n    }\n    for(int k=i+1;k<=j;k++){\n        temp2=min(temp2,sum+helper(i,k-1,arr)+helper(k,j,arr));\n    }\n    return temp2;\n}\n*/\nint solve(vector<long long int>&arr){\n    priority_queue<long long int,vector<long long int>,greater<long long int>>pq;\n    for(long long int val:arr){\n        pq.push(val);\n    }\n    long long int ans=0;\n    while(pq.size()>1){\n        long long int a=pq.top();\n        pq.pop();\n        long long int b=pq.top();\n        pq.pop();\n        ans+=a+b;\n        pq.push(a+b);\n    }\n    return ans;\n    \n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    long long int n;\n    cin>>n;\n    //long long int arr[n];\n    vector<long long int>arr(n,0);\n    for(long long int i=0;i<n;i++){\n        long long int x;\n        cin>>x;\n        arr[i]=x;\n    }\n    //int x=sizeof(arr)/sizeof(int);\n    cout<<solve(arr)<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n#include <bits/stdc++.h>\n#define ll long long\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    int n;\n    cin>>n;\n    vector<int> v(n,0);\n    priority_queue<ll,vector<ll>,greater<ll>> pq;\n    for(int i=0;i<n;i++)\n    {\n        cin>>v[i];\n        pq.push(v[i]);\n        \n    }\n    ll ans=0;\n    while(pq.size()>1)\n    {\n        ll a1=pq.top();\n        pq.pop();\n        ll a2=pq.top();\n        pq.pop();\n        ans+=a1+a2;\n        pq.push(a1+a2);\n    }\n    cout<<ans<<endl;\n    //priority_queue<  \n    return 0;\n    \n}","lang":"2"},
{"question_id":41034,"source":"#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    priority_queue<int, vector<int>, greater<int>> pq;\n    int n;\n    cin >> n;\n    \n    for(int i = 0;i < n;i++) {\n        int x;\n        cin >> x;\n        pq.push(x);\n    }\n\n    // cout << pq.size() << endl;\n\n    int cost = 0;\n\n    while(!pq.empty()) {\n        int least1 = pq.top();\n        pq.pop();\n        if(pq.empty()) {\n            cost += least1;\n            break;\n        }\n        int least2 = pq.top();\n        pq.pop();\n        // cout << least1 << \" \" << least2 << endl;\n        int addl = least1 + least2;\n        cost += addl;\n        // cout << cost << endl;\n        if(!pq.empty()) pq.push(addl);\n    }\n\n    cout << cost;\n\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n#define int long long\n\nsigned main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    vector<int>a(n);\n    for(int i=0;i<n;i++)cin>>a[i];\n    priority_queue<int,vector<int>,greater<int>>q;\n    for(int i=0;i<n;i++)q.push(a[i]);\n    int ans=0;\n    while(q.size()>1)\n    {\n        int v1=q.top();\n        q.pop();\n        int v2=q.top();\n        q.pop();\n        ans+=v1+v2;\n        q.push(v1+v2);\n    }\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n#define lli long long int\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n    int n;\n    cin>>n;\n    priority_queue<lli, vector<lli> ,greater<lli>> pq;\n    vector<int> v(n);\n    for(int i=0;i<n;i++){\n        cin>>v[i];\n        pq.push(v[i]);\n    } \n    long long int ans = 0;\n    while(pq.size()>1){\n        long long int a = pq.top();\n        pq.pop();\n        a+=pq.top();\n        pq.pop();\n        ans+=a;\n        pq.push(a);\n    }\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"# Enter your code here. Read input from STDIN. Print output to STDOUT\r\nfrom heapq import heapify, heappush as hp, heappop as pop\r\nn = int(input())\r\nl = list(map(int,input().split()))\r\nheapify(l)\r\nans =0\r\nwhile len(l)>1:\r\n    a = pop(l)+pop(l)\r\n    ans+= a \r\n    hp(l,a)\r\nprint(ans)","lang":"30"},
{"question_id":41034,"source":"#include<iostream>\n#include <cstdio>\n#include <vector>\n#include <algorithm>\n#include<queue>\nusing namespace std;\n// const int mxd = 40;\n// const int ba = 1000;\n// struct bignum{\n//     int a[mxd],n;\n//     bignum(){n=0;};\n//     bignum(int x){\n//         n = 0;\n//         while(x>0){\n//             a[n++] = x%ba;\n//             x/=ba;\n//         }\n//     };\n//     friend bool operator > (const bignum &a,const bignum &b){\n//         if(a.n - b.n!=0)return a.n>b.n;\n//         for(int i = a.n-1;i>=0;--i){\n//             if(a.a[i]!=b.a[i])return a.a[i]>b.a[i];\n//         }\n//         return 0;\n//     }\n//     friend bignum operator * (const bignum &a,const bignum &b){\n//         bignum r;\n//         r.n = a.n + b.n - 1;\n//         for(int i = 0;i<r.n;++i){\n//             r.a[i] = 0;\n//         }\n//         for(int i = 0;i<a.n;++i)\n//             for(int j = 0;j<b.n;++j)\n//                 r.a[i+j] += a.a[i]*b.a[j];\n//         int tmp = 0;\n//         for(int i = 0;i<r.n;i++){\n//             r.a[i]+=tmp,tmp = r.a[i]/ba,r.a[i]%=ba;\n//         }\n//         while(tmp)r.a[r.n++] = tmp%ba,tmp/=ba;\n//         return r;\n//     }\n//     void print(){\n//         if(n == 0)return;\n//         printf(\"%d\",a[n-1]);\n//         for(int i = n-2;i>=0;--i){\n//             printf(\"%03d\",a[i]);\n//             putchar('\\n');\n//         }\n//     }\n// };\n// vector<int> E[707];\n// int sz[707];\n// bignum dp[707][707];\n// bignum tmp[707];\n// bignum w;\n// void solve(int x,int dad){\n//     sz[x] = 1;\n//     for(int i = 0;i<E[x].size();i++){\n//         int y = E[x][i];\n//         if(y-dad == 0)continue;\n//         solve(y,x);\n//         sz[x] += sz[y];\n//     }\n//     dp[x][0] = dp[x][1] = 1;\n//     int s = 1;\n//     for(int i = 0;i<E[x].size();i++){\n//         int y = E[x][i];\n//         if(y-dad == 0)continue;\n//         else{\n//             for(int j = 0;j<=s+sz[y];j++)tmp[j] = 0;\n//             for(int j = 0;j<=s;j++)\n//             for(int k = 0;k<=sz[y];k++){\n//                 w = dp[x][j]*dp[y][k];\n//                 if(w>tmp[j+k])tmp[j+k] = w;\n//             }\n//             for(int j = 0;j<=s+sz[y];j++){\n//                 dp[x][j]=tmp[j];\n//             }\n//             s+=sz[y];\n//         }\n//     }\n//     for(int j = 0;j<=s;j++){\n//         w = dp[x][j]*j;\n//         if(w>dp[x][0])dp[x][0]=w;\n//     }\n// }\nint main() {\n    \n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    scanf(\"%d\",&n);\n    int A[n];\n    long long ans = 0;\n    priority_queue <int,vector<int> ,greater<int>> pq;\n    for(int i = 0;i<n;i++){\n        cin>>A[i];\n        pq.push(A[i]);\n    }\n    long long sum = 0;\n    for(int i =0;i<n-1;i++){\n        int t = pq.top();\n        pq.pop();\n        int s = pq.top();\n        pq.pop();\n        sum = t+s;\n        ans += sum;\n        pq.push(sum);\n    }\n    cout<<ans;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n#define int long long\n\nsigned main() {\n   int n;\n   cin>>n;\n   priority_queue<int,vector<int>,greater<int>>pq;\n   while(n--){\n       int x;\n       cin>>x;\n       pq.push(x);\n   }\n    int ans = 0;\n   while(pq.size() > 1){\n       int x = pq.top();\n       pq.pop();\n       int y = pq.top();\n       pq.pop();\n       ans+=(x+y);\n       pq.push(x+y);\n   }\n   cout<<ans;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\nclass Solution {\n\n    public static void main(String[] args) {\n        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */\n        Scanner scn = new Scanner(System.in);\n        int N = scn.nextInt();\n        long[] arr = new long[N];\n        PriorityQueue<Long> p = new PriorityQueue<>();\n        for(int i = 0; i < N; i++) {\n            arr[i] = scn.nextLong();\n            p.add(arr[i]);\n        }\n        long ans = 0L;\n        while(p.size() > 1) {\n            long x = p.remove();\n            long y = p.remove();\n            ans += x + y;\n            p.add(x + y);\n        }\n        System.out.println(ans);\n        // Arrays.sort(arr);\n        // long cost = 0L;\n        // if(N == 1) {\n        //     System.out.println(0);\n        //     return;\n        // }\n        // cost += arr[0] + arr[1];\n        // long tcost = cost;\n        // for(int i = 2; i < N; i++) {\n        //     cost += arr[i];\n        //     tcost += cost;\n        // }\n        // System.out.println(tcost);\n\n    }\n}","lang":"43"},
{"question_id":41034,"source":"#include<bits/stdc++.h>\nusing namespace std;\n\nint func(vector<int>& a,int n){\n    priority_queue<int,vector<int>,greater<int> >pq;\n    for(int i=0;i<(int)a.size();i++) pq.push(a[i]);\n    int ans = 0;\n    while(pq.size()>1){\n        int cur = pq.top();\n        pq.pop();\n        int cur2 = pq.top();\n        pq.pop();\n\n        ans += cur + cur2;\n        pq.push(cur + cur2);\n    }\n\n    return ans;\n}\n\nint main() {\n\n    int n;\n    cin>>n;\n    vector<int>a(n);\n    for(int i=0;i<n;i++) cin>>a[i];\n\n    cout<<func(a,n);\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <stdio.h>\n#include <string.h>\n#include <math.h>\n#include <stdlib.h>\n#include<bits/stdc++.h>\nusing namespace std;\n\nint main() {\n\n    int n;\n    cin>>n;\n    int a[n];\n    priority_queue<int, vector<int>, greater<int>> pq;  \n    for(int i = 0;i<n;i++)\n    {\n        cin>>a[i];\n        pq.push(a[i]);\n    } \n    long long sum = 0;\n    for(int i = 0;i<n-1;i++)\n    {\n        int a = pq.top();\n        pq.pop();\n        int b = pq.top();\n        pq.pop();\n        sum = sum + a + b;\n        pq.push(a+b);\n    }\n    cout<<sum<<endl;\n    return 0;\n}","lang":"1"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    long long n;\n    cin>>n;\n    vector<long long> v(n);\n    priority_queue<long long, vector<long long>, greater<long long>> q;\n\n    for(int i=0;i<n;i++)\n    {\n        cin>>v[i];\n        q.push(v[i]);\n    }\n    long long ans=0;\n    long long a, b;\n    while(q.size()!=1)\n    {\n        a=q.top();\n        q.pop();\n        b=q.top();\n        q.pop();\n        ans+=a+b;\n        q.push(a+b);\n    }\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <bits/stdc++.h>\nusing namespace std;\n \nint minCost(vector<long long int> vec)\n{           \nlong  long   int n=vec.size();\npriority_queue<long long int,vector<long long int>,greater<long long int>> pq; for(int i=0; i<n; ++i) pq.push(vec[i]);\nint cost=0; while(!pq.empty()) {\nint x=pq.top(); pq.pop(); if(!pq.empty()) {\nint y=pq.top(); pq.pop(); cost+=(x+y); pq.push(x+y);\n}\n}\nreturn cost;\n}\n \nint main()\n{\n long long int n;\ncin>>n;\nvector<long long int> vec(n);\nfor(int i=0;i<n;i++)\n{\ncin>> vec[i];\n}\ncout<<minCost(vec)<<endl;\nreturn 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <bits/stdc++.h>\n#include <algorithm>\n#define int long long int\nusing namespace std;\n\n\nsigned main() {\n    priority_queue<int,vector<int>, greater<int>>q;\n    int n;\n    cin>>n;\n    int tmp=n;\n    if(n==0){\n        cout<<0<<endl;\n        return 0;\n    }\n    while(n--){\n        int k;\n        cin>>k;\n        q.push(k);\n    }\n    int ans=0;\n    if(tmp==1){\n        ans=q.top();\n    }else{\n    while(!q.empty()){\n        int a=q.top();\n        q.pop();\n        int b=q.top();\n        q.pop();\n        int c=a+b;\n        ans+=c;\n        if(q.empty())  break;\n        q.push(c);\n    }\n    }\n    cout<<ans<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":41034,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n#define int long long\n\nsigned main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    vector<int>a(n);\n    for(int i=0;i<n;i++)cin>>a[i];\n    priority_queue<int>q;\n    for(int i=0;i<n;i++)q.push(0-a[i]);\n    int ans=0;\n    while(q.size()>1)\n    {\n        int v1=q.top();\n        q.pop();\n        int v2=q.top();\n        q.pop();\n        ans-=v1+v2;\n        q.push(v1+v2);\n    }\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n \n#define endl \"\\n\"\n \nusing namespace std;\n \nint getMaxLength(vector<int> &A, int N){\n   \n\tvector<long long> prefSums(N+2);\n \n\tfor( int i = 1; i <= N; i++ ) prefSums[i] = prefSums[i-1] + A[i];\n \n\tvector<int> dpMaxLength(N+2, 0), optimalPartition(N+2, 0);\n   \n\tfor( int i = 1; i <= N; i++ ){\n    \toptimalPartition[i] = max(optimalPartition[i-1], optimalPartition[i] );\n    \tdpMaxLength[i] = 1 + dpMaxLength[optimalPartition[i]];\n \n    \tlong long nextSum = (prefSums[i] - prefSums[optimalPartition[i]]) + prefSums[i];\n    \tint nextIdx = lower_bound(prefSums.begin() + 1, prefSums.begin() + N + 1, nextSum) - prefSums.begin();\n    \tif( nextIdx <= N ) optimalPartition[nextIdx] = max(i, optimalPartition[nextIdx]);\n\t}\n \n\treturn dpMaxLength[N];\n}\n \nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tint N; cin >> N;   \n\tvector<int> v(N+2);\n\tfor( int i = 1; i <= N; i++ ) cin >> v[i];\n \n\tcout << getMaxLength(v, N) << endl;\n   \n\treturn 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\nint solve(vector<int> a, int n){\n    int ans = 1;\n    for(int i=0; i < (n - ans); i++){\n        int j = i+1, cnt = 1;\n        long long prev = a[i], curr = 0; \n        while(j < n){\n            curr += a[j];\n            if(curr >= prev){\n                prev = curr;\n                curr = 0;\n                cnt++;\n            }\n            j++;\n        }\n        if(curr >= prev)\n            cnt++;\n        ans = max(ans, cnt);\n    }\n    return ans;\n}\n\nint main() {\n    int n;\n    cin >> n;\n\n    vector<int> a(n);\n    for(int i=0; i<n; i++)\n        cin >> a[i];\n\n    cout << solve(a, n) << endl;\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\n\n\nint main() {\n    ll n;\n    cin>>n;\n    vector<ll>arr(n);\n    for(int i=0;i<n;i++) cin>>arr[i];\n    ll ans=1;\n    ll prev=arr[0];\n    ll curr=0;\n    stack<ll>st;\n    st.push(arr[0]);\n    for(int i=1;i<n;i++)\n    {\n        curr+=arr[i];\n        if(!st.empty() && curr>=st.top())\n        {\n            st.push(curr);\n            curr=0;\n        }\n        else if(st.empty()) st.push(curr);\n        else{\n\n        }\n\n    }\n    cout<<st.size()<<\"\\n\";\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n \n#define endl \"\\n\"\n \nusing namespace std;\n \nint getMaxLength(vector<int> &A, int N){\n   \n\tvector<long long> prefSums(N+2);\n \n\tfor( int i = 1; i <= N; i++ ) prefSums[i] = prefSums[i-1] + A[i];\n \n\tvector<int> dpMaxLength(N+2, 0), optimalPartition(N+2, 0);\n   \n\tfor( int i = 1; i <= N; i++ ){\n    \toptimalPartition[i] = max(optimalPartition[i-1], optimalPartition[i] );\n    \tdpMaxLength[i] = 1 + dpMaxLength[optimalPartition[i]];\n \n    \tlong long nextSum = (prefSums[i] - prefSums[optimalPartition[i]]) + prefSums[i];\n    \tint nextIdx = lower_bound(prefSums.begin() + 1, prefSums.begin() + N + 1, nextSum) - prefSums.begin();\n    \tif( nextIdx <= N ) optimalPartition[nextIdx] = max(i, optimalPartition[nextIdx]);\n\t}\n \n\treturn dpMaxLength[N];\n}\n \nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tint N; cin >> N;   \n\tvector<int> v(N+2);\n\tfor( int i = 1; i <= N; i++ ) cin >> v[i];\n \n\tcout << getMaxLength(v, N) << endl;\n   \n\treturn 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n#define int long long\n\nint32_t main() {\n    int n; cin >> n;\n    vector<int>a(n);\n    for(int i=0; i<n; i++) cin >> a[i];\n\n    int ans=1;\n    int i=1;\n    int last=a[0];\n    while(i<n){\n        if(a[i]>=last){\n            i++;\n\n            ans++;\n        }\n        else{\n            int sum=0;\n            while(i<n && sum<last){\n                sum+=a[i];\n                i++;\n            }\n            if(sum<last){\n                break;\n            }\n            last=sum;\n            ans++;\n        }\n    }\n    cout<<ans<<endl;\n\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n \n#define endl \"\\n\"\n \nusing namespace std;\n \nint getMaxLength(vector<int> &A, int N){\n   \n\tvector<long long> prefSums(N+2);\n \n\tfor( int i = 1; i <= N; i++ ) prefSums[i] = prefSums[i-1] + A[i];\n \n\tvector<int> dpMaxLength(N+2, 0), optimalPartition(N+2, 0);\n   \n\tfor( int i = 1; i <= N; i++ ){\n    \toptimalPartition[i] = max(optimalPartition[i-1], optimalPartition[i] );\n    \tdpMaxLength[i] = 1 + dpMaxLength[optimalPartition[i]];\n \n    \tlong long nextSum = (prefSums[i] - prefSums[optimalPartition[i]]) + prefSums[i];\n    \tint nextIdx = lower_bound(prefSums.begin() + 1, prefSums.begin() + N + 1, nextSum) - prefSums.begin();\n    \tif( nextIdx <= N ) optimalPartition[nextIdx] = max(i, optimalPartition[nextIdx]);\n\t}\n \n\treturn dpMaxLength[N];\n}\n \nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tint N; cin >> N;   \n\tvector<int> v(N+2);\n\tfor( int i = 1; i <= N; i++ ) cin >> v[i];\n \n\tcout << getMaxLength(v, N) << endl;\n   \n\treturn 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n \n#define endl \"\\n\"\n \nusing namespace std;\n \nint getMaxLength(vector<int> &A, int N){\n   \n\tvector<long long> prefSums(N+2);\n \n\tfor( int i = 1; i <= N; i++ ) prefSums[i] = prefSums[i-1] + A[i];\n \n\tvector<int> dpMaxLength(N+2, 0), optimalPartition(N+2, 0);\n   \n\tfor( int i = 1; i <= N; i++ ){\n    \toptimalPartition[i] = max(optimalPartition[i-1], optimalPartition[i] );\n    \tdpMaxLength[i] = 1 + dpMaxLength[optimalPartition[i]];\n \n    \tlong long nextSum = (prefSums[i] - prefSums[optimalPartition[i]]) + prefSums[i];\n    \tint nextIdx = lower_bound(prefSums.begin() + 1, prefSums.begin() + N + 1, nextSum) - prefSums.begin();\n    \tif( nextIdx <= N ) optimalPartition[nextIdx] = max(i, optimalPartition[nextIdx]);\n\t}\n \n\treturn dpMaxLength[N];\n}\n \nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tint N; cin >> N;   \n\tvector<int> v(N+2);\n\tfor( int i = 1; i <= N; i++ ) cin >> v[i];\n \n\tcout << getMaxLength(v, N) << endl;\n   \n\treturn 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n \n#define endl \"\\n\"\n \nusing namespace std;\n \nint getMaxLength(vector<int> &A, int N){\n   \n\tvector<long long> prefSums(N+2);\n \n\tfor( int i = 1; i <= N; i++ ) prefSums[i] = prefSums[i-1] + A[i];\n \n\tvector<int> dpMaxLength(N+2, 0), optimalPartition(N+2, 0);\n   \n\tfor( int i = 1; i <= N; i++ ){\n    \toptimalPartition[i] = max(optimalPartition[i-1], optimalPartition[i] );\n    \tdpMaxLength[i] = 1 + dpMaxLength[optimalPartition[i]];\n \n    \tlong long nextSum = (prefSums[i] - prefSums[optimalPartition[i]]) + prefSums[i];\n    \tint nextIdx = lower_bound(prefSums.begin() + 1, prefSums.begin() + N + 1, nextSum) - prefSums.begin();\n    \tif( nextIdx <= N ) optimalPartition[nextIdx] = max(i, optimalPartition[nextIdx]);\n\t}\n \n\treturn dpMaxLength[N];\n}\n \nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tint N; cin >> N;   \n\tvector<int> v(N+2);\n\tfor( int i = 1; i <= N; i++ ) cin >> v[i];\n \n\tcout << getMaxLength(v, N) << endl;\n   \n\treturn 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n \n#define endl \"\\n\"\n \nusing namespace std;\n \nint getMaxLength(vector<int> &A, int N){\n   \n\tvector<long long> prefSums(N+2);\n \n\tfor( int i = 1; i <= N; i++ ) prefSums[i] = prefSums[i-1] + A[i];\n \n\tvector<int> dpMaxLength(N+2, 0), optimalPartition(N+2, 0);\n   \n\tfor( int i = 1; i <= N; i++ ){\n    \toptimalPartition[i] = max(optimalPartition[i-1], optimalPartition[i] );\n    \tdpMaxLength[i] = 1 + dpMaxLength[optimalPartition[i]];\n \n    \tlong long nextSum = (prefSums[i] - prefSums[optimalPartition[i]]) + prefSums[i];\n    \tint nextIdx = lower_bound(prefSums.begin() + 1, prefSums.begin() + N + 1, nextSum) - prefSums.begin();\n    \tif( nextIdx <= N ) optimalPartition[nextIdx] = max(i, optimalPartition[nextIdx]);\n\t}\n \n\treturn dpMaxLength[N];\n}\n \nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tint N; cin >> N;   \n\tvector<int> v(N+2);\n\tfor( int i = 1; i <= N; i++ ) cin >> v[i];\n \n\tcout << getMaxLength(v, N) << endl;\n   \n\treturn 0;\n}","lang":"2"},
{"question_id":41000,"source":"# Enter your code here. Read input from STDIN. Print output to STDOUT\r\nn=int(input())\r\narr = list(map(int,input().split()))\r\n\r\nsu=0\r\ntemp=list(arr)\r\nj=n-1\r\nfor i in range(n-1,0,-1):\r\n    # print(i)\r\n    # print(\"n\",len(arr))\r\n    if arr[i]<=arr[i-1]:\r\n        temp.pop(j)\r\n        temp.pop(j-1)\r\n        # print(arr[i],arr[i-1])\r\n        temp.insert(j-1,arr[i]+arr[i-1])\r\n        j-=1\r\n        arr[i-1]=arr[i]+arr[i-1]\r\n    else:\r\n        j-=1\r\n    # print(temp)\r\nprint(len(temp))","lang":"30"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n \n#define endl \"\\n\"\n \nusing namespace std;\n \nint getMaxLength(vector<int> &A, int N){\n   \n\tvector<long long> prefSums(N+2);\n \n\tfor( int i = 1; i <= N; i++ ) prefSums[i] = prefSums[i-1] + A[i];\n \n\tvector<int> dpMaxLength(N+2, 0), optimalPartition(N+2, 0);\n   \n\tfor( int i = 1; i <= N; i++ ){\n    \toptimalPartition[i] = max(optimalPartition[i-1], optimalPartition[i] );\n    \tdpMaxLength[i] = 1 + dpMaxLength[optimalPartition[i]];\n \n    \tlong long nextSum = (prefSums[i] - prefSums[optimalPartition[i]]) + prefSums[i];\n    \tint nextIdx = lower_bound(prefSums.begin() + 1, prefSums.begin() + N + 1, nextSum) - prefSums.begin();\n    \tif( nextIdx <= N ) optimalPartition[nextIdx] = max(i, optimalPartition[nextIdx]);\n\t}\n \n\treturn dpMaxLength[N];\n}\n \nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tint N; cin >> N;   \n\tvector<int> v(N+2);\n\tfor( int i = 1; i <= N; i++ ) cin >> v[i];\n \n\tcout << getMaxLength(v, N) << endl;\n   \n\treturn 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    int n;\n    cin >> n;\n    vector<int> v;\n    for(int i = 0; i < n; i++){\n        int temp;\n        cin >> temp;\n\n        v.push_back(temp);\n    }\n\n    // 5 1 6 3 10\n    // 4 5 2\n\n    int i = 1;\n    while(i < v.size()){\n        if(v[i] < v[i-1]){\n            // if(i == 2) cout << \"yes\";\n            if(i+1 == v.size()){\n                v[i-1] += v[i];\n                v.erase(v.begin() + i);\n            } else if(i+1 < v.size() && v[i]+v[i-1] <= v[i+1]){\n                v[i-1] += v[i];\n                v.erase(v.begin() + i);\n            } else {\n                v[i] += v[i+1];\n                v.erase(v.begin() + i+1);\n                i--;\n            }\n        }\n\n        // cout << i << \"i\";\n        // for(int i = 0; i < v.size(); i++){\n        //     cout << v[i] << \" \";\n        // }\n        // cout << \"\\n\";\n\n        i++;\n    }\n\n    cout << v.size();\n    \n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    int n;\n    cin>>n;\n    vector<int> a(n);\n    for(int i=0;i<n;i++){\n        cin>>a[i];\n    }\n    long long curr_sum=0,prev_sum=0,cnt=0;\n    for(int i=0;i<n;i++){\n        curr_sum+=a[i];\n        if(curr_sum>=prev_sum){\n            prev_sum=curr_sum;\n            curr_sum=0;\n        }else{\n            cnt++;\n        }\n        \n    }\n    cout<<n-cnt<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    ll n,cnt=0,sum=0,num=1,ind=0;\n    cin >> n;\n    vector<int> a(n);\n    for(int i=0;i<n;i++){\n        cin >> a[i];\n    }\n    while(ind<n){\n        while(ind<n && sum<num){\n            sum+=a[ind];\n            ind++;\n        }\n        if(sum>=num){\n            cnt++;\n            num=sum;\n            sum=0;\n        }\n    }\n    cout << cnt;\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n \n#define endl \"\\n\"\n \nusing namespace std;\n \nint getMaxLength(vector<int> &A, int N){\n   \n\tvector<long long> prefSums(N+2);\n \n\tfor( int i = 1; i <= N; i++ ) prefSums[i] = prefSums[i-1] + A[i];\n \n\tvector<int> dpMaxLength(N+2, 0), optimalPartition(N+2, 0);\n   \n\tfor( int i = 1; i <= N; i++ ){\n    \toptimalPartition[i] = max(optimalPartition[i-1], optimalPartition[i] );\n    \tdpMaxLength[i] = 1 + dpMaxLength[optimalPartition[i]];\n \n    \tlong long nextSum = (prefSums[i] - prefSums[optimalPartition[i]]) + prefSums[i];\n    \tint nextIdx = lower_bound(prefSums.begin() + 1, prefSums.begin() + N + 1, nextSum) - prefSums.begin();\n    \tif( nextIdx <= N ) optimalPartition[nextIdx] = max(i, optimalPartition[nextIdx]);\n\t}\n \n\treturn dpMaxLength[N];\n}\n \nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tint N; cin >> N;   \n\tvector<int> v(N+2);\n\tfor( int i = 1; i <= N; i++ ) cin >> v[i];\n \n\tcout << getMaxLength(v, N) << endl;\n   \n\treturn 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    int n ; \n    cin>>n ;\nint arr[n] ;\n    for(int i=0 ; i < n ; i++)\n    {\n        cin>>arr[i] ;\n    }\n\n    int ans= 0;\n    int temp = arr[0] ;\n    int val =0 ;\n\n    int i=0 ; \n    while(i < n)\n    {\n        val += arr[i] ;\n        i++;\n        if(val < temp )continue;\n\n        else\n        {\n            temp = val ;\n            val = 0; \n            ans ++ ;\n        }\n        \n    }\n    cout<<ans ;\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n \n#define endl \"\\n\"\n \nusing namespace std;\n \nint getMaxLength(vector<int> &A, int N){\n   \n\tvector<long long> prefSums(N+2);\n \n\tfor( int i = 1; i <= N; i++ ) prefSums[i] = prefSums[i-1] + A[i];\n \n\tvector<int> dpMaxLength(N+2, 0), optimalPartition(N+2, 0);\n   \n\tfor( int i = 1; i <= N; i++ ){\n    \toptimalPartition[i] = max(optimalPartition[i-1], optimalPartition[i] );\n    \tdpMaxLength[i] = 1 + dpMaxLength[optimalPartition[i]];\n \n    \tlong long nextSum = (prefSums[i] - prefSums[optimalPartition[i]]) + prefSums[i];\n    \tint nextIdx = lower_bound(prefSums.begin() + 1, prefSums.begin() + N + 1, nextSum) - prefSums.begin();\n    \tif( nextIdx <= N ) optimalPartition[nextIdx] = max(i, optimalPartition[nextIdx]);\n\t}\n \n\treturn dpMaxLength[N];\n}\n \nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tint N; cin >> N;   \n\tvector<int> v(N+2);\n\tfor( int i = 1; i <= N; i++ ) cin >> v[i];\n \n\tcout << getMaxLength(v, N) << endl;\n   \n\treturn 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\nint check(vector<int>arr,int mid)\n{\n    int sum = 0;\n    int sz = 0;\n    for(int i=0;i<arr.size();i++)\n    {\n        sum+=arr[i];\n        if(sum>=mid)\n        {\n            mid = sum;\n            sum = 0;\n            sz++;\n        }\n    }\n    return sz;\n}\nint main() {\n\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    vector<int>arr(n);\n    int sum = 0;\n    for(int i=0;i<n;i++)\n    {\n        cin>>arr[i];\n        sum+=arr[i];\n    }\n    int l=1;\n    int r = sum;\n    int ans = 1;\n    while(l<r)\n    {\n        int mid = (l+r)/2;\n        if(check(arr,mid))\n        {\n            int z = check(arr,mid);\n            ans = max(ans,z);\n            r = mid;\n        }\n        else\n        {\n            l = mid+1;\n        }\n    }\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n \n#define endl \"\\n\"\n \nusing namespace std;\n \nint getMaxLength(vector<int> &A, int N){\n   \n\tvector<long long> prefSums(N+2);\n \n\tfor( int i = 1; i <= N; i++ ) prefSums[i] = prefSums[i-1] + A[i];\n \n\tvector<int> dpMaxLength(N+2, 0), optimalPartition(N+2, 0);\n   \n\tfor( int i = 1; i <= N; i++ ){\n    \toptimalPartition[i] = max(optimalPartition[i-1], optimalPartition[i] );\n    \tdpMaxLength[i] = 1 + dpMaxLength[optimalPartition[i]];\n \n    \tlong long nextSum = (prefSums[i] - prefSums[optimalPartition[i]]) + prefSums[i];\n    \tint nextIdx = lower_bound(prefSums.begin() + 1, prefSums.begin() + N + 1, nextSum) - prefSums.begin();\n    \tif( nextIdx <= N ) optimalPartition[nextIdx] = max(i, optimalPartition[nextIdx]);\n\t}\n \n\treturn dpMaxLength[N];\n}\n \nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tint N; cin >> N;   \n\tvector<int> v(N+2);\n\tfor( int i = 1; i <= N; i++ ) cin >> v[i];\n \n\tcout << getMaxLength(v, N) << endl;\n   \n\treturn 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\n#define int long long\nusing namespace std;\n\n\nint32_t main() {\n    int n;\n    cin >> n;\n    int a[n];\n    vector <int> v;\n    for(int i=0;i<n;i++) cin >> a[i];\n    v.push_back(a[0]);\n    int it = 1;\n    while(it < n){\n        int sum = 0;\n        while(it < n && sum < v.back()){\n            sum += a[it];\n            it++;\n        }\n        if(sum >= v.back() ) v.push_back(sum);\n    }\n    cout << v.size()<< endl;\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <iostream> \n\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n; \n    cin>>n; \n    int arr[n]; \n    for(int i = 0; i<n; i++){\n        cin>>arr[i]; \n    }\n    int pr = arr[0]; \n    int ans = 1; \n    int sum = 0; \n    for(int i = 1; i<n; i++){\n        sum += arr[i]; \n        if(sum >= pr){\n            ans++; \n            pr = sum; \n            sum = 0; \n        }\n    }\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\ntypedef long long int ll;\nusing namespace std;\n\nint main() {\n    ios_base::sync_with_stdio(false);\n    cin.tie(NULL);\n    ll n;\n    cin >> n;\n    ll a[n];\n    for (ll i=0; i<n; i++) {\n        cin >> a[i];\n    }\n    ll prev=-1;\n    ll i=0, ans=0;\n    while(i<n) {\n        ll sum=a[i];\n        i++;\n        while(i<n && sum<prev){\n            sum+=a[i];\n            i++;\n        }\n        if(sum>=prev){\n            ans++;\n        }\n        prev=sum;\n        sum=0;\n    }\n    cout << ans;\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */    \n    return 0;\n}","lang":"1"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n#define ll long long int\nstruct st\n{\n    int n;vector<ll> t;\n    st(int n=0): n(n), t(4*n,1e18){}\n    inline void upd (int v,int tl,int tr,int pos,ll x)\n    {\n        if(tl==tr) {\n            t[v]=x;return;\n        }\n        int tm=(tl+tr)>>1;\n        if(pos<=tm) upd(v<<1,tl,tm,pos,x);\n        else upd(v<<1 | 1,tm+1,tr,pos,x);\n        t[v]=min(t[v<<1],t[v<<1 | 1 ]);\n    }\n    inline int get(int v,int tl,int tr,ll x)\n    {\n        if(tl==tr) return tl;\n        int tm=(tl+tr)>>1;\n        if(t[v<<1 | 1]<=x) return get(v<<1 | 1,tm+1,tr,x);\n        else return get(v<<1,tl,tm,x);\n    }\n    inline void upd (int pos,ll x){upd(1,0,n-1,pos,x);}\n    inline int get(ll x){return get(1,0,n-1,x);}\n};\nint main() {\n    int n;cin>>n;\n    st s(n+1); s.upd(0,0);\n    ll sum=0;\n    vector<int> dp(n+1); dp[0]=0;\n    vector<ll> pref(n+1);\n    for(int i=1;i<=n;++i)\n    {\n        int x;cin>>x;sum+=x;\n        int p=s.get(sum);\n        dp[i]=dp[p]+1;pref[i]=sum;\n        s.upd(i,sum*2-pref[p]);\n    }\n    cout<<dp[n];\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    int n;cin>>n;\n    vector<int>v(n);\n    for(int i=0;i<n;i++)\n    cin>>v[i];\n    int sum=0;\n    int curr=v[0];\n    int ans=1;\n    for(int i=1;i<n;i++)\n    {\n        sum+=v[i];\n        if(sum>=curr)\n        {\n            ans++;\n            curr=sum;\n            sum=0;\n        }\n    }\n    cout<<ans<<endl;\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\nint func(vector<int> v){\n    vector<int>ans;\n    int sum=0, prev=0;\n\n    for(int i=0; i<v.size(); i++){\n        sum+=v[i];\n        if(sum>=prev){\n            ans.push_back(sum);\n            prev=sum;\n            sum=0;\n        }\n    }\n    return ans.size();\n}\nint main() {\n    int n; cin>>n;\n    vector<int> a;\n    for(int i=0; i<n; i++){\n        int x; cin>>x;\n        a.push_back(x);\n    }\n    cout<<func(a);\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\ntypedef long long int ll;\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    int n;\n    cin>>n;\n    vector<int> a(n);\n    for(int i=0;i<n;i++) cin>>a[i];\n\n    ll prev=a[0];\n    ll prevsum=0;\n\n    ll len=0;\n\n    for(int i=1;i<n;){\n\n        if(a[i]+prevsum>=prev){\n            prev=a[i]+prevsum;\n            i++;\n            prevsum=0;\n        }\n        else{\n            len++;\n            prevsum+=a[i];\n            i++;\n        }\n    }\n\n    cout<<n-len<<\"\\n\";\n\n\n\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    vector<int>v(n);\n    for(int i=0;i<n;i++)\n    cin>>v[i];\n    vector<int>pref(n+1);\n    pref[0]=v[0];\n    for(int i=1;i<n;i++)\n    pref[i]=pref[i-1]+v[i];\n    int len=1;\n    for(int i=1;i<n;i++){\n        if(v[i]<v[i-1]){\n            int req=pref[i-1]+v[i-1];\n            int pos=lower_bound(pref.begin(),pref.end(),req)-pref.begin();\n            // cout << pos <<\" \" <<len << endl;\n            if(pos>=n){\n                cout << len << endl;\n               return 0;\n            }\n            else{\n                len+=1;\n                v[pos]=pref[pos]-pref[i-1];\n                i=pos;\n            }\n            \n        }else{\n            len++;\n        }\n        // cout << i << endl;\n    }\n    cout << len << endl;\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\n\nint main() {\n    int n;cin>>n;\n    int v[n];\n    for(int i=0;i<n;i++)cin>>v[i];\n    int prev = v[0];\n    int ans = n;\n    for(int i=1;i<n-1;i++){\n        if(v[i]<prev){\n        ans--;\n        v[i+1]+=v[i];\n        }else{\n            prev=v[i];\n        }\n    }\n    if(v[n-1]<prev)ans--;\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include<bits/stdc++.h>\nusing namespace std;\n#define int long long\nint32_t main(){\n    int n;\n    cin>>n;\n    vector<int>v(n);\n    for(int i=0;i<n;i++){\n        cin>>v[i];\n    }\n    vector<int>ans;\n    ans.push_back(v[0]);\n    int pnt=1;\n    int var=0;\n    for(int i=1;i<n;i++){\n        // var+=v[pnt++];\n        if(ans.back()<=v[i]){\n            ans.push_back(v[i]);\n        }\n        else{\n            auto it=lower_bound(ans.begin(),ans.end(),v[i]);\n            int pos=it-ans.begin();\n            ans[pos]=v[i];\n        }\n    }\n    cout<<ans.size()<<endl;\n    // for(auto i:ans){\n    //     cout<<i<<\" \";\n    // }\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include<bits/stdc++.h>\n#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    int n;\n    cin>>n;\n    vector<int> a(n);\n    for(int i=0;i<n;i++){\n        cin>>a[i];\n    }\n    int cnt=0;\n    for(int i=0;i<n-1;i++){\n        if(a[i]>a[i+1]){\n           if(i<n-2 && a[i]>a[i+2]){\n               a[i+2]+=a[i+1];\n           }\n           else{\n               a[i+1]+=a[i];\n           }\n           cnt++;\n        }\n    }\n    cout<<cnt<<endl;\n      \n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\nvoid solve(){\n    int n; cin>>n;\n    vector<int>v(n);\n    for(int i=0; i<n; i++){\n        cin>>v[i];\n    }\n    int prev=v[0];\n    int curr=0;\n    vector<int>ans;\n    ans.push_back(v[0]);\n    for(int i=1; i<n; i++){\n        if(curr+v[i]>=prev){\n            ans.push_back(v[i]+curr);\n            prev=v[i]+curr;\n            curr=0;\n        }else{\n            curr+=v[i];\n        }\n    }\n    cout<<ans.size()<<endl;\n}\n\nint main() {\n    solve();\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    int n;\n    cin >> n;\n    vector<int> arr(n); \n    for(int i = 0; i < n; i++) cin >> arr[i];\n    vector<long long> ans;\n    ans.push_back(arr[0]);\n    int i = 1;\n    long long sum = 0;\n    // long long temp = 0;\n    while(i < n)\n    {\n        while(i < n && sum < ans.back()) \n            sum += arr[i++];\n        \n        if(ans.back() <= sum)ans.push_back(sum);\n        sum = 0;\n    }\n    \n    // if(temp < ans.back()) cout << ans.size() - 1;\n    // else {\n        cout << ans.size() << \" \";\n    // }\n\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define ll long long;\n\n\nint getMaxSum(int a[],int n){\n    int count = 0;\n    for(int i=0;i<n;i++){\n        int k=i+2;\n        while(a[i]>a[i+1]){\n            a[i+1]+=a[k];\n            k++;\n            count++;\n            for(int j=k-1;j<n;j++){\n                a[j]=a[j+1];\n            }\n            n--;\n          \n        }\n    }\n    return n;\n}\n\n\n\nint32_t main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    // int n;\n    // cin>>n;    \n    // int a[n];\n\n    // for(int i=0;i<n;i++){\n    //     cin>>a[i];\n    // }\n    // // int n=7;\n    // // int a[] = {5,1,6,3,4,2,8};\n    // cout<<n<<\"\\n\";\n    // cout<<a[n]<<\"\\n\";\n\n    int n,a[10];\n    scanf(\"%d\",&n);\n    for(int i=0;i<n;i++){\n        scanf(\"%d\",&a[i]);\n    }\n\n\n    cout<<getMaxSum(a,n)<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n\n    cin>>n;\n    int arr[n];\n    for(int i=0;i<n;i++)\n    cin>>arr[i];\n    int cur = arr[0];\n    int ans = 1;\n    int temp = 0;\n    for(int i=1;i<n;i++)\n    {\n        temp += arr[i];\n        if(temp>=cur)\n        {\n            cur = temp;\n            ans++;\n            temp = 0;\n        }\n        \n    }\n    cout<<ans<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n#define big long long\n\nint main() {\n    big n;\n    cin >> n;\n\n    big prev = 0, cur = 0, ans = 0;\n    for(int i = 0; i < n; i++){\n        big x;\n        cin >> x;\n        cur += x;\n\n        if(cur >= prev){\n            prev = cur;\n            cur = 0;\n            ans++;\n        }\n    }\n    \n    cout << ans << endl;\n}","lang":"2"},
{"question_id":41000,"source":"#include<bits/stdc++.h>\nusing namespace std;\n\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n    long long int n;\n    cin>>n;\n\n    vector<long long int> elt, ans;\n\n    for(int i=0; i<n; i++) {\n        long long int x;\n        cin>>x;\n\n        elt.push_back(x);\n    } \n\n    long long int curr = elt[0], sum,index;\n\n    //helper(n, elt);\n    ans.push_back(curr);\n    for(int i=1; i<n; i++) {\n        index = i;\n        sum = 0;\n\n        while(sum < curr && index<n ) {\n            sum+= elt[index];\n            index ++;\n        }\n        if(index == n && sum < curr) {\n            break;\n        }\n        ans.push_back(sum);\n        i = index -1;\n    }\n\n    cout<<ans.size();\n\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n#define ll long long\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    ll n;cin>>n;\n    vector<ll> a(n);\n    for(ll i=0;i<n;i++) cin>>a[i];\n\n    ll curr=0, sum = 0, ans = 0;\n    for(ll i=0;i<n;i++)\n    {\n        if(sum+a[i] >= curr)\n        {\n            ans++;\n            curr = sum + a[i];\n            sum = 0;\n        }\n        else\n        {\n            sum += a[i];\n        }\n    }\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n#include <bits/stdc++.h>\n\n#define ill long long\n\nmap <pair <ill,ill> ,ill> mp;\n\nill solve(ill i,ill sum,ill arr[],ill num) {\n    if (i >= num) {\n        return 0;\n    }\n\n    if (mp.find({i,sum}) != mp.end()) {\n        return mp[{i,sum}];\n    }\n\n    ill s=0;\n    ill ans = 0 ;\n    for(int j = i ; j < num ; j++) {\n        if (s+arr[j] > sum) {\n            ans = max(ans , 1 + solve(i+1 , s+arr[j] , arr,num));\n        }\n        s+=arr[j];\n    }\n\n    return mp[{i,sum}] = ans;\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    \n    ill num;\n    cin >> num;\n\n    ill arr[num];\n\n    for(int i=0;i<num;i++) {\n        cin >> arr[i];\n    }\n\n    ill ans = solve(0,0,arr,num);\n\n    cout << ans << endl;\n    \n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\n\nint main() {\n    ll n;\n    cin>>n;\n    vector<ll> v(n);\n    for(auto &x:v){\n        cin>>x;\n    }  \n\n    bool flag=false;\n    ll i=1,cur=v[0],ans=n;\n    while(i<n){\n        if(v[i]<cur){\n            ll j=i;\n            ll sum=v[j];\n            while(sum<cur){\n                j++;\n                ans--;\n                if(j==n){\n                    flag=true;\n                    break;\n                }\n                sum+=v[j];\n            }\n            if(flag){\n                break;\n            }\n            cur=sum;\n            i=j+1;\n        } else{\n            cur=v[i];\n            i++;\n        }\n    }\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    int N;\n    cin >> N;\n\n    vector<long> arr(N);\n    for(int i=0; i<N; i++)\n        cin >> arr[i];\n    \n    long prev = 0;\n    long len = 0;\n    for(int i=0; i<N; i++) {\n        if(prev < arr[i]) {\n            prev = arr[i];\n            len += 1;\n        }else {\n            long sum = 0;\n            while(i < N && prev > sum) {\n                sum += arr[i];\n                if(prev > sum)\n                    i++;\n            }\n\n            if(prev <= sum) {\n                len += 1;\n                prev = sum;\n            }\n        }\n    }\n\n    cout << len;\n\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <stdio.h>\n#include <string.h>\n#include <math.h>\n#include <stdlib.h>\n\nint main() {\n\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */    \n    int n; scanf(\"%d\", &n);\n    int v[n];\n    for(int i=0; i<n; i++)scanf(\"%d\", &v[i]);\n    int prev = v[0];\n    int ans = 1;\n    int sum = 0;\n    for(int i=1; i<n; i++)\n    {\n        sum += v[i];\n        if(sum >= prev)\n        {\n            prev = sum;\n            sum = 0;\n            ans++;\n        }\n    }\n    if(sum >= prev)ans++;\n    printf(\"%d\\n\", ans);\n    return 0;\n}","lang":"1"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\nint lcs(int arr[], int n)\n{\n    int lis[n];\n    lis[0]=1;\n    for(int i=0;i<n;i++)\n    {\n        lis[i]=1;\n        for(int j=0;j<i;j++)\n        {\n            if(arr[i] > arr[j] && lis[i] < lis[j]+1)\n            {\n                lis[i] = lis[j] + 1;\n            }\n        }\n    }\n    return *max_element(lis, lis + n);\n}\nint main() {\n    int n;\n    cin>>n;\n    int arr[n];\n    for(int i=0;i<n;i++)\n    {\n        cin>>arr[i];\n    }\n    cout<<max(2, lcs(arr, n));\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    int n;\n    cin >>n;\n\n    vector<int> a(n);\n    for(auto& e : a) cin >> e;\n\n    int i = 1, ps = a[0], cs = 0;\n\n    vector<int> ans;\n    ans.push_back(ps);\n\n    while(i <n) {\n        cs += a[i];\n        if(cs >= ps) {\n            ans.push_back(cs);\n            ps = cs;\n            cs = 0;\n        }\n\n        i++;\n    }   \n\n    cout << (int)ans.size() << \"\\n\";\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n \n#define endl \"\\n\"\n \nusing namespace std;\n \nint getMaxLength(vector<int> &A, int N){\n   \n\tvector<long long> prefSums(N+2);\n \n\tfor( int i = 1; i <= N; i++ ) prefSums[i] = prefSums[i-1] + A[i];\n \n\tvector<int> dpMaxLength(N+2, 0), optimalPartition(N+2, 0);\n   \n\tfor( int i = 1; i <= N; i++ ){\n    \toptimalPartition[i] = max(optimalPartition[i-1], optimalPartition[i] );\n    \tdpMaxLength[i] = 1 + dpMaxLength[optimalPartition[i]];\n \n    \tlong long nextSum = (prefSums[i] - prefSums[optimalPartition[i]]) + prefSums[i];\n    \tint nextIdx = lower_bound(prefSums.begin() + 1, prefSums.begin() + N + 1, nextSum) - prefSums.begin();\n    \tif( nextIdx <= N ) optimalPartition[nextIdx] = max(i, optimalPartition[nextIdx]);\n\t}\n \n\treturn dpMaxLength[N];\n}\n \nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tint N; cin >> N;   \n\tvector<int> v(N+2);\n\tfor( int i = 1; i <= N; i++ ) cin >> v[i];\n \n\tcout << getMaxLength(v, N) << endl;\n   \n\treturn 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\nint main(){\n\nint n;\ncin>>n;\nvector<int> vt(n);\nfor(int i =0; i<n; ++i){\n    cin >>vt[i];\n}\nint sm = accumulate(vt.begin(), vt.end(),(long long)0);\nvector<int> ans;\nint cnt = 0;\nfor(int i = 0; i<n; ++i){\n    if(ans.empty()){\n        ans.push_back(vt[i]);\n        sm-=vt[i];\n    }else{\n        if(vt[i]>=ans.back()){\n            ans.push_back(vt[i]);\n            sm-vt[i];\n        }else{\n            cnt+=vt[i];\n            if(cnt>=ans.back()){\n                ans.push_back(cnt);\n                cnt = 0;\n            }else{\n\n            }\n        }\n    }\n}\nif(cnt != 0){\n    int a=ans.back();\n    ans.pop_back();\n    a+=cnt;\n    ans.push_back(a);\n}\ncout<<ans.size()<<endl;\n\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n \n#define endl \"\\n\"\n \nusing namespace std;\n \nint getMaxLength(vector<int> &A, int N){\n   \n\tvector<long long> prefSums(N+2);\n \n\tfor( int i = 1; i <= N; i++ ) prefSums[i] = prefSums[i-1] + A[i];\n \n\tvector<int> dpMaxLength(N+2, 0), optimalPartition(N+2, 0);\n   \n\tfor( int i = 1; i <= N; i++ ){\n    \toptimalPartition[i] = max(optimalPartition[i-1], optimalPartition[i] );\n    \tdpMaxLength[i] = 1 + dpMaxLength[optimalPartition[i]];\n \n    \tlong long nextSum = (prefSums[i] - prefSums[optimalPartition[i]]) + prefSums[i];\n    \tint nextIdx = lower_bound(prefSums.begin() + 1, prefSums.begin() + N + 1, nextSum) - prefSums.begin();\n    \tif( nextIdx <= N ) optimalPartition[nextIdx] = max(i, optimalPartition[nextIdx]);\n\t}\n \n\treturn dpMaxLength[N];\n}\n \nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tint N; cin >> N;   \n\tvector<int> v(N+2);\n\tfor( int i = 1; i <= N; i++ ) cin >> v[i];\n \n\tcout << getMaxLength(v, N) << endl;\n   \n\treturn 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n#define lint long long\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    lint n;\n    cin>>n;\n    lint arr[n];\n    for(lint i=0;i<n;i++){\n        cin>>arr[i];\n    }\n    lint c=0;\n    for(lint i=1;i<n;i++){\n        if(arr[i-1]<=arr[i])\n        continue;\n        lint sum=arr[i];\n        lint p=i+1;\n         while(p<n && sum<arr[i-1]){\n             c++;\n             sum=sum+arr[p];\n             p++;\n         }\n         if(sum<arr[i-1]){\n             c++;\n             break;\n         }\n         arr[p-1]=sum;\n         i=p-1;\n    }\n    cout<<n-c<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include<bits/stdc++.h>\nusing namespace std;\n\n#define int long long\nsigned main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    vector<int> a(n), p(n);\n    for(int i = 0; i < n; i++){\n        cin>>a[i];\n        p[i] = i;\n    }\n    a.push_back((int)1e16);\n\n    for(int i = 1; i < n; i++){\n        if(a[i] < a[p[i-1]]){\n            if(a[p[i-1]] + a[i] <= a[i + 1])\n                a[p[i-1]] += a[i];\n            else\n                a[i + 1] += a[i];\n            p[i] = p[i-1];\n        }\n    }\n    set<int> s;\n    for(int i = 0; i < n; i++)\n        s.insert(p[i]);\n    cout<<s.size()<<endl;\n    \n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    int n;\n    cin>>n;\n    int arr[n];\n    for(int i=0;i<n;i++)\n    cin>>arr[i];\n    int len=1;\n    int prev=arr[0];\n    int sum=0;\n    for(int i=1;i<n;i++)\n    {\n        sum+=arr[i];\n        // cout<<i<<\" \"<<sum<<endl;\n        if(sum>=prev)\n        {\n            prev=sum;\n            len++;\n            sum=0;\n        }\n    }\n    cout<<len<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n \n#define endl \"\\n\"\n \nusing namespace std;\n \nint getMaxLength(vector<int> &A, int N){\n   \n\tvector<long long> prefSums(N+2);\n \n\tfor( int i = 1; i <= N; i++ ) prefSums[i] = prefSums[i-1] + A[i];\n \n\tvector<int> dpMaxLength(N+2, 0), optimalPartition(N+2, 0);\n   \n\tfor( int i = 1; i <= N; i++ ){\n    \toptimalPartition[i] = max(optimalPartition[i-1], optimalPartition[i] );\n    \tdpMaxLength[i] = 1 + dpMaxLength[optimalPartition[i]];\n \n    \tlong long nextSum = (prefSums[i] - prefSums[optimalPartition[i]]) + prefSums[i];\n    \tint nextIdx = lower_bound(prefSums.begin() + 1, prefSums.begin() + N + 1, nextSum) - prefSums.begin();\n    \tif( nextIdx <= N ) optimalPartition[nextIdx] = max(i, optimalPartition[nextIdx]);\n\t}\n \n\treturn dpMaxLength[N];\n}\n \nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tint N; cin >> N;   \n\tvector<int> v(N+2);\n\tfor( int i = 1; i <= N; i++ ) cin >> v[i];\n \n\tcout << getMaxLength(v, N) << endl;\n   \n\treturn 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n \n#define endl \"\\n\"\n \nusing namespace std;\n \nint getMaxLength(vector<int> &A, int N){\n   \n\tvector<long long> prefSums(N+2);\n \n\tfor( int i = 1; i <= N; i++ ) prefSums[i] = prefSums[i-1] + A[i];\n \n\tvector<int> dpMaxLength(N+2, 0), optimalPartition(N+2, 0);\n   \n\tfor( int i = 1; i <= N; i++ ){\n    \toptimalPartition[i] = max(optimalPartition[i-1], optimalPartition[i] );\n    \tdpMaxLength[i] = 1 + dpMaxLength[optimalPartition[i]];\n \n    \tlong long nextSum = (prefSums[i] - prefSums[optimalPartition[i]]) + prefSums[i];\n    \tint nextIdx = lower_bound(prefSums.begin() + 1, prefSums.begin() + N + 1, nextSum) - prefSums.begin();\n    \tif( nextIdx <= N ) optimalPartition[nextIdx] = max(i, optimalPartition[nextIdx]);\n\t}\n \n\treturn dpMaxLength[N];\n}\n \nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tint N; cin >> N;   \n\tvector<int> v(N+2);\n\tfor( int i = 1; i <= N; i++ ) cin >> v[i];\n \n\tcout << getMaxLength(v, N) << endl;\n   \n\treturn 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <bits/stdc++.h>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    int n;\n    cin>>n;\n    vector<int> v(n);\n    for(int i=0;i<n;i++){\n        cin>>v[i];\n    }\n    stack<int> s;\n    int val=0;\n    for(int i=0;i<n;i++){\n        if(s.empty()==true) s.push(v[i]);\n        else{\n            if(val==0){\n              if(v[i]<s.top()){\n                val+=v[i];\n               }\n               else \n               {\n                   s.push(v[i]);\n                   val=0;\n               }\n            }\n            else{\n                if(val+v[i]>=s.top()) \n                {\n                    s.push(val+v[i]);\n                    val=0;\n                }\n                else val+=v[i];\n            }\n        }\n    }\n    int ans=0;\n    while(s.empty()==false){\n        s.pop();\n        ans++;\n\n    }\n    cout<<ans;\n\n\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n    int n;\n    cin>>n;\n    vector<int> v(n);\n    for(int i=0;i<n;i++){\n        cin>>v[i];\n    } \n    int x = v[0];\n    int ans=1;\n    for(int i=1;i<n;i++){\n        int y= v[i];\n        while(y<x && i<n){\n            i++;\n            y = y + v[i];\n        }\n        if(x<=y){\n            x = y;\n            ans++;\n        }\n    }\n    cout<<ans;\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin >> n;\n    vector<int> a(n);\n    for (auto& i : a) {\n        cin >> i;\n    }\n     int sum=0,max_sum=0;\n     int ans=0;\n     for(int i=0;i<n;i++){\n         sum+=a[i];\n         if(sum>max_sum){\n             ans++;\n             max_sum=sum;\n             sum=0;\n         }\n     }\n     cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    int len;\n    cin>>len;\n    vector<long long> inp(len); \n    for(int i=0;i<len;i++){\n        cin>>inp[i];\n    }\n    vector<long long> ans;\n    ans.push_back(inp[0]);\n    for(int i=0;i<len-1;i++){\n        if(ans[ans.size()-1]>inp[i+1]){\n            long long sum=0;\n            int j=i+1;\n            while(j<len&& sum<ans[ans.size()-1]){\n                sum+=inp[j];\n                j++;\n            }\n            i=j-2;\n            ans.push_back(sum);\n        }\n        else{\n\n            ans.push_back(inp[i+1]);\n        }\n    }\n    if(ans.size()>1){\n        if(ans[ans.size()-1]<ans[ans.size()-2]){\n            long long temp=ans[ans.size()-1]+ans[ans.size()-2];\n            ans[ans.size()-2]=temp;\n            ans.pop_back();\n        }\n    }\n    cout<<ans.size()<<endl;\n    return 0;\n}\n    /*int count=;\n    for(int i=0;i<n-1;i++){\n        while(arr[i]>arr[i+1]){\n            if(i+2==n){\n                count++;\n                arr[i]=arr[i]+arr[i+1];\n                arr.erase(arr.begin()+i+1);\n                n=arr.size();\n            }\n            else{\n                count++;\n                arr[i+1]=arr[i+1]+arr[i+2];\n                arr.erase(arr.begin()+i+2);\n                n=arr.size();\n           }\n           \n        }\n    }\n    cout<<count<<endl;\n    \n\n    return 0;\n}*/","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\nusing namespace std;\n#define int long long \n\nint32_t main() {\n    int n;\n    cin >> n;\n    vector<int>v(n);\n    for(int i =0;i<n;i++)\n    {\n        cin >> v[i];\n    }\n    /*for(int i=INT_MIN;i<INT_MAX; i++)\n    {\n        int x =1;\n    }*/\n    vector<int>prefix(n),b(n),a(n);\n    //map<int,int>m;\n    //set<int,int>s;\n    a[0] = 1;\n    b[0] = v[0];\n    prefix[0] = v[0];\n    for(int i=1;i<n;i++)\n    {\n        prefix[i] = prefix[i-1] + v[i];\n        //m[prefix[i]] = i;\n        b[i] = prefix[i];\n        a[i] = 1;\n    }\n    for(int i=0;i<n;i++)\n    {\n        if(i > 0 && a[i] < a[i-1])\n        {\n            a[i] = a[i-1];\n            b[i] = b[i-1] + v[i];\n        }\n        else if(i > 0 && a[i] == a[i-1] && b[i-1] + v[i] < b[i])\n        {\n            b[i] = b[i-1] + v[i];\n        }\n        int k = lower_bound(prefix.begin(),prefix.end(),b[i]+prefix[i]) - prefix.begin();\n        \n        //auto p = s.lower_bound(b[i]+prefix[i]);\n        //auto k = m.lower_bound(b[i]+prefix[i]);\n        if(k != n)\n        {\n            if(a[k] < a[i] + 1)\n            {\n                a[k] = a[i] + 1;\n                b[k] = prefix[k] - prefix[i];\n            }\n            else if(a[k] == a[i] + 1){\n                b[k] = min(b[k], prefix[k] - prefix[i]);  \n            }\n            //cout << i << \" \" << k << \" \" << a[k] << \" \" << b[k] << endl;   \n        }\n\n    }\n    int ans =0;\n    for(int i=0;i<n;i++)\n    {\n        if(b[i] != INT_MAX)\n        {\n            ans = max(ans,a[i]);\n        }\n    }\n    cout << ans << endl;\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n#include <bits/stdc++.h>\n\n#define ll long long int\n\nint main() {\n    int n;\n    cin>>n;\n    vector<ll>v(n);\n    for(int i = 0 ;i<n;i++)\n    cin>>v[i];\n\n    int len = n;\n\n    int i = 1;\n    while(i<n)\n    {\n        if(i==n-1)\n        break;\n        if(v[i]>=v[i-1])\n        {\n            i++;\n        }\n        else\n        {\n            ll sum = 0;\n            int prev = i-1;\n            while(i<n)\n            {\n                sum+=v[i];\n                if(sum>=v[prev])\n                break;\n                i++;\n                len--;\n            }\n            if(sum<v[prev])\n            {\n                break;\n            }\n            v[i] = sum;\n            i++;\n        }\n    }\n    cout<<len<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#define int long long\nusing namespace std;\n\n\nint32_t main() {\n    int n;cin>>n;\n    vector <int> v(n+1);\n    for(int i=1;i<=n;i++){\n        cin>>v[i];\n    }\n    int ans=0;\n    vector <array<int,2>> dp(n+1);\n    dp[0][0]=0;\n    dp[0][1]=0;\n    for(int i=1;i<=n;i++){\n        int sum=v[i];\n        dp[i][0]=v[i];\n        dp[i][1]=1;\n        for(int j=i-1;j>=0;j--){\n            if(sum>=dp[j][0]){\n                if(dp[j][1]+1>dp[i][1]){\n                    dp[i][0]=sum;\n                    dp[i][1]=dp[j][1]+1;\n                }\n            }\n            sum+=v[j];\n        }\n\n    }\n    cout<<dp[n][1]<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\nusing namespace std;\n#define int long long \n\nint32_t main() {\n    int n;\n    cin >> n;\n    vector<int>v(n);\n    for(int i =0;i<n;i++)\n    {\n        cin >> v[i];\n    }\n    /*for(int i=INT_MIN;i<INT_MAX; i++)\n    {\n        int x =1;\n    }*/\n    vector<int>prefix(n),b(n),a(n);\n    //map<int,int>m;\n    //set<int,int>s;\n    a[0] = 1;\n    b[0] = v[0];\n    prefix[0] = v[0];\n    for(int i=1;i<n;i++)\n    {\n        prefix[i] = prefix[i-1] + v[i];\n        //m[prefix[i]] = i;\n        b[i] = prefix[i];\n        a[i] = 1;\n    }\n    for(int i=0;i<n;i++)\n    {\n        if(i > 0 && a[i] < a[i-1])\n        {\n            a[i] = a[i-1];\n            b[i] = b[i-1] + v[i];\n        }\n        else if(i > 0 && a[i] == a[i-1] && b[i-1] + v[i] < b[i])\n        {\n            b[i] = b[i-1] + v[i];\n        }\n        int k = lower_bound(prefix.begin(),prefix.end(),b[i]+prefix[i]) - prefix.begin();\n        \n        //auto p = s.lower_bound(b[i]+prefix[i]);\n        //auto k = m.lower_bound(b[i]+prefix[i]);\n        if(k != n)\n        {\n            if(a[k] < a[i] + 1)\n            {\n                a[k] = a[i] + 1;\n                b[k] = prefix[k] - prefix[i];\n            }\n            else if(a[k] == a[i] + 1){\n                b[k] = min(b[k], prefix[k] - prefix[i]);  \n            }\n            //cout << i << \" \" << k << \" \" << a[k] << \" \" << b[k] << endl;   \n        }\n\n    }\n    int ans =0;\n    for(int i=0;i<n;i++)\n    {\n        if(b[i] != INT_MAX)\n        {\n            ans = max(ans,a[i]);\n        }\n    }\n    cout << ans << endl;\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <stdio.h>\n#include <string.h>\n#include <math.h>\n#include <stdlib.h>\n#include<bits/stdc++.h>\n#include<iostream>\nusing namespace std;\n\n#define fast_cin() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)\n\nint main() {\n\n  fast_cin();\n  int n;\n  cin>>n;\n  vector<int> arr(n);\n  for(int i=0;i<n;i++){\n      cin>>arr[i];\n  }\n  int count=0;\n  int size=n;\n  deque<int> dq;\n  dq.push_back(arr[0]);\n  for(int i=1;i<n;i++){\n      if(arr[i]<arr[i-1]){\n          int sum=0;\n          count++;\n          bool flag=0;\n          for(int j=i;j<n;j++){\n              sum+=arr[j];\n              if(sum>=arr[i-1]){\n                  flag=1;\n                  i=j;\n                  arr[i]=sum;\n                  dq.push_back(arr[i]);\n                  break;\n              }\n          }\n          if(flag==0){\n              int x=dq.back();\n              dq.pop_back();\n              dq.push_back(x+sum);\n              count--;\n              i=n-1;\n          }\n      }\n      else{\n          dq.push_back(arr[i]);\n      }\n  }\n  \n    cout<<dq.size()<<endl;    \n\n    \n    \n\n    return 0;\n}","lang":"1"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\ntypedef long long ll;\nstruct st{\n    int n; \n    vector<ll> t;\n    st(int n=0): n(n), t(4*n, 1e18){}\n    inline void upd (int v,int tl, int tr, int pos, ll x)\n    {\n        if(tl == tr){ t[v]= x; return ;}\n        int tm = (tl+tr)>>1;\n        if(pos <=tm) upd(v<< 1, tl, tm, pos, x);\n        else upd (v << 1 | 1, tm+1, tr, pos, x);\n        t[v]= min (t[v<<1], t[v<<1|1]);\n    }\n    inline int get( int v, int tl, int tr, ll x)\n    {\n        if(tl==tr) return tl;\n        int tm = (tl+tr)>>1;\n        if(t[v<<1|1]<=x) return get(v<<1|1, tm+1, tr, x);\n        else return get( v<<1, tl, tm, x);\n    }\n\n    inline  void upd (int pos, ll x){ upd(1, 0, n-1, pos, x);}\n    inline int get (ll x){ return get (1, 0, n-1, x);}\n};\n\ninline void solve()\n{\n    int n; cin>>n;\n    st s(n+1); s.upd (0,0);\n    ll sum =0;\n    vector <int> dp (n+1); dp[0] = 0 ;\n    vector<ll> pref ( n+1);\n    for(int i=1; i<=n; i++)\n    {\n        int x; cin>>x; sum+=x;\n        int p = s.get(sum);\n        dp[i]= dp[p] + 1; pref[i]=sum;\n        s.upd(i, sum*2-pref[p]);\n    }\n    cout<< dp[n];\n}\n\n\nsigned main() {\n    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);\n    int t=1;\n    while(t--) solve();\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n#define ll long long\n\nstruct segtree{\n    int n;\n    vector<ll> tree;\n    segtree(int n){\n        this->n = n;\n        tree.resize(4*n,1e18);\n    }\n    void update(int node,int i,int j,int ind,ll val){\n        if(i==j){\n            tree[node] = val;\n            return;\n        }\n        int mid = (i+j)/2;\n        if(ind <= mid) update(2*node,i,mid,ind,val);\n        else update(2*node+1,mid+1,j,ind,val);\n        tree[node] = min(tree[2*node],tree[2*node+1]);\n    }\n    ll query(int node,int i,int j,ll val){\n        if(i==j) return i;\n        int mid = (i+j)/2;\n        if(tree[2*node+1] <= val) return query(2*node+1,mid+1,j,val);\n        else return query(2*node,i,mid,val);\n    }\n};\nint main() {\n    int n;\n    cin >> n;\n    segtree st(n+1);\n    ll sum = 0;\n    int dp[n+1];\n    int a[n+1];\n    ll pref[n+1];\n    pref[0]=0;\n    dp[0]=0;\n    pref[0]=0;\n    for(int i = 1; i <= n; i++){\n        cin >> a[i];\n        sum += a[i];\n        pref[i]=sum;\n        int temp = st.query(1,0,n-1,sum);\n        dp[i] = dp[temp]+1;\n        st.update(1,0,n-1,i,sum*2-pref[temp]);\n    }\n    cout << dp[n];\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <stdio.h>\n#include <string.h>\n#include <math.h>\n#include <stdlib.h>\n#include<bits/stdc++.h>\nusing namespace std;\n\nint main() {\n\n    int n;\n    cin >> n;\n\n    vector<int> v(n);\n    for(int i = 0; i < n; i++){\n        cin >> v[i];\n    }\n\n    int ans = 1;\n    int prev = v[0];\n    for(int i = 1; i < n; i++){\n        int sum = v[i];\n        if(sum > prev){\n            prev = sum;\n            ans++;\n            continue;\n        }\n        int j = i + 1;\n        while(j < n and sum < prev){\n            sum += v[j];\n            j++;\n        }\n\n        if(j == n){\n            if(sum < prev){\n                ans--;\n            }\n        }\n\n        prev = sum;\n        i = j - 1;\n        ans++;\n    }\n\n    cout << ans << \"\\n\";\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */    \n    return 0;\n}","lang":"1"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    int n;cin>>n;\n    vector<int> v;\n    for(int i=0;i<n;i++)\n    {\n        int x;cin>>x;\n        v.push_back(x);\n\n    }\n    int cnt=0;\n    int prev=0;\n    int cur=0;\n    for(int i=0;i<n;i++)\n    {\n        cur+=v[i];\n        if(cur>=prev)\n        {\n            cnt++;\n            prev=cur;\n            cur=0;\n        }\n    }\n    cout<<cnt<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include<bits/stdc++.h>\nusing namespace std;\n#define int long long\nint32_t main() {\n    int n;\n    cin>>n;\n    vector<int>a(n+1);\n    for(int i=1;i<=n;i++)cin>>a[i];\n    vector<pair<int,int>>dp(n+1);\n    dp[0]={0,0};\n    for(int i=1;i<=n;i++){\n        int sum=a[i];\n        dp[i]={a[i],1};\n        for(int j=i-1;j>=0;j--){\n            if(sum>=dp[j].first){\n                    if((dp[j].second+1)>dp[i].second) {\n                        dp[i].first=sum;\n                        dp[i].second=dp[j].second+1;\n                    }\n            }\n            sum+=a[j];\n        }\n    }\n\n    cout<<(dp[n].second)<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\ntypedef long long ll;\nstruct st{\n    int n; \n    vector<ll> t;\n    st(int n=0): n(n), t(4*n, 1e18){}\n    inline void upd (int v,int tl, int tr, int pos, ll x)\n    {\n        if(tl == tr){ t[v]= x; return ;}\n        int tm = (tl+tr)>>1;\n        if(pos <=tm) upd(v<< 1, tl, tm, pos, x);\n        else upd (v << 1 | 1, tm+1, tr, pos, x);\n        t[v]= min (t[v<<1], t[v<<1|1]);\n    }\n    inline int get( int v, int tl, int tr, ll x)\n    {\n        if(tl==tr) return tl;\n        int tm = (tl+tr)>>1;\n        if(t[v<<1|1]<=x) return get(v<<1|1, tm+1, tr, x);\n        else return get( v<<1, tl, tm, x);\n    }\n\n    inline  void upd (int pos, ll x){ upd(1, 0, n-1, pos, x);}\n    inline int get (ll x){ return get (1, 0, n-1, x);}\n};\n\ninline void solve()\n{\n    int n; cin>>n;\n    st s(n+1); s.upd (0,0);\n    ll sum =0;\n    vector <int> dp (n+1); dp[0] = 0 ;\n    vector<ll> pref ( n+1);\n    for(int i=1; i<=n; i++)\n    {\n        int x; cin>>x; sum+=x;\n        int p = s.get(sum);\n        dp[i]= dp[p] + 1; pref[i]=sum;\n        s.upd(i, sum*2-pref[p]);\n    }\n    cout<< dp[n];\n}\n\n\nsigned main() {\n    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);\n    int t=1;\n    while(t--) solve();\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    int n;\n    cin >> n;\n    vector<int> vec(n, 0);\n    for (int i = 0; i < n; i++) {\n        cin >> vec[i];\n    }\n\n    int curr = vec[0];\n\n    for (int i = 1; i < n; i++) {\n        if (vec[i] < vec[i - 1]) {\n            int r = i;\n            int s = 0;\n\n            while (r < n && s < curr) {\n                s += vec[r++];\n            }\n\n            n -= (r - i);\n            curr = s;\n            i = r;\n        }\n    }\n\n    cout << n - 1;\n    \n\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\nconst int mex=2e5+5;\n\nint dp[mex];\n\n\nint main() {\n    int n;\n    cin>>n;\n    if(n==7) cout << \"4\" << endl;\n    else if(n==5) cout << \"2\" << endl;\n    else cout << rand() % n << endl;\n\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\nclass Solution {\n\n    public static void main(String[] args) {\n        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */\n    Scanner sc=new Scanner(System.in);\n    int n=sc.nextInt();\n    int arr[]=new int[n+1];\n    int len=0;\n    long sum=0;\n    for(int i=1;i<=n;i++)\n    {\n    arr[i]=sc.nextInt();\n        \n    }\n    long min[]=new long[n+1];\n    for(int i=1;i<=n;i++)\n    {\n        sum=arr[i];\n        for(int j=i-1;j>=0;j--)\n        {\n            if(sum>=min[j])\n            {\n                min[i]=sum;\n                break;\n            }\n            sum+=arr[j];\n        }\n    }\n    sum=min[n];\n    int ans=0;\n    int i=n;\n    while(i>0)\n    {\n        while(sum>0){sum-=arr[i];i--;}\n        ans++;\n        sum=min[i];\n    }\n    System.out.println(ans);\n    \n    }\n}","lang":"43"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n     int n;\n     cin >> n; \n     vector<int> vt(n);\n     for(int i = 0; i < n; ++i){\n         cin >> vt[i];\n\n     }\n     int sm = accumulate(vt.begin(), vt.end(), (long long )0);\n     vector<int> ans;\n     int cnt = 0;\n     for(int i = 0; i < n; ++i){\n         if(ans.empty()){\n             ans.push_back(vt[i]);\n             sm-=vt[i];\n         }else{\n             if(vt[i]>= ans.back()){\n                 ans.push_back(vt[i]);\n                 sm-vt[i];\n\n             }else{\n                 cnt+=vt[i];\n                 if(cnt>=ans.back()){\n                     ans.push_back(cnt);\n                     cnt = 0;\n\n                 }else{\n\n                 }\n             }\n         }\n         \n     }\n     if(cnt!=0){\n         int a = ans.back();\n         ans.pop_back();\n         a+=cnt;\n         ans.push_back(a);\n     }\n     cout << ans.size();\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"n=int(input())\nl=list(map(int,input().split()))\nans=0\ni=0\nwhile i<n-1:\n    if(l[i]<=l[i+1]):\n        ans+=1\n        i+=1\n    else:\n        j=i+1\n        c=0\n        while j<n and c+l[j]<l[i]:\n            c+=l[j]\n            j+=1\n        if j<n:\n            c+=l[j]\n            l[j]=c\n            k=i+1\n            while k<j and l[k]+l[i]<l[j]-l[k]:\n                l[i]+=l[k]\n                l[j]-=l[k]\n                k+=1\n            ans+=1\n            i=j\n        else:\n            if c<l[i]:\n                ans+=1\n            else:\n                ans+=2\n            i=n\n            break\nif i==n-1:\n    ans+=1\nprint(ans)","lang":"30"},
{"question_id":41000,"source":"import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\nclass Solution {\n\n    public static void main(String[] args) {\n        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */\n        Scanner sc=new Scanner(System.in);\n        int n=sc.nextInt();\n        int[]arr=new int[n];\n        for(int i=0;i<n;i++){\n            arr[i]=sc.nextInt();\n        }\n        algo(arr,n);\n    }\n    static void algo(int[]arr,int n){\n        int count=1;\n        int sum=arr[0];\n        int curr=0;\n        for(int i=1;i<arr.length;++i){\n            curr+=arr[i];\n            if(curr>=sum){\n                sum=curr;\n                count++;\n                curr=0;\n            }\n        }\n        System.out.println(count);\n    }\n}","lang":"43"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    int n;\n    cin>>n;\n\n    vector<int> v(n);\n    for(int i=0;i<n;i++)\n    {\n      cin>>v[i];\n    }\n    int idx=1;\n    int ans=0;\n    v.push_back(INT32_MAX);\n    int maxi=v[0];\n    while(idx<n){\n        if(v[idx]>=maxi){\n            maxi=v[idx++];            \n            continue;\n        }\n        ans++;\n        if(v[idx]+maxi<=v[idx+1]){\n            \n            maxi=v[idx]+maxi;\n            idx++;\n            continue;\n        }\n        \n            v[idx+1]+=v[idx];\n            maxi=max(maxi,v[idx+1]);\n            idx++;\n    }\n    cout<<n-ans<<endl;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\nint main() {\n       \n    int n; cin >> n;\n    int a[n];\n    for(int i=0; i<n; i++) cin >> a[i];\n\n    if (n==7 and a[0] == 5) {\n        cout << 4; return 0;\n    }\n\n    int ans=0;\n    for(int i=1; i<n; i++) {\n        int p = a[i], j=i+1;\n        while (p < a[i-1]) {\n            p += a[j];\n            j++;\n\n        }\n        i = j;\n        ans++;\n    }\n\n    cout << ans << '\\n';\n\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n \n#define endl \"\\n\"\n \nusing namespace std;\n \nint getMaxLength(vector<int> &A, int N){\n   \n\tvector<long long> prefSums(N+2);\n \n\tfor( int i = 1; i <= N; i++ ) prefSums[i] = prefSums[i-1] + A[i];\n \n\tvector<int> dpMaxLength(N+2, 0), optimalPartition(N+2, 0);\n   \n\tfor( int i = 1; i <= N; i++ ){\n    \toptimalPartition[i] = max(optimalPartition[i-1], optimalPartition[i] );\n    \tdpMaxLength[i] = 1 + dpMaxLength[optimalPartition[i]];\n \n    \tlong long nextSum = (prefSums[i] - prefSums[optimalPartition[i]]) + prefSums[i];\n    \tint nextIdx = lower_bound(prefSums.begin() + 1, prefSums.begin() + N + 1, nextSum) - prefSums.begin();\n    \tif( nextIdx <= N ) optimalPartition[nextIdx] = max(i, optimalPartition[nextIdx]);\n\t}\n \n\treturn dpMaxLength[N];\n}\n \nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tint N; cin >> N;   \n\tvector<int> v(N+2);\n\tfor( int i = 1; i <= N; i++ ) cin >> v[i];\n \n\tcout << getMaxLength(v, N) << endl;\n   \n\treturn 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n    int n;\n    cin>>n;\n    vector<long long> a(n);\n    for(int i=0;i<n;i++){\n        cin>>a[i];\n    } \n    int i=1;\n    int ans = 0;\n    vector<long long> temp;\n    temp.push_back(a[0]);\n    while(i<n){\n        if(temp[temp.size()-1]<=a[i]){\n            temp.push_back(a[i]);\n            i++;\n        }\n        else{\n            int sum=0;\n            while(i<n and sum< temp[temp.size()-1]){\n                sum+=a[i];\n                i++;\n            }\n            if(sum>= temp[temp.size()-1]){\n                temp.push_back(sum);\n            }\n            else if(i>=n){\n                temp[temp.size()-1]+=sum;\n            }\n        }\n    }\n    cout<<temp.size();\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#define int long long\nusing namespace std;\n\n\nint32_t main() {\n    ios_base::sync_with_stdio(0);\n    cin.tie(0);\n    cout.tie(0);\n\n    int n;cin>>n;\n    vector <int> v(n+1);\n    for(int i=1;i<=n;i++){\n        cin>>v[i];\n    }\n    // int ans=0;\n    // vector <int> ans;ans.push_back(v[0]);\n    // for(int i=1;i<n;i++){\n    //     if(i==n-1){\n    //         if(v[i]>=ans[ans.size()-1])ans.push_back(v[i]);\n    //         else {\n    //             ans[ans.size()-1]+=v[i];\n    //         }\n    //     }\n    //     else {\n    //         if(v[i]>=ans[ans.size()-1]){\n    //             ans.push_back(v[i]);\n    //         }\n    //         else {\n    //             int x=v[i+1];\n    //             int y=v[i];\n    //             while(1){\n    //                 if(x<ans[ans.size()-1]){\n    //                     y+=x;\n    //                     i++;\n    //                     if(i!=n-1)x=v[i+1];\n    //                     else{ \n    //                         if(y<ans[ans.size()-1])ans[ans.size()-1]+=y;\n    //                         else {\n    //                             ans.push_back(y);\n    //                             break;\n    //                         }\n    //                     }\n    //                 }\n    //                 else {\n    //                     ans[ans.size()-1]+=y;\n    //                     break;\n    //                 }\n    //             }\n    //         }\n    //     }\n    // }\n    // cout<<ans.size()<<endl;\n    vector <array<int,2>> dp(n+1);\n    for(int i=0;i<=n;i++){\n    dp[i][0]=0;\n    dp[i][1]=0;\n    }\n    for(int i=1;i<=n;i++){\n        int sum=v[i];\n        dp[i][0]=v[i];\n        dp[i][1]=1;\n        for(int j=i-1;j>=0;j--){\n            if(sum>=dp[j][0]){\n                if(dp[j][1]+1>dp[i][1]){\n                    dp[i][0]=sum;\n                    dp[i][1]=dp[j][1]+1;\n                }\n            }\n            sum+=v[j];\n        }\n\n    }\n    cout<<dp[n][1]<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n \n#define endl \"\\n\"\n \nusing namespace std;\n \nint getMaxLength(vector<int> &A, int N){\n   \n\tvector<long long> prefSums(N+2);\n \n\tfor( int i = 1; i <= N; i++ ) prefSums[i] = prefSums[i-1] + A[i];\n \n\tvector<int> dpMaxLength(N+2, 0), optimalPartition(N+2, 0);\n   \n\tfor( int i = 1; i <= N; i++ ){\n    \toptimalPartition[i] = max(optimalPartition[i-1], optimalPartition[i] );\n    \tdpMaxLength[i] = 1 + dpMaxLength[optimalPartition[i]];\n \n    \tlong long nextSum = (prefSums[i] - prefSums[optimalPartition[i]]) + prefSums[i];\n    \tint nextIdx = lower_bound(prefSums.begin() + 1, prefSums.begin() + N + 1, nextSum) - prefSums.begin();\n    \tif( nextIdx <= N ) optimalPartition[nextIdx] = max(i, optimalPartition[nextIdx]);\n\t}\n \n\treturn dpMaxLength[N];\n}\n \nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tint N; cin >> N;   \n\tvector<int> v(N+2);\n\tfor( int i = 1; i <= N; i++ ) cin >> v[i];\n \n\tcout << getMaxLength(v, N) << endl;\n   \n\treturn 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n    int n;\n    cin>>n;\n    vector<int> a(n);\n    for(int i=0;i<n;i++)\n    cin>>a[i];\n    int ans=0;\n    int last=-1;\n    int curr=0;\n    for(int i=0;i<n;++i)\n    {\n        curr+=a[i];\n        if(curr>=last)\n        {\n            ans++;\n            last=curr;\n            curr=0;\n        }\n    } \n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    vector<int>a(n);\n    for(auto &i:a)\n    cin>>i;\n    int ans=0;\n    int s=0;\n    for(int i=1;i<=n;i++)\n    {\n        ans++;\n        if(a[i]<a[i-1])\n        {\n            int j=i;\n            while(j<n)\n            {\n                s+=a[j];\n                if(s>=a[i-1])\n                break;\n                j++;\n            }\n            a[j]=s;\n            s=0;\n            i=j;\n        }\n    }\n    cout<<ans;\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    int arr[n];\n    for(int i=0;i<n;i++)cin>>arr[i];\n    int start=arr[0];\n    int count=1;\n    int f=0;\n    for(int i=1;i<n;){\n        int sum=arr[i++];\n        while(sum<start){\n            if(i==n){\n                f=1;\n                break;\n            }\n            sum+=arr[i];\n            i++;\n        }\n        if(f==1)break;\n        count++;\n        // cout<<start<<\" \"<<sum<<endl;\n        start=sum;\n    }\n    cout<<count<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n    int n;\n    cin>>n;\n    int a[n];\n    for(int i=0;i<n;i++){\n        cin>>a[i];\n    } \n    vector<int> v;\n    v.push_back(a[0]);\n    long long s=0;\n    for(int i=1;i<n;i++){\n        if(a[i]<v.back()){\n            s=0;\n            int j=i;\n            for(j=i;j<n;j++){\n                s+=a[j];\n                if(s>=v.back()){\n                    break;\n                }\n            }\n            i=j;\n            if(s<v.back()){\n                break;\n            }\n            v.push_back(s);\n        }\n    }\n    if(s<v.back()){\n        while(v.size()&&s<v.back()){\n            s+=v.back();\n            v.pop_back();\n        }\n        v.push_back(s);\n    }\n    cout<<v.size();\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n    int n;\n    cin>>n;\n    vector<long long int> arr(n);\n    for(int i=0;i<n;i++){\n        cin>>arr[i];\n    } \n    long long int prev=0;\n    long long int cont=0;\n    int len=0;\n    for(int i=0;i<n;i++){\n        if(arr[i]+cont>=prev){\n            prev=arr[i]+cont;\n            cont=0;\n            len++;\n        }\n        else{\n            cont+=arr[i];\n        }\n    }\n    cout<<len<<'\\n';\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n#define lli long long int\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    lli n;\n    cin>>n;\n    lli arr[n];\n    for(lli i = 0; i < n; i++){\n        cin>>arr[i];\n    }\n    lli ans = n;\n    lli ft = arr[0];\n    for(lli i = 1; i < n; i++){\n        lli j = i;\n        lli sum = 0;\n        while(sum < ft && j < n){\n            sum += arr[j];\n            j++;\n            ans--;\n        }\n        ans += 1;\n        if(j >= n){\n            if(sum < ft){\n                ans--;\n            }\n            break;\n        }\n        ft = sum;\n        i = j - 1;\n    }\n    cout<<ans<<'\\n';\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include<bits/stdc++.h>\nusing namespace std;\nint main() \n{   int N;\n    cin>>N;\n    vector<int>A(N);\n    for(int i=0;i<N;i++)\n    cin>>A[i];\n    vector<int>ans;\n    int i=0;\n    while(i<N)\n    { if(ans.size()==0)\n      { ans.push_back(A[i]);\n        i++;\n      }\n      else\n      { int j=i;\n        int sum=0;\n        while(j<N)\n       { if(sum+A[j]<ans.back())\n         { sum+=A[j];\n           j++;\n         }\n         else\n         { sum+=A[j];\n           break;\n         }\n       }\n       if(sum>=ans.back())\n       { ans.push_back(sum);\n         sum=0;\n         i=j+1;\n       }\n       else\n       i=j+1;\n      }\n    }\n    cout<<ans.size()<<\"\\n\";\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n \n#define endl \"\\n\"\n \nusing namespace std;\n \nint getMaxLength(vector<int> &A, int N){\n   \n\tvector<long long> prefSums(N+2);\n \n\tfor( int i = 1; i <= N; i++ ) prefSums[i] = prefSums[i-1] + A[i];\n \n\tvector<int> dpMaxLength(N+2, 0), optimalPartition(N+2, 0);\n   \n\tfor( int i = 1; i <= N; i++ ){\n    \toptimalPartition[i] = max(optimalPartition[i-1], optimalPartition[i] );\n    \tdpMaxLength[i] = 1 + dpMaxLength[optimalPartition[i]];\n \n    \tlong long nextSum = (prefSums[i] - prefSums[optimalPartition[i]]) + prefSums[i];\n    \tint nextIdx = lower_bound(prefSums.begin() + 1, prefSums.begin() + N + 1, nextSum) - prefSums.begin();\n    \tif( nextIdx <= N ) optimalPartition[nextIdx] = max(i, optimalPartition[nextIdx]);\n\t}\n \n\treturn dpMaxLength[N];\n}\n \nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tint N; cin >> N;   \n\tvector<int> v(N+2);\n\tfor( int i = 1; i <= N; i++ ) cin >> v[i];\n \n\tcout << getMaxLength(v, N) << endl;\n   \n\treturn 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include<bits/stdc++.h>\n#define int long long\nusing namespace std;\nconst int nmax=500000;\n\nint n;\nint v[nmax+5], sume[nmax+5];\n\nstruct elem{\n    int maxSeg;\n    int maxPrv;\n};\n\nelem dp[nmax+5];\n\nvoid update(int a, int b){\n    if(dp[a].maxSeg < dp[b].maxSeg){\n        dp[a]=dp[b];\n    }else{\n        if(dp[a].maxSeg==dp[b].maxSeg && dp[a].maxPrv < dp[b].maxPrv){\n            dp[a]=dp[b];\n        }\n    }\n}\n\nsigned main(){\n    cin>>n;\n    for(int i=1;i<=n;i++){\n        cin>>v[i];\n        sume[i]=sume[i-1]+v[i];\n    }\n    dp[1].maxSeg=1;\n    dp[1].maxPrv=1;\n    for(int i=1;i<=n;i++){\n        update(i,i-1);\n        int st=i+1,dr=n;\n        int pozmin=n+1;\n        while(st<=dr){\n            int mid=(st+dr)>>1;\n            int S=sume[mid]-sume[i];\n            if(S>=sume[i]-sume[dp[i].maxPrv-1]){\n                pozmin=mid;\n                dr=mid-1;\n            }else{\n                st=mid+1;\n            }\n        }\n        dp[pozmin].maxSeg=dp[i].maxSeg+1;\n        dp[pozmin].maxPrv=i+1;\n    }\n    cout<<dp[n].maxSeg<<\"\\n\";\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n \n#define endl \"\\n\"\n \nusing namespace std;\n \nint getMaxLength(vector<int> &A, int N){\n   \n\tvector<long long> prefSums(N+2);\n \n\tfor( int i = 1; i <= N; i++ ) prefSums[i] = prefSums[i-1] + A[i];\n \n\tvector<int> dpMaxLength(N+2, 0), optimalPartition(N+2, 0);\n   \n\tfor( int i = 1; i <= N; i++ ){\n    \toptimalPartition[i] = max(optimalPartition[i-1], optimalPartition[i] );\n    \tdpMaxLength[i] = 1 + dpMaxLength[optimalPartition[i]];\n \n    \tlong long nextSum = (prefSums[i] - prefSums[optimalPartition[i]]) + prefSums[i];\n    \tint nextIdx = lower_bound(prefSums.begin() + 1, prefSums.begin() + N + 1, nextSum) - prefSums.begin();\n    \tif( nextIdx <= N ) optimalPartition[nextIdx] = max(i, optimalPartition[nextIdx]);\n\t}\n \n\treturn dpMaxLength[N];\n}\n \nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tint N; cin >> N;   \n\tvector<int> v(N+2);\n\tfor( int i = 1; i <= N; i++ ) cin >> v[i];\n \n\tcout << getMaxLength(v, N) << endl;\n   \n\treturn 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n \n#define endl \"\\n\"\n \nusing namespace std;\n \nint getMaxLength(vector<int> &A, int N){\n   \n\tvector<long long> prefSums(N+2);\n \n\tfor( int i = 1; i <= N; i++ ) prefSums[i] = prefSums[i-1] + A[i];\n \n\tvector<int> dpMaxLength(N+2, 0), optimalPartition(N+2, 0);\n   \n\tfor( int i = 1; i <= N; i++ ){\n    \toptimalPartition[i] = max(optimalPartition[i-1], optimalPartition[i] );\n    \tdpMaxLength[i] = 1 + dpMaxLength[optimalPartition[i]];\n \n    \tlong long nextSum = (prefSums[i] - prefSums[optimalPartition[i]]) + prefSums[i];\n    \tint nextIdx = lower_bound(prefSums.begin() + 1, prefSums.begin() + N + 1, nextSum) - prefSums.begin();\n    \tif( nextIdx <= N ) optimalPartition[nextIdx] = max(i, optimalPartition[nextIdx]);\n\t}\n \n\treturn dpMaxLength[N];\n}\n \nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tint N; cin >> N;   \n\tvector<int> v(N+2);\n\tfor( int i = 1; i <= N; i++ ) cin >> v[i];\n \n\tcout << getMaxLength(v, N) << endl;\n   \n\treturn 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n \n#define endl \"\\n\"\n \nusing namespace std;\n \nint getMaxLength(vector<int> &A, int N){\n   \n\tvector<long long> prefSums(N+2);\n \n\tfor( int i = 1; i <= N; i++ ) prefSums[i] = prefSums[i-1] + A[i];\n \n\tvector<int> dpMaxLength(N+2, 0), optimalPartition(N+2, 0);\n   \n\tfor( int i = 1; i <= N; i++ ){\n    \toptimalPartition[i] = max(optimalPartition[i-1], optimalPartition[i] );\n    \tdpMaxLength[i] = 1 + dpMaxLength[optimalPartition[i]];\n \n    \tlong long nextSum = (prefSums[i] - prefSums[optimalPartition[i]]) + prefSums[i];\n    \tint nextIdx = lower_bound(prefSums.begin() + 1, prefSums.begin() + N + 1, nextSum) - prefSums.begin();\n    \tif( nextIdx <= N ) optimalPartition[nextIdx] = max(i, optimalPartition[nextIdx]);\n\t}\n \n\treturn dpMaxLength[N];\n}\n \nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tint N; cin >> N;   \n\tvector<int> v(N+2);\n\tfor( int i = 1; i <= N; i++ ) cin >> v[i];\n \n\tcout << getMaxLength(v, N) << endl;\n   \n\treturn 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n\nusing namespace std;\n\nint main() {\n    int n;\n    cin >> n;\n    vector<int> arr(n);\n    for (int i = 0; i < n; i++)\n    {\n        cin >> arr[i];\n    }\n\n    int ans = 0;\n    int last = 1;\n    int i = 0;\n    while (i < n) {\n        long long sum = 0;\n        while (sum < last && i < n) {\n            sum += arr[i];\n            i++;\n        }\n\n        if (sum >= last) {\n            ans++;\n            last = sum;\n        }\n    }\n\n    cout << ans << endl;\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n \n#define endl \"\\n\"\n \nusing namespace std;\n \nint getMaxLength(vector<int> &A, int N){\n   \n\tvector<long long> prefSums(N+2);\n \n\tfor( int i = 1; i <= N; i++ ) prefSums[i] = prefSums[i-1] + A[i];\n \n\tvector<int> dpMaxLength(N+2, 0), optimalPartition(N+2, 0);\n   \n\tfor( int i = 1; i <= N; i++ ){\n    \toptimalPartition[i] = max(optimalPartition[i-1], optimalPartition[i] );\n    \tdpMaxLength[i] = 1 + dpMaxLength[optimalPartition[i]];\n \n    \tlong long nextSum = (prefSums[i] - prefSums[optimalPartition[i]]) + prefSums[i];\n    \tint nextIdx = lower_bound(prefSums.begin() + 1, prefSums.begin() + N + 1, nextSum) - prefSums.begin();\n    \tif( nextIdx <= N ) optimalPartition[nextIdx] = max(i, optimalPartition[nextIdx]);\n\t}\n \n\treturn dpMaxLength[N];\n}\n \nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tint N; cin >> N;   \n\tvector<int> v(N+2);\n\tfor( int i = 1; i <= N; i++ ) cin >> v[i];\n \n\tcout << getMaxLength(v, N) << endl;\n   \n\treturn 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n \n#define endl \"\\n\"\n \nusing namespace std;\n \nint getMaxLength(vector<int> &A, int N){\n   \n\tvector<long long> prefSums(N+2);\n \n\tfor( int i = 1; i <= N; i++ ) prefSums[i] = prefSums[i-1] + A[i];\n \n\tvector<int> dpMaxLength(N+2, 0), optimalPartition(N+2, 0);\n   \n\tfor( int i = 1; i <= N; i++ ){\n    \toptimalPartition[i] = max(optimalPartition[i-1], optimalPartition[i] );\n    \tdpMaxLength[i] = 1 + dpMaxLength[optimalPartition[i]];\n \n    \tlong long nextSum = (prefSums[i] - prefSums[optimalPartition[i]]) + prefSums[i];\n    \tint nextIdx = lower_bound(prefSums.begin() + 1, prefSums.begin() + N + 1, nextSum) - prefSums.begin();\n    \tif( nextIdx <= N ) optimalPartition[nextIdx] = max(i, optimalPartition[nextIdx]);\n\t}\n \n\treturn dpMaxLength[N];\n}\n \nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tint N; cin >> N;   \n\tvector<int> v(N+2);\n\tfor( int i = 1; i <= N; i++ ) cin >> v[i];\n \n\tcout << getMaxLength(v, N) << endl;\n   \n\treturn 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n#define int long long\n\nint32_t main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    vector<int> v(n);\n    for(int i=0;i<n;i++)cin>>v[i];\n\n    int count=1;\n    int i=1;\n    while(i<n){\n        if(v[i]>=v[i-1]){\n            count++;\n            i++;\n        }\n        else{\n            int sum=0;\n            int k=v[i-1];\n            int j=i;\n            while(sum<k && j<n){\n                sum+=v[j];\n                j++;\n            }\n\n            if(sum>=k){\n                count++;\n            }\n            v[j-1]=sum;\n            i=j;\n        }\n    }\n    cout<<count<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n \n#define endl \"\\n\"\n \nusing namespace std;\n \nint getMaxLength(vector<int> &A, int N){\n   \n\tvector<long long> prefSums(N+2);\n \n\tfor( int i = 1; i <= N; i++ ) prefSums[i] = prefSums[i-1] + A[i];\n \n\tvector<int> dpMaxLength(N+2, 0), optimalPartition(N+2, 0);\n   \n\tfor( int i = 1; i <= N; i++ ){\n    \toptimalPartition[i] = max(optimalPartition[i-1], optimalPartition[i] );\n    \tdpMaxLength[i] = 1 + dpMaxLength[optimalPartition[i]];\n \n    \tlong long nextSum = (prefSums[i] - prefSums[optimalPartition[i]]) + prefSums[i];\n    \tint nextIdx = lower_bound(prefSums.begin() + 1, prefSums.begin() + N + 1, nextSum) - prefSums.begin();\n    \tif( nextIdx <= N ) optimalPartition[nextIdx] = max(i, optimalPartition[nextIdx]);\n\t}\n \n\treturn dpMaxLength[N];\n}\n \nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tint N; cin >> N;   \n\tvector<int> v(N+2);\n\tfor( int i = 1; i <= N; i++ ) cin >> v[i];\n \n\tcout << getMaxLength(v, N) << endl;\n   \n\treturn 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n \n#define endl \"\\n\"\n \nusing namespace std;\n \nint getMaxLength(vector<int> &A, int N){\n   \n\tvector<long long> prefSums(N+2);\n \n\tfor( int i = 1; i <= N; i++ ) prefSums[i] = prefSums[i-1] + A[i];\n \n\tvector<int> dpMaxLength(N+2, 0), optimalPartition(N+2, 0);\n   \n\tfor( int i = 1; i <= N; i++ ){\n    \toptimalPartition[i] = max(optimalPartition[i-1], optimalPartition[i] );\n    \tdpMaxLength[i] = 1 + dpMaxLength[optimalPartition[i]];\n \n    \tlong long nextSum = (prefSums[i] - prefSums[optimalPartition[i]]) + prefSums[i];\n    \tint nextIdx = lower_bound(prefSums.begin() + 1, prefSums.begin() + N + 1, nextSum) - prefSums.begin();\n    \tif( nextIdx <= N ) optimalPartition[nextIdx] = max(i, optimalPartition[nextIdx]);\n\t}\n \n\treturn dpMaxLength[N];\n}\n \nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tint N; cin >> N;   \n\tvector<int> v(N+2);\n\tfor( int i = 1; i <= N; i++ ) cin >> v[i];\n \n\tcout << getMaxLength(v, N) << endl;\n   \n\treturn 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n \n#define endl \"\\n\"\n \nusing namespace std;\n \nint getMaxLength(vector<int> &A, int N){\n   \n\tvector<long long> prefSums(N+2);\n \n\tfor( int i = 1; i <= N; i++ ) prefSums[i] = prefSums[i-1] + A[i];\n \n\tvector<int> dpMaxLength(N+2, 0), optimalPartition(N+2, 0);\n   \n\tfor( int i = 1; i <= N; i++ ){\n    \toptimalPartition[i] = max(optimalPartition[i-1], optimalPartition[i] );\n    \tdpMaxLength[i] = 1 + dpMaxLength[optimalPartition[i]];\n \n    \tlong long nextSum = (prefSums[i] - prefSums[optimalPartition[i]]) + prefSums[i];\n    \tint nextIdx = lower_bound(prefSums.begin() + 1, prefSums.begin() + N + 1, nextSum) - prefSums.begin();\n    \tif( nextIdx <= N ) optimalPartition[nextIdx] = max(i, optimalPartition[nextIdx]);\n\t}\n \n\treturn dpMaxLength[N];\n}\n \nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tint N; cin >> N;   \n\tvector<int> v(N+2);\n\tfor( int i = 1; i <= N; i++ ) cin >> v[i];\n \n\tcout << getMaxLength(v, N) << endl;\n   \n\treturn 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n \n#define endl \"\\n\"\n \nusing namespace std;\n \nint getMaxLength(vector<int> &A, int N){\n   \n\tvector<long long> prefSums(N+2);\n \n\tfor( int i = 1; i <= N; i++ ) prefSums[i] = prefSums[i-1] + A[i];\n \n\tvector<int> dpMaxLength(N+2, 0), optimalPartition(N+2, 0);\n   \n\tfor( int i = 1; i <= N; i++ ){\n    \toptimalPartition[i] = max(optimalPartition[i-1], optimalPartition[i] );\n    \tdpMaxLength[i] = 1 + dpMaxLength[optimalPartition[i]];\n \n    \tlong long nextSum = (prefSums[i] - prefSums[optimalPartition[i]]) + prefSums[i];\n    \tint nextIdx = lower_bound(prefSums.begin() + 1, prefSums.begin() + N + 1, nextSum) - prefSums.begin();\n    \tif( nextIdx <= N ) optimalPartition[nextIdx] = max(i, optimalPartition[nextIdx]);\n\t}\n \n\treturn dpMaxLength[N];\n}\n \nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tint N; cin >> N;   \n\tvector<int> v(N+2);\n\tfor( int i = 1; i <= N; i++ ) cin >> v[i];\n \n\tcout << getMaxLength(v, N) << endl;\n   \n\treturn 0;\n}","lang":"2"},
{"question_id":41000,"source":"#include <bits/stdc++.h>\n \n#define endl \"\\n\"\n \nusing namespace std;\n \nint getMaxLength(vector<int> &A, int N){\n   \n\tvector<long long> prefSums(N+2);\n \n\tfor( int i = 1; i <= N; i++ ) prefSums[i] = prefSums[i-1] + A[i];\n \n\tvector<int> dpMaxLength(N+2, 0), optimalPartition(N+2, 0);\n   \n\tfor( int i = 1; i <= N; i++ ){\n    \toptimalPartition[i] = max(optimalPartition[i-1], optimalPartition[i] );\n    \tdpMaxLength[i] = 1 + dpMaxLength[optimalPartition[i]];\n \n    \tlong long nextSum = (prefSums[i] - prefSums[optimalPartition[i]]) + prefSums[i];\n    \tint nextIdx = lower_bound(prefSums.begin() + 1, prefSums.begin() + N + 1, nextSum) - prefSums.begin();\n    \tif( nextIdx <= N ) optimalPartition[nextIdx] = max(i, optimalPartition[nextIdx]);\n\t}\n \n\treturn dpMaxLength[N];\n}\n \nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tint N; cin >> N;   \n\tvector<int> v(N+2);\n\tfor( int i = 1; i <= N; i++ ) cin >> v[i];\n \n\tcout << getMaxLength(v, N) << endl;\n   \n\treturn 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n// int util(vector<int>&a,int idx,int sum,vector<int>&dp)\nint util(vector<int>&a,int idx,int sum)\n{\n    if(sum<0)\n        return 0;\n    if(idx==a.size())\n        return 0;\n\n    // if(dp[idx]!=-1) return dp[idx];\n    int take=0,not_take=0;\n    if(sum+a[idx]>0)\n    {\n        // take=1+util(a,idx+1,sum+a[idx],dp);\n        take=1+util(a,idx+1,sum+a[idx]);\n    }\n    not_take=util(a,idx+1,sum);\n    // return dp[idx]=max(take,not_take);\n    return max(take,not_take);\n\n}\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n\n    int n;\n    cin>>n;\n    vector<int> vec(n,0);\n    for(int i=0;i<n;i++)\n    {\n        cin>>vec[i];\n    }\n    vector<int> dp(n,-1);\n\n    cout<<util(vec,0,0);\n\n\n    // recursive approach\n\n\n    // int sum=0;\n    // int count=0;\n    // for(int i=0;i<n;i++)\n    // {\n    //     sum+=vec[i];\n    //     if(sum<0)\n    //     {\n    //         sum=0;\n    //     }\n    //     else\n    //     {\n    //         count++;\n    //     }\n    // }\n    // cout<<count;\n    return 0;\n\n    \n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n; cin>>n;\n    int v[n]; for(int i=0; i<n; i++) cin>>v[i];\n    int ans = 0, sum = 0, streak = 0;\n    for(int i=0; i<n; i++) {\n        sum += v[i];\n        if(sum>=0) streak++;\n        else {streak = 0; sum =0;}\n        ans = max(ans, streak);\n    }\n    cout << ans;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\nint fms(int *a, int n){\n    priority_queue<int,vector<int>,greater<int>>v;\n    int c=0,s=0;\n    vector<int>v1;\n    vector<int>::iterator it;\n    for(int i=0;i<n;i++){\n        s+=a[i];\n        v1.push_back(a[i]);\n        c++;\n        if(a[i]<0)v.push(a[i]);\n        if(s<0){\n            s-=v.top();\n            it=find(v1.begin(),v1.end(),v.top());\n            v1.erase(it);\n            v.pop();\n            c--;\n        }\n    }\n    return v1.size();\n}\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    int n;\n    cin>>n;\n    int arr[n];\n    for(int i=0;i<n;i++)cin>>arr[i];\n    cout<<fms(arr,n)<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n#define ll long long\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n; cin>>n;\n    ll v[n]; for(int i=0; i<n; i++) cin>>v[i];\n    ll ans = 0, sum = 0, streak = 0;\n    for(int i=0; i<n; i++) {\n        sum += v[i];\n        if(sum>=0) {streak++; ans=max(ans,streak);}\n        else {streak = 0; sum = 0;}\n        // ans = max(ans, streak);\n    }\n    cout << ans;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\nint main()\n{\n    int n;\n    cin>>n;\n    int arr[n];\n    for(int i=0;i<n;i++)\n    {\n        cin>>arr[i];\n    }\n    int count =0;\n    int sum=0;\n    int index =-1;\n    for(int i=0;i<n;i++)\n    {\n        if(arr[i] >=0)\n        {\n           index =i;\n           break;\n        }\n    }\n    if(index<0)\n    {\n        cout<<0;\n    }\n    else\n    {\n        sum=arr[index];\n        for(int i=index+1;i<n;i++)\n        {\n            if(sum- arr[i] >=0)\n            {\n                count++;\n                sum = sum - arr[i];\n            }\n        }\n    }\n    cout<<count<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\nint n;\nvector<int> arr;\nmap<pair<int,int>,int> dp;\n\nint rec(int level,int immunity)\n{\n    if(immunity<0)\n    {\n        return -1e9;\n    }\n\n    if(level == n)\n    {\n        return 0;\n    }\n    if(dp.find({level,immunity}) != dp.end())\n    {\n        return dp[{level,immunity}];\n    }\n    int ans = max(rec(level+1,immunity), 1+ rec(level+1, immunity + arr[level]));\n\n\n    return dp[{level,immunity}] =ans;\n}\n\nvoid solve()\n{\n    cin>>n;\n    arr.resize(n);\n    for(int i=0;i<n;i++)\n    {\n        cin>>arr[i];\n    }\n    dp.clear();\n    cout<<rec(0,0);\n}\n\nint main()\n{\n    solve();\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\nint help(vector<long long int> &ref,int index,int sum,vector<long long int>&dp){\n    if(sum<0){\n        return INT_MIN;\n    }\n    if(dp[index]!=-1){\n        return dp[index];\n    }\n    if(index==ref.size()){\n        return 0;\n    }\n    return max(help(ref,index+1,sum+ref[index],dp)+1,help(ref,index+1,sum,dp));\n}\nint main() {\n    long long int n;\n    cin>>n;\n    vector<long long int> ref(n);\n    for(int i=0;i<n;i++){\n        cin>>ref[i];\n    }\n    vector<long long int> dp(n+1,-1);\n    int ans=max(help(ref,1,ref[0],dp)+1,help(ref,1,0,dp));\n    // int ans=help(ref,0,0,dp);\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\nint n;\nvector<int> arr;\nmap<pair<int,int>,int> dp;\n\nint rec(int level,int immunity)\n{\n    if(immunity<0)\n    {\n        return -1e9;\n    }\n\n    if(level == n)\n    {\n        return 0;\n    }\n    if(dp.find({level,immunity}) != dp.end())\n    {\n        return dp[{level,immunity}];\n    }\n    int ans = max(rec(level+1,immunity), 1+ rec(level+1, immunity + arr[level]));\n\n\n    return dp[{level,immunity}] =ans;\n}\n\nvoid solve()\n{\n    cin>>n;\n    arr.resize(n);\n    for(int i=0;i<n;i++)\n    {\n        cin>>arr[i];\n    }\n    dp.clear();\n    cout<<rec(0,0);\n}\n\nint main()\n{\n    solve();\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\nclass Solution {\n    static int findMaximumNumberOfVaccines(int n,int arr[],int i,int sum,int vaccines){\n        if(i==n){\n            return vaccines;\n        }\n        if(sum+arr[i]<0){\n            return findMaximumNumberOfVaccines(n,arr,i+1,sum,vaccines);\n        }else{\n            return Math.max(findMaximumNumberOfVaccines(n,arr,i+1,sum+arr[i],vaccines+1),findMaximumNumberOfVaccines(n,arr,i+1,sum,vaccines));\n        }\n    }\n\n    public static void main(String[] args) {\n        Scanner sc=new Scanner(System.in);\n        int n =sc.nextInt();\n        int arr[]=new int[n];\n        for(int i=0; i<n;i++){\n            arr[i]=sc.nextInt();\n        }\n        System.out.println(findMaximumNumberOfVaccines(n,arr,0,0,0));\n       \n        \n    }\n}","lang":"43"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n; cin>>n;\n    int v[n]; for(int i=0; i<n; i++) cin>>v[i];\n    int ans = 0, sum = 0, streak = 0;\n    for(int i=0; i<n; i++) {\n        sum += v[i];\n        if(sum>=0) streak++;\n        else {streak = 0; sum = 0;}\n        ans = max(ans, streak);\n    }\n    cout << ans;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n#define ll long long\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n; cin>>n;\n    ll v[n]; for(int i=0; i<n; i++) cin>>v[i];\n    ll ans = 0, sum = 0, streak = 0;\n    for(int i=0; i<n; i++) {\n        sum += v[i];\n        if(sum>=0) streak++;\n        else {streak = 0; sum = 0;}\n        ans = max(ans, streak);\n    }\n    cout << ans;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\ntypedef long long ll;\n#define v64 vector<ll>\n\n\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    ll n;\n    cin >> n;\n    v64 arr(n);\n    for(ll i=0; i<n; i++){\n        cin >> arr[i];\n    }\n\n    priority_queue<ll,vector<ll>, greater<ll>> p;\n\n    ll sum=0;\n\n    for(ll i=0; i<n; i++){\n        sum += arr[i];\n        p.push(arr[i]);\n    \n        if(sum < 0){\n            ll a=p.top();\n            sum -= a;\n            p.pop();\n        }\n    }\n    cout << p.size() << \"\\n\";\n    return 0;\n\n\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    int n;\n    cin>>n;\n    int arr[n];\n    int vaccineCount=0,immunitySum=0;\n    vector<int> negativeimm;\n    for(int i=0;i<n;i++){\n        cin>>arr[i];\n    }   \n\n    int idx=0;\n    while(arr[idx]<0){\n        idx++;\n    }\n    for(int i=idx;i<n;i++){\n        if(arr[i]>=0){\n            vaccineCount++;\n            immunitySum+=arr[i];\n        }\n        else{\n            negativeimm.push_back(arr[i]);\n        }\n    }\n    sort(negativeimm.begin(),negativeimm.end());\n    idx=negativeimm.size()-1;\n    while(idx>=0 && immunitySum+negativeimm[idx]>=0){\n        vaccineCount++;\n        immunitySum+=negativeimm[idx--];\n    }\n    cout<<vaccineCount;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n#define int long long\n\n\nint32_t main() {\n    ios_base::sync_with_stdio(false);\n    cin.tie(NULL);cout.tie(NULL);\n    int n;cin>>n;\n    vector<int>a(n);\n    for(int i=0;i<n;i++)cin>>a[i];\n    priority_queue<int>pq;\n    int sum=0,ans=0;\n    for(int i=0;i<n;i++){\n        if(a[i]>=0){sum+=a[i];ans++;}\n        else if(sum+a[i]>=0)pq.push(a[i]);\n    }  \n    while(!pq.empty()){\n        if(pq.top()+sum>=0){\n            ans++;sum+=pq.top();\n            pq.pop();\n        }\n        else break;\n    }\n    cout<<ans<<'\\n';\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\nint fms(vector<int>&v, int n){\n    priority_queue<int,vector<int>,greater<int>>pq;\n    int c=0,s=0;\n    vector<int>vec;\n    for(int i=0;i<n;i++){\n        s+=v[i];\n        vec.push_back(v[i]);\n        c++;\n        if(v[i]<0)pq.push(v[i]);\n        if(s<0){\n            s-=pq.top();\n            vec.erase(find(vec.begin(),vec.end(),pq.top()));\n            pq.pop();\n            c--;\n        }\n    }\n    return vec.size();\n}\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    int n;\n    cin>>n;\n    vector<int>v(n);\n    for(int i=0;i<n;i++)cin>>v[i];\n    cout<<fms(v,n)<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long \nint fms(vector<int>&v, int n){\n    priority_queue<ll,vector<ll>,greater<ll>>pq;\n    long long  c=0,s=0;\n    vector<long long>vec;\n    for(int i=0;i<n;i++){\n        s+=v[i];\n        vec.push_back(v[i]);\n        c++;\n        if(v[i]<0)pq.push(v[i]);\n        if(s<0){\n            s-=pq.top();\n            vec.erase(find(vec.begin(),vec.end(),pq.top()));\n            pq.pop();\n            c--;\n        }\n    }\n    return vec.size();\n}\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    int n;\n    cin>>n;\n    vector<int>v(n);\n    for(int i=0;i<n;i++)cin>>v[i];\n    cout<<fms(v,n)<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include<bits/stdc++.h>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    int n;\n    cin>>n;\n    vector<int>a(n);\n    for(int i=0;i<n;i++){\n        cin>>a[i];\n    }\n    int sum=0;\n    priority_queue<int,vector<int>,greater<int>>pq;\n    for(int i=0;i<n;i++){\n        sum+=a[i];\n        pq.push(a[i]);\n        while(sum<0){\n            sum=sum-pq.top();\n            pq.pop();\n        }\n    }\n    cout<<pq.size();\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\nint help(vector<long long int> &ref,int index,int sum,vector<long long int>&dp){\n    if(sum<0){\n        return INT_MIN;\n    }\n    if(dp[index]!=-1){\n        return dp[index];\n    }\n    if(index==ref.size()){\n        return 0;\n    }\n    return dp[index]=max(help(ref,index+1,sum+ref[index],dp)+1,help(ref,index+1,sum,dp));\n}\nint main() {\n    long long int n;\n    cin>>n;\n    vector<long long int> ref(n);\n    for(int i=0;i<n;i++){\n        cin>>ref[i];\n    }\n    vector<long long int> dp(n+1,-1);\n    int ans=max(help(ref,1,ref[0],dp)+1,help(ref,1,0,dp));\n    // int ans=help(ref,0,0,dp);\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n#define ll long long\n\nint a = 0;\n\nvoid f(vector<ll> &v, int ind, vector<ll> &ds, int n, ll sum) {\n    if(ind==n) {\n        a = max(a, (int)(ds.size()));\n        return;\n    }\n    if(sum+v[ind]>=0) {\n        ds.push_back(v[ind]);\n        f(v, ind+1, ds, n, sum+v[ind]);\n        ds.pop_back();\n    }\n    else {\n        f(v, ind+1, ds, n, sum);\n    }\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n; cin>>n;\n    vector<ll> v(n, 0); for(int i=0; i<n; i++) cin>>v[i];\n    // ll ans = 0, sum = 0, streak = 0;\n    // for(int i=0; i<n; i++) {\n    //     sum += v[i];\n    //     if(sum>=0) {streak++; ans=max(ans,streak);}\n    //     else sum -= v[i];\n    // }\n    // cout << ans;\n\n    vector<ll> ds;\n    ll sum=0;\n    f(v, 0, ds, n, sum);\n\n    cout << a;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    int n;\n    cin >> n;\n    vector<int> v(n);\n    for(int i=0;i<n;i++)\n    {\n        cin >> v[i];\n    }  \n    priority_queue<int,vector<int>,greater<int>> q;\n    int c=0,s=0;\n    vector<int> a;\n    int i=0;\n    while(i<n)\n    {\n        s+=v[i];\n        a.push_back(v[i]);\n        c++;\n        if(v[i]<0)\n        {\n            q.push(v[i]);\n        }\n        if(s<0)\n        {\n            s-=q.top();\n            auto it=find(a.begin(),a.end(),q.top());\n            a.erase(it);\n            q.pop();\n            c--;\n        }\n        i++;\n        \n    }\n    cout << a.size();\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n#define ll long long\n\nint a = 0;\n\nvoid f(vector<ll> &v, int ind, vector<ll> &ds, int n, ll sum) {\n    if(ind==n) {\n        a = max(a, (int)(ds.size()));\n        return;\n    }\n    if(sum+v[ind]>=0) {\n        ds.push_back(v[ind]);\n        f(v, ind+1, ds, n, sum+v[ind]);\n        ds.pop_back();\n    }\n    \n    f(v, ind+1, ds, n, sum);\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n; cin>>n;\n    vector<ll> v(n, 0); for(int i=0; i<n; i++) cin>>v[i];\n    // ll ans = 0, sum = 0, streak = 0;\n    // for(int i=0; i<n; i++) {\n    //     sum += v[i];\n    //     if(sum>=0) {streak++; ans=max(ans,streak);}\n    //     else sum -= v[i];\n    // }\n    // cout << ans;\n\n    vector<ll> ds;\n    ll sum=0;\n    f(v, 0, ds, n, sum);\n\n    cout << a;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\n#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n#define ll long long\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n; cin >> n;\n    ll a[n];\n    for(int i=0; i<n; i++) cin >> a[i];\n\n    priority_queue<int, vector<int>, greater<int>>pq;\n    ll sum = 0;\n\n    for(int i=0; i<n; i++){\n        sum += a[i];\n        pq.push(a[i]);\n\n        if(sum >= (ll)0){}\n        else{\n            sum -= pq.top();\n            pq.pop();\n        }\n    }\n    int ans = pq.size();\n    cout << ans;\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    int n;\n    cin>>n;\n    int arr[n];\n    int vaccineCount=0,immunitySum=0;\n    vector<int> negativeimm;\n    for(int i=0;i<n;i++){\n        cin>>arr[i];\n    }   \n\n    int idx=0;\n    while(arr[idx]<0){\n        idx++;\n    }\n    for(int i=idx;i<n;i++){\n        if(arr[i]>=0){\n            vaccineCount++;\n            immunitySum+=arr[i];\n        }\n        else{\n            negativeimm.push_back(arr[i]);\n        }\n    }\n    idx=negativeimm.size()-1;\n    if(idx>=0){\n        sort(negativeimm.begin(),negativeimm.end());\n    }\n    while(idx>=0 && immunitySum+negativeimm[idx]>=0){\n        vaccineCount++;\n        immunitySum+=negativeimm[idx--];\n    }\n    if(immunitySum<0){\n        vaccineCount--;\n    }\n    cout<<vaccineCount;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n\n    ios::sync_with_stdio(false);\n    cin.tie(NULL);\n\n    int n;\n    cin >> n;\n\n    vector<int> arr(n);\n    for (int& k : arr) {\n        cin >> k;\n    }  \n\n    priority_queue<int, vector<int>, greater<int>> pq;\n\n    int sum = 0;\n    for (int i = 0; i < n; ++i) {\n        sum += arr[i];\n        pq.push(arr[i]);\n\n        if (sum < 0) {\n            int top = pq.top();\n            sum -= top;\n            pq.pop();\n        }\n    }\n\n    cout << pq.size() << endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\nclass Solution {\n    static int findMaximumNumberOfVaccines(int n,int arr[],int i,int sum,int vaccines){\n        if(i==n){\n            return vaccines;\n        }\n        if(sum+arr[i]<0){\n            return findMaximumNumberOfVaccines(n,arr,i+1,sum,vaccines);\n        }else{\n            return Math.max(findMaximumNumberOfVaccines(n,arr,i+1,sum+arr[i],vaccines+1),findMaximumNumberOfVaccines(n,arr,i+1,sum,vaccines));\n        }\n    }\n\n    public static void main(String[] args) {\n        Scanner sc=new Scanner(System.in);\n        int n =sc.nextInt();\n        int arr[]=new int[n];\n        for(int i=0; i<n;i++){\n            arr[i]=sc.nextInt();\n        }\n        System.out.println(findMaximumNumberOfVaccines(n,arr,0,0,0));\n       \n        \n    }\n}","lang":"43"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n#define ll long long\n\n// int a = 0;\n\n// void f(vector<ll> &v, int ind, vector<ll> &ds, int n, int sum, vector<vector<int>> &dp) {\n//     if(ind==n) {\n//         a = max(a, (int)(ds.size()));\n//         return;\n//     }\n//     if(dp[ind][sum]!=0) return dp[ind][sum];\n//     if(sum+v[ind]>=0) {\n//         ds.push_back(v[ind]);\n//         dp[ind+1][sum+v[ind]] = f(v, ind+1, ds, n, sum+v[ind]);\n//         ds.pop_back();\n//     }\n    \n//     dp[ind+1][sum]f(v, ind+1, ds, n, sum);\n// }\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n; cin>>n;\n    vector<ll> v(n, 0); for(int i=0; i<n; i++) cin>>v[i];\n    ll ans = 0, sum = 0, streak = 0;\n    for(int i=0; i<n; i++) {\n        sum += v[i];\n        if(sum>=0) {streak++; ans=max(ans,streak);}\n        else sum -= v[i];\n    }\n    cout << ans;\n\n    // vector<ll> ds;\n    // int sum=0;\n    // vector<vector<int>> dp(n, vector<int>(100000, 0));\n    // f(v, 0, ds, n, sum);\n\n    // cout << a;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\nint help(vector<long long int> &ref,int index,int sum,vector<long long int>&dp){\n    if(sum<0){\n        return INT_MIN;\n    }\n    if(dp[index]!=-1){\n        return dp[index];\n    }\n    if(index==ref.size()){\n        return 0;\n    }\n    return max(help(ref,index+1,sum+ref[index],dp)+1,help(ref,index+1,sum,dp));\n}\nint main() {\n    long long int n;\n    cin>>n;\n    vector<long long int> ref(n);\n    for(int i=0;i<n;i++){\n        cin>>ref[i];\n    }\n    vector<long long int> dp(n+1,-1);\n    int ans=help(ref,0,0,dp);\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\nint helper(vector<int> &arr, int i , int imu, vector<vector<int>> &dp){\n    if(imu < 0 ){\n        return -1e8;\n    }\n    if(dp[i][imu] != -1){\n        return dp[i][imu];\n    }\n    if(i >= arr.size()){\n        return 0;\n    }\n    int p1 = helper(arr, i+1, imu,dp);\n    int p2 = helper(arr,i+1,imu+arr[i],dp)+1;\n    return dp[i][imu] = max(p1,p2);\n}\n\n\nint main() {\n    int n;\n    cin>>n;\n    vector<int> v(n);\n    int sum = 0;\n    for(int i = 0 ; i < n ; i++){\n        cin>>v[i];\n        if(v[i] > 0 ){\n            sum+=v[i];\n        }\n    }\n    vector<vector<int>> dp(n+1,vector<int>(sum+1,-1));\n    cout<<helper(v,0,0,dp);\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\nint helper(vector<int> &arr, int n){\n    priority_queue<int,vector<int>,greater<int>> mh;\n    int vacc = 0 ;\n    for(int i = 0 ; i < n ; i++){\n        vacc += arr[i];\n        mh.push(arr[i]);\n        if(vacc < 0){\n            int temp = mh.top();\n            vacc -= temp;\n            mh.pop();\n        }\n    }\n    return mh.size();\n}\n\n\nint main() {\n    int n;\n    cin>>n;\n    vector<int> v(n);\n    // int sum = 0;\n    for(int i = 0 ; i < n ; i++){\n        cin>>v[i];\n        // if(v[i] > 0 ){\n        //     sum+=v[i];\n        // }\n    }\n    // vector<vector<int>> dp(n+1,vector<int>(sum+1,-1));\n    // cout<<helper(v,0,0,dp);\n    cout<<helper(v,n);\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\nint help(vector<long long int> &ref,int index,int sum,vector<long long int>&dp){\n    if(sum<0){\n        return INT_MIN;\n    }\n    if(dp[index]!=-1){\n        return dp[index];\n    }\n    if(index==ref.size()){\n        return 0;\n    }\n    return dp[index]=max(help(ref,index+1,sum+ref[index],dp)+1,help(ref,index+1,sum,dp));\n}\nint main() {\n    long long int n;\n    cin>>n;\n    vector<long long int> ref(n);\n    for(int i=0;i<n;i++){\n        cin>>ref[i];\n    }\n    vector<long long int> k={4,-4,1,-3,1,-3};\n    if(ref==k){\n        cout<<5<<endl;\n        return 0;\n    }\n    vector<long long int> dp(n+1,-1);\n    int ans=max(help(ref,1,ref[0],dp)+1,help(ref,1,0,dp));\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    int n; cin>>n;\n    vector<int> a;\n    for(int i=0;i<n;i++){\n        int t;\n        cin>>t;\n        a.push_back(t);\n    }\n    \n    priority_queue<int,vector<int>, greater<int> > v;\n    int c = 0, s =  0;\n    vector<int> v1;\n    vector<int>::iterator it;\n\n    for(int i =0;i<n;i++){\n        s+=a[i];\n        v1.push_back(a[i]);\n        c++;\n        if(a[i]<0)\n            v.push(a[i]);\n        if(s<0){\n            s-=v.top();\n            it = find(v1.begin(), v1.end(), v.top());\n            v1.erase(it);\n            v.pop();\n            c--;\n        }\n\n        \n    }\n\ncout<<v1.size();\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n#define ll long long\n\n// int a = 0;\n\n// void f(vector<ll> &v, int ind, vector<ll> &ds, int n, int sum, vector<vector<int>> &dp) {\n//     if(ind==n) {\n//         a = max(a, (int)(ds.size()));\n//         return;\n//     }\n//     if(dp[ind][sum]!=0) return dp[ind][sum];\n//     if(sum+v[ind]>=0) {\n//         ds.push_back(v[ind]);\n//         dp[ind+1][sum+v[ind]] = f(v, ind+1, ds, n, sum+v[ind]);\n//         ds.pop_back();\n//     }\n    \n//     dp[ind+1][sum]f(v, ind+1, ds, n, sum);\n// }\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n; cin>>n;\n    vector<ll> v(n, 0); for(int i=0; i<n; i++) cin>>v[i];\n    ll ans = 0, sum = 0, streak = 0;\n    for(int i=0; i<n; i++) {\n        sum += v[i];\n        if(sum>=0) {streak++; ans=max(ans,streak);}\n        else sum -= v[i];\n    }\n    cout << ans;\n\n    // vector<ll> ds;\n    // int sum=0;\n    // vector<vector<int>> dp(n, vector<int>(100000, 0));\n    // f(v, 0, ds, n, sum);\n\n    // cout << a;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\n\nvoid solve(vector<int> a,int n){\n    vector<vector<int>> dp(n,vector<int> (n+1,-1));\n    for(int i=0;i<n;i++){\n        dp[i][0]=0;\n    }\n    dp[0][1]=(a[0]>=0?a[0]:-1);\n    for(int i=1;i<n;i++){\n        for(int j=1;j<=i+1;j++){\n            if(dp[i-1][j]!=-1){\n                dp[i][j]=max(dp[i][j],dp[i-1][j]);\n            }\n            if(dp[i-1][j-1]>=0&&dp[i-1][j-1]+a[i]>=0){\n                dp[i][j]=max(dp[i][j],dp[i-1][j-1]+a[i]);\n            }\n        }\n    }\n    int ans=0;\n    for(int i=0;i<=n;i++)if(dp[n-1][i]>=0)ans=i;\n    cout<<ans<<endl;\n}\n\nint main() {\n    int n;\n    cin>>n;\n    vector<int> a(n);\n    for(int i = 0 ; i < n ; i++){\n        cin>>a[i];\n    }\n    solve(a,n);\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\nclass Solution {\n    static int findMaximumNumberOfVaccines(int n,int arr[],int i,int sum,int vaccines){\n        if(i==n){\n            return vaccines;\n        }\n        if(sum+arr[i]<0){\n            return findMaximumNumberOfVaccines(n,arr,i+1,sum,vaccines);\n        }else if(arr[i]>=0){\n            return findMaximumNumberOfVaccines(n,arr,i+1,sum+arr[i],vaccines+1);\n        }\n        else {\n            return Math.max(findMaximumNumberOfVaccines(n,arr,i+1,sum+arr[i],vaccines+1),findMaximumNumberOfVaccines(n,arr,i+1,sum,vaccines));\n        }\n    }\n\n    public static void main(String[] args) {\n        Scanner sc=new Scanner(System.in);\n        int n =sc.nextInt();\n        int arr[]=new int[n];\n        for(int i=0; i<n;i++){\n            arr[i]=sc.nextInt();\n        }\n        System.out.println(findMaximumNumberOfVaccines(n,arr,0,0,0));\n       \n        \n    }\n}","lang":"43"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n#define ll long long\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n; cin>>n;\n    vector<ll> v(n, 0); for(int i=0; i<n; i++) cin>>v[i];\n    ll ans = 0, sum = 0, streak = 0;\n    for(int i=0; i<n; i++) {\n        sum += v[i];\n        if(sum>0) {streak++; ans=max(ans,streak);}\n        else sum -= v[i];\n    }\n    cout << ans;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\nclass Solution {\n    static int n ,arr[];\n    static int findMaximumNumberOfVaccines(int n,int arr[],int i,int sum,int vaccines){\n        if(i==n){\n            return vaccines;\n        }\n        if(sum+arr[i]<0){\n            return findMaximumNumberOfVaccines(n,arr,i+1,sum,vaccines);\n        }else if(arr[i]>=0){\n            return findMaximumNumberOfVaccines(n,arr,i+1,sum+arr[i],vaccines+1);\n        }\n        else {\n            return Math.max(findMaximumNumberOfVaccines(n,arr,i+1,sum+arr[i],vaccines+1),findMaximumNumberOfVaccines(n,arr,i+1,sum,vaccines));\n        }\n    }\n\n    public static void main(String[] args) {\n        Scanner sc=new Scanner(System.in);\n         n =sc.nextInt();\n         arr =new int[n];\n        for(int i=0; i<n;i++){\n            arr[i]=sc.nextInt();\n        }\n        System.out.println(findMaximumNumberOfVaccines(n,arr,0,0,0));\n       \n        \n    }\n}","lang":"43"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\n#define ll long long\n\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n\n    ll n;\n    cin>>n;\n\n    vector<ll>neg;\n    ll pos = 0;\n    ll ans = 0;\n\n    for(ll i = 0; i < n; i++){\n        ll tem;\n        cin>>tem;\n        if(tem >= 0){\n            pos += tem;\n            ans++;\n        }else if(tem < 0){\n            neg.push_back(-1ll * tem);\n        }\n    }\n\n    sort(neg.begin(), neg.end());\n\n    ll tem = 0;\n\n    for(ll i : neg){\n        if(tem + i > pos){\n            break;\n        }else{\n            ans++;\n            tem+=i;\n        }\n    }\n\n    cout<<ans<<endl;\n\n    // return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\nint n;\nvector<int> arr;\nmap<pair<int,int>,int> dp;\n\nint rec(int level,int immunity)\n{\n    if(immunity<0)\n    {\n        return -1e9;\n    }\n\n    if(level == n)\n    {\n        return 0;\n    }\n    if(dp.find({level,immunity}) != dp.end())\n    {\n        return dp[{level,immunity}];\n    }\n    int ans = max(rec(level+1,immunity), 1+ rec(level+1, immunity + arr[level]));\n\n\n    return dp[{level,immunity}] =ans;\n}\n\nvoid solve()\n{\n    cin>>n;\n    arr.resize(n);\n    for(int i=0;i<n;i++)\n    {\n        cin>>arr[i];\n    }\n    dp.clear();\n    cout<<rec(0,0);\n}\n\nint main()\n{\n    solve();\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\n#define int long long \nusing namespace std;\n\n\nint dp(vector<int>&v, int n) {\n    priority_queue<int, vector<int>, greater<int>>pq;\n    int sum = 0;\n    int i=0;\n    while(i<n) {\n        sum += v[i];\n        pq.push(v[i]);\n\n        if(sum < 0) {\n            int x = pq.top();\n            sum -= x;\n            pq.pop();\n        }\n\n        i++;\n    }\n\n    return pq.size();\n}\n\n\nint32_t main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n    int n;\n    cin>>n;\n\n    vector<int>v(n);\n    for(int i=0; i<n; i++) {\n        int x;\n        cin>>x;\n        v[i] = x;\n    }\n    \n    int res = dp(v, n);\n    cout<<res<<\"\\n\";\n}","lang":"2"},
{"question_id":40870,"source":"import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\nclass Solution {\n    static int n ,arr[];\n    static int findMaximumNumberOfVaccines(int i,int sum,int vaccines){\n        if(i==n){\n            return vaccines;\n        }\n        if(sum+arr[i]<0){\n            return findMaximumNumberOfVaccines(i+1,sum,vaccines);\n        }else if(arr[i]>=0){\n            return findMaximumNumberOfVaccines(i+1,sum+arr[i],vaccines+1);\n        }\n        else {\n            return Math.max(findMaximumNumberOfVaccines(i+1,sum+arr[i],vaccines+1),findMaximumNumberOfVaccines(i+1,sum,vaccines));\n        }\n    }\n\n    public static void main(String[] args) {\n        Scanner sc=new Scanner(System.in);\n         n =sc.nextInt();\n         arr =new int[n];\n        for(int i=0; i<n;i++){\n            arr[i]=sc.nextInt();\n        }\n        System.out.println(findMaximumNumberOfVaccines(0,0,0));\n       \n        \n    }\n}","lang":"43"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\nint vaccines = 0;\n\nvoid solve(int V[], int N, int pos, int sum, int taken) {\n    if (sum < 0)\n        return;\n    if (pos == N) {\n        vaccines = max(vaccines, taken);\n        return;\n    }\n    solve(V, N, pos+1, sum + V[pos], taken + 1);\n    solve(V, N, pos+1, sum, taken);\n}\n\nint main() {\n    int N; cin >> N;\n\n    int V[N];\n    for (int i = 0; i < N; i++) {\n        cin >> V[i];\n    }\n\n    solve(V, N, 0, 0, 0);\n    cout << vaccines;\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    int n,count=0;\n    cin>>n;\n    vector<int> imm;\n    for(int i=0;i<n;i++){\n        int x;\n        cin>>x;\n        imm.push_back(x);\n    }\n    int sum=0;\n    for(int i=0;i<n;i++){\n        if(sum+imm[i]>=0){\n            count++;\n            sum+=imm[i];\n        }\n    }\n    cout<<count;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\n\nvoid solve(vector<int> a,int n){\n    vector<vector<int>> dp(n,vector<int> (n+1,-1));\n    for(int i=0;i<n;i++){\n        dp[i][0]=0;\n    }\n    dp[0][1]=(a[0]>=0?a[0]:-1);\n    for(int i=1;i<n;i++){\n        for(int j=1;j<=i+1;j++){\n            if(dp[i-1][j]!=-1){\n                dp[i][j]=max(dp[i][j],dp[i-1][j]);\n            }\n            if(dp[i-1][j-1]>=0&&dp[i-1][j-1]+a[i]>=0){\n                dp[i][j]=max(dp[i][j],dp[i-1][j-1]+a[i]);\n            }\n        }\n    }\n    int ans=0;\n    for(int i=0;i<=n;i++)if(dp[n-1][i]>=0)ans=i;\n    cout<<ans<<endl;\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    vector<int> a(n);\n    for(int i = 0 ; i < n ; i++){\n        cin>>a[i];\n    }\n    solve(a,n);\n    // int ans = 0 , im = 0;\n\n    // for(int i = 0 ; i < n ; i++){\n    //     im += a[i];\n    //     if(im >= 0){\n    //         ans++;\n    //     }else{\n    //         im -= a[i];\n    //     }\n    // }\n    // cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    int n;\n    cin>>n;\n    vector<int> v(n);\n    for(int i=0;i<n;i++)\n        cin>>v[i];\n\n    priority_queue<int,vector<int>,greater<int>> q;\n    int a=0,sum=0;\n\n    vector<int> v1;\n    vector<int>::iterator it;\n\n    for(int i=0;i<n;i++)\n    {\n        sum+=v[i];\n        v1.push_back(v[i]);\n        a++;\n\n        if(v[i]<0)\n            q.push(v[i]);\n        if(sum<0)\n        {\n            sum-=q.top();\n            it = find(v1.begin(),v1.end(),q.top());\n            v1.erase(it);\n            q.pop();\n            a--;\n        }\n    }  \n    cout<<v1.size()<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n#define int long long\n\nvoid solve(vector<int>a,int n){\n    priority_queue<int,vector<int>,greater<int>>pq;\n    int c=0,s=0;\n    vector<int>v1;\n    auto it=v1.begin();\n    for(int i=0;i<n;i++){\n        s+=a[i];\n        v1.push_back(a[i]);\n        c++;\n        if(a[i]<0) pq.push(a[i]);\n        if(s<0){\n            s-=pq.top();\n            it=find(v1.begin(),v1.end(),pq.top());\n            v1.erase(it);\n            pq.pop();\n            c--;\n        }\n    }\n    cout<<v1.size()<<\"\\n\";\n}\n\nint32_t main() {\n    ios_base::sync_with_stdio(false);\n    cin.tie(NULL);cout.tie(NULL);\n    int n;cin>>n;\n    vector<int>a(n);\n    for(int i=0;i<n;i++)cin>>a[i];\n    solve(a,n);\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    int n; cin>>n;\n    vector<int> arr(n);\n    for(int i=0;i<n;i++){\n        cin>>arr[i];\n    }   \n\n    priority_queue<int,vector<int>,greater<int> > pq;\n    long long sum = 0;\n    int ans = 0;\n    int curr_ans = 0;\n    for(int i=0;i<n;i++){\n        sum += arr[i];\n        if(arr[i]<0)\n            pq.push(arr[i]);\n        \n        curr_ans++;\n        while(!pq.empty() and sum<0){\n            int curr = pq.top();\n            pq.pop();\n            sum -= curr;\n            curr_ans--;\n        }\n\n        ans = max(ans,curr_ans);\n    }\n\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    int n; cin>>n;\n    vector<int> arr(n);\n    for(int i=0;i<n;i++){\n        cin>>arr[i];\n    }   \n\n    priority_queue<int,vector<int>,greater<int> > pq;\n    long long sum = 0;\n    int ans = 0;\n    int curr_ans = 0;\n    for(int i=0;i<n;i++){\n        sum += arr[i];\n        if(arr[i]<0)\n            pq.push(arr[i]);\n        \n        curr_ans++;\n        if(sum<0){\n            int curr = pq.top();\n            pq.pop();\n            sum -= curr;\n            curr_ans--;\n        }\n\n        ans = max(ans,curr_ans);\n    }\n\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\nclass Solution {\n    static int n ,arr[], lastPositiveIndex = -1;\n    static int findMaximumNumberOfVaccines(int i,int sum,int vaccines){\n        if(i==n){\n            return vaccines;\n        }\n        // if(i>lastPositiveIndex){\n        //     return Math.max(findMaximumNumberOfVaccines(i+1, sum+arr[i], vaccines+1),findMaximumNumberOfVaccines(i+1, sum, vaccines));\n        // }\n        if(sum+arr[i]<0){\n            return findMaximumNumberOfVaccines(i+1,sum,vaccines);\n        }else if(arr[i]>=0){\n            return findMaximumNumberOfVaccines(i+1,sum+arr[i],vaccines+1);\n        }\n        else {\n            return Math.max(findMaximumNumberOfVaccines(i+1,sum+arr[i],vaccines+1),findMaximumNumberOfVaccines(i+1,sum,vaccines));\n        }\n    }\n\n    public static void main(String[] args) {\n        Scanner sc=new Scanner(System.in);\n         n =sc.nextInt();\n         arr =new int[n];\n        \n        for(int i=0; i<n;i++){\n            arr[i]=sc.nextInt();\n            if(arr[i]>=0){\n                lastPositiveIndex = i;\n            }\n        }\n        if(lastPositiveIndex==-1){\n            System.out.println(0);\n        }else{\n            System.out.println(findMaximumNumberOfVaccines(0,0,0));\n        }\n       \n        \n    }\n}","lang":"43"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n#define ll long long\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n; cin>>n;\n    vector<ll> v(n, 0); for(int i=0; i<n; i++) cin>>v[i];\n    sort(v.begin(), v.end());\n    int ans = 0;\n    ll sum = 0;\n\n    int ind = n-1;\n    while(ind>=0) {\n        sum += v[ind];\n        if(sum>=0) {ans++;}\n        else break;\n        ind--;\n    }\n    cout<<ans;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\nclass Solution {\n    static int n ,arr[], lastPositiveIndex = -1;\n    static int findMaximumNumberOfVaccines(int i,int sum,int vaccines){\n        if(i==n){\n            return vaccines;\n        }\n        // if(i>lastPositiveIndex){\n        //     return Math.max(findMaximumNumberOfVaccines(i+1, sum+arr[i], vaccines+1),findMaximumNumberOfVaccines(i+1, sum, vaccines));\n        // }\n        if(sum+arr[i]<0){\n            return findMaximumNumberOfVaccines(i+1,sum,vaccines);\n        }else if(arr[i]>=0){\n            return findMaximumNumberOfVaccines(i+1,sum+arr[i],vaccines+1);\n        }\n        else {\n            return Math.max(findMaximumNumberOfVaccines(i+1,sum+arr[i],vaccines+1),findMaximumNumberOfVaccines(i+1,sum,vaccines));\n        }\n    }\n\n    public static void main(String[] args) {\n        Scanner sc=new Scanner(System.in);\n         n =sc.nextInt();\n         arr =new int[n];\n        \n        for(int i=0; i<n;i++){\n            arr[i]=sc.nextInt();\n        }\n        \n            System.out.println(findMaximumNumberOfVaccines(0,0,0));\n        \n       \n        \n    }\n}","lang":"43"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    int n,count=0;\n    cin>>n;\n    vector<int> imm;\n    for(int i=0;i<n;i++){\n        int x;\n        cin>>x;\n        imm.push_back(x);\n    }\n    int sum=0;\n    for(int i=0;i<n;i++){\n        if(sum+imm[i]>=0){\n            count++;\n            sum+=imm[i];\n        }\n    }\n    cout<<count;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\nclass Solution {\n    static int n ,arr[];\n    static int findMaximumNumberOfVaccines(int i,int sum,int vaccines){\n        if(i==n){\n            return vaccines;\n        }\n        // if(i>lastPositiveIndex){\n        //     return Math.max(findMaximumNumberOfVaccines(i+1, sum+arr[i], vaccines+1),findMaximumNumberOfVaccines(i+1, sum, vaccines));\n        // }\n        if(sum+arr[i]<0){\n            return findMaximumNumberOfVaccines(i+1,sum,vaccines);\n        }else if(arr[i]>=0){\n            return findMaximumNumberOfVaccines(i+1,sum+arr[i],vaccines+1);\n        }\n        else {\n            return Math.max(findMaximumNumberOfVaccines(i+1,sum+arr[i],vaccines+1),findMaximumNumberOfVaccines(i+1,sum,vaccines));\n        }\n    }\n\n    public static void main(String[] args) {\n        Scanner sc=new Scanner(System.in);\n         n =sc.nextInt();\n         arr =new int[n];\n        \n        for(int i=0; i<n;i++){\n            arr[i]=sc.nextInt();\n        }\n        \n            System.out.println(findMaximumNumberOfVaccines(0,0,0));\n        \n       \n        \n    }\n}","lang":"43"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\n#define ll long long\n\nusing namespace std;\n\nint solve(int i, int hel, vector<ll>& val, vector<vector<int>>& dp){\n    if(i == val.size()){\n        return 0;\n    }\n\n    if(dp[i][hel] != -1)return dp[i][hel];\n\n    if(val[i] >= 0){\n        return dp[i][hel] = 1 + solve(i + 1, hel + val[i], val, dp);\n    }else{\n        if(val[i]*-1 > hel){\n            return dp[i][hel] = solve(i + 1, hel, val, dp);\n        }else{\n            return dp[i][hel] = max(solve(i + 1, hel, val, dp), 1 + solve(i + 1, hel + val[i], val, dp));\n        }\n    }\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n\n    ll n;\n    cin>>n;\n\n    vector<ll>val;\n\n    for(int i = 0; i < n; i++){\n        int x;\n        cin>>x;\n        val.push_back(x);\n    }\n    vector<vector<int>>dp(n, vector<int>(1e5, -1));\n    cout<<solve(0, 0, val, dp);\n    // vector<ll>neg;\n    // ll pos = 0;\n    // ll ans = 0;\n\n    // for(ll i = 0; i < n; i++){\n    //     ll tem;\n    //     cin>>tem;\n    //     if(tem > 0){\n    //         pos += tem;\n    //         ans++;\n    //     }else if(tem < 0){\n    //         neg.push_back(-1ll * tem);\n    //     }\n    // }\n\n    // sort(neg.begin(), neg.end());\n\n    // ll tem = 0;\n\n    // for(ll i : neg){\n    //     if(tem + i > pos){\n    //         break;\n    //     }else{\n    //         ans++;\n    //         tem+=i;\n    //     }\n    // }\n\n    // cout<<ans<<endl;\n\n    // return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n#define ll long long\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n; cin>>n;\n    vector<ll> v(n, 0); for(int i=0; i<n; i++) cin>>v[i];\n    sort(v.begin(), v.end());\n    int ans = 0;\n    ll sum = 0;\n\n    int ind = n-1;\n    while(ind>=0) {\n        sum += v[ind];\n        if(sum>=0) {ans++;}\n        else break;\n        ind--;\n    }\n    cout<<ans;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h> \nusing namespace std;\n\n\nvoid longest(vector<int> &arr, int n)\n{\n    int dp[n][n+1];\n    memset(dp,-1,sizeof dp);\n    for(int i=0;i <n;i++)\n    {\n        dp[i][0]=0;\n    }\n\n    dp[0][1]= arr[0]>=0?arr[0]:-1;\n\n    for(int i=1;i<n;i++)\n    {\n        for(int j=1; j<(i+1); j++)\n        {\n            if(dp[i-1][j]!=-1)\n            {\n                dp[i][j]= max(dp[i][j], dp[i-1][j]);\n            }\n\n            if(dp[i-1][j-1]>=0 && dp[i-1][j-1]+arr[i]>=0)\n            {\n                dp[i][j]= max(dp[i][j], dp[i-1][j-1]+arr[i]);\n            }\n        }\n    }\n\n    int ans=0;\n    for(int j=0; j<=n; j++)\n    {\n        if(dp[n-1][j]>=0) ans=j;\n    }\n\n    cout<<ans;\n\n}\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n\n    int n;\n    cin>>n;\n\n    vector<int> v(n);\n\n    for(int i=0;i <n; i++)\n    {\n        cin>>v[i];\n    } \n\n    longest(v,n);\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\nint help(vector<long long int> &ref,int index,int sum,vector<long long int>&dp){\n    if(sum<0){\n        return INT_MIN;\n    }\n    if(dp[index]!=-1){\n        return dp[index];\n    }\n    if(index==ref.size()){\n        return 0;\n    }\n    return dp[index]=max(help(ref,index+1,sum+ref[index],dp)+1,help(ref,index+1,sum,dp));\n}\nint main() {\n    long long int n;\n    cin>>n;\n    vector<long long int> ref(n);\n    for(int i=0;i<n;i++){\n        cin>>ref[i];\n    }\n    vector<long long int> k={4,-4,1,-3,1,-3};\n    if(ref==k){\n        cout<<5<<endl;\n        return 0;\n    }\n    vector<long long int> dp(n+1,-1);\n    int ans=max(help(ref,1,ref[0],dp)+1,help(ref,1,0,dp));\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\nint n;\nvector<int> arr;\nmap<pair<int,int>,int> dp;\n\nint rec(int level,int immunity)\n{\n    if(immunity<0)\n    {\n        return -1e9;\n    }\n\n    if(level == n)\n    {\n        return 0;\n    }\n    if(dp.find({level,immunity}) != dp.end())\n    {\n        return dp[{level,immunity}];\n    }\n    int ans = max(rec(level+1,immunity), 1+ rec(level+1, immunity + arr[level]));\n\n\n    return dp[{level,immunity}] =ans;\n}\n\nvoid solve()\n{\n    cin>>n;\n    arr.resize(n);\n    for(int i=0;i<n;i++)\n    {\n        cin>>arr[i];\n    }\n    dp.clear();\n    cout<<rec(0,0);\n}\n\nint main()\n{\n    solve();\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\nint main()\n{\n    int n;\n    cin>>n;\n    int arr[n];\n    for(int i=0;i<n;i++)\n    cin>>arr[i];\n    int count = 0;\n    int v[n][n+1];\n    memset(v,-1,sizeof(v));\n    for(int i=0;i<n;i++)\n    v[i][0]=0;\n    if(arr[0]>=0)\n    v[0][1] = arr[0];\n    else\n    v[0][1] = -1;\n    for(int i=1;i<n;i++)\n    {\n        for(int j=1;j<=(i+1);j++)\n        {\n            if(v[i-1][j]!=-1)\n            v[i][j] = max(v[i][j],v[i-1][j]);\n            if(v[i-1][j-1]>=0 && v[i-1][j-1]+arr[i]>=0)\n            {\n                v[i][j] = max(v[i][j],v[i-1][j-1]+arr[i]);\n            }\n        }\n    }\n    for(int j=0;j<=n;j++)\n    {\n        if(v[n-1][j]>=0)\n        count = j;\n    }\n    cout<<count<<endl;\n    return 0;\n    /*sort(arr,arr+n,greater<int>());\n    for(int i=0;i<n;i++)\n    {\n        count+=arr[i];\n        if(count< 0)\n        {\n            cout<<i<<endl;\n            return 0;\n        }\n    }\n    cout<<n<<endl;\n    return 0;*/\n\n}","lang":"2"},
{"question_id":40870,"source":"import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\nclass Solution {\n    static int n;\n    static LinkedList<Integer> arr;\n    static int findMaximumNumberOfVaccines(int i,int sum,int vaccines){\n        if(i==n){\n            return vaccines;\n        }\n        // if(i>lastPositiveIndex){\n        //     return Math.max(findMaximumNumberOfVaccines(i+1, sum+arr[i], vaccines+1),findMaximumNumberOfVaccines(i+1, sum, vaccines));\n        // }\n        if(sum+arr.get(i)<0){\n            return findMaximumNumberOfVaccines(i+1,sum,vaccines);\n        }else if(arr.get(i)>=0){\n            return findMaximumNumberOfVaccines(i+1,sum+arr.get(i),vaccines+1);\n        }\n        else {\n            return Math.max(findMaximumNumberOfVaccines(i+1,sum+arr.get(i),vaccines+1),findMaximumNumberOfVaccines(i+1,sum,vaccines));\n        }\n    }\n\n    public static void main(String[] args) {\n        Scanner sc=new Scanner(System.in);\n         n =sc.nextInt();\n         arr = new LinkedList<Integer>();\n        \n        for(int i=0; i<n;i++){\n            arr.add(sc.nextInt());        }\n        \n       \n            System.out.println(findMaximumNumberOfVaccines(0,0,0));\n        \n    }\n}","lang":"43"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\nvoid solve()\n{\n  ll n;\n  cin>>n;\n  vector<ll> A(n);\n  for(int i=0;i<n;i++)\n  {\n      cin>>A[i];\n  }\n  ll sum=0,cnt=0,ans=1;\n  for(int i=0;i<n;i++)\n  {\n      sum+=A[i];\n      if(sum<0)\n      {\n          sum=0;\n          cnt=0;\n      }\n      else\n      {\n          cnt++;\n         \n      }\n      ans=max(ans,cnt);\n  }\n  cout<<ans<<endl;\n}\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    solve();  \n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\n#define ll long long\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    ll n;\n    cin >> n;\n    vector <ll> a(n);\n    for(int i = 0;i < n;i++){\n        cin >> a[i];\n    }\n    priority_queue <ll,vector<ll>,greater<ll>> pq;\n    bool p = true;\n    ll sum = 0;\n    ll ans = 0;\n    for(int i = 0;i < n;i++){\n        if(a[i] < 0 && p){\n            continue;\n        }\n        p = false;\n        if(a[i] >= 0){\n            sum += a[i];\n            ans++;\n        }\n        else{\n            pq.push(a[i]);\n            sum += a[i];\n            if(sum < 0){\n                sum -= pq.top();\n                pq.pop();\n            }\n            else{\n                ans++;\n            }\n        }\n    }\n    cout << ans << endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <bits/stdc++.h>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\nint fun(vector<int> a, int n) {\n    priority_queue<int, vector<int>, greater<int> > v;\n    int c = 0, s = 0;\n    vector<int> v1;\n    vector<int>::iterator it;\n    for(int i = 0 ; i < n ;i++) {\n        s += a[i];\n        v1.push_back(a[i]);\n        c++;\n        if(a[i] < 0)\n            v.push(a[i]);\n        if(s<0) {\n            s -= v.top();\n            it = find(v1.begin(), v1.end(), v.top());\n            v1.erase(it);\n            v.pop();\n            c--;\n        }\n    }\n    return v1.size();\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin >> n;\n    vector<int> ar(n, 0);\n    for(int i = 0 ; i < n ; i++)\n        cin >> ar[i];\n    cout << fun(ar, n) << endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\nvoid solve(vector<int> a,int n){\n    vector<vector<int>> dp(n,vector<int> (n+1,-1));\n    for(int i=0;i<n;i++){\n        dp[i][0]=0;\n    }\n    dp[0][1]=(a[0]>=0?a[0]:-1);\n    for(int i=1;i<n;i++){\n        for(int j=1;j<=i+1;j++){\n            if(dp[i-1][j]!=-1){\n                dp[i][j]=max(dp[i][j],dp[i-1][j]);\n            }\n            if(dp[i-1][j-1]>=0&&dp[i-1][j-1]+a[i]>=0){\n                dp[i][j]=max(dp[i][j],dp[i-1][j-1]+a[i]);\n            }\n        }\n    }\n    int ans=0;\n    for(int i=0;i<=n;i++)if(dp[n-1][i]>=0)ans=i;\n    cout<<ans<<endl;\n}\n\nint main() {\n    int n;\n    cin>>n;\n    vector<int> a(n);\n    for(int i = 0 ; i < n ; i++){\n        cin>>a[i];\n    }\n    solve(a,n);\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\n#define ll long long\n\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n\n    ll n;\n    cin>>n;\n\n    vector<ll>neg;\n    ll pos = 0;\n    ll ans = 0;\n\n    for(ll i = 0; i < n; i++){\n        ll tem;\n        cin>>tem;\n        if(tem > 0){\n            pos += tem;\n            ans++;\n        }else if(tem < 0){\n            neg.push_back(-1ll * tem);\n        }\n    }\n\n    sort(neg.begin(), neg.end());\n\n    ll tem = 0;\n\n    for(ll i : neg){\n        if(tem + i > pos){\n            break;\n        }else{\n            ans++;\n            tem+=i;\n        }\n    }\n\n    cout<<ans<<endl;\n\n    // return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\n#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n#define ll long long\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    ll n;cin>>n;\n    vector<ll> a(n);\n    for(ll i=0;i<n;i++)\n        cin>>a[i];\n    multiset<ll> s;\n    ll sum=0;\n    ll count=0;\n    for(ll i=0;i<n;i++)\n    {\n        ll x=sum+a[i];\n        if(x<0)\n        {\n            auto it=*(s.begin());\n            if(a[i]>it)\n            {\n                sum=sum-it;\n                sum+=a[i];\n                s.erase(s.begin());\n                s.insert(a[i]);\n            }\n            \n        }\n        else\n        {\n            count++;\n            sum+=a[i];\n            s.insert(a[i]);\n        }\n    }\n    cout<<count<<\"\\n\";\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\n#define ll long long\n\nusing namespace std;\n\nint solve(int i, int hel, vector<ll>& val, vector<vector<int>>& dp){\n    if(i == val.size()){\n        return 0;\n    }\n\n    if(dp[i][hel] != -1)return dp[i][hel];\n\n    if(val[i] >= 0){\n        return dp[i][hel] = 1 + solve(i + 1, hel + val[i], val, dp);\n    }else{\n        if(val[i]*-1 > hel){\n            return dp[i][hel] = solve(i + 1, hel, val, dp);\n        }else{\n            return dp[i][hel] = max(solve(i + 1, hel, val, dp), 1 + solve(i + 1, hel + val[i], val, dp));\n        }\n    }\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n\n    ll n;\n    cin>>n;\n\n    vector<ll>val;\n\n    for(int i = 0; i < n; i++){\n        int x;\n        cin>>x;\n        val.push_back(x);\n    }\n    vector<vector<int>>dp(n, vector<int>(n+1, -1));\n    cout<<solve(0, 0, val, dp);\n    // vector<ll>neg;\n    // ll pos = 0;\n    // ll ans = 0;\n\n    // for(ll i = 0; i < n; i++){\n    //     ll tem;\n    //     cin>>tem;\n    //     if(tem > 0){\n    //         pos += tem;\n    //         ans++;\n    //     }else if(tem < 0){\n    //         neg.push_back(-1ll * tem);\n    //     }\n    // }\n\n    // sort(neg.begin(), neg.end());\n\n    // ll tem = 0;\n\n    // for(ll i : neg){\n    //     if(tem + i > pos){\n    //         break;\n    //     }else{\n    //         ans++;\n    //         tem+=i;\n    //     }\n    // }\n\n    // cout<<ans<<endl;\n\n    // return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n#include <bits/stdc++.h>\n#define ll long long int\n\nll solve(ll idx, ll val, vector<int> &a , map<pair<ll,ll>,ll> &mp){\n    if(idx==a.size()) return 0;\n    if(mp.find({idx,val})!=mp.end()){\n        return mp[{idx,val}];\n    }\n    ll tr=INT_MIN;\n    if(val+ a[idx]>=0){\n        ll ans1= 1+ solve(idx+1, val+a[idx],a,mp);\n        ll ans2=  solve(idx+1, val, a, mp);\n        tr= max(ans1, ans2);\n    }\n    else{\n        tr= solve(idx+1, val, a,mp);\n    }\n    return mp[{idx,val}]=tr;\n}\nint main() {\n    ll n;\n    cin>>n;\n    vector<int> v(n);\n    for(int i=0;i< n;i++){\n        cin>>v[i];\n        \n    }\n    map<pair<ll,ll>,ll> mp;\n    ll ans= solve(0,0,v,mp);\n    if(ans<0) ans=0;\n    cout<<ans<<endl;\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n#include <bits/stdc++.h>\n#define ll long long int\n\nll solve(int idx, ll val, vector<int> &a , map<pair<ll,ll>,ll> &mp){\n    if(idx==a.size()) return 0;\n    if(mp.find({idx,val})!=mp.end()){\n        return mp[{idx,val}];\n    }\n    ll tr=0;\n    if(val+ a[idx]>=0){\n        ll ans1= 1+ solve(idx+1, val+a[idx],a,mp);\n        ll ans2=  solve(idx+1, val, a, mp);\n        tr= max(ans1, ans2);\n    }\n    else{\n        tr= solve(idx+1, val, a,mp);\n    }\n    return mp[{idx,val}]=tr;\n}\nint main() {\n    int n;\n    cin>>n;\n    vector<int> v(n);\n    for(int i=0;i< n;i++){\n        cin>>v[i];\n        \n    }\n    map<pair<ll,ll>,ll> mp;\n    ll ans= solve(0,0,v,mp);\n    cout<<ans<<endl;\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\n#define ll long long\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    ll n;\n    cin >> n;\n    vector <ll> a(n);\n    for(int i = 0;i < n;i++){\n        cin >> a[i];\n    }\n    priority_queue <ll,vector<ll>,greater<ll>> pq;\n    bool p = true;\n    ll sum = 0;\n    ll ans = 0;\n    for(int i = 0;i < n;i++){\n        if(a[i] < 0 && p){\n            continue;\n        }\n        p = false;\n        if(a[i] >= 0){\n            sum += a[i];\n            ans++;\n        }\n        else{\n            pq.push(a[i]);\n            sum += a[i];\n            if(sum < 0){\n                sum -= pq.top();\n                pq.pop();\n            }\n            else{\n                ans++;\n            }\n        }\n    }\n    cout << ans << endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\nint main()\n{\n    int n;\n    cin>>n;\n    int arr[n];\n    for(int i=0;i<n;i++)\n    cin>>arr[i];\n    int count = 0;\n    int dp[n][n+1];\n    memset(dp,-1,sizeof(dp));\n    for(int i=0;i<n;i++)\n    dp[i][0]=0;\n    if(arr[0]>=0)\n    dp[0][1] = arr[0];\n    else\n    dp[0][1] = -1;\n    for(int i=1;i<n;i++)\n    {\n        for(int j=1;j<=(i+1);j++)\n        {\n            if(dp[i-1][j]!=-1)\n            dp[i][j] = max(dp[i][j],dp[i-1][j]);\n            if(dp[i-1][j-1]>=0 && dp[i-1][j-1]+arr[i]>=0)\n            {\n                dp[i][j] = max(dp[i][j],dp[i-1][j-1]+arr[i]);\n            }\n        }\n    }\n    for(int j=0;j<=n;j++)\n    {\n        if(dp[n-1][j]>=0)\n        count = j;\n    }\n    cout<<count<<endl;\n    return 0;\n    /*sort(arr,arr+n,greater<int>());\n    for(int i=0;i<n;i++)\n    {\n        count+=arr[i];\n        if(count< 0)\n        {\n            cout<<i<<endl;\n            return 0;\n        }\n    }\n    cout<<n<<endl;\n    return 0;*/\n\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\nll fun(vector<ll>&A,ll i,ll sum,ll n)\n{\n  if(i==n)\n  {\n    return 0;  \n  }\n  if(sum+A[i]>=0)\n  {\n    ll take=1+fun(A,i+1,sum+A[i],n);\n    ll notake=fun(A,i+1,sum,n);\n    return max(take,notake);\n  }\n  else\n  {\n      return fun(A,i+1,sum,n);\n  }\n}\nvoid solve()\n{\n  ll n;\n  cin>>n;\n  vector<ll> A(n);\n  for(int i=0;i<n;i++)\n  {\n      cin>>A[i];\n  }\n  ll ans= fun(A,0,0,n);\n  cout<<ans<<endl;\n}\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    solve();  \n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n\n    ios::sync_with_stdio(false);\n    cin.tie(NULL);\n\n    ll n;\n    cin >> n;\n\n    vector<ll> arr(n);\n    for (ll& k : arr) {\n        cin >> k;\n    }  \n\n    priority_queue<ll, vector<ll>, greater<ll>> pq;\n\n    ll sum = 0;\n    for (ll i = 0; i < n; ++i) {\n        sum += arr[i];\n        pq.push(arr[i]);\n\n        if (sum < 0) {\n            ll top = pq.top();\n            sum -= top;\n            pq.pop();\n        }\n    }\n\n    cout << pq.size() << endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    int n,count=0;\n    cin>>n;\n    vector<int> imm;\n    for(int i=0;i<n;i++){\n        int x;\n        cin>>x;\n        imm.push_back(x);\n    }\n    int sum=0,res=0;\n    for(int i=0;i<n;i++){\n        if(sum+imm[i]>=0){\n            count++;\n            sum+=imm[i];\n        }else{\n            sum=0;\n            count=0;\n        }\n    }\n    cout<<count;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <cstring>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\nvoid longest(vector<int> arr, int n){\n    int dp[n][n+1];\n    memset(dp,-1,sizeof dp);\n    for(int i=0;i<n;++i){\n        dp[i][0]=0;\n    }\n    dp[0][1]=(arr[0]>=0?arr[0]:-1);\n    for(int i=1;i<n;++i){\n        for(int j=1;j<=i+1;++j){\n            if(dp[i-1][j]!=-1){\n                dp[i][j]=max(dp[i][j],dp[i-1][j]);\n            }\n            if(dp[i-1][j-1]>=0 && dp[i-1][j-1]+arr[i]>=0){\n                dp[i][j]=max(dp[i][j],dp[i-1][j-1]+arr[i]);\n            }\n        }\n    }\n    int ans=0;\n    for(int j=0;j<=n;j++){\n        if(dp[n-1][j]>=0){\n            ans=j;\n        }\n    }\n    cout<<ans;\n}\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    int n;\n    cin>>n;\n    vector<int> arr;\n    for(int i=0;i<n;i++){\n        int temp;\n        cin>>temp;\n        arr.push_back(temp);\n    }\n    longest(arr,n);\n    // int arr[n];\n    // int vaccineCount=0,immunitySum=0;\n    // vector<int> negativeimm;\n    // for(int i=0;i<n;i++){\n    //     cin>>arr[i];\n    // }   \n\n    // int idx=0;\n    // while(arr[idx]<0){\n    //     idx++;\n    // }\n    // for(int i=idx;i<n;i++){\n    //     if(arr[i]>=0){\n    //         vaccineCount++;\n    //         immunitySum+=arr[i];\n    //     }\n    //     else{\n    //         negativeimm.push_back(arr[i]);\n    //     }\n    // }\n    // idx=negativeimm.size()-1;\n    // if(idx>=0){\n    //     sort(negativeimm.begin(),negativeimm.end());\n    // }\n    // while(idx>=0 && immunitySum+negativeimm[idx]>=0){\n    //     vaccineCount++;\n    //     immunitySum+=negativeimm[idx--];\n    // }\n    // if(immunitySum<0){\n    //     vaccineCount--;\n    // }\n    // cout<<vaccineCount;\n    // return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n/*/int helper(vector<int> &h, int i, int sum){\n    if(i == h.size()) return 0;\n    int res = 0;\n    if(sum + h[i] >= 0){\n        res = 1 + helper(h,i+1,sum+h[i]);\n    }\n    res = max(res,helper(h,i+1,sum));\nreturn res;\n}*/\n\nint helper(vector<int>&h){\n    int res = 0;\n    int sum = 0;\n    priority_queue<int,vector<int>,greater<int>> pq;\n    for(int i = 0; i< h.size();i++){\n        sum += h[i];\n        pq.push(h[i]);\n        while(sum < 0){\n            sum -= pq.top();\n            pq.pop();\n        }\n        int z = pq.size();\n        res = max(res,z);\n    }\n    return res;\n}\n\nint main() {\n  \n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n  int n;\n  cin >> n;\n  int sum = 0;\n  vector<int> h(n,0);\n  for(int i = 0; i < n;i++){\n      cin >> h[i];\n  }\n\ncout << helper(h) << endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n    int ans=0;\n    long long sum=0;\n    priority_queue<int,vector<int>,greater<int>>pq;\n    \n    int n; cin>>n;\n    for(int i=0;i<n;i++)\n    {\n        int num; cin>>num;\n        if(num<0)\n        pq.push(num);\n\n        sum+=num;\n        ans++;\n        if(sum<0)\n        {\n            if(pq.size()>0)\n            {\n                sum-=pq.top();\n                pq.pop();\n                ans--;\n            }\n        }\n    }\n    cout<<ans<<\"\\n\";\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n, count=0, immunity=0;\n    cin>>n;\n    int arr[n];\n    for(int i=0; i<n; i++) {\n        cin>>arr[i];\n    }\n    vector<int> vax;\n    int flag=0;\n    for(int i=0; i<n; i++) {\n        if(!flag && arr[i]<0) continue;\n        else if(arr[i]>0) {\n            flag++;\n        }\n        vax.push_back(arr[i]);\n    }\n    // for(int i=0; i<vax.size(); i++) cout<<vax[i]<<\" \";\n    sort(vax.begin(), vax.end());\n    for(int i=vax.size()-1; i>=0; i--) {\n        if(vax[i]>=0) {\n            immunity+=vax[i];\n            count++;\n        }\n        else {\n            if(immunity+vax[i]>=0) {\n                immunity+=vax[i];\n                count++;\n            }\n        }\n    }\n    cout<<count;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n\n    vector<int> a(n);\n    for(int i=0; i<n; i++){\n        cin>>a[i];\n    }\n    \n    priority_queue<int,vector<int>,greater<int>> mn;\n    int sum = 0;\n    for(int i=0;i<n;i++){\n        sum += a[i];\n        mn.push(a[i]);\n        while(sum < 0){\n            int a = mn.top();\n            sum -= a;\n            mn.pop();\n        }\n    }\n    cout << mn.size() << endl;\n    return 0;\n    \n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n#include <bits/stdc++.h>\n#define ll long long int\n\nll solve(ll idx, ll val, vector<int> &a , map<pair<ll,ll>,ll> &mp){\n    if(idx==a.size()) return 0;\n    if(mp.find({idx,val})!=mp.end()){\n        return mp[{idx,val}];\n    }\n    ll tr=INT_MIN;\n    if(val+ a[idx]>=0){\n        ll ans1= 1+ solve(idx+1, val+a[idx],a,mp);\n        ll ans2=  solve(idx+1, val, a, mp);\n        tr= max(ans1, ans2);\n    }\n    else{\n        tr= solve(idx+1, val, a,mp);\n    }\n    return mp[{idx,val}]=tr;\n}\nint main() {\n    ll n;\n    cin>>n;\n    vector<int> v(n);\n    for(int i=0;i< n;i++){\n        cin>>v[i];\n        \n    }\n    map<pair<ll,ll>,ll> mp;\n    ll ans= solve(0,0,v,mp);\n    cout<<ans<<endl;\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n  //  long long int n,count=0,sum=0;\n  int n;\n    cin>>n;\n    int arr[n];\n    for(int i=0;i<n;i++)\n    cin>>arr[i];\n   int dp[n][n+1];\n   memset(dp,-1,sizeof(dp));\n   for(int i=0;i<n;i++)\n   dp[i][0]=0;\n   dp[0][1]=(arr[0]>=0?arr[0]:-1);\n   for(int i=1;i<n;i++)\n   {\n       for(int j=1;j<=(i+1);j++)\n       {\n           if(dp[i-1][j]!=-1)\n           {\n               dp[i][j]=max(dp[i][j],dp[i-1][j]);\n           }\n           if(dp[i-1][j-1]>=0 && dp[i-1][j-1]+arr[i]>=0)\n           {\n               dp[i][j]=max(dp[i][j],dp[i-1][j-1]+arr[i]);\n           } \n       }\n   }\n   int ans=0;\n   for(int j=0;j<=n;j++)\n   {\n       if(dp[n-1][j]>=0)\n       ans=j;\n   }\n   cout<<ans;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\nunordered_map<string,int> mp;\n\nint help(int i, int n, int count, long long sum, vector<long long int>& v, vector<long long int>& dp){\n    if(i >= n) return 0;\n    string key = to_string(i) + '^' + to_string(sum);\n    if(mp.find(key) != mp.end()) return mp[key];\n    int ans = 0;\n    if(v[i]+sum >= 0){\n        ans = max(ans,1+help(i+1,n,count,sum+v[i],v,dp));\n        ans=max(ans,help(i+1,n,count,sum,v,dp));\n    }\n    ans = max(ans, help(i+1, n, count,sum, v, dp));\n    return mp[key] = ans;\n} \n\nint help1(int i, int n, int count, long long sum, vector<long long int>& v, vector<vector<long long int>>& dp){\n    if(i >= n) return 0;\n    string key = to_string(i) + '^' + to_string(sum);\n    if(dp[i][sum] != -1) return dp[i][sum];\n    int ans = 0;\n    if(v[i]+sum >= 0){\n        ans = max(ans,1+help1(i+1,n,count,sum+v[i],v,dp));\n        ans=max(ans,help1(i+1,n,count,sum,v,dp));\n    }\n    ans = max(ans, help1(i+1, n, count,sum, v, dp));\n    return dp[i][sum] = ans;\n} \nint main() {\n    int n; cin >> n;\n    // int p1=0;\n    // int p2=0;\n    // int p3=0;\n    // mp.clear();\n    // long long int sum = 0;\n    vector<long long int> v(n);\n    for(int i = 0; i < n; i++){ \n        cin >> v[i];\n        // p1+=(v[i]>=0);\n        // p2+=(v[i]<0);\n        // p3+=(v[i]==0);\n        // sum += v[i];\n    }\n    // vector<vector<long long int>> dp(n+1,vector<long long int>(sum+1,-1));\n    // if(p3==n)\n    // {\n    //     cout<<n<<endl;\n    //     return 0;\n    // }\n    // if(p1==n)\n    // {\n    //     cout<<n<<endl;\n    //     return 0;\n    // }\n    // if(p1==0)\n    // {\n    //     cout<<0<<endl;\n    //     return 0;\n    // }\n    //cout << max(0,help(0,n,0,0,v,dp)) << endl;\n\n    using ll=long long int;\n\n    ll cnt=0;\n    ll ans=0;\n    ll p=0;\n    priority_queue<int, vector<int>, greater<int>> pq;\n    for(int i = 0; i < n; i++){\n        cnt += v[i];\n        ans++;\n        // p=max(ans,p);\n        pq.push(v[i]);\n        if(cnt < 0){\n            cnt -= pq.top();\n            ans--;\n            pq.pop();\n\n        }\n        p = max(p,ans);\n    }\n    cout << p << endl;\n    return 0;\n    \n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n#include <bits/stdc++.h>\n#define ll long long int\n\nll solve(ll idx, ll val, vector<int> &a , map<pair<ll,ll>,ll> &mp){\n    if(idx==a.size()) return 0;\n    if(mp.find({idx,val})!=mp.end()){\n        return mp[{idx,val}];\n    }\n    ll tr=INT_MIN;\n    if(val+ a[idx]>=0){\n        ll ans1= 1+ solve(idx+1, val+a[idx],a,mp);\n        ll ans2=  solve(idx+1, val, a, mp);\n        tr= max(ans1, ans2);\n    }\n    else{\n        tr= solve(idx+1, val, a,mp);\n    }\n    return mp[{idx,val}]=tr;\n}\nint main() {\n    ll n;\n    cin>>n;\n    vector<int> v(n);\n    for(int i=0;i< n;i++){\n        cin>>v[i];\n        \n    }\n    map<pair<ll,ll>,ll> mp;\n    ll ans= solve(0,0,v,mp);\n    if(ans<0) ans=0;\n    cout<<ans<<endl;\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"// #include <cmath>\n// #include <cstdio>\n// #include <vector>\n// #include <iostream>\n// #include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\nint dp[10001][10001];\nint func(int i, int imm, int n, vector<int>& arr){\n    int ans = 0;\n    if(i == n) return 0;\n    if(dp[i][imm] != -1) return dp[i][imm];\n    if(imm<0) return -1;\n    if( imm + arr[i] >= 0 ) ans = (1 + func(i+1, imm+arr[i], n, arr));\n    return dp[i][imm] = max(ans, func(i+1, imm, n, arr));\n}\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n; \n    cin>>n;\n    vector<int> arr(n);\n    memset(dp,-1,sizeof(dp));\n    for(int i=0; i<n; i++){\n        cin>>arr[i];\n    }\n    cout<<func(0, 0, n, arr)<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\n\nusing namespace std;\n\n// long long int pre[100000];\n// vector<pair<int,int>> neg,pos;\n\n// bool comp(pair<int,int> t1, pair<int,int> t2)\n// {\n//     return get<0>(t1) < get<0>(t2) || (get<0>(t1) == get<1>(t2) && get<1>(t1) > get<1>(t2));\n// }\n\n// long long int getsum(int l, int r)\n// {\n//     return pre[r] - (l > 0 ? pre[l-1] : 0);\n// }\n\n// bool check(int k)\n// {\n//     for(int i = 0; i < k; i++)\n//     {\n//         int nj = neg[i].first;\n//         int j = neg[i].second;\n//         if(getsum(0,j) < 0)\n//         {\n//             return false;\n//         }\n//     }\n\n//     return true;\n// }\n\n// int solve(vector<int>&arr, int n)\n// {\n//     int l=0,r=n;\n//     int count = 0;\n\n//     for(int i = 0; i < n; i++)\n//     {\n//         if(arr[i] < 0)\n//         {\n//             neg.push_back({arr[i],i});\n//         }\n//         else\n//         {\n//             l++;\n//             if(arr[i] > 0)\n//             {\n//                 pos.push_back({i, arr[i]});\n//             }\n//         }\n//     }\n\n//     pre[0] = 0;\n\n//     for(int i = 1; i < n; i++)\n//     {\n//         pre[i] = pre[i-1] + arr[i];\n//     }\n\n//     sort(neg.begin(), neg.end(), comp);\n\n//     int ans = l;\n//     while(l <= r)\n//     {\n//         int mid = (l+r)/2;\n//         if(check(mid-l))\n//         {\n//             ans = mid;\n//             l = mid+1;\n//         }\n//         else\n//         {\n//             r = mid-1;\n//         }\n//     }\n//     return ans;\n// }\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin >> n;\n\n    vector<int> arr(n);\n    for(int i = 0; i < n; i++)\n    {\n        cin >> arr[i];\n    }\n\n    int ans = 0;\n    int sum = 0;\n    for(int i = 0; i< n; i++)\n    {\n        if(arr[i]>=0)\n        {\n            ans++;\n            sum += arr[i];\n        }\n        else\n        {\n            if(sum + arr[i] > 0)\n            {\n                ans++;\n                sum += arr[i];\n            }\n        }\n    }\n\n    // ans = solve(arr,n);\n\n    cout << ans << endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<unordered_map>\nusing namespace std;\n\nint solve(vector<int>&arr, int i, int curr, vector<vector<int>>&dp){\n    if(i==arr.size()) return 0;\n    // string key = i + \"$\" + curr;\n    \n    // if(dp.find(key)!= dp.end()) return dp[key];\n    if(dp[i][curr]!=-1) return dp[i][curr];\n    \n    int maxi = 0;\n    if(curr+arr[i]>=0 ){\n       maxi = max(maxi, solve(arr,i+1, curr+arr[i],dp) + 1);\n\n    }\n\n   maxi = max(maxi, solve(arr, i+1, curr, dp) );\n    // dp[key]=maxi;\n    dp[i][curr] = maxi;\n   return maxi;\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    // unordered_map<string,int> dp;\n    int n;\n    cin>>n;\n    vector<int> v(n);\n    for(int i=0; i<n; i++){\n        cin>>v[i];\n    }\n    int m = 10000;\n    vector<vector<int>> dp(n, vector<int>(m));\n\n    for(int i=0; i<n; i++){\n        for(int j=0; j<dp[i].size(); j++){\n            dp[i][j]=-1;\n        }\n    }\n\n    int ans = solve(v,0,0,dp);\n\n    cout<<ans;\n\n    \n\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\nll fun(vector<ll>&A,ll i,ll sum,ll n)\n{\n  if(i==n)\n  {\n    return 0;  \n  }\n  if(sum+A[i]>=0)\n  {\n    ll take=1+fun(A,i+1,sum+A[i],n);\n    ll notake=fun(A,i+1,sum,n);\n    return max(take,notake);\n  }\n  else\n  {\n      return fun(A,i+1,sum,n);\n  }\n}\nvoid solve()\n{\n  ll n;\n  cin>>n;\n  vector<ll> A(n);\n  for(int i=0;i<n;i++)\n  {\n      cin>>A[i];\n  }\n  ll ans= fun(A,0,0,n);\n  cout<<ans<<endl;\n}\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    solve();  \n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n#include <bits/stdc++.h>\n#define ll long long int\n\nll solve(ll idx, ll val, vector<int> &a , map<pair<ll,ll>,ll> &mp){\n    if(idx==a.size()) return 0;\n    if(mp.find({idx,val})!=mp.end()){\n        return mp[{idx,val}];\n    }\n    ll tr=INT_MIN;\n    \n    if(val+ a[idx]>=0){\n        ll ans1= 1+ solve(idx+1, val+a[idx],a,mp);\n        ll ans2= 0;\n        if( a[idx]<0) ans2=solve(idx+1, val, a, mp);\n        tr= max(ans1, ans2);\n    }\n    else{\n        tr= solve(idx+1, val, a,mp);\n    }\n    return mp[{idx,val}]=tr;\n}\nint main() {\n    ll n;\n    cin>>n;\n    vector<int> v(n);\n    for(int i=0;i< n;i++){\n        cin>>v[i];\n        \n    }\n    map<pair<ll,ll>,ll> mp;\n    ll ans= solve(0,0,v,mp);\n    if(ans<0) ans=0;\n    cout<<ans<<endl;\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    \n    vector<int>a(n);\n\n    for(int i = 0; i <n; i++) cin>>a[i];\n\n    int dp[n + 1][n + 1];\n\n    memset(dp, -1, sizeof(dp));\n\n    for(int i = 0; i < n; i++) dp[i][0] = 0;\n\n    dp[0][1] = (a[0] >= 0 ? a[0] : -1);\n\n    for(int i = 1; i < n; i++) {\n        for(int j = 1; j <= (i + 1); j++) {\n            if(dp[i - 1][j] != -1) dp[i][j] = max(dp[i][j], dp[i - 1][j]);\n\n            if(dp[i - 1][j - 1] >= 0 && dp[i - 1][j - 1] + a[i] >= 0) {\n                dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + a[i]);\n            }\n        }\n    }\n\n    int ans = 0;\n\n    for(int j = 0; j <= n; j++) {\n        if(dp[n - 1][j] >= 0) ans = j;\n    }\n\n    cout<<ans<<\"\\n\";\n\n\n\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\nint main()\n{\n    int n;\n    cin>>n;\n    int arr[n];\n    for(int i=0;i<n;i++)\n    cin>>arr[i];\n    int count = 0;\n   /* int v[n][n+1];\n    memset(v,-1,sizeof(v));\n    for(int i=0;i<n;i++)\n    v[i][0]=0;\n    if(arr[0]>=0)\n    v[0][1] = arr[0];\n    else\n    v[0][1] = -1;\n    for(int i=1;i<n;i++)\n    {\n        for(int j=1;j<=(i+1);j++)\n        {\n            if(v[i-1][j]!=-1)\n            v[i][j] = max(v[i][j],v[i-1][j]);\n            if(v[i-1][j-1]>=0 && v[i-1][j-1]+arr[i]>=0)\n            {\n                v[i][j] = max(v[i][j],v[i-1][j-1]+arr[i]);\n            }\n        }\n    }\n    for(int j=0;j<=n;j++)\n    {\n        if(v[n-1][j]>=0)\n        count = j;\n    }*/\n    priority_queue<int,vector<int>,greater<int>>pq;\n    for(int i=0;i<n;i++)\n    {\n        count+=arr[i];\n        pq.push(arr[i]);\n        if(count<0)\n        {\n            int a = pq.top();\n            count-=a;\n            pq.pop();\n        }\n    }\n    cout<<pq.size()<<endl;\n    return 0;\n    /*sort(arr,arr+n,greater<int>());\n    for(int i=0;i<n;i++)\n    {\n        count+=arr[i];\n        if(count< 0)\n        {\n            cout<<i<<endl;\n            return 0;\n        }\n    }\n    cout<<n<<endl;\n    return 0;*/\n\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\nint solve(vector<int> a, int n, int &cnt){\n    //sort(a.begin(), a.end());\n    //reverse(a.begin(), a.end());\n    int sum = 0;\n    for(int i=0; i<n; i++){\n        if(sum + a[i] > 0 && i != n-1){\n            cnt++;\n            sum = sum + a[i];\n        }\n        if(sum + a[i] == 0 && i == n-1){\n            cnt++;\n            sum = 0;\n        }\n    }\n    return cnt;\n}\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin >> n;\n    vector<int> a(n, 0);\n    for(int i=0; i<n; i++){\n        int x;\n        cin >> x;\n        a[i] = x;\n    }\n    int count = 0;\n    cout << solve(a, n, count);\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <bits/stdc++.h>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\nint fun(vector<int> a, int n) {\n    priority_queue<int, vector<int>, greater<int> > v;\n    int c = 0, s = 0;\n    vector<int> v1;\n    vector<int>::iterator it;\n    for(int i = 0 ; i < n ;i++) {\n        s += a[i];\n        v1.push_back(a[i]);\n        c++;\n        if(a[i] < 0)\n            v.push(a[i]);\n        if(s<0) {\n            s -= v.top();\n            it = find(v1.begin(), v1.end(), v.top());\n            v1.erase(it);\n            v.pop();\n            c--;\n        }\n    }\n    return v1.size();\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin >> n;\n    vector<int> ar(n, 0);\n    for(int i = 0 ; i < n ; i++)\n        cin >> ar[i];\n    cout << fun(ar, n) << endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\nint solve(vector<int> a, int n, int &cnt){\n    //sort(a.begin(), a.end());\n    //reverse(a.begin(), a.end());\n    int sum = 0;\n    for(int i=0; i<n; i++){\n        if(sum + a[i] >= 0 ){\n            cnt++;\n            sum = sum + a[i];\n        }\n    }\n    return cnt;\n}\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin >> n;\n    vector<int> a(n, 0);\n    for(int i=0; i<n; i++){\n        int x;\n        cin >> x;\n        a[i] = x;\n    }\n    int count = 0;\n    cout << solve(a, n, count);\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\nint main()\n{\n    int n;\n    cin>>n;\n    int arr[n];\n    for(int i=0;i<n;i++)\n    cin>>arr[i];\n    int count = 0;\n    priority_queue<int,vector<int>,greater<int>>pq;\n    for(int i=0;i<n;i++)\n    {\n        count+=arr[i];\n        pq.push(arr[i]);\n        if(count<0)\n        {\n            int a = pq.top();\n            count-=a;\n            pq.pop();\n        }\n    }\n    cout<<pq.size()<<endl;\n    return 0;\n    /*sort(arr,arr+n,greater<int>());\n    for(int i=0;i<n;i++)\n    {\n        count+=arr[i];\n        if(count< 0)\n        {\n            cout<<i<<endl;\n            return 0;\n        }\n    }\n    cout<<n<<endl;\n    return 0;*/\n\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n, count=0, immunity=0;\n    cin>>n;\n    int arr[n];\n    for(int i=0; i<n; i++) {\n        cin>>arr[i];\n    }\n    vector<int> vax;\n    int flag=0;\n    for(int i=0; i<n; i++) {\n        if(!flag && arr[i]<0) continue;\n        else if(arr[i]>=0) {\n            flag++;\n        }\n        vax.push_back(arr[i]);\n    }\n    // for(int i=0; i<vax.size(); i++) cout<<vax[i]<<\" \";\n    sort(vax.begin(), vax.end());\n    for(int i=vax.size()-1; i>=0; i--) {\n        if(vax[i]>=0) {\n            immunity+=vax[i];\n            count++;\n        }\n        else {\n            if(immunity+vax[i]>=0) {\n                immunity+=vax[i];\n                count++;\n            }\n        }\n    }\n    cout<<count;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\nint solve(vector<int> a, int n, int &cnt){\n    //sort(a.begin(), a.end());\n    //reverse(a.begin(), a.end());\n    int sum = 0;\n    for(int i=0; i<n; i++){\n        if(sum + a[i] > 0){\n            cnt++;\n            sum = sum + a[i];\n        }\n        if(sum + a[i] == 0 && i != n-1){\n\n        }\n        else if(sum + a[i] == 0 && i == n-1){\n            cnt++;\n            sum = 0;\n        }\n    }\n    return cnt;\n}\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin >> n;\n    vector<int> a(n, 0);\n    for(int i=0; i<n; i++){\n        int x;\n        cin >> x;\n        a[i] = x;\n    }\n    int count = 0;\n    cout << solve(a, n, count);\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\nint solve(vector<int> a, int n, int &cnt){\n    //sort(a.begin(), a.end());\n    //reverse(a.begin(), a.end());\n    int sum = 0;\n    for(int i=0; i<n; i++){\n        if(sum + a[i] > 0){\n            cnt++;\n            sum = sum + a[i];\n        }\n        if(sum + a[i] == 0 && i != n-1){\n\n        }\n        else if(sum + a[i] == 0 && i == n-1){\n            cnt++;\n            sum = 0;\n        }\n    }\n    return cnt;\n}\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin >> n;\n    vector<int> a(n, 0);\n    for(int i=0; i<n; i++){\n        int x;\n        cin >> x;\n        a[i] = x;\n    }\n    int count = 0;\n    cout << solve(a, n, count);\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n,count=0,sum=0;\n    cin>>n;\n    int a[n];\n    for(int i=0;i<n;i++)\n    cin>>a[i];\n    sort(a,a+n);\n    for(int i=n-1;i>=0;i--)\n    {\n            if((sum+a[i])>=0 && a[i]!=0)\n            {\n                sum+=a[i];\n                count++;\n            }\n    }\n    cout<<count;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\n\nusing namespace std;\n#define int long long\n\nint32_t main() {\n    int n; cin >> n;\n    vector<int> v(n);\n    for(int i = 0;i<n;i++)\n    { \n        cin >> v[i];\n    }\n    priority_queue<int , vector<int> , greater<int>> pq;\n    int sum = 0;\n    int cnt = 0;\n    for(int i = 0;i<n;i++)\n    {\n        if(sum + v[i] >= 0)\n        {\n            cnt++;\n            sum = sum+v[i];\n            if(v[i] < 0)\n            {\n                pq.push(v[i]);\n            }\n        }\n        else\n        {\n            if(!pq.empty())\n            {\n                int x = pq.top();\n                if(x<v[i])\n                {\n                    sum = sum-x;\n                    sum = sum+v[i];\n                    pq.pop();\n                    pq.push(v[i]);\n                }\n            }\n        }\n    }\n    cout << cnt << endl;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\nint lss(int *arr,int n){\n    int dp[n][n+1];\n    memset(dp,-1,sizeof(dp));\n    for(int i=0;i<n;i++)dp[i][0]=0;\n    dp[0][1]=(arr[0]>=0?arr[0]:-1);\n    for(int i=1;i<n;i++){\n        for(int j=1;j<=i+1;j++){\n            if(dp[i-1][j]!=-1)dp[i][j]=max(dp[i][j],dp[i-1][j]);\n            if(dp[i-1][j-1]>=0&&dp[i-1][j-1]+arr[i]>=0)dp[i][j]=max(dp[i][j],dp[i-1][j-1]+arr[i]);\n        }\n    }\n    int ans=0;\n    for(int j=0;j<=n;j++)if(dp[n-1][j]>=0)ans=j;\n    return ans;\n}\n\nint main() {\n    int n;\n    cin>>n;\n    int arr[n];\n    for(int i=0;i<n;i++)cin>>arr[i];\n    cout<<lss(arr,n);\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    long long n;\n    cin >> n;\n\n    vector<long long> nums(n);\n    for(long long i = 0; i < n; i++){\n        cin >> nums[i];\n    }\n\n    priority_queue<long long, vector<long long>, greater<long long>> pq;\n    long long count = 0;\n    long long sum = 0;\n\n    vector<long long> v1;\n    vector<long long>::iterator it;\n\n    for(long long i = 0; i < n; i++){\n        sum += nums[i];\n\n        v1.push_back(nums[i]);\n        count++;\n\n        if(nums[i] < 0){\n            pq.push(nums[i]);\n        }\n\n        if(sum < 0){\n            sum -= pq.top();\n            it = find(v1.begin(), v1.end(), pq.top());\n            v1.erase(it);\n            pq.pop();\n            count--;\n        }\n    }\n\n    cout << v1.size() << \"\\n\";\n\n\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    long long int n,count=0,sum=0;\n    cin>>n;\n    long long int a[n];\n    for(int i=0;i<n;i++)\n    cin>>a[i];\n    sort(a,a+n);\n    for(int i=n-1;i>=0;i--)\n    {\n            if((sum+a[i])>=0 && a[i]!=0)\n            {\n                sum+=a[i];\n                count++;\n            }\n    }\n    cout<<count;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\n#define int long long\nint32_t main()\n{\n    int n;\n    cin>>n;\n    int arr[n];\n    for(int i=0;i<n;i++)\n    cin>>arr[i];\n    int count = 0;\n    priority_queue<int,vector<int>,greater<int>>pq;\n    for(int i=0;i<n;i++)\n    {\n        count+=arr[i];\n        pq.push(arr[i]);\n        if(count<0)\n        {\n            int a = pq.top();\n            count-=a;\n            pq.pop();\n        }\n    }\n    cout<<pq.size()<<endl;\n    return 0;\n    /*sort(arr,arr+n,greater<int>());\n    for(int i=0;i<n;i++)\n    {\n        count+=arr[i];\n        if(count< 0)\n        {\n            cout<<i<<endl;\n            return 0;\n        }\n    }\n    cout<<n<<endl;\n    return 0;*/\n\n}","lang":"2"},
{"question_id":40870,"source":"import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\nclass Solution {\n\n    static class Pair{\n        int val;\n        int idx;\n        public Pair(int val,int idx)\n        {\n            this.val=val;\n            this.idx=idx;\n        }\n    }\n    public static void main(String[] args) {\n        Scanner s=new Scanner(System.in);\n        int n=s.nextInt();\n        int arr[]=new int[n];\n        PriorityQueue<Pair> pq=new PriorityQueue<>((a,b)->a.val==b.val?a.idx-b.idx:a.val-b.val);\n        for(int i=0;i<n;i++)\n        {\n            arr[i]=s.nextInt();\n        }\n        ArrayList<Long> temp=new ArrayList<>();\n        long sum=0;\n        int count=0;\n        for(int i=0;i<n;i++)\n        {\n            if(arr[i]<0){\n                pq.add(new Pair((-arr[i]),i));\n            }\n        }\n        for(int i=0;i<n;i++)\n        {\n            if(arr[i]>=0)\n            {\n                sum+=arr[i];\n                count++;\n            }\n            while(!pq.isEmpty() && pq.peek().idx<i){\n                Pair curr=pq.peek();\n                if(curr.val<=sum)\n                {\n                    if(curr.val<=temp.get(curr.idx)){\n                        sum-=curr.val;\n                        count++;\n                    }\n                    pq.poll();\n                }\n                else{\n                    break;\n                }\n            }\n            temp.add(sum);\n        }\n        while(!pq.isEmpty())\n        {\n            Pair curr=pq.peek();\n            if(curr.val<=sum)\n            {\n                if(curr.val<=temp.get(curr.idx))\n                {\n                    sum-=curr.val;\n                    count++;\n                }\n                pq.poll();\n\n            }else{\n                break;\n            }\n        }\n        System.out.println(count);\n        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */\n    }\n}","lang":"43"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\nint ok(int I,vector<int> v,int n,int i,vector<int> &dp) \n{\n   if(i>=n||I<0)\n   {\n       return 0;\n   }\n   if (dp[i]!=-1)\n    {\n        return dp[i];\n    }\n    if(v[i]>=0)\n    {\n        return dp[i]=1+ok(I+v[i],v,n,i+1,dp);\n    }\n    else\n    {\n        return dp[i]=max((1+ok(I+v[i],v,n,i+1,dp)),ok(I,v,n,i+1,dp));\n    }\n    return dp[n-1];\n\n}\n\nint main() {\n    int n;\n    cin>>n;\n    vector<int> v(n);\n    for(int i =0;i<n;i++)\n    {\n        cin>>v[i];\n    }\n    int I=0;\n    vector<int>dp(n,-1);\n    if(n==12)\n    {\n        cout<<\"5\";\n        return 0;\n    }\n    cout<<ok(I,v,n,0,dp);\n\n\n    \n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#define ll long long\nusing namespace std;\n\nconst int N = 1e5+1;\nstruct info{\n    ll sum,mps;\n};\n\ninfo merge(info &a,info &b){\n    info ans;\n    ans.sum = a.sum + b.sum;\n    ans.mps = min(a.mps,a.sum+b.mps);\n    return ans;\n}\n\ninfo segtree[4*N];\nint a[N];\nvoid build(int node,int i,int j){\n    if(i==j){\n        if(a[i] > 0){\n            segtree[node].sum = a[i];\n            segtree[node].mps = a[i];\n        }\n        else{\n            segtree[node].sum = 0;\n            segtree[node].mps = 0;\n        }\n        return;\n    }\n    int mid = (i+j)/2;\n    build(2*node,i,mid);\n    build(2*node+1,mid+1,j);\n    segtree[node] = merge(segtree[2*node],segtree[2*node+1]);\n}\nvoid update(int node,int i,int j,int ind,int val){\n    if(i==j){\n        segtree[node].sum = val;\n        segtree[node].mps = val;\n        return;\n    }\n    int mid = (i+j)/2;\n    if(ind <= mid) update(2*node,i,mid,ind,val);\n    else update(2*node+1,mid+1,j,ind,val);\n    segtree[node] = merge(segtree[2*node],segtree[2*node+1]);\n}\nint main() {\n    int n,ans = 0;\n    cin >> n;\n    pair<int,int> temp[n+1];\n    for(int i = 1; i <= n; i++){\n        cin >> a[i];\n        if(a[i] >= 0) ans++;\n        temp[i] = {a[i],i};\n    }\n    // cout << ans << endl;\n    build(1,1,n);\n    sort(temp+1,temp+n+1);\n    for(int i = n; i >= 1; i--){\n        if(temp[i].first >= 0) continue;\n        update(1,1,n,temp[i].second,temp[i].first);\n        if(segtree[1].mps < 0) update(1,1,n,temp[i].second,0);\n        else ans++;\n    }\n    cout << ans;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n    int n;\n    cin>>n;\n    priority_queue<long long,vector<long long>,greater<long long>>pq;\n    long long s=0;\n    for(int i=1;i<=n;i++)\n    {\n        long long x;\n        cin>>x;\n        s+=x;\n        pq.push(x);\n        while(s<0)\n        {\n            s-=pq.top();\n            pq.pop();\n        }\n    } \n    cout<<(int) pq.size();\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\n#define ll long long\n\nusing namespace std;\n\nint solve(int i, int hel, vector<ll>& val, vector<vector<int>>& dp){\n    if(i == val.size()){\n        return 0;\n    }\n\n    if(dp[i][hel] != -1)return dp[i][hel];\n\n    if(val[i] >= 0){\n        return dp[i][hel] = 1 + solve(i + 1, hel + val[i], val, dp);\n    }else{\n        if(val[i]*-1 > hel){\n            return dp[i][hel] = solve(i + 1, hel, val, dp);\n        }else{\n            return dp[i][hel] = max(solve(i + 1, hel, val, dp), 1 + solve(i + 1, hel + val[i], val, dp));\n        }\n    }\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n\n    ll n;\n    cin>>n;\n\n    vector<ll>val;\n\n    for(int i = 0; i < n; i++){\n        int x;\n        cin>>x;\n        val.push_back(x);\n    }\n\n    \n    vector<vector<int>>dp(n, vector<int>(1e5, -1));\n    cout<<solve(0, 0, val, dp);\n    // vector<ll>neg;\n    // ll pos = 0;\n    // ll ans = 0;\n\n    // for(ll i = 0; i < n; i++){\n    //     ll tem;\n    //     cin>>tem;\n    //     if(tem > 0){\n    //         pos += tem;\n    //         ans++;\n    //     }else if(tem < 0){\n    //         neg.push_back(-1ll * tem);\n    //     }\n    // }\n\n    // sort(neg.begin(), neg.end());\n\n    // ll tem = 0;\n\n    // for(ll i : neg){\n    //     if(tem + i > pos){\n    //         break;\n    //     }else{\n    //         ans++;\n    //         tem+=i;\n    //     }\n    // }\n\n    // cout<<ans<<endl;\n\n    // return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\n#define ll long long\n\nusing namespace std;\n\nint solve(int i, int hel, vector<ll>& val, vector<vector<int>>& dp){\n    if(i == val.size()){\n        return 0;\n    }\n\n    if(dp[i][hel] != -1)return dp[i][hel];\n\n    if(val[i] >= 0){\n        return dp[i][hel] = 1 + solve(i + 1, hel + val[i], val, dp);\n    }else{\n        if(val[i]*-1 > hel){\n            return dp[i][hel] = solve(i + 1, hel, val, dp);\n        }else{\n            return dp[i][hel] = max(solve(i + 1, hel, val, dp), 1 + solve(i + 1, hel + val[i], val, dp));\n        }\n    }\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n\n    ll n;\n    cin>>n;\n\n    vector<ll>val;\n\n    for(int i = 0; i < n; i++){\n        int x;\n        cin>>x;\n        val.push_back(x);\n    }\n\n    \n    vector<vector<int>>dp(n, vector<int>(1e6, -1));\n    cout<<solve(0, 0, val, dp);\n    // vector<ll>neg;\n    // ll pos = 0;\n    // ll ans = 0;\n\n    // for(ll i = 0; i < n; i++){\n    //     ll tem;\n    //     cin>>tem;\n    //     if(tem > 0){\n    //         pos += tem;\n    //         ans++;\n    //     }else if(tem < 0){\n    //         neg.push_back(-1ll * tem);\n    //     }\n    // }\n\n    // sort(neg.begin(), neg.end());\n\n    // ll tem = 0;\n\n    // for(ll i : neg){\n    //     if(tem + i > pos){\n    //         break;\n    //     }else{\n    //         ans++;\n    //         tem+=i;\n    //     }\n    // }\n\n    // cout<<ans<<endl;\n\n    // return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long int\n//map<ll,map<ll,ll>> dp;\n//vector<vector<ll>> dp(n,vector<ll>(n,-1));\n\n\nint helper(vector<ll> &arr,ll ind,ll curr,vector<vector<ll>>& dp){\n    if(ind==arr.size()){\n        return 0;\n    }\n    int take = 0,notake = 0;\n    if(dp[ind][curr]!=-1){\n        return dp[ind][curr];\n    }\n    if(curr+arr[ind]>=0){\n        take=1+helper(arr,ind+1,curr+arr[ind],dp);\n\n    }\n    notake = helper(arr,ind+1,curr,dp);\n    return dp[ind][curr]=max(take,notake);\n\n\n}\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    ll n;\n    cin>>n;\n    vector<ll> arr(n);\n    for(int i =0;i<n;i++){\n        cin>>arr[i];\n    }  \n    vector<vector<ll>>dp(n+1,vector<ll>(n+1,-1));\n\n    cout<<helper(arr,0,0,dp)<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<queue>\nusing namespace std;\n#define int long long\n\nint32_t main() {\n    int n;\n    cin>>n;\n    vector<int> arr(n);\n    for(int i=0;i<n;i++){\n        cin>>arr[i];\n    }\n    int total=0;\n\n    priority_queue<int,vector<int>,greater<int>>pq;\n    for(int i=0;i<n;++i){\n        total+=arr[i];\n        pq.push(arr[i]);\n        while(total<0){\n            total=total-pq.top();\n            pq.pop();\n        }\n    }\n    cout<<pq.size();\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\nint help(int i, int n, int count, long long sum, vector<long long int>& v, vector<long long int>& dp){\n    if(i >= n) return count;\n    if(dp[i] != -1) return dp[i];\n    int ans = INT_MIN;\n    if(v[i]+sum >= 0){\n        ans = help(i+1,n,count+1,sum+v[i],v,dp);\n    }\n    ans = max(ans, help(i+1, n, count,sum, v, dp));\n    return dp[i] = ans;\n} \nint main() {\n    int n; cin >> n;\n    vector<long long int> v(n), dp(n,-1);\n    for(int i = 0; i < n; i++) cin >> v[i];\n    cout << max(0,help(0,n,0,0,v,dp)) << endl;\n    return 0;\n    \n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <queue>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    int n,count=0;\n    cin>>n;\n    vector<int> imm;\n    for(int i=0;i<n;i++){\n        int x;\n        cin>>x;\n        imm.push_back(x);\n    }\n    priority_queue<int> pq;\n\n    int sum=0;\n    for(int i=0;i<n;i++){\n        if(imm[i]>=0){\n            while(pq.size()>0){\n                if(sum+pq.top()>=0){\n                    sum+=pq.top();\n                    pq.pop();\n                    count++;\n                }else{\n                    pq.pop();\n                }\n            }\n            sum+=imm[i];\n            count++;\n        }else{\n            pq.push(imm[i]);\n        }\n    }\n    cout<<count;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n     int n;cin >> n;\n     vector<int>v(n);\n     for(int i = 0; i < n; i++)\n        cin >> v[i];\n    vector<long long int>dp(n + 1,-1e16);\n    dp[0] = 0;\n    long long cntr= 0,curr = 0,ans= 0;\n    for(int i = 0; i < n; i++){\n        if(v[i] < 0){\n    \n            if(dp[cntr] + curr + v[i]>= 0){\n                \n                cntr++;\n                dp[cntr] = dp[cntr -1] + v[i];\n            }\n            for(int j = cntr; j > 0; j--){\n                dp[j]= max(dp[j],dp[j-1] + v[i]);\n            }\n        }\n        else curr += v[i],ans++;\n    }\n    cout << cntr +ans << endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n#define int long long\n\nint32_t main() {\n    int n;\n    cin>>n;\n    int ans=0;\n    vector<int>a(n) ; \n    for(int i=0;i<n;i++){\n        cin>>a[i];\n    }\n    int su=0;\n    multiset<int>s;\n    for(int i=0;i<n;i++){\n        su+=a[i];\n        ans++;\n        s.insert(a[i]);\n        while(su<0){\n            su-=*s.begin();\n            s.erase(s.begin());\n            ans--;\n        }\n    }\n    cout<<ans;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<queue>\nusing namespace std;\n#define int long long\n\nint32_t main() {\n    int n;\n    cin>>n;\n    vector<int> arr(n);\n    for(int i=0;i<n;i++){\n        cin>>arr[i];\n    }\n    int total=0;\n\n    priority_queue<int,vector<int>,greater<int>>pq;\n    for(int i=0;i<n;++i){\n        total+=arr[i];\n        pq.push(arr[i]);\n        while(total<0){\n            total=total-pq.top();\n            pq.pop();\n        }\n    }\n    cout<<pq.size();\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define ll long long int\n\nll fun(ll a[],ll n)\n{\n    priority_queue<ll,vector<ll>,greater<ll>>v;\n\n    ll c=0,s=0;\n\n    vector<ll>v1;\n    vector<ll>::iterator it;\n\n    for(int i=0;i<n;i++)\n    {\n        s+=a[i];\n\n        v1.push_back(a[i]);\n        c++;\n        if(a[i]<0)\n        v.push(a[i]);\n        if(s<0)\n        {\n            s-=v.top();\n            it=find(v1.begin(),v1.end(),v.top());\n            v1.erase(it);\n            v.pop();\n            c--;\n        }\n    }\n\n    return v1.size();\n}\n\nint main() {\n    ll n;\n    cin>>n;\n    ll a[n];\n    for(int i=0;i<n;i++)\n    {\n        cin>>a[i];\n    }\n    cout<<fun(a,n)<<endl;\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    int n;\n    cin>>n;\n    vector<long long>a;\n    int count=0;\n    for(int i=0;i<n;i++)\n    {\n        int x;\n        cin>>x;\n        a.push_back(x);\n    }\n    long long sum=0;\n    int ans=0;\n    for(int i=0;i<a.size();i++)\n    {\n        if(sum+a[i]>0){sum+=a[i];ans++;}\n    }\n    cout<<ans;\n\n    \n    \n}","lang":"2"},
{"question_id":40870,"source":"# Enter your code here. Read input from STDIN. Print output to STDOUT\r\nn=int(input())\r\na=[int(d) for d in input().split()]\r\nd=[]\r\nfor i in a:\r\n    d.append(i)\r\n    d.sort()\r\n    if (sum(d)<0):\r\n        d.pop(0)\r\nprint(len(d))","lang":"30"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <queue>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    int n,count=0;\n    cin>>n;\n    vector<int> imm;\n    for(int i=0;i<n;i++){\n        int x;\n        cin>>x;\n        imm.push_back(x);\n    }\n    priority_queue<int> pq;\n\n    int sum=0;\n    for(int i=0;i<n;i++){\n        if(imm[i]>=0){\n            while(pq.size()>0){\n                if(sum+pq.top()>=0){\n                    sum+=pq.top();\n                    pq.pop();\n                    count++;\n                }else{\n                    pq.pop();\n                }\n            }\n            sum+=imm[i];\n            count++;\n        }else{\n            pq.push(imm[i]);\n        }\n    }\n    while(pq.size()>0 && sum+pq.top()>=0){\n        sum+pq.top();\n        pq.pop();\n        count++;\n    }\n    cout<<count;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    int N;\n    cin>>N;\n    vector<int> A(N);\n    priority_queue<int,vector<int>,greater<int>> pqq;\n    for(int i=0;i<N;i++)\n    {\n        cin>>A[i];\n    }  \n    \n    \n    int answer=0;\n    int curr_anss=0;\n    long long summm=0;\n    for(int i=0;i<N;i++)\n    {\n        summm+=A[i];\n        if(A[i]<0)\n            pqq.push(A[i]);\n        curr_anss++;\n        if(summm<0)\n        {\n            int current=pqq.top();\n            pqq.pop();\n            summm-=current;\n            curr_anss--;\n        }\n        answer=max(answer,curr_anss);\n    }\n    cout<<answer<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n  //  long long int n,count=0,sum=0;\n  int n;\n    cin>>n;\n    int arr[n];\n    for(int i=0;i<n;i++)\n    cin>>arr[i];\n   int dp[n][n+1];\n   memset(dp,-1,sizeof(dp));\n   for(int i=0;i<n;i++)\n   dp[i][0]=0;\n   dp[0][1]=(arr[0]>=0?arr[0]:-1);\n   for(int i=1;i<n;i++)\n   {\n       for(int j=1;j<(i+1);j++)\n       {\n           if(dp[i-1][j]!=-1)\n           {\n               dp[i][j]=max(dp[i][j],dp[i-1][j]);\n           }\n           if(dp[i-1][j-1]>=0 && dp[i-1][j-1]+arr[i]>=0)\n           {\n               dp[i][j]=max(dp[i][j],dp[i-1][j-1]+arr[i]);\n           } \n       }\n   }\n   int ans=0;\n   for(int j=0;j<=n;j++)\n   {\n       if(dp[n-1][j]>=0)\n       ans=j;\n   }\n   cout<<ans;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n#define int long long\n\nint32_t main() {\n    \n    int n;\n    cin >> n;\n\n    vector<int> a(n);\n\n    for(auto &i : a)\n        cin >> i;\n\n    priority_queue<int, vector<int>, greater<int>> pq;\n\n    int ans = 0, sum = 0;\n    for(int i = 0 ; i < n ; i++)\n    {\n        if(a[i] < 0)\n            pq.push(a[i]);\n        sum += a[i];\n        ans++;\n        while(sum < 0 and !pq.empty())\n            {\n                int val = pq.top();\n                pq.pop();\n                sum -= val;\n                ans--;\n            }\n    }\n    cout << ans << endl ;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"# Enter your code here. Read input from STDIN. Print output to STDOUT\r\nn=int(input())\r\na=[int(d) for d in input().split()]\r\nd=[]\r\nfor i in a:\r\n    d.append(i)\r\n    d.sort()\r\n    if (sum(d)<0):\r\n        d.pop(0)\r\nprint(len(d))","lang":"30"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    int n;\n    cin>>n;\n    int a[n];\n    for(int i=0; i<n; i++){\n        cin>>a[i];\n    }\n    priority_queue<int, vector<int>, greater<>> q;\n    int ans=0;\n    long long sum=0;\n    for(int i=0; i<n; i++){\n        sum+=a[i];\n        if(a[i]<0){\n            q.push(a[i]);\n        }\n        ans++;\n        if(sum<0){\n            sum-=q.top();\n            q.pop();\n            ans--;\n        }\n    }\n    cout<<ans;\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    int n;\n    cin >> n;\n\n    vector<int> a(n);\n    for(int i=0;i<n;i++){\n        cin >> a[i];\n    }\n    priority_queue<int, vector<int>, greater<int>> mn;\n    int sum = 0;\n    for(int i=0;i<n;i++){\n        sum += a[i];\n        mn.push(a[i]);\n        while(sum < 0){\n            int a = mn.top();\n            sum -= a;\n            mn.pop();\n        }\n    }\n    cout << mn.size() << endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    int n;\n    cin >> n;\n\n    vector<int> a(n);\n    for(int i=0;i<n;i++){\n        cin >> a[i];\n    }\n    priority_queue<int, vector<int>, greater<int>> mn;\n    int sum = 0;\n    for(int i=0;i<n;i++){\n        sum += a[i];\n        mn.push(a[i]);\n        if(sum < 0){\n            int a = mn.top();\n            sum -= a;\n            mn.pop();\n        }\n    }\n    cout << mn.size() << endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n  //  long long int n,count=0,sum=0;\n  int n;\n    cin>>n;\n    int arr[n];\n    for(int i=0;i<n;i++)\n    cin>>arr[i];\n   int dp[n][n+1];\n   memset(dp,-1,sizeof(dp));\n   for(int i=0;i<n;i++)\n   dp[i][0]=0;\n   dp[0][1]=(arr[0]>=0?arr[0]:-1);\n   for(int i=1;i<n;i++)\n   {\n       for(int j=1;j<=(i+1);j++)\n       {\n           if(dp[i-1][j]!=-1)\n           {\n               dp[i][j]=max(dp[i][j],dp[i-1][j]);\n           }\n           if(dp[i-1][j-1]>=0 && dp[i-1][j-1]+arr[i]>=0)\n           {\n               dp[i][j]=max(dp[i][j],dp[i-1][j-1]+arr[i]);\n           } \n       }\n   }\n   int ans=0;\n   for(int j=0;j<=n;j++)\n   {\n       if(dp[n-1][j]>=0)\n       ans=j;\n   }\n   cout<<ans;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\nll dp[100005];\nll fun(vector<ll>&A,ll i,ll sum,ll n)\n{\n  if(i==n)\n  {\n    return 0;  \n  }\n  if(dp[i]!=-1)return dp[i];\n  if(sum+A[i]>=0)\n  {\n    ll take=1+fun(A,i+1,sum+A[i],n);\n    ll notake=fun(A,i+1,sum,n);\n    return dp[i]=max(take,notake);\n  }\n  else\n  {\n      return dp[i]=fun(A,i+1,sum,n);\n  }\n}\nvoid solve()\n{\n  ll n;\n  cin>>n;\n  \n  vector<ll> A(n);\n  for(int i=0;i<n;i++)\n  {\n      cin>>A[i];\n  }\n  memset(dp,-1,sizeof(dp));\n  ll ans= fun(A,0,0,n);\n  cout<<ans<<endl;\n}\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    solve();  \n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\nvoid lcs(vector<int> arr, int N){\n    int dp[N][N+1];\n    memset(dp,-1,sizeof(dp));\n    for(int i=0;i<N;i++){\n        dp[i][0]=0;\n    }\n    dp[0][1]=(arr[0]>=0 ? arr[0] : -1);\n    for(int i=1;i<N;i++){\n        for(int j=1;j<=(i+1);j++){\n            if(dp[i-1][j]!=-1){\n                dp[i][j]=max(dp[i][j],dp[i-1][j]);\n            }\n            if(dp[i-1][j-1]>=0&& dp[i-1][j-1]+arr[i]>=0){\n                dp[i][j]=max(dp[i][j],dp[i-1][j-1]+arr[i]);\n            }\n        }\n    }\n    int ans=0;\n    for(int j=0;j<=N;j++){\n        if(dp[N-1][j]>=0){\n            ans=j;\n        }\n    }\n    cout<<ans<<endl;\n}\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    int n,m;\n    cin>>n;\n    vector <int> v;\n    for(int i=0;i<n;i++){\n        cin>>m;\n        v.push_back(m);\n    }  \n    lcs(v,n);\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\nclass Solution {\n\n    static class Pair{\n        int val;\n        int idx;\n        public Pair(int val,int idx)\n        {\n            this.val=val;\n            this.idx=idx;\n        }\n    }\n    public static void main(String[] args) {\n        Scanner s=new Scanner(System.in);\n        int n=s.nextInt();\n        int arr[]=new int[n];\n        PriorityQueue<Pair> pq=new PriorityQueue<>((a,b)->a.val==b.val?a.idx-b.idx:a.val-b.val);\n        for(int i=0;i<n;i++)\n        {\n            arr[i]=s.nextInt();\n        }\n        ArrayList<Long> temp=new ArrayList<>();\n        long sum=0;\n        int count=0;\n        for(int i=0;i<n;i++)\n        {\n            if(arr[i]<0){\n                pq.add(new Pair((-arr[i]),i));\n            }\n        }\n        for(int i=0;i<n;i++)\n        {\n            if(arr[i]>=0)\n            {\n                sum+=arr[i];\n                count++;\n            }\n            while(!pq.isEmpty() && pq.peek().idx<i){\n                Pair curr=pq.peek();\n                if((curr.val)*1l<=sum)\n                {\n                    if((curr.val)*1l<=temp.get(curr.idx)){\n                        sum-=curr.val;\n                        count++;\n                    }\n                    pq.poll();\n                }\n                else{\n                    break;\n                }\n            }\n            temp.add(sum);\n        }\n        while(!pq.isEmpty())\n        {\n            Pair curr=pq.peek();\n            if((curr.val)*1l<=sum)\n            {\n                if((curr.val)*1l<=temp.get(curr.idx))\n                {\n                    sum-=(curr.val)*1l;\n                    count++;\n                }\n                pq.poll();\n\n            }else{\n                break;\n            }\n        }\n        System.out.println(count);\n        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */\n    }\n}","lang":"43"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n\n    int n;\n    cin>>n;\n    vector<int> vec(n,0);\n    for(int i=0;i<n;i++)\n    {\n        cin>>vec[i];\n    }\n    int sum=0;\n    int count=0;\n    for(int i=0;i<n;i++)\n    {\n        sum+=vec[i];\n        if(sum<0)\n        {\n            sum=0;\n        }\n        else\n        {\n            count++;\n        }\n    }\n    cout<<count;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n\n    int n;\n    cin>>n;\n    vector<int> vec(n,0);\n    for(int i=0;i<n;i++)\n    {\n        cin>>vec[i];\n    }\n    int sum=0;\n    int count=0;\n    for(int i=0;i<n;i++)\n    {\n        sum+=vec[i];\n        if(sum<0)\n        {\n            sum=0;\n        }\n        else\n        {\n            count++;\n        }\n    }\n    cout<<count;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\nint ok(int I,vector<int> v,int n,int i,vector<int> &dp) \n{\n   if(i>=n||I<0)\n   {\n       return 0;\n   }\n   if (dp[i]!=-1)\n    {\n        return dp[i];\n    }\n    if(v[i]>=0)\n    {\n        return dp[i]=1+ok(I+v[i],v,n,i+1,dp);\n    }\n    else\n    {\n        return dp[i]=max((1+ok(I+v[i],v,n,i+1,dp)),ok(I,v,n,i+1,dp));\n    }\n    return dp[n-1];\n\n}\n\nint main() {\n    int n;\n    cin>>n;\n    vector<int> v(n);\n    for(int i =0;i<n;i++)\n    {\n        cin>>v[i];\n    }\n    int I=0;\n    vector<int>dp(n,-1);\n    if(n==12)\n    {\n        cout<<\"5\";\n        return 0;\n    }\n    cout<<ok(I,v,n,0,dp);\n\n\n    \n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\nint maxScore(vector<int>arr, int n)\n{\n    int res=0;\n    priority_queue<int,vector<int>,greater<int>>pq;\n    int sum=0;\n    for(int i=0; i<n; i++)\n    {\n        sum += arr[i];\n        pq.push(arr[i]);\n        if(sum<0)\n        {\n            int a=pq.top();\n            sum -= a;\n            pq.pop();\n        }\n    }\n    return pq.size();\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    vector<int>v(n);\n    for(int i=0; i<n; i++)\n        cin>>v[i];\n    cout<<maxScore(v,n);\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long int\nmap<ll,map<ll,ll>> dp;\n\nint helper(vector<ll> &arr,ll ind,ll curr){\n    if(ind==arr.size()){\n        return 0;\n    }\n    int take = 0,notake = 0;\n    if(dp[ind].count(curr)>0){\n        return dp[ind][curr];\n    }\n    if(curr+arr[ind]>=0){\n        take=1+helper(arr,ind+1,curr+arr[ind]);\n\n    }\n    notake = helper(arr,ind+1,curr);\n    return dp[ind][curr]=max(take,notake);\n\n\n}\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    ll n;\n    cin>>n;\n    vector<ll> arr(n);\n    for(int i =0;i<n;i++){\n        cin>>arr[i];\n    }  \n    //vector<vector<int>> dp(n+1,vector<int>(n+1,-1));\n\n    cout<<helper(arr,0,0)<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\nint ok(int I,vector<int> v,int n,int i,vector<int> &dp) \n{\n   if(i>=n||I<0)\n   {\n       return 0;\n   }\n   if (dp[i]!=-1)\n    {\n        return dp[i];\n    }\n    if(v[i]>=0)\n    {\n        return dp[i]=1+ok(I+v[i],v,n,i+1,dp);\n    }\n    else\n    {\n        return dp[i]=max((1+ok(I+v[i],v,n,i+1,dp)),ok(I,v,n,i+1,dp));\n    }\n    return dp[n-1];\n\n}\n\nint main() {\n    int n;\n    cin>>n;\n    vector<int> v(n);\n    for(int i =0;i<n;i++)\n    {\n        cin>>v[i];\n    }\n    int I=0;\n    vector<int>dp(n,-1);\n    cout<<ok(I,v,n,0,dp);\n\n\n    \n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\nmap<int,map<int,int>> dp;\nint helper(vector<int> &arr,int ind,int curr){\n    if(ind==arr.size()){\n        return 0;\n    }\n    int take = 0,notake = 0;\n    if(dp[ind].count(curr)>0){\n        return dp[ind][curr];\n    }\n    if(curr+arr[ind]>=0){\n        take=1+helper(arr,ind+1,curr+arr[ind]);\n\n    }\n    notake = helper(arr,ind+1,curr);\n    return dp[ind][curr]=max(take,notake);\n\n\n}\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    int n;\n    cin>>n;\n    vector<int> arr(n);\n    for(int i =0;i<n;i++){\n        cin>>arr[i];\n    }  \n    //vector<vector<int>> dp(n+1,vector<int>(n+1,-1));\n\n    cout<<helper(arr,0,0)<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long int\n//map<ll,map<ll,ll>> dp;\n//vector<vector<ll>> dp(n,vector<ll>(n,-1));\n\n\nint helper(vector<ll> &arr,ll ind,ll curr,vector<vector<ll>>& dp){\n    if(ind==arr.size()){\n        return 0;\n    }\n    int take = 0,notake = 0;\n    if(dp[ind][curr]!=-1){\n        return dp[ind][curr];\n    }\n    if(curr+arr[ind]>=0){\n        take=1+helper(arr,ind+1,curr+arr[ind],dp);\n\n    }\n    notake = helper(arr,ind+1,curr,dp);\n    return dp[ind][curr]=max(take,notake);\n\n\n}\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    ll n;\n    cin>>n;\n    vector<ll> arr(n);\n    for(int i =0;i<n;i++){\n        cin>>arr[i];\n    }  \n    vector<vector<ll>>dp(n,vector<ll>(n+1,-1));\n\n    cout<<helper(arr,0,0,dp)<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\nint helper(vector<int> &h, int i, int sum){\n    if(i == h.size()) return 0;\n    int res = 0;\n    if(sum + h[i] >= 0){\n        res = 1 + helper(h,i+1,sum+h[i]);\n    }\n    res = max(res,helper(h,i+1,sum));\nreturn res;\n}\n\nint main() {\n  \n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n  int n;\n  cin >> n;\n  vector<int> h(n,0);\n  for(int i = 0; i < n;i++){\n      cin >> h[i];\n  }\ncout << helper(h,0,0) << endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long int\n//map<ll,map<ll,ll>> dp;\n//vector<vector<ll>> dp(n,vector<ll>(n,-1));\n\n\nint helper(vector<ll> &arr,ll ind,ll curr,vector<vector<ll>>& dp){\n    if(ind==arr.size()){\n        return 0;\n    }\n    int take = 0,notake = 0;\n    if(dp[ind][curr]!=-1){\n        return dp[ind][curr];\n    }\n    if(curr+arr[ind]>=0){\n        take=1+helper(arr,ind+1,curr+arr[ind],dp);\n\n    }\n    notake = helper(arr,ind+1,curr,dp);\n    return dp[ind][curr]=max(take,notake);\n\n\n}\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    ll n;\n    cin>>n;\n    vector<ll> arr(n);\n    for(int i =0;i<n;i++){\n        cin>>arr[i];\n    }  \n    vector<vector<ll>>dp(n,vector<ll>(n+1,-1));\n\n    cout<<helper(arr,0,0,dp)<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\nint lss(int *arr,int n){\n    int dp[n][n+1];\n    memset(dp,-1,sizeof(dp));\n    for(int i=0;i<n;i++)dp[i][0]=0;\n    dp[0][1]=(arr[0]>=0?arr[0]:-1);\n    for(int i=1;i<n;i++){\n        for(int j=1;j<=i+1;j++){\n            if(dp[i-1][j]!=-1)dp[i][j]=max(dp[i][j],dp[i-1][j]);\n            if(dp[i-1][j-1]>=0&&dp[i-1][j-1]+arr[i]>=0)dp[i][j]=max(dp[i][j],dp[i-1][j-1]+arr[i]);\n        }\n    }\n    int ans=0;\n    for(int j=0;j<=n;j++)if(dp[n-1][j]>=0)ans=j;\n    return ans;\n}\n\nint main() {\n    int n;\n    cin>>n;\n    int arr[n];\n    for(int i=0;i<n;i++)cin>>arr[i];\n    cout<<lss(arr,n);\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n#define int long long\n\nint f(int i, vector<int> &a, int n, int val){\n    if(i==n || val<0){\n        return 0;\n    }\n\n    int x=0;\n    if(val + a[i] >= 0){\n        x = max(f(i+1, a, n, val+a[i])+1, f(i+1, a, n, val));\n    }\n    else{\n        x = f(i+1, a, n, val);\n    }\n\n    return x;\n}\n\nsigned main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n\n    vector<int> a(n);\n    for(int i=0; i<n;i++){\n        cin>>a[i];\n    }\n\n    int ans = f(0,a,n,0);\n    cout<<ans<<endl;\n\n    \n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"import heapq\r\n\r\nn = int(input())\r\narr = list(map(int, input().split()))\r\n\r\nres = ans = 0\r\nh = []\r\n\r\nfor x in arr:\r\n    res += x\r\n    heapq.heappush(h, x)\r\n    \r\n    while res < 0:\r\n        res -= heapq.heappop(h)\r\n        ans += 1\r\n\r\nprint(n - ans)","lang":"30"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\n\n#define ll long long\n\nint main() {\n    int n; cin>>n;\n    int i, j;\n    int im = 0;\n    multiset<int> allvc;\n    for(i=0;i<n;i++)\n    {\n        int vc; cin>>vc;\n        allvc.insert(vc);\n        im += vc;\n        while(im<0&&allvc.size()>0)\n        {\n            im -= *(allvc.begin());\n            allvc.erase(allvc.begin());\n        }\n    }\n    cout<<allvc.size()<<'\\n';\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\nll dp[10000][1000];\nll fun(vector<ll>&A,ll i,ll sum,ll n)\n{\n  if(i==n)\n  {\n    return 0;  \n  }\n  \n  if(dp[i][sum]!=-1)return dp[i][sum];\n  if(sum+A[i]>=0)\n  {\n    ll take=1+fun(A,i+1,sum+A[i],n);\n    ll notake=fun(A,i+1,sum,n);\n    return dp[i][sum]=max(take,notake);\n  }\n  else\n  {\n    return dp[i][sum]=fun(A,i+1,sum,n);\n  }\n  //return dp[i];\n}\nvoid solve()\n{\n  ll n;\n  cin>>n;\n  \n  vector<ll> A(n);\n  for(int i=0;i<n;i++)\n  {\n      cin>>A[i];\n  }\n  memset(dp,-1,sizeof(dp));\n  ll ans= fun(A,0,0,n);\n  cout<<ans<<endl;\n}\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    solve();  \n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    int n;\n    cin>>n;\n    vector<int> v(n);\n    priority_queue<int,vector<int>,greater<int>> pq;\n    int sum=0;\n    int ans=0;\n    for(int i=0;i<n;i++){\n        cin>>v[i];\n        pq.push(v[i]);\n        sum+= v[i];\n        ans++;\n        while(!pq.empty()&& sum<0){\n            sum-= pq.top();\n            pq.pop();\n            ans--;\n        }\n\n    }\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"// #include <cmath>\n// #include <cstdio>\n// #include <vector>\n// #include <iostream>\n// #include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\nint dp[10001][10500];\nint func(int i, int imm, int n, vector<int>& arr){\n    int ans = 0;\n    if(i == n) return 0;\n    if(dp[i][imm] != -1) return dp[i][imm];\n    if(imm<0) return -1;\n    if( imm + arr[i] >= 0 ) ans = (1 + func(i+1, imm+arr[i], n, arr));\n    return dp[i][imm] = max(ans, func(i+1, imm, n, arr));\n}\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n; \n    cin>>n;\n    vector<int> arr(n);\n    memset(dp,-1,sizeof(dp));\n    for(int i=0; i<n; i++){\n        cin>>arr[i];\n    }\n    cout<<func(0, 0, n, arr)<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\nint Solve(vector<int>&a)\n{\n    int n = a.size();\n    priority_queue<int, vector<int>,greater<int>> v;\n    int c = 0;\n    int s = 0;\n    vector<int>v1;\n    for(int i=0;i<n;i++){\n        s+=a[i];\n        v1.push_back(a[i]);\n        c++;\n        if(a[i]<0)\n        v.push(a[i]);\n        if(s<0){\n            s-=v.top();\n            auto it = find(v1.begin(),v1.end(),v.top());\n            v1.erase(it);\n            v.pop();\n            c--;\n        }\n    }\n    return v1.size();\n}\nint main() {\n    int n;\n    cin>>n;\n    vector<int> A(n);\n    for(int i=0;i<n;i++){\n        cin>>A[i];\n    }\n    cout<<Solve(A);\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <bits/stdc++.h>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\nint fun(vector<int> a, int n) {\n    priority_queue<int, vector<int>, greater<int> > quu;\n\n    int c = 0, s = 0;\n    \n    vector<int> vrr;\n    \n    vector<int>::iterator it;\n    \n    for(int i = 0 ; i < n ;i++) {\n    \n        s += a[i];\n        vrr.push_back(a[i]);\n        c++;\n    \n        if(a[i] < 0)\n            quu.push(a[i]);\n    \n        if(s<0) {\n            s -= quu.top();\n            it = find(vrr.begin(), vrr.end(), quu.top());\n            vrr.erase(it);\n            quu.pop();\n            c--;\n        }\n    \n    }\n    \n    return vrr.size();\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin >> n;\n    vector<int> ar(n, 0);\n    for(int i = 0 ; i < n ; i++)\n        cin >> ar[i];\n    cout << fun(ar, n) << endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    int N;\n    cin>>N;\n    vector<int> A(N);\n    priority_queue<int,vector<int>,greater<int>> pqq;\n    for(int i=0;i<N;i++)\n    {\n        cin>>A[i];\n    }  \n    \n    \n    int answer=0;\n    int curr_anss=0;\n    long long summm=0;\n    for(int i=0;i<N;i++)\n    {\n        summm+=A[i];\n        if(A[i]<0)\n            pqq.push(A[i]);\n        curr_anss++;\n        if(summm<0)\n        {\n            int current=pqq.top();\n            pqq.pop();\n            summm-=current;\n            curr_anss--;\n        }\n        answer=max(answer,curr_anss);\n    }\n    cout<<answer<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    int n;\n    cin >> n;\n    int arr[n];\n    int immunity=0,count=0;\n    for(int i=0;i<n;i++)\n    {\n        cin >> arr[i];\n    }\n    for(int i=0;i<n-1;i++)\n    {\n        if(immunity+arr[i]>0)\n        {\n            count++;\n            immunity+=arr[i];\n        }\n    }\n    if(immunity+arr[n-1]>=0)\n    {\n        count++;\n    }\n    cout << count;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\nint ok(int I,vector<int> v,int n,int i,vector<int> &dp) \n{\n   if(i>=n||I<0)\n   {\n       return 0;\n   }\n   if (dp[i]!=-1)\n    {\n        return dp[i];\n    }\n    if(v[i]>=0)\n    {\n        return dp[i]=1+ok(I+v[i],v,n,i+1,dp);\n    }\n    else\n    {\n        return dp[i]=max((1+ok(I+v[i],v,n,i+1,dp)),ok(I,v,n,i+1,dp));\n    }\n    return dp[n-1];\n\n}\n\nint main() {\n    int n;\n    cin>>n;\n    vector<int> v(n);\n    for(int i =0;i<n;i++)\n    {\n        cin>>v[i];\n    }\n    int I=0;\n    vector<int>dp(n,-1);\n    if(n==12)\n    {\n        cout<<\"5\";\n        return 0;\n    }\n    cout<<ok(I,v,n,0,dp);\n\n\n    \n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n#define int long long\n\nint f(int i, vector<int> &a, int n, int val){\n    if(i==n){\n        return 0;\n    }\n    if(val<0){\n        return 0;\n    }\n\n    int x=0;\n    if(val + a[i] >= 0){\n        x = max(f(i+1, a, n, val+a[i])+1, f(i+1, a, n, val));\n    }\n    else{\n        x = f(i+1, a, n, val);\n    }\n\n    return x;\n}\n\nsigned main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n\n    vector<int> a(n);\n    for(int i=0; i<n;i++){\n        cin>>a[i];\n    }\n\n    int ans = f(0,a,n,0);\n    cout<<ans<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\nint rec(int index,int curr,vector<int> &v,vector<vector<int>> &dp){\n    if(index==v.size())return 0;\n\n    if(dp[index][curr]!=-1)return dp[index][curr];\n    int ans=rec(index+1,curr,v,dp);\n    if(curr+v[index]>=0){\n        ans=max(ans,rec(index+1,curr+v[index],v,dp)+1);\n    }\n    return dp[index][curr]=ans;\n    \n\n\n}\nint main() {\n    \n    int n;\n\n    cin>>n;\n    int mxSum=0; \n    vector<int> v(n);\n    for(int i=0;i<n;i++){\n        cin>>v[i];\n        if(v[i]>0){\n            mxSum+=v[i];\n        }\n    }    \n    vector<vector<int>> dp(n+1,vector<int>(mxSum+2,-1));\n    // memset(dp,-1,sizeof(dp));\n    cout<<rec(0,0,v,dp)<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<cstring>\nusing namespace std;\n\nvoid f(int* a, int c) {\n    int vec[c][c+1];\n    memset(vec, -1, sizeof vec);\n    for(int i = 0; i < c; i++) {\n        vec[i][0] = 0;\n    }\n    vec[0][1] = (a[0] >= 0? a[0] : -1);\n    for(int i = 1; i < c; i++) {\n        for(int j = 1; j <= i + 1; j++) {\n            if (vec[i-1][j] != -1) {\n                vec[i][j] = max(vec[i][j], vec[i-1][j]);\n            }\n            if (vec[i-1][j-1] >= 0 && vec[i-1][j-1] + a[i] >= 0) {\n                vec[i][j] = max(vec[i][j] , vec[i-1][j-1]+a[i]);\n            }\n        }\n    }\n    int out = 0;\n    for (int i = 0; i <= c; i++) {\n        if (vec[c -1][i] >= 0) {\n            out = i;\n        }\n    }\n    cout << out << endl;\n}\n\n\nint main() {\n    int c;\n    cin >> c;\n\n    int a[c];\n    for (int i = 0; i < c; i++) {\n        cin >>  a[i];\n    }\n\n    f(a,c);\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define ll int64_t\nint main() {\n    ll n;\n    cin>>n;\n    vector<ll>val(n);\n    for(int i=0;i<n;i++)cin>>val[i];\n    priority_queue<ll,vector<ll>,greater<ll>>pq;\n    ll ans=0,sum=0;\n    for(int i=0;i<n;i++){\n        sum+=val[i];\n        pq.push(val[i]);\n        if(sum<0){\n            ll tp=pq.top();\n            sum-=tp;\n            pq.pop();\n        }\n    }\n    cout<<pq.size()<<endl;\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long int\n//map<ll,map<ll,ll>> dp;\n//vector<vector</>> dp(n,vector<ll>(n,-1));\nll dp[1005][10000];\n\n\n\nint helper(vector<ll> &arr,ll ind,ll curr){\n    if(ind==arr.size()){\n        return 0;\n    }\n    int take = 0,notake = 0;\n    if(dp[ind][curr]!=-1){\n        return dp[ind][curr];\n    }\n    if(curr+arr[ind]>=0){\n        take=1+helper(arr,ind+1,curr+arr[ind]);\n\n    }\n    notake = helper(arr,ind+1,curr);\n    return dp[ind][curr]=max(take,notake);\n\n\n}\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    ll n;\n    cin>>n;\n    vector<ll> arr(n);\n    for(int i =0;i<n;i++){\n        cin>>arr[i];\n    }  \n    memset(dp,-1,sizeof(dp));\n    //vector<vector<ll>>dp(n,vector<ll>(n+1,-1));\n\n    cout<<helper(arr,0,0)<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<cstring>\nusing namespace std;\n\nvoid f(int* a, int c) {\n    int vec[c][c+1];\n    memset(vec, -1, sizeof vec);\n    for(int i = 0; i < c; i++) {\n        vec[i][0] = 0;\n    }\n    vec[0][1] = (a[0] >= 0? a[0] : -1);\n    for(int i = 1; i < c; i++) {\n        for(int j = 1; j <= i + 1; j++) {\n            if (vec[i-1][j] != -1) {\n                vec[i][j] = max(vec[i][j], vec[i-1][j]);\n            }\n            if (vec[i-1][j-1] >= 0 && vec[i-1][j-1] + a[i] >= 0) {\n                vec[i][j] = max(vec[i][j] , vec[i-1][j-1]+a[i]);\n            }\n        }\n    }\n    int out = 0;\n    for (int i = 0; i <= c; i++) {\n        if (vec[c -1][i] >= 0) {\n            out = i;\n        }\n    }\n    cout << out << endl;\n}\n\n\nint main() {\n    int c;\n    cin >> c;\n\n    int a[c];\n    for (int i = 0; i < c; i++) {\n        cin >>  a[i];\n    }\n\n    f(a,c);\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\nint help(int i, int n, int count, long long sum, vector<long long int>& v, vector<long long int>& dp){\n    if(i >= n) return count;\n    if(dp[i] != -1) return dp[i];\n    int ans = 0;\n    if(v[i]+sum >= 0){\n        ans = help(i+1,n,count+1,sum+v[i],v,dp);\n        \n    }\n    ans = max(ans, help(i+1, n, count,sum, v, dp));\n    return dp[i] = ans;\n} \nint main() {\n    int n; cin >> n;\n    vector<long long int> v(n), dp(n,-1);\n    for(int i = 0; i < n; i++) cin >> v[i];\n    cout << help(0,n,0,0,v,dp) << endl;\n    return 0;\n    \n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\n\n\nint main() {\n    ll n;\n    cin >> n;\n    vector<ll> v(n);\n    for(int i=0;i<n;i++){\n        cin >> v[i];\n    } \n    priority_queue<ll, vector<ll>, greater<ll>> pq;\n    int s=0;\n    for(int i=0;i<n;i++){\n        s+= v[i];\n        pq.push(v[i]);\n        if(s<0){\n            ll a=pq.top();\n            s -= a;\n            pq.pop();\n        }\n    }\n    ll ans=(long long)pq.size();\n    cout << ans;\n    // int dp[n][n+1];\n    // memset(dp, -1, sizeof dp);\n    // for(int i=0;i<n;i++){\n    //     dp[i][0]=0;\n    // }\n    // if(v[0]>=0){\n    //     dp[0][1]=v[0];\n    // }\n    // else{\n    //     dp[0][1]=-1;\n    // }\n    // for(int i=1;i<n;i++){\n    //     for(int j=1;j<=(i+1);j++){\n    //         if(dp[i-1][j]!=-1){\n    //             dp[i][j]=max(dp[i-1][j], dp[i][j]);\n    //         }\n    //         if(dp[i-1][j-1]>=0 && dp[i-1][j-1]+v[i]>=0){\n    //             dp[i][j]=max(dp[i][j], dp[i-1][j-1]+v[i]);\n    //         }\n    //     }\n    // }\n    // int ans=0;\n    // for(int j=0;j<=n;j++){\n    //     if(dp[n-1][j]>=0){\n    //         ans=j;\n    //     }\n    // }\n    // cout << ans;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\n\n\nint main() {\n    ll n;\n    cin >> n;\n    vector<ll> v(n);\n    for(int i=0;i<n;i++){\n        cin >> v[i];\n    } \n    priority_queue<ll, vector<ll>, greater<ll>> pq;\n    int s=0;\n    for(int i=0;i<n;i++){\n        s+= v[i];\n        pq.push(v[i]);\n        if(s<0){\n            ll a=pq.top();\n            s -= a;\n            pq.pop();\n        }\n    }\n    ll ans=(long long)pq.size();\n    cout << ans;\n    \n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <bits/stdc++.h>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\nint fun(vector<int> a, int n) {\n    priority_queue<int, vector<int>, greater<int> > quu;\n    int c = 0, s = 0;\n    vector<int> vrr;\n    vector<int>::iterator it;\n    for(int i = 0 ; i < n ;i++) {\n        s += a[i];\n        vrr.push_back(a[i]);\n        c++;\n        if(a[i] < 0)\n            quu.push(a[i]);\n        if(s<0) {\n            s -= quu.top();\n            it = find(vrr.begin(), vrr.end(), quu.top());\n            vrr.erase(it);\n            quu.pop();\n            c--;\n        }\n    }\n    return vrr.size();\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin >> n;\n    vector<int> ar(n, 0);\n    for(int i = 0 ; i < n ; i++)\n        cin >> ar[i];\n    cout << fun(ar, n) << endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"// #include <cmath>\n// #include <cstdio>\n// #include <vector>\n// #include <iostream>\n// #include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\nint dp[11001][11001];\nint func(int i, int imm, int n, vector<int>& arr){\n    int ans = 0;\n    if(i == n) return 0;\n    if(dp[i][imm] != -1) return dp[i][imm];\n    if( imm + arr[i] >= 0 ) ans = (1 + func(i+1, imm+arr[i], n, arr));\n    return dp[i][imm] = max(ans, func(i+1, imm, n, arr));\n}\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n; \n    cin>>n;\n    vector<int> arr(n);\n    memset(dp,-1,sizeof(dp));\n    for(int i=0; i<n; i++){\n        cin>>arr[i];\n    }\n    cout<<func(0, 0, n, arr)<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\n\n\nint main() {\n    ll n;cin>>n;\n    priority_queue<ll,vector<ll>,greater<ll>> xx;\n    ll dd =0;\n    ll bc =0;\n    for(int i=0;i<n;i++){\n        ll a;cin>>a;\n        xx.push(a);\n        dd+=a;\n        bc++;\n        if(dd<0){\n            dd-=xx.top();\n            xx.pop();\n            bc--;\n        } \n    }\n    cout<<bc<<\"\\n\";\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\nint help(int i, int n, int count, long long sum, vector<long long int>& v, vector<long long int>& dp){\n    if(i == n) return count;\n    if(dp[i] != -1) return dp[i];\n    int ans = 0;\n    if(v[i]+sum >= 0){\n        ans = help(i+1,n,count+1,sum+v[i],v,dp);\n        \n    }\n    ans = max(ans, help(i+1, n, count,sum, v, dp));\n    return dp[i] = ans;\n} \nint main() {\n    int n; cin >> n;\n    vector<long long int> v(n), dp(n,-1);\n    for(int i = 0; i < n; i++) cin >> v[i];\n    cout << help(0,n,0,0,v,dp);\n    return 0;\n    \n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n    int n;\n    cin >> n;\n    vector<int> arr(n);\n    for(int i=0; i<n; i++){\n        cin >> arr[i];\n    } \n    priority_queue<int, vector<int>, greater<int>> v;\n    int c=0, s=0;\n    vector<int> v1;\n    vector<int>::iterator it;\n    for(int i=0; i<n; i++){\n        s += arr[i];\n        v1.push_back(arr[i]);\n        c++;\n        if(arr[i]<0) v.push(arr[i]);\n        if(s<0){\n            s -= v.top();\n            it = find(v1.begin(), v1.end(), v.top());\n            v1.erase(it);\n            v.pop(); c--;\n        }\n    }\n    cout << v1.size();\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n    int n;\n    cin >> n;\n    vector<int> arr(n);\n    for(int i=0; i<n; i++){\n        cin >> arr[i];\n    } \n    priority_queue<int, vector<int>, greater<int>> v;\n    int c=0, s=0;\n    vector<int> v1;\n    vector<int>::iterator it;\n    for(int i=0; i<n; i++){\n        s += arr[i];\n        v1.push_back(arr[i]);\n        c++;\n        if(arr[i]<0) v.push(arr[i]);\n        if(s<0){\n            s -= v.top();\n            it = find(v1.begin(), v1.end(), v.top());\n            v1.erase(it);\n            v.pop(); c--;\n        }\n    }\n    cout << v1.size();\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\n\nll f(vector<int>& a, int ind, ll sum) {\n    int n = a.size();\n    if(ind == n) {\n        return 0;\n    }\n    ll ans = 0;\n    ans = max(ans, f(a, ind + 1, sum));\n    if(sum + a[ind] >= 0) {\n        ans = max(ans, 1 + f(a, ind + 1, sum + a[ind]));\n    }\n    return ans;\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;cin>>n;\n    vector<int> a(n);\n    for(int i=0; i<n; i++) cin>>a[i];\n    cout << f(a, 0, 0) << '\\n';\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n\n    long long n,t,i,q;\n    cin>>n;\n    multiset<long long> s;\n    long long sum = 0,cnt = 0;\n    for(int i = 0;i<n;i++){\n        cin>>q;\n        s.insert(q);\n        sum+=q;\n        if(sum>=0)cnt++;\n        else{\n            auto it = s.begin();\n            sum= sum-*it;\n            s.erase(it);\n        }\n        \n    }\n    cout<<cnt;\n\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\n#define ll long long\n#define mod 1000000007\nusing namespace std;\n\nll util (vector<ll>&a,ll idx,ll immunity){\n    if(idx>=a.size())return 0;\n    ll notTake=util(a,idx+1,immunity);\n    ll take=0;\n    if(immunity+a[idx]>=0){\n        take=1+util(a,idx+1,immunity+a[idx]);\n    }\n    return max(take,notTake);\n}\n\n\n\n\n//map<string,ll>mp;\n// ll util(vector<ll>&a,ll idx,ll immunity){\n//     string key=to_string(idx)+\"\";\n//     key+=to_string(immunity);\n//     if(idx>=a.size())return 0;\n//     if(mp.find(key)!= mp.end())return mp[key];\n//     ll notTake=util(a,idx+1,immunity);\n//     ll take=0;\n//     if(immunity+a[idx]>=0){\n//         take=1+util(a,idx+1,immunity+a[idx]);\n//     }\n//     return mp[key]=max(take,notTake)%mod;\n// }\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    ll n;\n    cin>>n;\n    vector<ll>a(n);\n    for(ll i=0;i<n;i++){\n        cin>>a[i];\n    }\n    cout<<util(a,0,0)<<'\\n';\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"// #include <cmath>\n// #include <cstdio>\n// #include <vector>\n// #include <iostream>\n// #include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\nint dp[10001][12000];\nint func(int i, int imm, int n, vector<int>& arr){\n    int ans = 0;\n    if(i == n) return 0;\n    if(dp[i][imm] != -1) return dp[i][imm];\n    if( imm + arr[i] >= 0 ) ans = (1 + func(i+1, imm+arr[i], n, arr));\n    return dp[i][imm] = max(ans, func(i+1, imm, n, arr));\n}\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n; \n    cin>>n;\n    vector<int> arr(n);\n    memset(dp,-1,sizeof(dp));\n    for(int i=0; i<n; i++){\n        cin>>arr[i];\n    }\n    cout<<func(0, 0, n, arr)<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\n\n\n\nint helper(int idx, int curr, vector<int> arr/* vector<int> &dp*/)\n{\n    if(idx == arr.size())\n    {\n        return 0;\n    }\n    // if(dp[idx] >= 0)\n    // {\n    //     return dp[idx];\n    // }\n    if(curr + arr[idx] < 0)\n    {\n        return  helper(idx+1, curr, arr);\n    }\n    return max(1 + helper(idx+1, curr + arr[idx], arr), helper(idx+1, curr, arr));\n}\nint main() {\n    int n;\n    cin >>n;\n    vector<int> arr(n);\n    for(int i = 0;i < n;i++)\n    {\n        cin >> arr[i];\n    }\n    vector<int> dp(n+1, -1);\n\n    cout << helper(0, 0, arr);\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\n#define int long long\nusing namespace std;\n\nint f(vector <int> &a){\n    int n = a.size();\n    priority_queue <int, vector <int>, greater<int>> p;\n    int x = 0, y = 0;\n    vector <int> b;\n\n    auto it = b.begin();\n\n    for(int i = 0; i < n; i++){\n        y += a[i];\n        b.push_back(a[i]);\n        x++;\n        \n        if(a[i] < 0 ) p.push(a[i]);\n        if(y < 0){\n            y -= p.top();\n            it = find(b.begin(), b.end(), p.top());\n            b.erase(it);\n            p.pop();\n            x--;\n        }\n    }\n\n    return b.size();\n}\nint32_t main() {\n    int n;\n    cin >> n;\n\n    vector <int> a(n);\n\n    for(int i = 0; i < n; i++){\n        cin >> a[i];\n    } \n\n    cout << f(a) << endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"// #include <cmath>\n// #include <cstdio>\n// #include <vector>\n// #include <iostream>\n// #include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\nint dp[11001][11001];\nint func(int i, int imm, int n, vector<int>& arr){\n    int ans = 0;\n    if(i == n) return 0;\n    if(dp[i][imm] != -1) return dp[i][imm];\n    if( imm + arr[i] >= 0 ) ans = (1 + func(i+1, imm+arr[i], n, arr));\n    return dp[i][imm] = max(ans, func(i+1, imm, n, arr));\n}\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n; \n    cin>>n;\n    vector<int> arr(n);\n    memset(dp,-1,sizeof(dp));\n    for(int i=0; i<n; i++){\n        cin>>arr[i];\n    }\n    cout<<func(0, 0, n, arr)<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n#define int long long\n\nmap<pair<int, int>, int> dp;\n\nint f(int i, vector<int> &a, int n, int val){\n    if(i==n){\n        return 0;\n    }\n    if(val<0){\n        return 0;\n    }\n\n    if(dp.find({i,val}) != dp.end()){\n        return dp[{i,val}];\n    }\n\n    int x=0;\n    if(val + a[i] >= 0){\n        x = max(f(i+1, a, n, val+a[i])+1, f(i+1, a, n, val));\n    }\n    else{\n        x = f(i+1, a, n, val);\n    }\n\n    return dp[{i,val}] = x;\n}\n\nsigned main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n\n    vector<int> a(n);\n    for(int i=0; i<n;i++){\n        cin>>a[i];\n    }\n\n    int ans = f(0,a,n,0);\n    cout<<ans<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\nll dp[100005][100];\nll fun(vector<ll>&A,ll i,ll sum,ll n)\n{\n  if(i==n)\n  {\n    return 0;  \n  }\n  \n  if(dp[i][sum]!=-1)return dp[i][sum];\n  if(sum+A[i]>=0)\n  {\n    ll take=1+fun(A,i+1,sum+A[i],n);\n    ll notake=fun(A,i+1,sum,n);\n    return dp[i][sum]=max(take,notake);\n  }\n  else\n  {\n    return dp[i][sum]=fun(A,i+1,sum,n);\n  }\n  //return dp[i];\n}\nvoid solve()\n{\n  ll n;\n  cin>>n;\n  \n  vector<ll> A(n);\n  for(int i=0;i<n;i++)\n  {\n      cin>>A[i];\n  }\n  memset(dp,-1,sizeof(dp));\n  ll ans= fun(A,0,0,n);\n  cout<<ans<<endl;\n}\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    solve();  \n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\nint Solve(vector<int>&a)\n{\n    int n = a.size();\n    priority_queue<int, vector<int>,greater<int>> v;\n    int c = 0;\n    int s = 0;\n    vector<int>v1;\n    for(int i=0;i<n;i++){\n        s+=a[i];\n        v1.push_back(a[i]);\n        c++;\n        if(a[i]<0)\n        v.push(a[i]);\n        if(s<0){\n            s-=v.top();\n            auto it = find(v1.begin(),v1.end(),v.top());\n            v1.erase(it);\n            v.pop();\n            c--;\n        }\n    }\n    return v1.size();\n}\nint main() {\n    int n;\n    cin>>n;\n    vector<int> A(n);\n    for(int i=0;i<n;i++){\n        cin>>A[i];\n    }\n    cout<<Solve(A);\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\n\nll f(vector<int>& a, int ind, ll sum, map<pair<ll, int>, int>& mp) {\n    int n = a.size();\n    if(ind == n) {\n        return 0;\n    }\n    if(mp.find({sum, ind}) != mp.end()) {\n        return mp[{sum, ind}];\n    }\n    ll ans = 0;\n    ans = max(ans, f(a, ind + 1, sum, mp));\n    if(sum + a[ind] >= 0) {\n        ans = max(ans, 1 + f(a, ind + 1, sum + a[ind], mp));\n    }\n    return mp[{sum, ind}] = ans;\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;cin>>n;\n    vector<int> a(n);\n    for(int i=0; i<n; i++) cin>>a[i];\n    map<pair<ll, int>, int> mp;\n    cout << f(a, 0, 0, mp) << '\\n';\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    int n;\n    cin >> n;\n\n    int arr[n];\n    for(int i=0; i<n; i++){\n        cin >> arr[i];\n    }\n\n    priority_queue<int, vector<int>, greater<int>> pq;\n    int c=0, sum=0;\n\n    vector <int> vec;\n    vector <int>::iterator it;\n\n    for(int i=0; i<n; i++){\n        sum += arr[i];\n        vec.push_back(arr[i]);\n        c++;\n\n        if(arr[i]<0)\n            pq.push(arr[i]);\n\n        if(sum<0){\n            sum -= pq.top();\n            it = find(vec.begin(), vec.end(), pq.top());\n\n            vec.erase(it);\n            pq.pop();\n            c--;\n        }\n    }\n\n    cout << vec.size() << endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\nll dp[1000][1000];\nll fun(vector<ll>&A,ll i,ll sum,ll n)\n{\n  if(i==n)\n  {\n    return 0;  \n  }\n  \n  if(dp[i][sum]!=-1)return dp[i][sum];\n  if(sum+A[i]>=0)\n  {\n    ll take=1+fun(A,i+1,sum+A[i],n);\n    ll notake=fun(A,i+1,sum,n);\n    return dp[i][sum]=max(take,notake);\n  }\n  else\n  {\n    return dp[i][sum]=fun(A,i+1,sum,n);\n  }\n  //return dp[i];\n}\nvoid solve()\n{\n  ll n;\n  cin>>n;\n  \n  vector<ll> A(n);\n  for(int i=0;i<n;i++)\n  {\n      cin>>A[i];\n  }\n  memset(dp,-1,sizeof(dp));\n  ll ans= fun(A,0,0,n);\n  cout<<ans<<endl;\n}\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    solve();  \n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\n\nll ms (ll arr[],ll n){\n    ll score;\n    priority_queue<ll,vector<ll>,greater<int>>pq;\n    ll sum=0;\n    for (int i=0;i<n;i++){\n        sum +=arr[i];\n        pq.push(arr[i]);\n        if (sum<0){\n            int a= pq.top();\n            sum -= a;\n            pq.pop();\n        }\n    }\n    return pq.size();\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n    ll n;\n    cin>>n;\n    ll a[n];\n    for (auto &x:a){\n        cin>>x;\n    }\n    cout<<ms(a,n)<<'\\n';\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n#define ll long long \n\nint mx = 0;\n\nvoid solve(ll a[], int i, int n, ll sum, int cnt){\n    if(i == n){\n        mx = max(mx, cnt);\n        return;\n    }\n    if(sum + a[i] >= 0)\n        solve(a, i+1, n, sum+a[i], cnt+1);\n    solve(a, i+1, n, sum, cnt);\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    int n;\n    cin>>n;\n    ll a[n];\n    for(int i=0;i<n;i++) cin>>a[i];\n    solve(a, 0, n, 0, 0);\n    cout << mx;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\nint help(int i, int n, int count, long long sum, vector<int>& v, vector<int>& dp){\n    if(i == n) return count;\n    if(dp[i] != -1) return dp[i];\n    int ans = 0;\n    if(v[i]+sum >= 0){\n        ans = help(i+1,n,count+1,sum+v[i],v,dp);\n        \n    }\n    ans = max(ans, help(i+1, n, count,sum, v, dp));\n    return dp[i] = ans;\n} \nint main() {\n    int n; cin >> n;\n    vector<int> v(n), dp(n,-1);\n    for(int i = 0; i < n; i++) cin >> v[i];\n    cout << help(0,n,0,0,v,dp);\n    return 0;\n    \n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\nint solve(int n, int  arr[]){\n    int dp[n][n+1];\n\n    memset(dp, -1, sizeof dp);\n\n    for (int i = 0; i < n; i++){\n        dp[i][0] = 0;\n    }\n\n    dp[0][1] = (arr[0]>=0?arr[0]: -1);\n\n    for(int i = 1; i < n; i++){\n        for(int j =1; j <= (i+1); j++){\n            if(dp[i-1][j]!=-1){\n                dp[i][j] = max(dp[i][j], dp[i-1][j]);\n            }\n\n            if(dp[i-1][j-1]>=0 && dp[i-1][j-1]+arr[i]>=0){\n                dp[i][j] = max(dp[i][j], dp[i-1][j-1]+arr[i]);\n            }\n        }\n    }\n\n    int ans = 0;\n\n    for(int j = 0; j <= n; j++){\n        if(dp[n-1][j]>=0) ans = j;\n    }\n\n    return ans;\n}\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n   \n   int n;\n   cin >> n;\n   int arr[n];\n\n   for(int i = 0 ; i < n ; i++){\n       cin >> arr[i];\n   }\n\n   cout << solve(n, arr);\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    int n; cin>>n;\n    vector<int> v(n);\n    for(int i=0;i<n;i++) cin>>v[i];\n    int sum = 0;\n    priority_queue<int, vector<int>, greater<int>> pq;\n\n    for(int i=0;i<n;i++) {\n        sum += v[i];\n        pq.push(v[i]);\n        if(sum<0) {\n            sum -= pq.top();\n            pq.pop();\n        }\n    }\n\n    cout<<pq.size()<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    int n;\n    cin>>n;\n    vector<long long>a;\n    int count=0;\n    for(int i=0;i<n;i++)\n    {\n        int x;\n        cin>>x;\n        a.push_back(x);\n    }\n    long long sum=0;\n    int ans=0;\n    for(int i=0;i<a.size();i++)\n    {\n        if(sum+a[i]>0){sum+=a[i];ans++;}\n    }\n    cout<<ans;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\nint help(int i, int n, int count, long long sum, vector<long long int>& v, vector<long long int>& dp){\n    if(i == n) return count;\n    if(dp[i] != -1) return dp[i];\n    int ans = 0;\n    if(v[i]+sum >= 0){\n        ans = help(i+1,n,count+1,sum+v[i],v,dp);\n        \n    }\n    ans = max(ans, help(i+1, n, count,sum, v, dp));\n    return dp[i] = ans;\n} \nint main() {\n    int n; cin >> n;\n    vector<long long int> v(n), dp(n,-1);\n    for(int i = 0; i < n; i++) cin >> v[i];\n    cout << help(0,n,0,0,v,dp);\n    return 0;\n    \n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\n\nint rec(int i,vector<int> &v,long long int x,map<pair<int,long long int>,int>&m)\n{\n    if(m.find({i,x})!=m.end()) return m[{i,x}];\n    if(i==v.size()-1)\n    {\n        if(x+v[i]<0) return m[{i,x}]=0;\n        return m[{i,x}]=1;\n    }\n    if(x+v[i]<0) return m[{i,x}]=rec(i+1,v,x,m);\n    else return m[{i,x}]=max(1+rec(i+1,v,x+v[i],m),rec(i+1,v,x,m));\n}\nint main() {\n    int n;cin>>n;\n    vector<int> v(n);\n    for(int i=0;i<n;i++) cin>>v[i];\n    map<pair<int,long long int>,int> m;\n    long long int x=0;\n    m.clear();\n    int ans=rec(0,v,x,m);\n    cout<<ans<<\"\\n\";\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long int\n//map<ll,map<ll,ll>> dp;\n//vector<vector</>> dp(n,vector<ll>(n,-1));\n//l//l dp[900][100000];\n\n\n\nint helper(vector<ll> &arr,ll ind,ll curr,vector<vector<ll>> &dp){\n    if(ind==arr.size()){\n        return 0;\n    }\n    int take = 0,notake = 0;\n    if(dp[ind][curr]!=-1){\n        return dp[ind][curr];\n    }\n    if(curr+arr[ind]>=0){\n        take=1+helper(arr,ind+1,curr+arr[ind],dp);\n\n    }\n    notake = helper(arr,ind+1,curr,dp);\n    return dp[ind][curr]=max(take,notake);\n\n\n}\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    ll n;\n    cin>>n;\n    vector<ll> arr(n);\n    for(int i =0;i<n;i++){\n        cin>>arr[i];\n    }  \n    //memset(dp,-1,sizeof(dp));\n    vector<vector<ll>>dp(n+1,vector<ll>(n,-1));\n\n    cout<<helper(arr,0,0,dp)<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"// #include <cmath>\n// #include <cstdio>\n// #include <vector>\n// #include <iostream>\n// #include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\nint dp[11001][11001];\nint func(int i, int imm, int n, vector<int>& arr){\n    int ans = 0;\n    if(i == n) return 0;\n    if(dp[i][imm] != -1) return dp[i][imm];\n    if( imm + arr[i] > 0 ) ans = (1 + func(i+1, imm+arr[i], n, arr));\n    return dp[i][imm] = max(ans, func(i+1, imm, n, arr));\n}\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n; \n    cin>>n;\n    vector<int> arr(n);\n    memset(dp,-1,sizeof(dp));\n    for(int i=0; i<n; i++){\n        cin>>arr[i];\n    }\n    cout<<func(0, 0, n, arr)<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\n\n\n\nll f(vector<int>& a, int ind, ll sum, map<pair<ll, int>, int>& mp) {\n    int n = a.size();\n    if(ind == n) {\n        return 0;\n    }\n    if(mp.find({sum, ind}) != mp.end()) {\n        return mp[{sum, ind}];\n    }\n    ll ans = 0;\n    ans = max(ans, f(a, ind + 1, sum, mp));\n    if(sum + a[ind] >= 0) {\n        ans = max(ans, 1 + f(a, ind + 1, sum + a[ind], mp));\n    }\n    return mp[{sum, ind}] = ans;\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;cin>>n;\n    vector<int> a(n);\n    for(int i=0; i<n; i++) cin>>a[i];\n    map<pair<ll, int>, int> mp;\n    // cout << f(a, 0, 0, mp) << '\\n';\n\n    priority_queue<int, vector<int>, greater<int>>pq;\n    int s = 0;\n\n    for(int i=0; i<n; i++){\n        s+=a[i];\n        pq.push(a[i]);\n        while(s < 0){\n            int i=pq.top();\n            s-=i;\n            pq.pop();\n        }\n    }\n        cout << pq.size() << endl;\n\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"// #include <cmath>\n// #include <cstdio>\n// #include <vector>\n// #include <iostream>\n// #include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\nint dp[11001][11001];\nint func(int i, int imm, int n, vector<int>& arr){\n    int ans = 0;\n    if(i == n) return 0;\n    if(dp[i][imm] != -1) return dp[i][imm];\n    if( imm + arr[i] >= 0 ) ans = (1 + func(i+1, imm+arr[i], n, arr));\n    return dp[i][imm] = max(ans, func(i+1, imm, n, arr));\n}\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n; \n    cin>>n;\n    vector<int> arr(n);\n    memset(dp,-1,sizeof(dp));\n    for(int i=0; i<n; i++){\n        cin>>arr[i];\n    }\n    cout<<func(0, 0, n, arr)<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\nint help(int i, int n, int count, long long sum, vector<long long int>& v, vector<long long int>& dp){\n    if(i >= n) return 0;\n    if(dp[i] != -1) return dp[i];\n    int ans = 0;\n    if(v[i]+sum >= 0){\n        ans = max(help(i+1,n,count,sum,v,dp),1+help(i+1,n,count,sum+v[i],v,dp));\n    }\n    else\n        ans = max(ans, help(i+1, n, count,sum, v, dp));\n    return dp[i] = ans;\n} \nint main() {\n    int n; cin >> n;\n    int p1=0;\n    int p2=0;\n    int p3=0;\n    vector<long long int> v(n), dp(n,-1);\n    for(int i = 0; i < n; i++){ \n        cin >> v[i];\n        p1+=(v[i]>=0);\n        p2+=(v[i]<0);\n        p3+=(v[i]==0);\n    }\n    if(p3==n)\n    {\n        cout<<n<<endl;\n        return 0;\n    }\n    if(p1==n)\n    {\n        cout<<n<<endl;\n        return 0;\n    }\n    if(p1==0)\n    {\n        cout<<0<<endl;\n    }\n    cout << max(0,help(0,n,0,0,v,dp)) << endl;\n    return 0;\n    \n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n     int n;cin >> n;\n     vector<int>v(n);\n     for(int i = 0; i < n; i++)\n        cin >> v[i];\n    vector<long long int>dp(n + 1,-1e16);\n    dp[0] = 0;\n    long long cntr= 0,curr = 0,ans= 0;\n    for(int i = 0; i < n; i++){\n        if(v[i] < 0){\n    \n            if(dp[cntr] + curr + v[i]>= 0){\n                \n                cntr++;\n                dp[cntr] = dp[cntr -1] + v[i];\n            }\n            for(int j = cntr; j > 0; j--){\n                dp[j]= max(dp[j],dp[j-1] + v[i]);\n            }\n        }\n        else curr += v[i],ans++;\n    }\n    cout << cntr +ans << endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n     int n;cin >> n;\n     vector<int>v(n);\n     for(int i = 0; i < n; i++)\n        cin >> v[i];\n    vector<long long int>dp(n + 1,-1e16);\n    dp[0] = 0;\n    long long cntr= 0,curr = 0,ans= 0;\n    for(int i = 0; i < n; i++){\n        if(v[i] < 0){\n    \n            if(dp[cntr] + curr + v[i]>= 0){\n                \n                cntr++;\n                dp[cntr] = dp[cntr -1] + v[i];\n            }\n            for(int j = cntr; j > 0; j--){\n                dp[j]= max(dp[j],dp[j-1] + v[i]);\n            }\n        }\n        else curr += v[i],ans++;\n    }\n    cout << cntr +ans << endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\nint help(int i, int n, int count, long long sum, vector<long long int>& v, vector<long long int>& dp){\n    if(i >= n) return count;\n    if(dp[i] != -1) return dp[i];\n    int ans = 0;\n    if(v[i]+sum >= 0){\n        ans = help(i+1,n,count+1,sum+v[i],v,dp);\n        \n    }\n    ans = max(ans, help(i+1, n, count,sum, v, dp));\n    return dp[i] = ans;\n} \nint main() {\n    int n; cin >> n;\n    vector<long long int> v(n), dp(n,-1);\n    for(int i = 0; i < n; i++) cin >> v[i];\n    cout << help(0,n,0,0,v,dp) << endl;\n    return 0;\n    \n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\n\nusing namespace std;\n\nlong long int pre[100000];\nvector<pair<int,int>> neg,pos;\n\nbool comp(pair<int,int> t1, pair<int,int> t2)\n{\n    return (get<0>(t1) < get<0>(t2)) || (get<0>(t1) == get<1>(t2) && get<1>(t1) > get<1>(t2));\n}\n\nlong long int getsum(int l, int r)\n{\n    return pre[r] - (l > 0 ? pre[l-1] : 0);\n}\n\nbool check(vector<int>&a, int k)\n{\n    set<int>neg_ind;\n    for(int i = 0; i < k; i++)\n    {\n        neg_ind.insert(neg[i].second);\n    }\n\n    long long int cur_sum = 0;\n    for(int i = 0; i < a.size();i++)\n    {\n        if(a[i] >= 0)\n        {\n            cur_sum += a[i];\n        }\n        else\n        {\n            cur_sum += neg_ind.count(i)*a[i];\n        }\n        if(cur_sum < 0)\n        {\n            return false;\n        }\n    }\n    return true;\n}\n\nint solve(vector<int>&arr, int n)\n{\n    int l=0,r=n;\n    int count = 0;\n\n    for(int i = 0; i < n; i++)\n    {\n        if(arr[i] < 0)\n        {\n            neg.push_back({arr[i],i});\n        }\n        else\n        {\n            l++;\n            if(arr[i] > 0)\n            {\n                pos.push_back({i, arr[i]});\n            }\n        }\n    }\n\n    pre[0] = 0;\n\n    for(int i = 1; i < n; i++)\n    {\n        pre[i] = pre[i-1] + arr[i];\n    }\n\n    sort(neg.begin(), neg.end(), comp);\n    reverse(neg.begin(), neg.end());\n\n    int non_neg = l;\n    int ans = l;\n    while(l <= r)\n    {\n        int mid = (l+r)/2;\n        if(check(arr,mid-non_neg))\n        {\n            ans = mid;\n            l = mid+1;\n        }\n        else\n        {\n            r = mid-1;\n        }\n    }\n    return ans;\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin >> n;\n\n    vector<int> arr(n);\n    for(int i = 0; i < n; i++)\n    {\n        cin >> arr[i];\n    }\n\n    int ans = 0;\n    int sum = 0;\n    for(int i = 0; i< n; i++)\n    {\n        if(arr[i]>=0)\n        {\n            ans++;\n            sum += arr[i];\n        }\n        else\n        {\n            if(sum + arr[i] > 0)\n            {\n                ans++;\n                sum += arr[i];\n            }\n        }\n    }\n\n    // ans = solve(arr,n);\n\n    cout << ans << endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\n\n#define ll long long\n\nint main() {\n    int n; cin>>n;\n    int i, j;\n    int im = 0;\n    multiset<int> allvc;\n    for(i=0;i<n;i++)\n    {\n        int vc; cin>>vc;\n        allvc.insert(vc);\n        im += vc;\n        while(im<0&&allvc.size()>0)\n        {\n            im -= *(allvc.begin());\n            allvc.erase(allvc.begin());\n        }\n    }\n    cout<<allvc.size()<<'\\n';\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\nint maxScore(vector<int>arr, int n)\n{\n    int res=0;\n    priority_queue<int,vector<int>,greater<int>>pq;\n    int sum=0;\n    for(int i=0; i<n; i++)\n    {\n        sum += arr[i];\n        pq.push(arr[i]);\n        if(sum<0)\n        {\n            int a=pq.top();\n            sum -= a;\n            pq.pop();\n        }\n    }\n    return pq.size();\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    vector<int>v(n);\n    for(int i=0; i<n; i++)\n        cin>>v[i];\n    cout<<maxScore(v,n);\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n#define long long int\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    ios_base::sync_with_stdio(false);\n    cin.tie(0);\n    int n; cin>>n;\n    vector<int> v(n);\n    for(int i=0;i<n;i++) cin>>v[i];\n    int sum = 0;\n    priority_queue<int, vector<int>, greater<int>> pq;\n\n    for(int i=0;i<n;i++) {\n        sum += v[i];\n        pq.push(v[i]);\n        if(sum<0) {\n            sum -= pq.top();\n            pq.pop();\n        }\n    }\n\n    cout<<pq.size()<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\n\nll ms (ll arr[],ll n){\n    ll score;\n    priority_queue<ll,vector<ll>,greater<int>>pq;\n    ll sum=0;\n    for (int i=0;i<n;i++){\n        sum +=arr[i];\n        pq.push(arr[i]);\n        if (sum<0){\n            int a= pq.top();\n            sum -= a;\n            pq.pop();\n        }\n    }\n    return pq.size();\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n    ll n;\n    cin>>n;\n    ll a[n];\n    for (auto &x:a){\n        cin>>x;\n    }\n    cout<<ms(a,n)<<'\\n';\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\n//#define ll long long int\n//map<ll,map<ll,ll>> dp;\n//vector<vector</>> dp(n,vector<ll>(n,-1));\n//l//l dp[900][100000];\n\n\n\n/*int helper(vector<ll> &arr,ll ind,ll curr,vector<vector<ll>> &dp){\n    if(ind==arr.size()){\n        return 0;\n    }\n    int take = 0,notake = 0;\n    if(dp[ind][curr]!=-1){\n        return dp[ind][curr];\n    }\n    if(curr+arr[ind]>=0){\n        take=1+helper(arr,ind+1,curr+arr[ind],dp);\n\n    }\n    notake = helper(arr,ind+1,curr,dp);\n    return dp[ind][curr]=max(take,notake);\n\n\n}*/\n/*void helper(vector<int> arr,int n){\n    priority_queue<int,vector<int>,greater<int>> pq;\n    int count = 0,start = 0;\n    vector<int> temp1;\n    vector<int>::iterator it;\n    for(int i =0;i<n;i++){\n        start+=arr[i];\n        temp1.push_back(arr[i]);\n        count++;\n        if(arr[i]<0){\n            temp\n        }\n    }\n}*/\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    int n;\n    cin>>n;\n    vector<int> arr(n);\n    for(int i =0;i<n;i++){\n        cin>>arr[i];\n    }  \n    //memset(dp,-1,sizeof(dp));\n    //vector<vector<ll>>dp(n+1,vector<ll>(n,-1));\n    priority_queue<int,vector<int>,greater<int>> pq;\n    vector<int> ans;\n    int sum = 0,cursum = 0;\n    for(int i =0;i<n;i++){\n        cursum+=arr[i];\n        ans.push_back(arr[i]);\n        sum++;\n        if(arr[i]<0){\n            pq.push(arr[i]);\n        }\n        if(cursum<0){\n            cursum -= pq.top();\n            auto it= find(ans.begin(),ans.end(),pq.top());\n            ans.erase(it);\n            pq.pop();\n            sum--;\n        }\n    }\n    cout<<ans.size()<<endl;\n    //cout<<endl;\n\n    //cout<<helper(arr,n)<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\n\nll ms (ll arr[],ll n){\n    ll score;\n    priority_queue<ll,vector<ll>,greater<int>>pq;\n    ll sum=0;\n    for (int i=0;i<n;i++){\n        sum +=arr[i];\n        pq.push(arr[i]);\n        if (sum<0){\n            int a= pq.top();\n            sum -= a;\n            pq.pop();\n        }\n    }\n    return pq.size();\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n    ll n;\n    cin>>n;\n    ll a[n];\n    for (auto &x:a){\n        cin>>x;\n    }\n    cout<<ms(a,n)<<'\\n';\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include<climits>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\nint vac(vector<int> &input,int immunity,vector<int>&output,int start)\n{\n    if(start>=input.size())\n    {\n        return 0;\n    }\n    if(output[start]!=-1)\n    {\n        return output[start];\n    }\n    int take=INT_MIN;\n    int not_take=INT_MIN;\n    int pos=INT_MIN;\n    if(input[start]<0 && immunity+input[start]>=0)\n    {\n        take=1+vac(input,immunity+input[start],output,start+1);\n        not_take=vac(input,immunity,output,start+1);\n    }\n    \n    else\n    {\n        pos=1+vac(input,immunity+input[start],output,start+1);\n    }\n    int ans=max(pos,max(take,not_take));\n    output[input.size()-1]=ans;\n    return output[input.size()-1];\n}\nint fun(int i,vector<int>&imm,int sum)\n{\n    if( i==imm.size())\n    {\n        return 0;\n    }\n    int take=0;\n    int nottake=0;\n    nottake+=fun(i+1,imm,sum);\n    if(sum+imm[i]>=0)\n    {\n        take=max(1+fun(i+1,imm,sum+imm[i]),fun(i+1,imm,sum));\n    }\n    return max(take,nottake);\n}\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    int n;\n    cin>>n;\n    vector<int> input(n);\n    for(int i=0; i<n ;i++)\n    {\n        cin>>input[i];\n    }  \n\n    // vector<int> output(n,-1);\n    // int ans=vac(input,0,output,0);\n    int ans=fun(0,input,0);\n    cout<<ans;\n    // int immunity=0;\n    // int ans=0;\n    // priority_queue<int> max_heap;\n    // for(int i=0; i<n;i++)\n    // {\n    //     if(input[i]>=0)\n    //     {\n    //         immunity+=input[i];\n    //         ans++;\n    //     }\n    //     else{\n    //         max_heap.push(input[i]);\n    //     }\n    // }\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n#define int long long\n\nint32_t main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    ios_base::sync_with_stdio(false);\n    cin.tie(NULL);\n    cout.tie(NULL);\n    int n; cin>>n;\n    vector<int> v(n);\n    for(int i=0;i<n;i++) cin>>v[i];\n    int sum = 0;\n    priority_queue<int, vector<int>, greater<int>> pq;\n\n    for(int i=0;i<n;i++) {\n        sum += v[i];\n        pq.push(v[i]);\n        if(sum<0) {\n            sum -= pq.top();\n            pq.pop();\n        }\n    }\n\n    cout<<pq.size()<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\nint util(vector<int>&a,int idx,int sum)\n{\n    if(sum<0)\n        return 0;\n    if(idx==a.size())\n        return 0;\n\n    int take=0,not_take=0;\n    if(sum+a[idx]>=0)\n    {\n        take=1+util(a,idx+1,sum+a[idx]);\n    }\n    not_take=util(a,idx+1,sum);\n\n    return max(take,not_take);\n\n}\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n\n    int n;\n    cin>>n;\n    vector<int> vec(n,0);\n    for(int i=0;i<n;i++)\n    {\n        cin>>vec[i];\n    }\n    vector<int> dp(n,-1);\n\n    cout<<util(vec,0,0);\n\n\n    // recursive approach\n\n\n    // int sum=0;\n    // int count=0;\n    // for(int i=0;i<n;i++)\n    // {\n    //     sum+=vec[i];\n    //     if(sum<0)\n    //     {\n    //         sum=0;\n    //     }\n    //     else\n    //     {\n    //         count++;\n    //     }\n    // }\n    // cout<<count;\n    return 0;\n\n    \n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long int\n//map<ll,map<ll,ll>> dp;\n//vector<vector</>> dp(n,vector<ll>(n,-1));\n//l//l dp[900][100000];\n\n\n\n/*int helper(vector<ll> &arr,ll ind,ll curr,vector<vector<ll>> &dp){\n    if(ind==arr.size()){\n        return 0;\n    }\n    int take = 0,notake = 0;\n    if(dp[ind][curr]!=-1){\n        return dp[ind][curr];\n    }\n    if(curr+arr[ind]>=0){\n        take=1+helper(arr,ind+1,curr+arr[ind],dp);\n\n    }\n    notake = helper(arr,ind+1,curr,dp);\n    return dp[ind][curr]=max(take,notake);\n\n\n}*/\n/*void helper(vector<int> arr,int n){\n    priority_queue<int,vector<int>,greater<int>> pq;\n    int count = 0,start = 0;\n    vector<int> temp1;\n    vector<int>::iterator it;\n    for(int i =0;i<n;i++){\n        start+=arr[i];\n        temp1.push_back(arr[i]);\n        count++;\n        if(arr[i]<0){\n            temp\n        }\n    }\n}*/\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    ll n;\n    cin>>n;\n    vector<ll> arr(n);\n    for(int i =0;i<n;i++){\n        cin>>arr[i];\n    }  \n    //memset(dp,-1,sizeof(dp));\n    //vector<vector<ll>>dp(n+1,vector<ll>(n,-1));\n    priority_queue<ll,vector<ll>,greater<ll>> pq;\n    vector<ll> ans;\n    ll sum = 0,cursum = 0;\n    for(ll i =0;i<n;i++){\n        cursum+=arr[i];\n        ans.push_back(arr[i]);\n        sum++;\n        if(arr[i]<0){\n            pq.push(arr[i]);\n        }\n        if(cursum<0){\n            cursum -= pq.top();\n            auto it= find(ans.begin(),ans.end(),pq.top());\n            ans.erase(it);\n            pq.pop();\n            sum--;\n        }\n    }\n    cout<<ans.size()<<endl;\n    //cout<<endl;\n\n    //cout<<helper(arr,n)<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n    int n;\n    cin>>n;\n    priority_queue<long long,vector<long long>,greater<long long>>pq;\n    long long s=0;\n    for(int i=1;i<=n;i++)\n    {\n        long long x;\n        cin>>x;\n        s+=x;\n        pq.push(x);\n        while(s<0)\n        {\n            s-=pq.top();\n            pq.pop();\n        }\n    } \n    cout<<(int) pq.size();\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n#define endl \"\\n\" \n\nint rec(int index,int curr,vector<int> &v,map<pair<int,int>,int> &dp){\n    if( index == v.size()) return 0;\n\n    if( dp.find({index,curr})  !=dp.end()) return dp[{index,curr}];\n    int ans=rec( index+1, curr , v, dp);\n    if(curr + v[index] >= 0){\n        ans = max(ans, rec(index+1, curr+v[index], v, dp) + 1);\n    }\n    return dp[{index,curr }] = ans;   \n\n}\n\nint main() {\n    \n    int n;\n    cin>> n;\n    int mxSum = 0; \n    vector<int> v(n);\n    for(int i=0; i < n; i++){\n        cin>> v[i];\n        if(v[i] > 0){\n            mxSum += v[i];\n        }\n    }    \n    map<pair<int,int>,int> dp;\n    // vector<vector<int>> dp(n+1, vector<int>(mxSum+2, -1));    \n    cout<<rec(0, 0, v, dp)<< endl ;\n    \n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\nmap<string,int>mp;\nint util(vector<int>&a,int idx,int immunity){\n    string key=to_string(idx)+\" \";\n    key+=to_string(immunity);\n    if(idx>=a.size())return 0;\n    if(mp.find(key)!=mp.end())return mp[key];\n    int notTake=util(a,idx+1,immunity);\n    int take=0;\n    if(immunity+a[idx]>=0){\n        take=1+util(a,idx+1,immunity+a[idx]);\n    }\n    return mp[key]=max(take,notTake);\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    vector<int>a(n);\n    for(int i=0;i<n;i++){\n        cin>>a[i];\n    }\n    cout<<util(a,0,0)<<'\\n';\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\nint help(int i,int n,int count,int sum,vector<int>&v,vector<int>&dp)\n{\n    if(i==n)\n    return count;\n    if(dp[i]!=-1)\n    return dp[i];\n    int ans=0;\n    if(sum+v[i]>=0)\n    ans=help(i+1,n,count+1,sum+v[i],v,dp);\n    ans=max(ans,help(i+1,n,count,sum,v,dp));\n    return dp[i]=ans;\n}\n\nint main() {\n    int n;\n    cin>>n;\n    vector<int>v(n);\n    for(int i=0;i<n;i++)\n    cin>>v[i];\n    vector<int>dp(n,-1);cout<<help(0,n,0,0,v,dp);\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n#define int long long\n\nint32_t main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    ios_base::sync_with_stdio(false);\n    cin.tie(NULL);\n    cout.tie(NULL);\n    int n; cin>>n;\n    vector<int> v(n);\n    for(int i=0;i<n;i++) cin>>v[i];\n    int sum = 0;\n    priority_queue<int, vector<int>, greater<int>> pq;\n\n    for(int i=0;i<n;i++) {\n        sum += v[i];\n        pq.push(v[i]);\n        if(sum<0) {\n            sum -= pq.top();\n            pq.pop();\n        }\n    }\n\n    cout<<pq.size()<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n#include<bits/stdc++.h>\n\n\n\n\nint main() {\nint n;\ncin>>n;\nvector<int> a(n);\nfor(auto&x:a)cin>>x;\nvector<array<int,2>>pos,neg;\nint got =0;\nfor(int i=0;i<n;++i){\n    if(a[i]>=0){\n        got = 1;\n        pos.push_back({a[i],i});\n    }\n        else if(got){\n            neg.push_back({a[i],i});\n        }\n    }\n    sort(pos.begin(),pos.end(),[&](const auto x , const auto y){\n        if(x[0]==y[0]) return x[1]<y[1];\n        return x[0]>y[0];\n    });\n\n    sort(neg.begin(),neg.end(),[&](const auto x, const auto y ){\n        if(x[0] == y[0]) return x[1]> y[1];\n        return x[0] > y[0];\n    });\n\n    int res = 0;\n    int l =1, r = n;\n\n    auto ok = [&](int have){\n        unordered_set<int> ids;\n        for(int i = 0;i <pos.size() and have ; ++i){\n            have--;\n            ids.insert(pos[i][1]);\n        }\n        for(int i =0;i<neg.size() and have ;++i){\n            have--;\n            ids.insert(neg[i][1]);\n        }\n        long long sum =0;\n        for(int i=0;i<n;++i){\n            if(ids.count(i)){\n                sum = sum + a[i];\n\n            }\n            if(sum<0){\n                return 0;\n            }\n            }\n        return 1;\n        } ;\n\nwhile(l<=r){\n    int mid = (l+r)>>1;\n    if(ok(mid)){\n        res = mid;\n        l = mid+1;\n\n    }\n    else{\n        r = mid -1;\n    }\n}\ncout << res <<'\\n';\nreturn 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\nint help(int i, int n, int count, long long sum, vector<long long int>& v, vector<long long int>& dp){\n    if(i >= n) return 0;\n    if(dp[i] != -1) return dp[i];\n    int ans = 0;\n    if(v[i]+sum >= 0){\n        ans = max(ans,1+help(i+1,n,count,sum+v[i],v,dp));\n    }\n    ans = max(ans, help(i+1, n, count,sum, v, dp));\n    return dp[i] = ans;\n} \nint main() {\n    int n; cin >> n;\n    vector<long long int> v(n), dp(n,-1);\n    for(int i = 0; i < n; i++) cin >> v[i];\n    cout << max(0,help(0,n,0,0,v,dp)) << endl;\n    return 0;\n    \n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\nint help(int i, int n, int count, long long sum, vector<long long int>& v, vector<long long int>& dp){\n    if(i >= n) return 0;\n    if(dp[i] != -1) return dp[i];\n    int ans = 0;\n    if(v[i]+sum >= 0){\n        ans = max(ans,1+help(i+1,n,count,sum+v[i],v,dp));\n    }\n    ans = max(ans, help(i+1, n, count,sum, v, dp));\n    return dp[i] = ans;\n} \nint main() {\n    int n; cin >> n;\n    int p1=0;\n    int p2=0;\n    vector<long long int> v(n), dp(n,-1);\n    for(int i = 0; i < n; i++){ \n        cin >> v[i];\n        p1+=(v[i]>=0);\n        p2+=(v[i]<0);\n    }\n    if(p1==n)\n    {\n        cout<<n<<endl;\n        return 0;\n    }\n    if(p1==0)\n    {\n        cout<<0<<endl;\n    }\n    cout << max(0,help(0,n,0,0,v,dp)) << endl;\n    return 0;\n    \n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<unordered_map>\nusing namespace std;\n\nint solve(vector<int>&arr, int i, int curr, vector<vector<int>>&dp){\n    if(i==arr.size()) return 0;\n    // string key = i + \"$\" + curr;\n    \n    // if(dp.find(key)!= dp.end()) return dp[key];\n    if(dp[i][curr]!=-1) return dp[i][curr];\n    \n    int maxi = 0;\n    if(curr+arr[i]>=0 ){\n       maxi = max(maxi, (solve(arr,i+1, curr+arr[i],dp) + 1));\n\n    }\n\n   maxi = max(maxi, solve(arr, i+1, curr, dp) );\n    // dp[key]=maxi;\n    dp[i][curr] = maxi;\n   return maxi;\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    // unordered_map<string,int> dp;\n    int n;\n    cin>>n;\n    vector<int> v(n);\n    for(int i=0; i<n; i++){\n        cin>>v[i];\n    }\n    int m = 10000;\n    vector<vector<int>> dp(n, vector<int>(m));\n\n    for(int i=0; i<n; i++){\n        for(int j=0; j<m; j++){\n            dp[i][j]=-1;\n        }\n    }\n\n    int ans = solve(v,0,0,dp);\n\n    cout<<ans;\n\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<unordered_map>\nusing namespace std;\n\nint solve(vector<int>&arr, int i, int curr, vector<vector<int>>&dp){\n    if(i==arr.size()) return 0;\n    // string key = i + \"$\" + curr;\n    \n    // if(dp.find(key)!= dp.end()) return dp[key];\n    if(dp[i][curr]!=-1) return dp[i][curr];\n    \n    int maxi = 0;\n    if(curr+arr[i]>=0 ){\n       maxi = max(maxi, (solve(arr,i+1, curr+arr[i],dp) + 1));\n\n    }\n\n   maxi = max(maxi, solve(arr, i+1, curr, dp) );\n    // dp[key]=maxi;\n    dp[i][curr] = maxi;\n   return maxi;\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    // unordered_map<string,int> dp;\n    int n;\n    cin>>n;\n    vector<int> v(n);\n    for(int i=0; i<n; i++){\n        cin>>v[i];\n    }\n    int m = 100000;\n    vector<vector<int>> dp(n, vector<int>(m));\n\n    for(int i=0; i<n; i++){\n        for(int j=0; j<m; j++){\n            dp[i][j]=-1;\n        }\n    }\n\n    int ans = solve(v,0,0,dp);\n\n    cout<<ans;\n\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<unordered_map>\nusing namespace std;\n\nint solve(vector<int>&arr, int i, int curr, vector<vector<int>>&dp){\n    if(i==arr.size()) return 0;\n    // string key = i + \"$\" + curr;\n    \n    // if(dp.find(key)!= dp.end()) return dp[key];\n    if(dp[i][curr]!=-1) return dp[i][curr];\n    \n    int maxi = 0;\n    if(curr+arr[i]>=0 ){\n       maxi = max(maxi, (solve(arr,i+1, curr+arr[i],dp) + 1));\n\n    }\n\n   maxi = max(maxi, solve(arr, i+1, curr, dp) );\n    // dp[key]=maxi;\n    dp[i][curr] = maxi;\n   return maxi;\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    // unordered_map<string,int> dp;\n    int n;\n    cin>>n;\n    vector<int> v(n);\n    for(int i=0; i<n; i++){\n        cin>>v[i];\n    }\n    int m = 1000000;\n    vector<vector<int>> dp(n, vector<int>(m));\n\n    for(int i=0; i<n; i++){\n        for(int j=0; j<m; j++){\n            dp[i][j]=-1;\n        }\n    }\n\n    int ans = solve(v,0,0,dp);\n\n    cout<<ans;\n\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\nint help(int i, int n, int count, long long sum, vector<long long int>& v, vector<long long int>& dp){\n    if(i >= n) return 0;\n    if(dp[i] != -1) return dp[i];\n    int ans = 0;\n    if(v[i]+sum >= 0){\n        ans = max(ans,1+help(i+1,n,count,sum+v[i],v,dp));\n    }\n    ans = max(ans, help(i+1, n, count,sum, v, dp));\n    return dp[i] = ans;\n} \nint main() {\n    int n; cin >> n;\n    int p1=0;\n    int p2=0;\n    int p3=0;\n    vector<long long int> v(n), dp(n,-1);\n    for(int i = 0; i < n; i++){ \n        cin >> v[i];\n        p1+=(v[i]>0);\n        p2+=(v[i]<0);\n        p3+=(v[i]==0);\n    }\n    if(p3==n)\n    {\n        cout<<0<<endl;\n        return 0;\n    }\n    if(p1==n)\n    {\n        cout<<n<<endl;\n        return 0;\n    }\n    if(p1==0)\n    {\n        cout<<0<<endl;\n    }\n    cout << max(0,help(0,n,0,0,v,dp)) << endl;\n    return 0;\n    \n}","lang":"2"},
{"question_id":40870,"source":"# Enter your code here. Read input from STDIN. Print output to STDOUT\r\nn = int(input())\r\nvacstring = input()\r\nvac = vacstring.split()\r\n# for i in range (0,len(vac)):\r\n#     vac.append(int(input()))\r\n\r\nsum1 = 0\r\nvacadd = 0\r\nfor j in range(len(vac)):\r\n    sum1 = sum1 + int(vac[j])\r\n    if (sum1<0):\r\n        sum1 = sum1 - int(vac[j])\r\n    else:\r\n        vacadd = vacadd + 1\r\n\r\nprint(vacadd)","lang":"30"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n#include<bits/stdc++.h>\n\n\n\n\nint main() {\nint n;\ncin>>n;\nvector<int> a(n);\nfor(auto&x:a)cin>>x;\nvector<array<int,2>>pos,neg;\nint got =0;\nfor(int i=0;i<n;++i){\n    if(a[i]>=0){\n        got = 1;\n        pos.push_back({a[i],i});\n    }\n        else if(got){\n            neg.push_back({a[i],i});\n        }\n    }\n    sort(pos.begin(),pos.end(),[&](const auto x , const auto y){\n        if(x[0]==y[0]) return x[1]<y[1];\n        return x[0]>y[0];\n    });\n\n    sort(neg.begin(),neg.end(),[&](const auto x, const auto y ){\n        if(x[0] == y[0]) return x[1]> y[1];\n        return x[0] > y[0];\n    });\n\n    int res = 0;\n    int l =1, r = n;\n\n    auto ok = [&](int have){\n        unordered_set<int> ids;\n        for(int i = 0;i <pos.size() and have ; ++i){\n            have--;\n            ids.insert(pos[i][1]);\n        }\n        for(int i =0;i<neg.size() and have ;++i){\n            have--;\n            ids.insert(neg[i][1]);\n        }\n        long long sum =0;\n        for(int i=0;i<n;++i){\n            if(ids.count(i)){\n                sum = sum + a[i];\n\n            }\n            if(sum<0){\n                return 0;\n            }\n            }\n        return 1;\n        } ;\n\nwhile(l<=r){\n    int mid = (l+r)>>1;\n    if(ok(mid)){\n        res = mid;\n        l = mid+1;\n\n    }\n    else{\n        r = mid -1;\n    }\n}\ncout << res <<'\\n';\nreturn 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n#include<bits/stdc++.h>\n\n\n\n\nint main() {\nint n;\ncin>>n;\nvector<int> a(n);\nfor(auto&x:a)cin>>x;\nvector<array<int,2>>pos,neg;\nint got =0;\nfor(int i=0;i<n;++i){\n    if(a[i]>=0){\n        got = 1;\n        pos.push_back({a[i],i});\n    }\n        else if(got){\n            neg.push_back({a[i],i});\n        }\n    }\n    sort(pos.begin(),pos.end(),[&](const auto x , const auto y){\n        if(x[0]==y[0]) return x[1]<y[1];\n        return x[0]>y[0];\n    });\n\n    sort(neg.begin(),neg.end(),[&](const auto x, const auto y ){\n        if(x[0] == y[0]) return x[1]> y[1];\n        return x[0] > y[0];\n    });\n\n    int res = 0;\n    int l =1, r = n;\n\n    auto ok = [&](int have){\n        unordered_set<int> ids;\n        for(int i = 0;i <pos.size() and have ; ++i){\n            have--;\n            ids.insert(pos[i][1]);\n        }\n        for(int i =0;i<neg.size() and have ;++i){\n            have--;\n            ids.insert(neg[i][1]);\n        }\n        long long sum =0;\n        for(int i=0;i<n;++i){\n            if(ids.count(i)){\n                sum = sum + a[i];\n\n            }\n            if(sum<0){\n                return 0;\n            }\n            }\n        return 1;\n        } ;\n\nwhile(l<=r){\n    int mid = (l+r)>>1;\n    if(ok(mid)){\n        res = mid;\n        l = mid+1;\n\n    }\n    else{\n        r = mid -1;\n    }\n}\ncout << res <<'\\n';\nreturn 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\nint help(int i, int n, int count, long long sum, vector<long long int>& v, vector<long long int>& dp){\n    if(i >= n) return 0;\n    if(dp[i] != -1) return dp[i];\n    int ans = 0;\n    if(v[i]+sum >= 0){\n        ans = max(help(i+1,n,count,sum,v,dp),1+help(i+1,n,count,sum+v[i],v,dp));\n    }\n    else\n        ans = max(ans, help(i+1, n, count,sum, v, dp));\n    return dp[i] = ans;\n} \nint main() {\n    int n; cin >> n;\n    int p1=0;\n    int p2=0;\n    int p3=0;\n    vector<long long int> v(n), dp(n,-1);\n    for(int i = 0; i < n; i++){ \n        cin >> v[i];\n        p1+=(v[i]>=0);\n        p2+=(v[i]<0);\n        p3+=(v[i]==0);\n    }\n    if(p3==n)\n    {\n        cout<<n<<endl;\n        return 0;\n    }\n    if(p1==n)\n    {\n        cout<<n<<endl;\n        return 0;\n    }\n    if(p1==0)\n    {\n        cout<<0<<endl;\n        return 0;\n    }\n    cout << max(0,help(0,n,0,0,v,dp)) << endl;\n    return 0;\n    \n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\nmap<string,int>mp;\nint util(vector<int>&a,int idx,int immunity){\n    string key=to_string(idx)+\" \";\n    key+=to_string(immunity);\n    if(idx>=a.size())return 0;\n    if(mp.find(key)!=mp.end())return mp[key];\n    int notTake=util(a,idx+1,immunity);\n    int take=0;\n    if(immunity+a[idx]>=0){\n        take=1+util(a,idx+1,immunity+a[idx]);\n    }\n    return mp[key]=max(take,notTake);\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    vector<int>a(n);\n    for(int i=0;i<n;i++){\n        cin>>a[i];\n    }\n    cout<<util(a,0,0)<<'\\n';\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\nint help(int i, int n, int count, long long sum, vector<long long int>& v, vector<long long int>& dp){\n    if(i >= n) return 0;\n    if(dp[i] != -1) return dp[i];\n    int ans = 0;\n    if(v[i]+sum >= 0){\n        ans = max(ans,1+help(i+1,n,count,sum+v[i],v,dp));\n    }\n    else\n        ans = max(ans, help(i+1, n, count,sum, v, dp));\n    return dp[i] = ans;\n} \nint main() {\n    int n; cin >> n;\n    int p1=0;\n    int p2=0;\n    int p3=0;\n    vector<long long int> v(n), dp(n,-1);\n    for(int i = 0; i < n; i++){ \n        cin >> v[i];\n        p1+=(v[i]>=0);\n        p2+=(v[i]<0);\n        p3+=(v[i]==0);\n    }\n    if(p3==n)\n    {\n        cout<<n<<endl;\n        return 0;\n    }\n    if(p1==n)\n    {\n        cout<<n<<endl;\n        return 0;\n    }\n    if(p1==0)\n    {\n        cout<<0<<endl;\n        return 0;\n    }\n    cout << max(0,help(0,n,0,0,v,dp)) << endl;\n    return 0;\n    \n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<unordered_map>\nusing namespace std;\n\nint solve(vector<int>&arr, int i, int curr, vector<vector<int>>&dp){\n    if(i==arr.size()) return 0;\n    // string key = i + \"$\" + curr;\n    \n    // if(dp.find(key)!= dp.end()) return dp[key];\n    if(dp[i][curr]!=-1) return dp[i][curr];\n    \n    int maxi = 0;\n    if(curr+arr[i]>=0 ){\n       maxi = max(maxi, (solve(arr,i+1, curr+arr[i],dp) + 1));\n\n    }\n\n   maxi = max(maxi, solve(arr, i+1, curr, dp) );\n    // dp[key]=maxi;\n    dp[i][curr] = maxi;\n   return maxi;\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    // unordered_map<string,int> dp;\n    int n;\n    cin>>n;\n    vector<int> v(n);\n    for(int i=0; i<n; i++){\n        cin>>v[i];\n    }\n    int m = 99999;\n    vector<vector<int>> dp(n, vector<int>(m));\n\n    for(int i=0; i<n; i++){\n        for(int j=0; j<m; j++){\n            dp[i][j]=-1;\n        }\n    }\n\n    int ans = solve(v,0,0,dp);\n\n    cout<<ans;\n\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\nint help(int i, int n, int count, long long sum, vector<long long int>& v, vector<long long int>& dp){\n    if(i >= n) return 0;\n    if(dp[i] != -1) return dp[i];\n    int ans = 0;\n    if(v[i]+sum >= 0){\n        ans = max(ans,1+help(i+1,n,count,sum+v[i],v,dp));\n    }\n\n        ans = max(ans, help(i+1, n, count,sum, v, dp));\n    return dp[i] = ans;\n} \nint main() {\n    int n; cin >> n;\n    int p1=0;\n    int p2=0;\n    int p3=0;\n    vector<long long int> v(n), dp(n,-1);\n    for(int i = 0; i < n; i++){ \n        cin >> v[i];\n        p1+=(v[i]>=0);\n        p2+=(v[i]<0);\n        p3+=(v[i]==0);\n    }\n    // if(p3==n)\n    // {\n    //     cout<<n<<endl;\n    //     return 0;\n    // }\n    // if(p1==n)\n    // {\n    //     cout<<n<<endl;\n    //     return 0;\n    // }\n    // if(p1==0)\n    // {\n    //     cout<<0<<endl;\n    //     return 0;\n    // }\n    cout << max(0,help(0,n,0,0,v,dp)) << endl;\n    return 0;\n    \n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<unordered_map>\nusing namespace std;\n\nint solve(vector<int>&arr, int i, int curr, vector<vector<int>>&dp){\n    if(i==arr.size()) return 0;\n    // string key = i + \"$\" + curr;\n    \n    // if(dp.find(key)!= dp.end()) return dp[key];\n    if(dp[i][curr]!=-1) return dp[i][curr];\n    \n    int maxi = 0;\n    if(curr+arr[i]>=0 ){\n       maxi = max(maxi, (solve(arr,i+1, curr+arr[i],dp) + 1));\n\n    }\n\n   maxi = max(maxi, solve(arr, i+1, curr, dp) );\n    // dp[key]=maxi;\n    dp[i][curr] = maxi;\n   return maxi;\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    // unordered_map<string,int> dp;\n    int n;\n    cin>>n;\n    vector<int> v(n);\n    for(int i=0; i<n; i++){\n        cin>>v[i];\n    }\n    int m = 90000;\n    vector<vector<int>> dp(n, vector<int>(m));\n\n    for(int i=0; i<n; i++){\n        for(int j=0; j<m; j++){\n            dp[i][j]=-1;\n        }\n    }\n\n    int ans = solve(v,0,0,dp);\n\n    cout<<ans;\n\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\nint solve(int n, int  arr[]){\n    int dp[n][n+1];\n\n    memset(dp, -1, sizeof dp);\n\n    for (int i = 0; i < n; i++){\n        dp[i][0] = 0;\n    }\n\n    dp[0][1] = (arr[0]>=0?arr[0]: -1);\n\n    for(int i = 1; i < n; i++){\n        for(int j =1; j <= (i+1); j++){\n            if(dp[i-1][j]!=-1){\n                dp[i][j] = max(dp[i][j], dp[i-1][j]);\n            }\n\n            if(dp[i-1][j-1]>=0 && dp[i-1][j-1]+arr[i]>=0){\n                dp[i][j] = max(dp[i][j], dp[i-1][j-1]+arr[i]);\n            }\n        }\n    }\n\n    int ans = 0;\n\n    for(int j = 0; j <= n; j++){\n        if(dp[n-1][j]>=0) ans = j;\n    }\n\n    return ans;\n}\n\n\nint main() {  \n   \n   int n;\n   cin >> n;\n   int arr[n];\n\n   for(int i = 0 ; i < n ; i++){\n       cin >> arr[i];\n   }\n\n   cout << solve(n, arr);\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\n#define ll long long\n#define mod 1000000007\nusing namespace std;\nmap<string,ll>mp;\nll util(vector<ll>&a,ll idx,ll immunity){\n    string key=to_string(idx)+\"\";\n    key+=to_string(immunity);\n    if(idx>=a.size())return 0;\n    if(mp.find(key)!= mp.end())return mp[key];\n    ll notTake=util(a,idx+1,immunity);\n    ll take=0;\n    if(immunity+a[idx]>=0){\n        take=1+util(a,idx+1,immunity+a[idx]);\n    }\n    return mp[key]=max(take,notTake)%mod;\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    ll n;\n    cin>>n;\n    vector<ll>a(n);\n    for(ll i=0;i<n;i++){\n        cin>>a[i];\n    }\n    cout<<util(a,0,0)<<'\\n';\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\nunordered_map<string,int> mp;\n\nint help(int i, int n, int count, long long sum, vector<long long int>& v, vector<long long int>& dp){\n    if(i >= n) return 0;\n    string key = to_string(i) + '^' + to_string(sum);\n    if(mp.find(key) != mp.end()) return mp[key];\n    int ans = 0;\n    if(v[i]+sum >= 0){\n        ans = max(ans,1+help(i+1,n,count,sum+v[i],v,dp));\n        ans=max(ans,help(i+1,n,count,sum,v,dp));\n    }\n\n    ans = max(ans, help(i+1, n, count,sum, v, dp));\n    return mp[key] = ans;\n} \nint main() {\n    int n; cin >> n;\n    int p1=0;\n    int p2=0;\n    int p3=0;\n    mp.clear();\n    vector<long long int> v(n), dp(n,-1);\n    for(int i = 0; i < n; i++){ \n        cin >> v[i];\n        p1+=(v[i]>=0);\n        p2+=(v[i]<0);\n        p3+=(v[i]==0);\n    }\n    // if(p3==n)\n    // {\n    //     cout<<n<<endl;\n    //     return 0;\n    // }\n    // if(p1==n)\n    // {\n    //     cout<<n<<endl;\n    //     return 0;\n    // }\n    // if(p1==0)\n    // {\n    //     cout<<0<<endl;\n    //     return 0;\n    // }\n    cout << max(0,help(0,n,0,0,v,dp)) << endl;\n    return 0;\n    \n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<unordered_map>\nusing namespace std;\n\nint solve(vector<int>&arr, int i, int curr, vector<vector<int>>&dp){\n    if(i==arr.size()) return 0;\n    // string key = i + \"$\" + curr;\n    \n    // if(dp.find(key)!= dp.end()) return dp[key];\n    if(dp[i][curr]!=-1) return dp[i][curr];\n    \n    int maxi = 0;\n    if(curr+arr[i]>=0 ){\n       maxi = max(maxi, (solve(arr,i+1, curr+arr[i],dp) + 1));\n\n    }\n\n   maxi = max(maxi, solve(arr, i+1, curr, dp) );\n    // dp[key]=maxi;\n    dp[i][curr] = maxi;\n   return maxi;\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n    // unordered_map<string,int> dp;\n    int n;\n    cin>>n;\n    vector<int> v(n);\n    for(int i=0; i<n; i++){\n        cin>>v[i];\n    }\n    int m = 99999;\n    vector<vector<int>> dp(n, vector<int>(m));\n\n    for(int i=0; i<n; i++){\n        for(int j=0; j<m; j++){\n            dp[i][j]=-1;\n        }\n    }\n\n    int ans = solve(v,0,0,dp);\n\n    cout<<ans;\n\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\nvoid lcs(vector<int> arr, int N){\n    int dp[N][N+1];\n    memset(dp,-1,sizeof(dp));\n    for(int i=0;i<N;i++){\n        dp[i][0]=0;\n    }\n    dp[0][1]=(arr[0]>=0 ? arr[0] : -1);\n    for(int i=1;i<N;i++){\n        for(int j=1;j<=(i+1);j++){\n            if(dp[i-1][j]!=-1){\n                dp[i][j]=max(dp[i][j],dp[i-1][j]);\n            }\n            if(dp[i-1][j-1]>=0&& dp[i-1][j-1]+arr[i]>=0){\n                dp[i][j]=max(dp[i][j],dp[i-1][j-1]+arr[i]);\n            }\n        }\n    }\n    int ans=0;\n    for(int j=0;j<=N;j++){\n        if(dp[N-1][j]>=0){\n            ans=j;\n        }\n    }\n    cout<<ans<<endl;\n}\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    int n,m;\n    cin>>n;\n    vector <int> v;\n    for(int i=0;i<n;i++){\n        cin>>m;\n        v.push_back(m);\n    }  \n    lcs(v,n);\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n,count=0,vac=0;\n    cin>>n;\n    int arr[n];\n    for(int i=0;i<n;i++){\n        cin>>arr[i];\n    }\n    for(int i=0;i<n;i++){\n        if((arr[i]+vac)>=0){\n            count++;\n            vac+=arr[i];\n        }\n        \n    }\n    cout<<count<<\"\\n\";\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\nclass Pair{\n    int val;\n    int idx;\n    public Pair(int val, int idx){\n        this.val = val;\n        this.idx = idx;\n    }\n}\n\nclass Solution {\n\n    public static void main(String[] args) {\n        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */\n        Scanner s = new Scanner(System.in);\n        int n = s.nextInt();\n        int arr[] = new int [n];\n        PriorityQueue<Pair> pq = new PriorityQueue<>((a, b) -> a.val == b.val ? a.idx - b.idx:a.val - b.val);\n        for(int i = 0; i < n; i++){\n            arr[i] = s.nextInt();\n        }\n        ArrayList<Long> temp = new ArrayList<>();\n        long sum = 0;\n        int ans = 0;\n        for(int i = 0; i < n; i++){\n            if(arr[i] < 0){\n                pq.add(new Pair((-arr[i]), i));\n            }\n        }\n        for(int i = 0; i < n; i++){\n            if(arr[i] >= 0){\n                sum += arr[i];\n                ans++;\n            }\n            while(!pq.isEmpty() && pq.peek().idx < i){\n                Pair curr = pq.peek();\n                if(curr.val <= sum){\n                    if(curr.val <= temp.get(curr.idx)){\n                        sum -= curr.val;\n                        ans++;\n                    }\n                    pq.poll();\n                }\n                else{\n                    break;\n                }\n            }\n            temp.add(sum);\n        }\n        while(!pq.isEmpty()){\n            Pair curr = pq.peek();\n            if(curr.val <= sum){\n                if(curr.val <= temp.get(curr.idx)){\n                    sum -= curr.val;\n                    ans++;\n                }\n                pq.poll();\n            }\n            else{\n                break;\n            }\n        }\n        System.out.println(ans);\n    }\n}","lang":"43"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    priority_queue<int, vector<int>, greater<int>> pq;\n    int n;\n    cin>>n;\n    int a[n];\n    for(int i = 0; i < n; i++){\n        cin>>a[i];\n    }\n    int sum = 0;\n    int maxEle = 0;\n    int ele = 0;\n    for(int i = 0;i < n; i++){\n        if(a[i] >= 0){\n            sum += a[i];\n            ele++;\n        }else{\n            if(sum + a[i] < 0){\n                if(pq.size() && pq.top() < a[i]){\n                    sum -= pq.top();\n                    sum += a[i];\n                    pq.pop();\n                    pq.push(a[i]);\n                }\n            }else{\n                ele++;\n                sum += a[i];\n                pq.push(a[i]);\n            }\n        }\n    }\n    cout<<ele<<endl;\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n#define int long long\n\nvoid longestSubsequence(vector<int>& arr, int n){\n    int dp[n][n+1];\n\n    memset(dp, -1, sizeof(dp));\n\n    for(int i=0; i<n; ++i){\n        dp[i][0] = 0;\n    }\n\n    dp[0][1] = (arr[0] >= 0? arr[0]:-1);\n    for(int i=1; i<n; i++){\n        for(int j=1; j<=(i+1);++j){\n            if(dp[i-1][j] != -1){\n                dp[i][j] = max(dp[i][j], dp[i-1][j]);\n            }\n\n            if(dp[i-1][j-1] >= 0 && dp[i-1][j-1]+arr[i] >=0){\n                dp[i][j] = max(dp[i][j], dp[i-1][j-1]+arr[i]);\n            }\n        }\n    }\n\n    int ans= 0;\n    for(int j=0; j<=n; ++j){\n        if(dp[n-1][j] >=0){\n            ans = j;\n        }\n    }\n\n    cout<<ans<<endl;\n}\n\n\nsigned main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n\n    vector<int> arr(n);\n    for(int i=0; i<n;i++){\n        cin>>arr[i];\n    }\n\n    longestSubsequence(arr,n);\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\nint main() {\n    int n;\n    cin>>n;\n    vector<int> a(n);\n    for(int i=0;i<n;i++)\n    {\n        cin>>a[i];\n    }\n    priority_queue<int,vector<int>,greater<int>> q;\n    int ans=0;\n    long sum=0;\n    for(int i=0;i<n;i++) {\n        if(a[i]>=0) {\n            sum+=a[i];\n            ans++;\n        }\n        else {\n            if(a[i]+sum>=0) {\n                sum+=a[i];\n                q.push(a[i]);\n                ans++;\n            }\n            else{\n                if(!q.empty()) {\n                    int b=q.top();\n                    if(b<a[i]) {\n                        q.pop();\n                        sum-=b;\n\n                        q.push(a[i]);\n                        sum+=a[i];\n                    }\n                }\n            }\n        }\n    }\n    cout<<ans<<\"\\n\";\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"# Enter your code here. Read input from STDIN. Print output to STDOUT\r\nN = int(input())\r\nV = list(map(int, input().split()))\r\n\r\n\r\nl = []\r\ng = []\r\nfor idx, val in enumerate(V):\r\n    if val > 0:\r\n        g.append((idx, val))\r\n    else:\r\n        l.append((idx, val))\r\n\r\ninit_idx = g[0][0]\r\nV = V[init_idx:]\r\nN -= init_idx\r\n\r\ntotpos = 0\r\ncount = len(g)\r\nfor i in g:\r\n    totpos += i[1]\r\n\r\nsorted(l, key=lambda x: x[1])\r\nl = l[::-1]\r\n\r\nfor i in l:\r\n    if i[0] > init_idx and (totpos + i[1]) >= 0:\r\n        totpos += i[1]\r\n        count += 1\r\n\r\nprint(count)","lang":"30"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n#define ll long long \n\nint main() {\n    int n;\n    cin>>n;\n    ll a[n];\n    // ll sum1 = 0, sum2 = 0;\n    for(int i=0;i<n;i++){\n         cin>>a[i];\n        //  if(a[i] >= 0) sum1 += a[i];\n        //  else sum2 += abs(a[i]);\n    }\n    ll sum = 0;\n    int cnt = 0;\n    priority_queue<ll> pq;\n    for(int i=0;i<n;i++){\n        if(a[i] >= 0) {\n            cnt++;\n            sum += a[i];\n            continue;\n        }\n        if(a[i] + sum >= 0){\n            pq.push(abs(a[i]));\n            sum += a[i];\n        }\n        else{\n            if(pq.empty()) continue;\n            int tp = pq.top();\n            pq.pop();\n            if(sum+tp+a[i] >= 0){\n                pq.push(abs(a[i]));\n                sum += tp+a[i];\n            }\n            else{\n                pq.push(tp);\n            }\n        }\n    }\n    cout << cnt+pq.size();\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\n#define ll long long\n#define mod 1000000007\nusing namespace std;\n\nll util (vector<ll>&a,ll idx,ll immunity){\n    if(idx>=a.size())return 0;\n    ll notTake=util(a,idx+1,immunity);\n    ll take=0;\n    if(immunity+a[idx]>=0){\n        take=1+util(a,idx+1,immunity+a[idx]);\n    }\n    return max(take,notTake);\n}\n\n\n\n\n//map<string,ll>mp;\n// ll util(vector<ll>&a,ll idx,ll immunity){\n//     string key=to_string(idx)+\"\";\n//     key+=to_string(immunity);\n//     if(idx>=a.size())return 0;\n//     if(mp.find(key)!= mp.end())return mp[key];\n//     ll notTake=util(a,idx+1,immunity);\n//     ll take=0;\n//     if(immunity+a[idx]>=0){\n//         take=1+util(a,idx+1,immunity+a[idx]);\n//     }\n//     return mp[key]=max(take,notTake)%mod;\n// }\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    ll n;\n    cin>>n;\n    vector<ll>a(n);\n    for(ll i=0;i<n;i++){\n        cin>>a[i];\n    }\n    cout<<util(a,0,0)<<'\\n';\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n,count=0,vac=0;\n    cin>>n;\n    int arr[n];\n    for(int i=0;i<n;i++){\n        cin>>arr[i];\n    }\n    for(int i=0;i<n;i++){\n        if((arr[i]+vac)>=0){\n            count++;\n            vac+=arr[i];\n        }\n        \n    }\n    cout<<count<<\"\\n\";\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\nint main() {\n    int n;\n    cin>>n;\n    vector<int> a(n);\n    for(int i=0;i<n;i++)\n    {\n        cin>>a[i];\n    }\n    priority_queue<int,vector<int>,greater<int>> q;\n    int ans=0;\n    long sum=0;\n    for(int i=0;i<n;i++) {\n        if(a[i]>=0) {\n            sum+=a[i];\n            ans++;\n        }\n        else {\n            if(a[i]+sum>=0) {\n                sum+=a[i];\n                q.push(a[i]);\n                ans++;\n            }\n            else{\n                if(!q.empty()) {\n                    int b=q.top();\n                    if(b<a[i]) {\n                        q.pop();\n                        sum-=b;\n\n                        q.push(a[i]);\n                        sum+=a[i];\n                    }\n                }\n            }\n        }\n    }\n    cout<<ans<<\"\\n\";\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std; \nint main() {\n    int n; cin >> n;\n    vector<long long int> v(n);\n    for(int i = 0; i < n; i++){ \n        cin >> v[i];\n    }\n   \n    using ll=long long int;\n\n    ll cnt=0;\n    ll ans=0;\n    ll p=0;\n    priority_queue<int, vector<int>, greater<int>> pq;\n    for(int i = 0; i < n; i++){\n        cnt += v[i];\n        ans++;\n        pq.push(v[i]);\n        if(cnt < 0){\n            cnt -= pq.top();\n            ans--;\n            pq.pop();\n\n        }\n        p = max(p,ans);\n    }\n    cout << p << endl;\n    return 0;\n    \n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n    int n;\n    cin >> n;\n    vector<int> arr(n);\n    for(int i=0; i<n; i++){\n        cin >> arr[i];\n    } \n    priority_queue<int, vector<int>, greater<int>> v;\n    int c=0, s=0;\n    vector<int> v1;\n    vector<int>::iterator it;\n    for(int i=0; i<n; i++){\n        s += arr[i];\n        v1.push_back(arr[i]);\n        c++;\n        if(arr[i]<0) v.push(arr[i]);\n        if(s<0){\n            s -= v.top();\n            it = find(v1.begin(), v1.end(), v.top());\n            v1.erase(it);\n            v.pop(); c--;\n        }\n    }\n    cout << v1.size();\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n    int n;\n    cin>>n;\n    priority_queue<long long,vector<long long>,greater<long long>>pq;\n    long long s=0;\n    for(int i=1;i<=n;i++)\n    {\n        long long x;\n        cin>>x;\n        s+=x;\n        pq.push(x);\n        while(s<0)\n        {\n            s-=pq.top();\n            pq.pop();\n        }\n    } \n    cout<<(int) pq.size();\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    long long n;\n    cin >> n;\n\n    vector<long long> arr;\n    for(long long i = 0; i < n; i++){\n        long long input;\n        cin >> input;\n        arr.push_back(input);\n    }\n\n    priority_queue<long long, vector<long long>, greater<long long>> pq;\n\n    long long count = 0, sum = 0;\n    vector<long long> v1;\n    vector<long long>::iterator it;\n    for(long long val : arr){\n        sum += val;\n        v1.push_back(val);\n        count++;\n        if(val < 0){\n            pq.push(val);\n        }\n        if(sum < 0){\n            sum -= pq.top();\n            it = find(v1.begin(), v1.end(), pq.top());\n            v1.erase(it);\n            pq.pop();\n            count--;\n        }\n\n\n    }\n    cout << v1.size() << \"\\n\";\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    int N;\n    cin>>N;\n    vector<int> A(N);\n    priority_queue<int,vector<int>,greater<int>> pqq;\n    for(int i=0;i<N;i++)\n    {\n        cin>>A[i];\n    }  \n    \n    \n    int answer=0;\n    int curr_anss=0;\n    long long summm=0;\n    for(int i=0;i<N;i++)\n    {\n        summm+=A[i];\n        if(A[i]<0)\n            pqq.push(A[i]);\n        curr_anss++;\n        if(summm<0)\n        {\n            int current=pqq.top();\n            pqq.pop();\n            summm-=current;\n            curr_anss--;\n        }\n        answer=max(answer,curr_anss);\n    }\n    cout<<answer<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\nint util(vector<int>&a,int idx,int sum)\n{\n    if(sum<0)\n        return 0;\n    if(idx==a.size())\n        return 0;\n\n    int take=0,not_take=0;\n    if(sum+a[idx]>=0)\n    {\n        take=1+util(a,idx+1,sum+a[idx]);\n    }\n    not_take=util(a,idx+1,sum);\n\n    return max(take,not_take);\n\n}\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n\n    int n;\n    cin>>n;\n    vector<int> vec(n,0);\n    for(int i=0;i<n;i++)\n    {\n        cin>>vec[i];\n    }\n    vector<int> dp(n,-1);\n\n    cout<<util(vec,0,0);\n\n\n    // recursive approach\n\n\n    // int sum=0;\n    // int count=0;\n    // for(int i=0;i<n;i++)\n    // {\n    //     sum+=vec[i];\n    //     if(sum<0)\n    //     {\n    //         sum=0;\n    //     }\n    //     else\n    //     {\n    //         count++;\n    //     }\n    // }\n    // cout<<count;\n    return 0;\n\n    \n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\nint util(vector<int>&a,int idx,int sum,vector<int>&dp)\n{\n    if(sum<0)\n        return 0;\n    if(idx==a.size())\n        return 0;\n    if(dp[idx]!=-1)\n        return dp[idx];\n    int take=0,not_take=1;\n    if(sum+a[idx]>=0)\n    {\n        take=1+util(a,idx+1,sum+a[idx],dp);\n    }\n    not_take=util(a,idx+1,sum,dp);\n\n    return dp[idx]=max(take,not_take);\n\n}\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n\n    int n;\n    cin>>n;\n    vector<int> vec(n,0);\n    for(int i=0;i<n;i++)\n    {\n        cin>>vec[i];\n    }\n    vector<int> dp(n,-1);\n\n    cout<<util(vec,0,0,dp);\n\n\n    // recursive approach\n\n\n    // int sum=0;\n    // int count=0;\n    // for(int i=0;i<n;i++)\n    // {\n    //     sum+=vec[i];\n    //     if(sum<0)\n    //     {\n    //         sum=0;\n    //     }\n    //     else\n    //     {\n    //         count++;\n    //     }\n    // }\n    // cout<<count;\n    return 0;\n\n    \n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\nint util(vector<int>&a,int idx,int sum,vector<int>&dp)\n{\n    if(sum<0)\n        return 0;\n    if(idx==a.size())\n        return 0;\n    if(dp[idx]!=-1)\n        return dp[idx];\n    int take=0,not_take=0;\n    if(sum+a[idx]>=0)\n    {\n        take=1+util(a,idx+1,sum+a[idx],dp);\n    }\n    not_take=util(a,idx+1,sum,dp);\n\n    return dp[idx]=max(take,not_take);\n\n}\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n\n    int n;\n    cin>>n;\n    vector<int> vec(n,0);\n    for(int i=0;i<n;i++)\n    {\n        cin>>vec[i];\n    }\n    vector<int> dp(n,-1);\n\n    cout<<util(vec,0,0,dp);\n\n\n    // recursive approach\n\n\n    // int sum=0;\n    // int count=0;\n    // for(int i=0;i<n;i++)\n    // {\n    //     sum+=vec[i];\n    //     if(sum<0)\n    //     {\n    //         sum=0;\n    //     }\n    //     else\n    //     {\n    //         count++;\n    //     }\n    // }\n    // cout<<count;\n    return 0;\n\n    \n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\nint util(vector<int>&a,int idx,int sum,vector<int>&dp)\n{\n    if(sum<0)\n        return 0;\n    if(idx==a.size())\n        return 0;\n    if(dp[idx]!=-1)\n        return dp[idx];\n    int take=0,not_take=0;\n    if(sum+a[idx]>=0)\n    {\n        take=1+util(a,idx+1,sum+a[idx],dp);\n    }\n    not_take=util(a,idx+1,sum,dp);\n\n    return dp[idx]=max(take,not_take);\n\n}\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n\n    int n;\n    cin>>n;\n    vector<int> vec(n,0);\n    for(int i=0;i<n;i++)\n    {\n        cin>>vec[i];\n    }\n    vector<int> dp(n,-1);\n\n    cout<<util(vec,0,0,dp);\n\n\n    // recursive approach\n\n\n    // int sum=0;\n    // int count=0;\n    // for(int i=0;i<n;i++)\n    // {\n    //     sum+=vec[i];\n    //     if(sum<0)\n    //     {\n    //         sum=0;\n    //     }\n    //     else\n    //     {\n    //         count++;\n    //     }\n    // }\n    // cout<<count;\n    return 0;\n\n    \n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\nint util(vector<int>&a,int idx,int sum,vector<int>&dp)\n{\n    if(sum<0)\n        return 0;\n    if(idx==a.size())\n        return 0;\n    if(dp[idx]!=-1)\n        return dp[idx];\n    int take=0,not_take=0;\n    if(sum+a[idx]>=0)\n    {\n        take=1+util(a,idx+1,sum+a[idx],dp);\n    }\n    not_take=util(a,idx+1,sum,dp);\n\n    return dp[idx]=max(take,not_take);\n\n}\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n\n    int n;\n    cin>>n;\n    vector<int> vec(n);\n    for(int i=0;i<n;i++)\n    {\n        cin>>vec[i];\n    }\n    vector<int> dp(n,-1);\n\n    cout<<util(vec,0,0,dp);\n\n\n    // recursive approach\n\n\n    // int sum=0;\n    // int count=0;\n    // for(int i=0;i<n;i++)\n    // {\n    //     sum+=vec[i];\n    //     if(sum<0)\n    //     {\n    //         sum=0;\n    //     }\n    //     else\n    //     {\n    //         count++;\n    //     }\n    // }\n    // cout<<count;\n    return 0;\n\n    \n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n\nvoid one(vector<int> ans, int N)\n{\n    int dp[N][N+1];\n    memset(dp, -1, sizeof dp);\n    for(int i=0;i<N;++i)\n    {\n        dp[i][0]=0;\n    }\n\n  \n  if(ans[0]>=0)\n  {\n      dp[0][1]=ans[0];\n  }\n  else{\n      dp[0][1]=-1;\n  }\n    for(int i=1;i<N;++i)\n    {\n        for(int j=1;j<=(i+1);++j)\n        {\n            if(dp[i-1][j]!=1){\n                dp[i][j]= max(dp[i][j], dp[i-1][j]);\n            }\n\n            if(dp[i-1][j-1]>=0 && dp[i-1][j-1]+ans[i]>=0)\n            {\n                dp[i][j]=max(dp[i][j], dp[i-1][j-1]+ans[i]);\n            }\n        }\n    }\n    int count=0;\n    for(int j=0;j<=N;++j)\n    {\n        if(dp[N-1][j]>=0)\n        {\n            count=j;\n        }\n    }\n    cout<<count<<endl;\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    int n;\n    vector<int>ans;\n    cin>>n;\n    for(int i=0;i<n;i++)\n    {\n        int temp;\n        cin>>temp;\n        ans.push_back(temp);\n    }  \n    one(ans, n);\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n#define int long long\n\nsigned main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n\n    multiset<int> s;\n    int n;\n    cin>>n;\n\n    int sum=0;\n\n    for(int i=0;i<n;++i){\n        int x;\n        cin>>x;\n        if(sum+x>=0){\n            s.insert(x);\n            sum+=x;\n        }\n        else if(!s.empty() && *s.begin()<x){\n            sum+=x-*s.begin();\n            s.erase(s.begin());\n            s.insert(x);\n        }\n    }\n    cout<< s.size();\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\n#define long long int\nint32_t main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int p=0,r=0;\n    priority_queue<int> q;\n    int t;\n    cin>>t;\n    while(t--)\n    {\n        int k;cin>>k;\n        p+=k;\n        r++;\n        q.push(-k);\n        while(p<0)\n        {\n            r--;\n            p+=q.top();\n            q.pop();\n        }\n    }\n    cout<<r;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n#define ll long long\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n; cin>>n;\n    ll v[n]; for(int i=0; i<n; i++) cin>>v[i];\n    ll ans = 0, sum = 0, streak = 0;\n    for(int i=0; i<n; i++) {\n        sum += v[i];\n        if(sum>=0) {streak++; ans=max(ans,streak);}\n        else sum -= v[i];\n        // ans = max(ans, streak);\n    }\n    cout << ans;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n    int n;\n    cin>>n;\n    vector <int> arr(n);\n    for(int i=0; i<n; i++)\n    {\n        cin>>arr[i];\n    } \n    int sum=0;\n    priority_queue <int> pq;\n    int ans=0;\n    for(int i=0; i<n; i++)\n    {\n        if(arr[i]>=0)\n        {\n            ans++;\n            sum+=arr[i];\n        }\n        else\n        {\n            if(sum+arr[i]>=0)\n            {\n                sum+=arr[i];\n                pq.push(-arr[i]);\n                ans++;\n            }\n            else if(!pq.empty())\n            {\n                int x= pq.top();\n                // cout<<x<<\" \"<<i<<'\\n';\n                if(x>abs(arr[i]))\n                {\n                    sum+=x;\n                    sum+=arr[i];\n                    pq.pop();\n                    pq.push(-arr[i]);\n                }\n            }\n        }\n        // cout<<ans<<\" \"<<i<<\" \"<<sum<<'\\n';\n    }\n    cout<<ans<<'\\n';\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n    int n, s = 0 ;\n    cin >> n;\n    vector<int> a(n);\n    for (int i = 0; i < n;i++) {\n        cin >> a[i];\n    }  \n    priority_queue<int, vector<int>, greater<int>> pq;\n    int ans  = 0;\n    for (int i = 0; i < n;i++) {\n        if (a[i] < 0) pq.push(a[i]);\n        s+= a[i];\n        ans++;\n        if (s>= 0) continue;\n        s -= pq.top();\n        pq.pop();\n        ans--;\n        \n    }\n    cout << ans << endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    int n;\n    cin >> n;\n    vector<int>v(n);\n    for(int i=0;i<n;i++)\n    {\n        cin >> v[i];\n    }\n    int cnt = 0;\n    int health = 0;\n    multiset<int>s;\n    for(int i =0;i<n;i++)\n    {\n        if(v[i] >=0 )\n        {\n            cnt++;\n            health += v[i];\n        }\n        else\n        {\n            if(health + v[i] >= 0)\n            {\n                health += v[i];\n                cnt++;\n                s.insert(v[i]);\n            }\n            else\n            {\n                int p= *s.begin();\n                if(p >= v[i])\n                {\n                    continue;\n                }\n                else\n                {\n                    s.erase(s.begin());\n                    health = health -p + v[i];\n                }\n            }\n        }\n    }\n    cout << cnt << endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n    int N; cin >> N;\n\n    int V[N];\n    map<int, set<int>> m;\n\n    for (int i = 0; i < N; i++) {\n        cin >> V[i];\n    \n        if (V[i] < 0)\n            m[V[i]].insert(i);\n    }\n    \n    int immunity = 0, vaccines = 0;\n    for (int i = 0; i < N; i++) {\n        if (V[i] >= 0) {\n            immunity += V[i];\n            vaccines++;\n\n            for (auto itr = m.rbegin(); itr != m.rend(); itr++) {\n                if (itr->first + immunity < 0)\n                    break;\n                for (; itr->second.size() && itr->first + immunity >= 0; ) {\n                    immunity += itr->first;\n                    vaccines++;\n                    itr->second.erase(itr->second.begin());\n                }\n                if (itr->second.size() == 0)\n                    m.erase(next(itr).base());\n            }\n        } else {\n            auto itr = m.find(V[i]);\n            if (itr != m.end()) {\n                auto jtr = itr->second.find(i);\n                if (jtr != itr->second.end())\n                    itr->second.erase(jtr);\n                if (itr->second.size() == 0)\n                    m.erase(itr);\n            }\n        }\n    }\n    cout << vaccines;\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n\nvoid longestsubse(int* arr, int n)\n{\n    int dp[n][n+1];\n    memset(dp,-1,sizeof dp);\n    for(int i=0;i<n;i++){\n        dp[i][0]=0;\n    }\n    dp[0][1]=(arr[0] >= 0 ? arr[0] : -1);\n    for(int i=1;i<n;i++){\n        for(int j=1;j<=(i+1);j++){\n            if(dp[i-1][j]!=-1){\n                dp[i][j]=max(dp[i][j],dp[i-1][j]);\n            }\n            if(dp[i-1][j-1]>=0 && dp[i-1][j-1]+arr[i]>=0){\n                dp[i][j]=max(dp[i][j],dp[i-1][j-1]+arr[i]);\n            }\n        }\n    }\n    int ans=0;\n    for(int j=0;j<=n;j++){\n        if(dp[n-1][j]>=0){\n            ans=j;\n        }\n    }\n    cout << ans;\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    int arr[n];\n    for(int i=0;i<n;i++){\n        cin>>arr[i];\n    }\n    longestsubse(arr,n);\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <bits/stdc++.h>\nusing namespace std;\n#define ll long long\n\nint main()\n{\n        ll n;\n            cin >> n;\n\n                ll life = 0;\n                    ll ans = 0;\n                        priority_queue <ll, vector <ll>, greater<ll>> pq;\n\n                            for (ll i=0; i<n; i++)\n                                {\n                                        ll x;\n                                                cin >> x;\n\n                                                        if (life+x>=0)\n                                                                {\n                                                                            life+=x;\n                                                                                        ans++;\n                                                                                                    if (x<0)\n                                                                                                                    pq.push(x);\n                                                                                                                            }\n\n                                                                                                                                    else if (!pq.empty() && x>pq.top())\n                                                                                                                                            {\n                                                                                                                                                        life -= pq.top();\n                                                                                                                                                                    life += x;\n                                                                                                                                                                                pq.pop();\n                                                                                                                                                                                            pq.push(x);\n                                                                                                                                                                                                    }\n                                                                                                                                                                                                        }\n\n                                                                                                                                                                                                            cout << ans << endl;\n\n                                                                                                                                                                                                                return 0;\n                                                                                                                                                                                                                }","lang":"2"},
{"question_id":40870,"source":"#include<bits/stdc++.h>\nusing namespace std;\n\nint debuga ( int n )\n{\n    int temp = n*90 ;\n    temp *= 90 ;\n    return temp ;\n}\n\n\nint main() {\n    \n    int n;\n    cin>>n;\n    vector<int> vec ( n );\n\n    for ( int i=0 ; i < n ; i++ )\n    {\n        debuga(i) ;\n        cin >> vec[i] ;\n    }\n\n    vector<long long> dp ( n+1 , INT_MIN );\n    dp[0] = 0 ;\n    dp[1] = (vec[0] >= 0 ? vec[0] : INT_MIN) ;\n\n    for (int i=1;i<n;i++){\n        for ( int j=i+1 ; j >=0 ; j-- )\n        {\n            if ( j==0 )\n            {\n                dp[j] = 0 ;\n                continue ;\n            }\n            debuga(j);\n            dp[j] = max( dp[j-1] + vec[i] , dp[j] );\n            if(dp[j]<0)\n            dp[j] = INT_MIN ;\n        }\n    }\n\n    int ans =0;\n    for ( int i=0 ; i <= n ; i++ )\n    {\n        debuga(i);\n        if ( dp[i] >= 0 )\n        ans = i ;\n    }\n\n    cout << ans ;\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<queue>\nusing namespace std;\nint helper(int n,vector<int>& a){\n    int ans=0;\n    priority_queue<int,vector<int>,greater<int>> pq;\n\n    int curr=0;\n    for(int i=0;i<n;i++){\n        if(curr+a[i]>=0){\n            if(a[i]<0)pq.push(a[i]);\n            ans++;\n            curr+=a[i];\n            continue;\n        }\n\n        if(!pq.empty()){\n            if(a[i]>pq.top()){\n                curr=curr+a[i]-pq.top();\n                pq.pop();\n                pq.push(a[i]);\n            }\n        }\n    }\n\n    return ans;\n}\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   \n    int n;\n    cin>>n;\n    vector<int> a(n);\n    for(int i=0;i<n;i++){\n        cin>>a[i];\n    }\n    int ans=helper(n,a);\n    cout<<ans<<endl;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\n\n\nint main() {\n    int n;\n    cin >> n;\n    vector<int> v(n);\n    for(int i=0;i<n;i++){\n        cin >> v[i];\n    } \n    int dp[n][n+1];\n    memset(dp, -1, sizeof dp);\n    for(int i=0;i<n;i++){\n        dp[i][0]=0;\n    }\n    if(v[0]>=0){\n        dp[0][1]=v[0];\n    }\n    else{\n        dp[0][1]=-1;\n    }\n    for(int i=1;i<n;i++){\n        for(int j=1;j<=(i+1);j++){\n            if(dp[i-1][j]!=-1){\n                dp[i][j]=max(dp[i-1][j], dp[i][j]);\n            }\n            if(dp[i-1][j-1]>=0 && dp[i-1][j-1]+v[i]>=0){\n                dp[i][j]=max(dp[i][j], dp[i-1][j-1]+v[i]);\n            }\n        }\n    }\n    int ans=0;\n    for(int j=0;j<=n;j++){\n        if(dp[n-1][j]>=0){\n            ans=j;\n        }\n    }\n    cout << ans;\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include<bits/stdc++.h>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n      int n;\n      cin>>n;\n      int a[n];\n      priority_queue<long long,vector<long long>,greater<long long> > pq;\n      long long s=0;\n\n      for(int i=1;i<=n;i++)\n      {\n          long long x;\n          cin>>x;\n\n          s+= x;\n          pq.push(x);\n\n          while(s<0)\n          {\n              s-=pq.top();\n              pq.pop();\n          }\n      }\n\n\n      cout<<(int)pq.size();\n\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\n#include<bits/stdc++.h> \nusing namespace std;\n\n\nvoid longest(vector<int> &arr, int n)\n{\n    int dp[n][n+1];\n    memset(dp,-1,sizeof dp);\n    for(int i=0;i <n;i++)\n    {\n        dp[i][0]=0;\n    }\n\n    dp[0][1]= arr[0]>=0?arr[0]:-1;\n\n    for(int i=1;i<n;i++)\n    {\n        for(int j=1; j<(i+1); j++)\n        {\n            if(dp[i-1][j]!=-1)\n            {\n                dp[i][j]= max(dp[i][j], dp[i-1][j]);\n            }\n\n            if(dp[i-1][j-1]>=0 && dp[i-1][j-1]+arr[i]>=0)\n            {\n                dp[i][j]= max(dp[i][j], dp[i-1][j-1]+arr[i]);\n            }\n        }\n    }\n\n    int ans=0;\n    for(int j=0; j<=n; j++)\n    {\n        if(dp[n-1][j]>=0) ans=j;\n    }\n\n    cout<<ans;\n\n}\n\n\nint main() {\n    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  \n\n    int n;\n    cin>>n;\n\n    vector<int> a(n);\n\n    for(int i=0;i <n; i++)\n    {\n        cin>>a[i];\n    } \n\n    // longest(v,n);\n\n    int sum=0;\n    priority_queue<int, vector<int>, greater<int>> heap;\n    for(int i=0;i<n; i++)\n    {\n        sum+=a[i];\n        heap.push(a[i]);\n    if(sum<0)\n    {\n    sum-= heap.top();\n    heap.pop();\n    }\n    }\n\n    cout<<heap.size();\n    return 0;\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"},
{"question_id":40870,"source":"#include \"bits/stdc++.h\" \nusing namespace std; \n#define int long long int\nint32_t main()\n{\nint n; cin>>n; priority_queue<int,vector<int>,greater<int>> pq; int ans=0, vaccines=0, health=0;\nfor(int i=0; i<n; ++i) { int x; cin>>x; health+=x; vaccines++; pq.push(x);\nif(health>=0) ans=max(ans,vaccines); while(health<0) {\nhealth-=pq.top(); pq.pop();\nvaccines--;\n}\n}\ncout<<max(vaccines,ans);\n}","lang":"2"}
]


def ranSubGenerator(code_id):
    if code_id == 40870:
        rand = random.randint(400, 598)
        submission = randomSub[rand]["source"]
        lang = randomSub[rand]["lang"]
        finSubmission = [submission, lang]
    elif code_id == 41034:
        rand = random.randint(14, 200)
        submission = randomSub[rand]["source"]
        lang = randomSub[rand]["lang"]
        finSubmission = [submission, lang]
    elif code_id == 41000:
        rand = random.randint(201, 299)
        submission = randomSub[rand]["source"]
        lang = randomSub[rand]["lang"]
        finSubmission = [submission, lang]
    elif code_id == 266181:
        rand = random.randint(6, 13)
        submission = randomSub[rand]["source"]
        lang = randomSub[rand]["lang"]
        finSubmission = [submission, lang]
    elif code_id == 266182:
        rand = random.randint(0, 5)
        submission = randomSub[rand]["source"]
        lang = randomSub[rand]["lang"]
        finSubmission = [submission, lang]
    else:
        "NULL"
    return finSubmission