akhauriyash/Code-Regression huggingface dataset:
import itertools
H, W, K = map(int,input().split())
S = [list(map(int,list(input()))) for _ in range(H)]
def check(k):
    if k <= K:
        return(True)
    else:
        return(False)
        
noans = 0
def make_lst(i):
    global noans, lst, havelst
    temp = S[0][i]
    for h in range(H-1):
        if y[h]:
            lst.append(temp)
            temp = S[h+1][i]
        else:
            temp += S[h+1][i]
    lst.append(temp)
    if check(max(lst)):
        havelst = 1
    else:
        noans = 1
#    print(y,i,lst, "makelst")
               
def nocut(i):
    global cutnum, lst, havelst, noans
    prelst = []
    temp = S[0][i]
    if i == W-1:
        if not check(temp):
            noans = 1
    j = 0
    for h in range(H-1):            
        if y[h]:
            lst[j] += temp
            prelst.append(temp)
            j += 1
            temp = S[h+1][i]
        else:
            temp += S[h+1][i]
        if i == W-1:
            if not check(temp):
                noans = 1
    prelst.append(temp)
    lst[-1] += temp
    if check(max(lst)):
#        print(y,i,lst,"nocut", "cutnum = ",cutnum)
        return(True)
    else:
        cutnum += 1
        lst = prelst        
#        print(y,i,lst,"cut","cutnum =",cutnum)
        
                 
ans = float("inf")    
for y in itertools.product((0, 1), repeat=H-1):
    havelst = 0
    lst = []
    cutnum = sum(y)
    for x in range(W):
        if noans:
            break
        if havelst:
            nocut(x)
        else:
            make_lst(x)
#    print(y,cutnum)
    if noans:
        noans = 0
        continue
    else:
        ans = min(cutnum, ans)
print(ans)


Measured memory_bytes: 56924
/****************************
 * ×÷Õß£ºzxf
 * ÈÕÆÚ£º2017/8/8
 * ±êÌâ£º¤³¤À¤ï¤êÕß¤¤¤í¤Ï¤Á¤ã¤ó / Iroha's Obsession
 * ÌâºÅ£ºARC058C
 * ×öÌâ·½·¨£º...
 * ½á¹û£º
 * Time used£º
 * Memory used£º
 ****************************/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define LL long long
#define pb push_back
#define pob pop_back
#define mp make_pair
#define FILL(a,v) memset((void*)a,v,sizeof(a))
#define FILL0(a) FILL(a,0)
#define FILL1(a) FILL(a,-1)
#define ALL(a) (a).begin(),(a).end()
#define Inf 1e9
#define Mod 1000000007
#define foreach(it,x) for(typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define FOR(i,x) for(int i=0;i<x;i++)
#define RFOR(i,x) for(int i=x-1;i>=0;i--)
#define FFOR(i,a,b) for(int i=a;i<b;i++)
#define FRFOR(i,a,b) for(int i=a-1;i>=b;i--)
#define SZ(a) ((int)(a).size())
#define FI first
#define SE second
#define OVER(a) return puts(a),0
#define fastio ios::sync_with_stdio(0)
#define filei(f) freopen(f,"r",stdin)
#define fileo(f) freopen(f,"w",stdout)
using namespace std;
typedef pair<int,int> pii;
typedef unsigned long long UINT;
typedef unsigned int Uint;
typedef long long INT;
typedef pair<INT,INT> PII;
typedef stringstream sst;
typedef istringstream iss;
typedef vector<int> vint;
typedef vector<INT> VINT;
typedef vector<pii> vpii;
typedef vector<PII> VPII;
typedef priority_queue<int> pqi;
typedef priority_queue<INT> PQI;
typedef priority_queue<pii> pqp;
typedef priority_queue<PII> PQP;
typedef priority_queue<int,vint,greater<int> > xqi;
typedef priority_queue<INT,VINT,greater<INT> > XQI;
typedef priority_queue<pii,vpii,greater<pii> > xqp;
typedef priority_queue<PII,VPII,greater<PII> > XQP;

int n,m;
char s[10];
set<char> cant;

int main()
{
	scanf("%d%d",&n,&m);
	int c;
	for(int i=0;i<m;i++)
	{
		scanf("%d",&c);
		cant.insert(c+'0');
	}
	while(1)
	{
		sprintf(s,"%d",n);
		int can=1;
		for(int i=0;i<strlen(s);i++)
			if(cant.count(s[i]))
				can=0;
		if(can==1)return printf("%d\n",n),0;
		n++;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

typedef long long ll; // ll  is 64bit same as double

int main() {
	
	// make input and output more efficient
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int N;
	
	cin >> N;
	
	int d = N%10;
	
	string ans = "";
	
	if(d==0 || d==1 || d==6 || d==8) {
		ans = "pon";
	}
	else if(d == 3){
		ans = "bon";
	}
	else
		ans = "hon";
	
	cout << ans << "\n";
	
	return 0;
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("ant");
            WillReturn.Add("obe");
            WillReturn.Add("rec");
            //abc
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("edu");
            WillReturn.Add("cat");
            WillReturn.Add("ion");
            //ean
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        char c11 = InputList[0][0];
        char c22 = InputList[1][1];
        char c33 = InputList[2][2];
        Console.WriteLine("{0}{1}{2}", c11, c22, c33);
    }
}


Measured memory_bytes: 13140
N = int(input())
A = list(map(int,input().split()))
for i in range(N):
    A.append(A[i]+1)
    A.append(A[i]-1)
import collections 
C = collections.Counter(A)
ans = 0
for k,v in C.items():
    if v>ans:
        ans = v
print(ans)

Measured memory_bytes: 67532
#include <cstdio>
#include <queue>
#include <vector>
const int MAXN = 1005;
const int NOPE = -1;
typedef std::vector<int> vin;
int  dist[MAXN];
bool seen[MAXN];
vin G[MAXN];
int M, N;
int a, b;

struct State {
  int sink;
  int size;
  int upper[MAXN];

  void reset() {
    sink = NOPE;
    size = NOPE;
    for (int i = 1; i <= N; ++i) {
      upper[i] = NOPE;
    }
  }
} best, S;

void reset() {
  for (int i = 1; i <= N; ++i) {
    dist[i] = NOPE;
    seen[i] = false;
  }
  S.reset();
}

void bfs(int src) {
  reset();
  std::queue<int> Q;
  dist[src] = 0;
  seen[src] = true;
  Q.push(src);

  while (!Q.empty()) {
    int cur = Q.front();
    Q.pop();
    for (int nxt: G[cur]) {
      if (nxt == src) {
        if ((S.sink == NOPE) ||
            (dist[cur] < S.size)) {
          S.sink = cur;
          S.size = dist[cur];
        } // Shortest cycle at "src"
      }
      if (seen[nxt]) continue;
      dist[nxt] = dist[cur] + 1;
      seen[nxt] = true;
      S.upper[nxt] = cur;
      Q.push(nxt);
    }
  }
}

void solve() {
  best.reset();
  for (int i = 1; i <= N; ++i) {
    bfs(i);
    if (S.sink == NOPE) continue;
    if ((best.sink == NOPE) || (S.size < best.size)) {
      best = S;
    } // Shortest cycle.
  }
}

int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < M; ++i) {
    scanf(" %d%d", &a, &b);
    G[a].push_back(b);
  }
  solve();
  int ret = best.sink;
  if (ret != NOPE) {
    printf("%d\n", best.size + 1);
    int cur = ret;
    while (cur != NOPE) {
      printf("%d\n", cur);
      cur = best.upper[cur];
    }
  } else {
    puts("-1");
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;

int main(){
  int n,x; cin >> n >> x;
  int l[n+1];
  l[0] = 0;
  int i;
  for(i=0;i<n;i++){
    cin >> l[i+1];
    l[i+1] += l[i];
    if(l[i+1]>x) break;
  }
  cout << i+1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9 + 7;

void FAST(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int main(){
  FAST();

  int n;
  cin >> n;
  vi v(n);
  REP(i, 0, n)  cin >> v[i];
  sort(all(v));

  double ans = v[0];
  REP(i, 1, n){
      ans = (ans + v[i])/2;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;

#define pb emplace_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define vi vector
#define forn(i, l, r) for(int i = l; i <= r; i++)
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pii pair<int,int>
#define f80 double
#define LOCAL 0
#define endl '\n'

typedef long long int ll;
#define int long long int

const int mod = 1e9 + 7;
const int N = 100005;
const int inf = 2e9;

signed main(){
    IO;
    if(LOCAL){
        freopen("inp.txt", "r", stdin);
    }
    string s, t;
    cin >> s >> t;
    int n = s.size();
    for(int p = 0; p < n; p++){
        bool yes = 1;
        int pp = p;
        for(int i = 0; i < n; i++){
            if(s[pp] != t[i])
                yes = 0;
            pp = (pp + 1) % n;
        }
        if(yes)
        {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int h, n;
    cin >> h >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
        sum += a[i];
    }

    if (h <= sum) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 640
n, a, b, c, d = map(int, input().split())
s = input()
a -= 1
b -= 1
c -= 1
d -= 1
if '##' in s[a:max(c, d)]:
    print('No')
    exit()
if c < d:
    print('Yes')
    exit()
if '...' in s[b-1:d+2]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3700
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

#define ll long long

#define inf -1000000000000
const ll mod = 1e9+7;

vector<vector<ll>> dp;

ll longest_path(vector<vector<char>> &a,ll n, ll m ,ll i, ll j)
{
    
    if(n-1==i && m-1==j)
    {
        return 1;
    }
    else if(i>=n || j>=m)
    {
        return 0;
    }
    else if(a[i][j]=='#')
        return 0;
        
    if(dp[i][j]!=-1)
        return dp[i][j];
    ll a1 =0,b1=0;
    a1 = longest_path(a,n,m,i+1,j);
    b1 = longest_path(a,n,m,i,j+1);
    
    dp[i][j]=((__int128)a1+b1)%mod;
    
    
    
    
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    ll n,m;
    cin>>n>>m;
    
    vector<vector<char>> a(n+1,vector<char>(m+1));
    
    dp.resize(n+2,vector<ll>(m+2,-1));
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<m;j++)
        {
            cin>>a[i][j];
        }
    }
    
    cout<<longest_path(a,n,m,0,0)%mod<<endl;
    
    
    
	return 0;
}

Measured memory_bytes: 9344
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007

ll dp[101][100005], n, k, arr[101];

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> arr[i];
	}
	//dp[0][0] = 1;

	for (int i = 0; i <= n; i++) {
		for (ll candies = 0; candies <= k; candies++) {
			//dp[i][candies] = 0;
			if (i == 0 &&  candies == 0) {
				dp[i][candies] = 1;
				continue;
			}
			if (i == 0 && candies > 0) {
				dp[i][candies] = 0;
				continue;
			}
			if (candies == 0) {
				dp[i][candies] = dp[i - 1][candies];
				continue;
			}

			if (candies - 1 - arr[i] < 0) {
				dp[i][candies] = (dp[i][candies - 1] + dp[i - 1][candies]) % mod;
				continue;
			}

			dp[i][candies] = (mod + dp[i][candies - 1] - dp[i - 1][candies - 1 - arr[i]] + dp[i - 1][candies]) % mod;
			//cur = previosly calculated upto candies -1 - (state that is unreachabele cur_candies but was reachable cur_candies-1) + (state that is reachable from cur_candies but was unreachabele from cur_candies -1)

		}
	}

	cout << dp[n][k];
	return 0;
}


Measured memory_bytes: 79104
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int cnt, m;
	cin >> cnt;
	string s1, s2, ans;
	for(int i = 0; i < cnt; i++){
		cin >> s1 >> s2;
		ans = "";
		m = max(s1.size(), s2.size());
		while( s1.size() < m ) 
			s1 = '0' + s1;
		while( s2.size() < m )
			s2 = '0' + s2;		
		int c = 0;	
		for(int i = m-1; i >= 0; i--){
			char ch = ((s1[i] - '0') + (s2[i] - '0') + c) % 10 + '0';
			c = ((s1[i] - '0') + (s2[i] - '0') + c) / 10;
			ans += ch;
		}		
		if(c) 
			ans += c + '0';
		reverse(ans.begin(), ans.end());
		while(ans.size() > 1 && ans[0] == '0') 
			ans.erase(ans.begin());		
		if(ans.size() > 80)
			cout << "overflow" << endl;
		else
			cout << ans << endl;
	}
}

Measured memory_bytes: 3104
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    int max = 0;
    for (int i = 1; i <= s.length(); i++) {
      int count = 0;
      String head = s.substring(0, i);
      String tail = s.substring(i);
       char[] alphabetHead = head.toCharArray();
       char[] alphabetTail = tail.toCharArray();
       Set<Character> hsHead = new HashSet<Character>();
       Set<Character> hsTail = new HashSet<Character>();
       for (int j = 0; j < head.length(); j++) {
         hsHead.add(alphabetHead[j]);
       }
       for (int k = 0; k < tail.length(); k++) {
         hsTail.add(alphabetTail[k]);
       }
       for (char c1 : hsHead) {
         for (char c2 : hsTail) {
           if (c1 == c2) count++;
         }
       }
       max = Math.max(max, count);
       
    }
    System.out.println(max);
  }
}

Measured memory_bytes: 23764
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    int  a, b;
    cin >> a >> b;
    if(a < 6){
        cout << 0;
    }
    else if(a < 13){
        cout << b/2;
    }
    else
        cout << b;
    
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 1e5+23;

int a[N], n;

bool check(int s) {
  long long size = a[s];
  for (int i = 0; i < n; ++i) {
    if (i == s) continue;
    if (a[i] > 2*size) return false;
    size += a[i];
  }
  return true;
}

void solve() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a+i);
  }
  sort(a, a+n);
  int lo = -1, hi = n;
  while (lo+1 < hi) {
    int mid = (lo+hi)/2;
    if (check(mid)) hi = mid;
    else lo = mid;
  }
  printf("%d", n-hi);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 640
//2020年4月17日現在

#include<stdio.h>
#include<cmath>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>
#include<queue>
#include<set>
#include<utility>
#include<iomanip>
#include<limits>
#include<thread>
#include<map>
#include<stack>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<tuple>
#include <cstdio>

using namespace std;

template <class... A>
void prints() { cout << "\n"; }
template <class... A>
void prints_rest() { cout << "\n"; }
template <class T, class... A>
void prints_rest(const T &first, const A &... rest) { cout << " " << first; prints_rest(rest...); }
template <class T, class... A>
void prints(const T &first, const A &... rest) { cout << first; prints_rest(rest...); }

namespace {
    // printElems(&a[0], &a[n]);　みたいな感じで使う。
    void printElems(const int* begin, const int* end)
    {
        for (const int* p = begin; p != end; ++p) {
            std::cout << *p << ' ';
        }
        std::cout << std::endl;
    }
}

#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1; i<n+1; i++)
#define repr(i,n) for(int i=n-1; i>=0; i--)
#define repr1(i,n) for(int i=n; i>0; i--)
#define FOR(i,j,n) for(int i=j; i < n; i++)
#define souatari(i,j,n) rep1(i,n-1)rep(j,i)
#define souatari1(i,j,n) for(int i=2; i<n+1; i++)rep1(j,i-1)
#define mp make_pair
#define F first
#define S second
#define elif else if

typedef long long ll;
typedef vector<int>  vi;
typedef vector<vi>  vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef array<int,3> arr3;
typedef long double D;


const ll llinf =  numeric_limits<ll>::max();
const ll _llinf = numeric_limits<ll>::lowest();
const int inf = numeric_limits<int>::max();
const int _inf = numeric_limits<int>::lowest();
const double dinf = numeric_limits<double>::infinity();
const ll MOD = 1000000007;
const ll BIG = 10000000000000000;

pll a[2005];
//int ap[2005]; //左なら0 右なら1
ll dp[2005][2005];

int main(){
	int n;
	cin >> n;
	priority_queue<pll> q;

	rep(i,n){
		ll tmp;
		cin >> tmp;
		//値、場所
		a[i] = mp(tmp,i);
		q.push(mp(tmp,i));
	}
/*
	pll tmp = q.top();
	q.pop();
	dp[1][0] = q.F*(q.S-0);
	dp[0][1] = q.F*(n-1-q.S);
*/
	rep1(s,n){
		pll tmp = q.top();
		q.pop();
		rep(i,s+1){
			ll l = s-i-1>=0 ?  dp[s-i-1][i]+tmp.F*abs(tmp.S-(s-i-1)) : -1;
			ll r = i-1>=0 ?  dp[s-i][i-1]+tmp.F*abs(tmp.S-(n-i)) : -1;

			dp[s-i][i] = max(l,r);
		}
	}

	ll ans = 0;
	rep(i,n){
		ans = max(ans,dp[n-i][i]);
//		prints(dp[n-i][i]);
	}

/*	rep(i,n+1){
		rep(j,n+1){
			cout << dp[i][j] << ' ';
		}
		prints();
	}
*/
	prints(ans);

	return 0;
}



Measured memory_bytes: 26372
import sys


def input(): return sys.stdin.readline().strip()


def main():
    N, K, Q = map(int, input().split())
    win = [0] * N

    for _ in range(Q):
        a = int(input()) - 1
        win[a] += 1

    for w in win:
        is_win = K - (Q - w) > 0
        if is_win:
            print('Yes')
        else:
            print('No')


if __name__ == "__main__":
    main()


Measured memory_bytes: 4680
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>

#define _GLIBCXX_DEBAC
using namespace std;


int main() {
	int a, b;
	cin >> a >> b;
	int ans = 0,x=1;
	while (x < b) {
		x -= 1;
		x += a;
		ans += 1;
	}
	cout << ans;
		return 0;
}









Measured memory_bytes: 256
import sys

num = int(sys.stdin.readline().strip())
s = (num+1) * num // 2
num3 = num // 3
num5 = num // 5
num15 = num // 15
result = s - 3 *( (num3+1) * num3 // 2 ) - 5 * ( (num5 + 1) * num5 // 2 ) + 15 * ((num15+1) * num15 // 2 )
print(result)

Measured memory_bytes: 61724
#include<iostream>
#include<vector>
main(){for(int p,q,i;std::cin>>p>>q;puts("")){std::vector<int>r,u(q,1);for(;(p%=q)*u[p];u[p]=i=0,printf("%d",(p*=10)/q))r.push_back(p);if(p)for(puts("");i<r.size();printf(q?" ":"^"))q=r[i++]^p?q:0;}}

Measured memory_bytes: 3612
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: i64 = s.next().unwrap().parse().unwrap();
	let mut d = vec![1; n as usize + 1];
	for i in 2..=n {
		for j in (i..=n).step_by(i as usize) {
			d[j as usize] += 1;
		}
	}
	let mut ans = 0i64;
	for c in 1..n {
		ans += d[(n - c) as usize];
	}
	println!("{}", ans);
}


Measured memory_bytes: 9664
import sys
from collections import defaultdict
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N, C = in_nn()
    D = [list(map(int, readline().split())) for _ in range(C)]
    c = [list(map(int, readline().split())) for _ in range(N)]

    grid = [defaultdict(int) for _ in range(3)]

    for y in range(N):
        for x in range(N):
            d = grid[(x + y + 2) % 3]
            d[c[y][x]] += 1

    comb = itertools.permutations(range(1, C + 1), 3)

    ans = 10**9 + 7
    for com in comb:
        iwa = 0
        for i in range(3):
            n_c = com[i]
            for k, v in grid[i].items():
                iwa += D[k - 1][n_c - 1] * v
        ans = min(ans, iwa)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 76892
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> inline bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> inline bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
struct Init {
    Init() {
        cout << fixed << setprecision(20);
    };
} init;
 
int N;
int x[110], y[110];
signed main() {
    cin >> N;
    for (int i = 0; i < N; i++) { cin >> x[i] >> y[i]; }
    double pi = acos(-1);
    double ans = 0;
    for (double theta = 0; theta < 2 * pi; theta += 2e-5) {
        double a = cos(theta), b = sin(theta);
        double cur = 0;
        for (int i = 0; i < N; i++) {
            double nai = x[i] * a + y[i] * b;
            if (nai > 0) { cur += nai; }
        }
        chmax(ans, cur);
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
/*bool check(vector<int> v,vector<int> t)
{
	int i=0,flag=0;
	for(auto x:v)
	{
		if(x==t[i])
			i++;
		else
		{
			flag=1;
			break;
		}
	}
	if(flag==1)
		return false;
	else
		return true;
}*/
/*void swap1(int *a,int *b)
{
	int t;
	t=*a;
	*a=*b;
	*b=t;
}*/
int main()
{
	int n,count=0;
	cin>>n;
	int dup = n+1;
	vector<int> v,t;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		v.push_back(x);
	}
	/*int count=0,flag=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			if(v[i]>v[j])
			{
				swap(v[i],v[j]);
				count++;
				if(count<=1)
				{
					if(check(v,t))
					{
						flag=1;
						cout<<"YES";
						return 0;
					}
				}
			}
		}
	}*/
	for(int i=0;i<n;i++)
		{if(v[i]!=i+1)count++;}
	if(count==0 or count==2 or n==2)
		cout<<"YES";
	else
		cout<<"NO";
	//if(flag==0)
		//cout<<"NO";

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
void leap_year(int start_year, int end_year);
 
int main(void)
{
    int start_year;
    int end_year;
    int i = 0;
    while(1) {
        scanf("%d %d", &start_year, &end_year);
        if (start_year == 0 && end_year == 0) {
            break;
        } else {
            if ( i == 1) {
                printf("\n");
            }
            leap_year(start_year, end_year);
            i = 1;
        }
    }
    return 0;
}
 
void leap_year(int start_year, int end_year)
{
    int n = 0;
    for (int year = start_year; year <= end_year; year++) {
        if (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)) {
            printf("%d\n", year);
            n++;
        }
    }
    if (n == 0) {
    printf("NA\n");
    }
}

Measured memory_bytes: 1040
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    string ABCD;
    cin >> ABCD;

    vector<int> v(4);
    rep(i, ABCD.size()) v[i] = ABCD[i] - '0';

    rep(pat, 1 << 3) {
        int x = v[0];
        rep(i, 3) {
            if ((pat >> i) & 1) {
                x += v[i + 1];
            }
            else {
                x -= v[i + 1];
            }
        }
        if (x == 7) {
            printf("%d%c%d%c%d%c%d=7\n",
                v[0],
                (pat >> 0) & 1 ? '+' : '-',
                v[1],
                (pat >> 1) & 1 ? '+' : '-',
                v[2],
                (pat >> 2) & 1 ? '+' : '-',
                v[3]
            );
            return 0;

        }
    }

    return 0;
}

Measured memory_bytes: 3716
#include <iostream>
#include <stack>
#include <map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <string.h>

using namespace std;

int N, M;
long x[2000];
long y[2000];
long z[2000];
long xyz[2000];

int main(int argc, char** argv) {
    cin >> N >> M;
    for(int i=1;i<=N;i++) cin >> x[i] >> y[i] >> z[i];

    long ans = -1e9;
    for (int px=0; px<=1; px++) for (int py=0; py<=1; py++) for (int pz=0; pz<=1; pz++) {
        vector<pair<long, int>> v(N);
        for(int i=1;i<=N;i++) {
            xyz[i] = 0;
            if (px)
                xyz[i] += x[i];
            else
                xyz[i] -= x[i];
            if (py)
                xyz[i] += y[i];
            else
                xyz[i] -= y[i];
            if (pz)
                xyz[i] += z[i];
            else
                xyz[i] -= z[i];
            pair<long, int> p(xyz[i], i);
            v[i - 1] = p;
        }
        sort(v.begin(), v.end());
        long ans_ = 0;
        long x_, y_, z_;
        x_ = 0;
        y_ = 0;
        z_ = 0;
        for (int i=N; N-M<i; i--) x_ += x[v[i-1].second];
        for (int i=N; N-M<i; i--) y_ += y[v[i-1].second];
        for (int i=N; N-M<i; i--) z_ += z[v[i-1].second];
        if (px && x_ < 0) break;
        if (py && y_ < 0) break;
        if (pz && z_ < 0) break;
        for (int i=N; N-M<i; i--) ans_ += v[i-1].first;
        ans = max(ans_, ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main
{
	public static void main(String []args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String []s=br.readLine().split(" ");
		int n = Integer.parseInt(s[0]);
		int m = Integer.parseInt(s[1]);
		
		if(n==m)
			out.println("Yes");
		else
			out.println("No");
	}
}




Measured memory_bytes: 23124
#include <iostream>
#include <algorithm>
#include<string>
#include<cmath>
#include<stack>
#include <vector>
#include<queue>
#include <random>
#include <cstdint>
#include <bitset>
#include <iomanip>
#include<utility>
using namespace std;
using ll = long long;
const ll modulo = 1000000007;

int main(){
	int n, m;
	ll x[100000], y[100000];
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> y[i];
	}
	ll sumx = 0, sumy = 0;
	for (int i = 0; i < n; i++) {
		sumx += ((-n + 2 * i + 1)*x[i]%modulo);
		sumx %= modulo;
	}
	for (int i = 0; i < m; i++) {
		sumy += ((-m + 2 * i + 1)*y[i]%modulo);
		sumy %= modulo;
	}
	cout << (sumx * sumy)%modulo << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;

bool check(vector<int> v, int n) {
    int a[n] = {0};
    for (int i = 0; i < n; i++) {
        a[v[i]]++;
    }
    if (n % 2 == 0) {
        for (int i = 1; i < n; i += 2) {
            if (a[i] != 2) {
                return false;
            }
        }
    } else {
        if (a[0] != 1) return false;
        for (int i = 2; i < n; i += 2) {
            if (a[i] != 2) {
                return false;
            }
        }
    }
    return true;
}
int main() {
    long long unsigned int m = 1e9 + 7, ans = 1;
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    if (check(v, n) == false) {
        cout << 0 << endl;
    } else {
        for (int i = 1; i < n; i += 2) {
            ans = (ans *= 2) %= m;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1408
"use strict";

const main = arg => {
    const input = arg.trim().split("\n");

    const x = parseInt(input[0]);
    for(let a = -120; a<= 120; a++){
        for(let b = -120; b<= 120; b++){
            let tmp = a*a*a*a*a - b*b*b*b*b
            if(x === tmp){
                console.log(`${a} ${b}`)
                return
            }
        } 
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));  

Measured memory_bytes: 32592
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int a,b,c;
    a=b=c=0;
    for(int i=0;i<s.size();i++)
        if(s[i]=='a') a++;
    else if(s[i]=='b') b++;
    else c++;
    int ans=0;
    ans=max(ans,abs(a-b));
    ans=max(ans,abs(a-c));
    ans=max(ans,abs(b-c));
    if(ans>=2) printf("NO\n");
    else printf("YES\n");
}


Measured memory_bytes: 512
# https://atcoder.jp/contests/abc144/submissions/8168248
# is_okでscoreを割るアイディア

def binary_search(*, ok, ng, func):
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if func(mid):
            ok = mid
        else:
            ng = mid
    return ok


def main():
    N, K = map(int, input().split())
    *A, = sorted(map(int, input().split()))
    *F, = sorted(map(int, input().split()), reverse=True)

    def is_ok(score):
        rest = K
        for a, f in zip(A, F):
            max_a = score // f
            rest -= max(0, a - max_a)
            if rest < 0: return False
        return True

    ans = binary_search(ok=10 ** 12, ng=-1, func=is_ok)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 122132
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i,a) for(int i = 0;i < (a); i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)
#define repd(i,a,b) for(int i = (a); i >= (b); i--)
#define repit(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())
#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

int main() {
    int n;
    while(cin >> n, n){
        bool ontv[32][25] = {false};
        map<string,int> id;
        vector<string> v;
        rep(i,n){
            string name;
            int m;
            cin >> name >> m;
            id[name] = i;
            v.pb(name);
            rep(j,m){
                int d;
                cin >> d;
                ontv[d][i] = true;
            }
        }

        int point[25] = {0};
        rep(i,30){
            int cnt = 0;
            rep(j,n){
                if(ontv[i][j]) cnt++;
            }
            rep(j,n){
                if(ontv[i][j]) point[j] += (n-cnt+1); 
            }
        }
        string s;
        int ans = INF;
        rep(i,n){
            if(ans > point[i]){
                ans = point[i];
                s = v[i];
            }else if(ans == point[i] && v[i] < s){
                ans = point[i];
                s = v[i];
            }
        }
        cout << ans << ' ' << s << endl;
    }
    return 0;
}

Measured memory_bytes: 1224
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static         Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static long mod =1000000007;

	public static void main(String[] args) {
		String S=sc.next();
		String v[]= {"Sunny","Cloudy","Rainy"};
		
		for(int i=0;i<3;i++) {
			if(S.equals(v[i])) {
				p(v[(i+1)%3]);
			}
		}
		
	}
	//N==S
	//E==W
//83 S 
	//69E
	//78N
	//87W
	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 21204
#include <iostream>
#include <vector>

void printVector(std::vector<int> &a, int q) {
  int n = a.size();
  for (int i = 0; i < n; ++i) {
    if (i == q)
      std::cout << "[";
    std::cout << a.at(i);
    if (i == q)
      std::cout << "]";
    if (i < n - 1)
      std::cout << " ";
    else
      std::cout << std::endl;
  }
}

int partition(std::vector<int> &a, int p, int r) {
  int x = a.at(r);
  int i = p - 1;
  for (int j = p; j < r; ++j) {
    if (a.at(j) <= x) {
      ++i;
      std::swap(a.at(i), a.at(j));
    }
  }
  std::swap(a.at(i + 1), a.at(r));
  return i + 1;
}

int main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n, 0);
  for (int i = 0; i < n; ++i) {
    std::cin >> a.at(i);
  }
  
  printVector(a, partition(a, 0, n-1));
}



Measured memory_bytes: 3108
from collections import Counter

N, P = map(int, input().split())
S = list(map(int, input()))

def solve_2(S):
    ind = (i for i, x in enumerate(S, 1) if x % 2 == 0)
    return sum(ind)

def solve_5(S):
    ind = (i for i, x in enumerate(S, 1) if x % 5 == 0)
    return sum(ind)

def solve(S,P):
    if P == 2:
        return solve_2(S)
    if P == 5:
        return solve_5(S)
    S = S[::-1]
    T = [0] * len(S)
    T[0] = S[0] % P
    power = 1
    for i in range(1, len(S)):
        power *= 10
        power %= P
        T[i] = T[i-1] + power * S[i]
        T[i] %= P
    counter = Counter(T)
    return sum(x * (x - 1) // 2 for x in counter.values()) + counter[0]


print(solve(S,P))


Measured memory_bytes: 14996
#include <cctype>
#include <iostream>
#include <string>
using namespace std;

int main(void) {
    int n, k;
    string s;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    cin >> s;
    s[k - 1] = tolower(s[k - 1]);
    cout << s << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define rep(i,n) for(long long  i = 0; i < n; i++)
#define rep2(i,a,n) for(long long  i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

using namespace std;

int main() 
{
    int n; cin >> n;
    vector<int> dp(n+10, INF);
    
    dp[0] = 0;
    for(int i = 1; i <= n; i++) {
        int power_6 = 1;
        while(power_6 <= n) {
            if(i - power_6 < 0) { break; } 
            dp[i] = min(dp[i-power_6]+1, dp[i]); 
            power_6 *= 6;
        }

        int power_9 = 1;
        while(power_9 <= n) {
            if(i - power_9 < 0) { break; } 
            dp[i] = min(dp[i-power_9]+1, dp[i]); 
            power_9 *= 9;
        }
    }
    //for(auto v : dp) { cout << v << endl; }
    cout << dp[n] << endl;
    return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    int n;cin>>n;
    ll a[n];
    rep(i,n){
        cin>>a[i];
    }
    ll ans=0;
    for (int i = 0; i < n-1; i++)
    {
        /* code */
        for (int j = i; j < n; j++)
        {
            /* code */
            ans=max(ans,abs(a[i]-a[j]));
        }
        
    }
    cout<<ans<<endl;
    

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

int main() {
	int N, C;
	cin >> N >> C;

	vector<vector<bool>> channel(C, vector<bool>(100000));
	for (int i = 0; i < N; i++) {
		int s, t, c;
		cin >> s >> t >> c;
		for (int j = s - 1; j < t; j++) channel.at(c - 1).at(j) = 1;
	}

	int ans = 0;
	for (int i = 0; i < 100000; i++) {
		int cnt = 0;

		for (int j = 0; j < C; j++) {
			if (channel.at(j).at(i)) cnt++;
		}

		ans = max(ans, cnt);
	}

	cout << ans << endl;
}

Measured memory_bytes: 3720
#include<bits/stdc++.h>
 
#define rep(i,n) for(int i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;

 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    ll n,m;
    cin >> n >> m;
    vector<int> h(n);
    set<int> ans;
    set<int> history;//道があるかどうか
    set<int> out;
    rep(i,n){
        cin >> h[i];
    }
    rep(i,m){
        int a,b;
        cin >> a >> b;

        history.insert(a); 
        history.insert(b);

        if(h[a-1] > h[b-1]){ 
           if(!out.count(a-1)) ans.insert(a-1);
            out.insert(b-1);
            if(ans.count(b-1)){
                ans.erase(b-1);
            }
        }else if(h[b-1] > h[a-1]){
            if(!out.count(b-1))ans.insert(b-1);
            out.insert(a-1);
            if(ans.count(a-1)){
                ans.erase(a-1);
            }
        }else if(h[a-1] == h[b-1]){ // 以下追加分
    out.insert(a-1);
    if(ans.count(a-1)){
        ans.erase(a-1);
    }
    out.insert(b-1);
    if(ans.count(b-1)){
        ans.erase(b-1);
    }
}
    }
    int number;
    number = n - history.size();//道がない展望台の個数
    cout << number + ans.size() << endl;

    cout << endl;
    return 0;
}


Measured memory_bytes: 11700
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		System.out.println(a * b + " " + (2 * a + 2 * b));
		sc.close();
	}
}


Measured memory_bytes: 26220
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define nthElement(x) find_by_order(x)
#define lessThan(x) order_of_key(x)
#define dd double
#define pb push_back
#define pf push_front
#define ll long long
#define ull unsigned long long
#define ld long double
#define mx 200
#define mod 1000000007
#define fr first
#define se second
#define End cout<<"\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define memo(Array,val) memset(Array, val, sizeof Array)
#define PI acos(-1)
#define per(i) cout<<fixed<<setprecision(i)
#define con continue
#define all(ele) (ele).begin(),(ele).end()
#define Ones(x) __builtin_popcount(x)
#define trailingZero(x) __builtin_ctz(x)
#define len(ele) (ele).size()

template<typename... T> void get(T&... args) { ((cin >> args), ...); }

template<typename... T> void Get(T&... args){ ((getline(cin,args)), ...); }

template<typename... T> void print(T&&... args) { ((cout << args << ""), ...); }

bool check(ll n, ll pos){ return (n&(1<<pos)); }
bool Set(ll n, ll pos) {  return (n | (1<<pos)); }
ld LOG(ld b, ld e){ return log(b)/log(e); }
ld rad(ld x) {  return ((ld)PI*x)/180.0; }

/// Code Starts From Here.............................................///

int tc=1;

void solve(int kk)
{
    ll n, mo;
    cin >> n;
    mo = n%1000;
    if(mo>0){
        mo = 1000-mo;
    }
    cout << mo << "\n";


}

int main()
{
   //freopen("text.txt", "r", stdin);
   //freopen("text2.txt", "w", stdout);
   fast;
   int kk=0;
   //cin >> tc;
   //scanf("%d", &tc);
   while(++kk<=tc) solve(kk);

   return 0;
}


Measured memory_bytes: 3692
fun main() {
    val n = readInt()
    val a = readInts()
    val order = IntArray(n)
    a.forEachIndexed { index, ai -> order[ai - 1] = index + 1 }
    println(order.joinToString(" "))
}

// Input Reader
private fun readLn() = readLine()!!

private fun readStrings() = readLn().trim().split(" ")
private fun readInt() = readLn().toInt()
private fun readInts() = readStrings().map { it.toInt() }


Measured memory_bytes: 57048
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{ min, max };

macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

#[allow(dead_code)]
const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let m: usize = sc.cin();
    let mut xs: Vec<u64> = (0..n).map(|_| sc.cin()).collect();
    xs.sort();
    // xs.reverse();
    let mut opts = (0..m).map(|_| {
        let b: usize = sc.cin();
        let c: u64 = sc.cin();
        (c,b)
    }).collect::<Vec<_>>();
    opts.sort();
    opts.reverse();

    {
        let mut i = 0;
        for j in 0..m {
            if i >= n { break; }
            let (c, b) = opts[j];
            for _ in 0..b {
                if i >= n { break; }
                if xs[i] < c {
                    xs[i] = c;
                    i += 1;
                } else {
                    break;
                }
            }
        }
    }

    put!(xs.iter().sum::<u64>());
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 14588
#include <vector>
#include <iostream>
#include <deque>

using namespace std;
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

#define ff first
#define ss second

int main() {

	int n; cin >> n;
	deque<long long> dq;

	for (int i = 1; i <= n; i++) {
		int a; cin >> a;
		dq.push_front(a);

		while (dq.size() > 2) {
			long long curr = dq.front(); dq.pop_front();
			long long prev = dq.front(); dq.pop_front();
			long long spre = dq.front(); dq.pop_front();

			if (prev >= curr and prev >= spre) dq.push_front(curr + spre - prev);
			else {
				dq.push_front(spre);
				dq.push_front(prev);
				dq.push_front(curr);
				break;
			}
		}
	}

	long long ans = 0;
	int sgn = 1;
	while (!dq.empty()) {
		if (dq.front() > dq.back()) {
			ans += (sgn * dq.front());
			dq.pop_front();
		}
		else {
			ans += (sgn * dq.back());
			dq.pop_back();
		}
		sgn = -sgn;
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second
#define all(c) ((c).begin()), ((c).end())
#define sz(x) ((int)(x).size())
#define ld long double

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<", "<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	for(int i = 0;i < (int)v.size(); i++){
		if(i)os<<", ";
		os<<v[i];
	}
	os<<"}";
	return os;
}

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

int main(){
	ll A, B, V, W, T;
	cin >> A >> V >> B >> W >> T;
	if(V <= W){
		printf("NO\n");
		return 0;
	}
	cout << ((abs(A - B) <= (V - W) * T) ? "YES\n" : "NO\n");
}

Measured memory_bytes: 3592
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
//----------------------------------------------------------------

// int MOD = 998244353;
int MOD = 1000000007;


//----------------------------------------------------------------
signed main(){

	string s;
	cin >> s;
	for(int bit = 0;bit < (1<<3);bit++){
		ll ans = 0;
		ans += s[0]-'0';
		rep(i,3){
			if(bit&(1<<i))ans += s[1+i]-'0';
			else ans -= s[1+i]-'0';
		}
		if(ans == 7){
			cout << s[0];
			rep(i,3){
				if(bit&(1<<i))cout << '+';
				else cout << '-';
				cout << s[1+i];
			}
			cout << "=7";
			cout << endl;
			return 0;
		}
	}

	

	return 0;
}

//----------------------------------------------------------------

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2017-final.contest.atcoder.jp/tasks/ddcc2017_final_b
// rm -r -f test;oj dl https://abc079.contest.atcoder.jp/tasks/abc079_c

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    ll n; vector<ll> a(4, 0);
    rep(i, 4) cin >> a[i];
    cin >> n;

    vector<ll> l1(3), l2(4);
    l1[0] = 4 * a[0];
    l1[1] = 2 * a[1];
    l1[2] = a[2];
    l2[0] = 8 * a[0];
    l2[1] = 4 * a[1];
    l2[2] = 2 * a[2];
    l2[3] = a[3];
    sort(all(l1)); sort(all(l2));
    n *= 4;

    ll ans = 0;
    ans += l2[0] * (n / 8);
    if (n % 8 != 0) ans += l1[0];
    cout << ans << endl;
}


Measured memory_bytes: 256