akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int di[10] = {1, 1, 0, 2, 0, 0, 1, 0, 1, 0};
char C[3] = {'h', 'p', 'b'};

int main(){
	int N; cin >> N;
	cout << C[di[N%10]] << "on" << endl;
  return 0;
}


Measured memory_bytes: 3640
def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)

def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max,mod=DIV):
    fac,finv,inv = [0]*max, [0]*max, [0]*max
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod -inv[mod%i] * (mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
    class CONV:
        def __init__(self):
            pass
        def ncr(self,n,k):
            if(n<k):
                return 0
            if(n<0 or k<0 ):
                return 0
            return fac[n]*(finv[k]*finv[n-k]%mod)%mod
    return CONV()



def main():
    N = iRaw()
    numTB = [[0]*10 for _ in range(0,10)]

    for n in range(1,N+1):
        strN = str(n)
        numTB[int(strN[0])][int(strN[-1])]+=1
    ans = 0
    for a in range(1,10):
        for b in range(1,10):
            ans+= numTB[a][b] * numTB[b][a]
    return ans


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 40684
#include<iostream>

using namespace std;

int main(){
    int n;
    int home[110];
    cin >> n;
    for(int i=0;i < n;i++){
        cin >> home[i];
    }
    int ans = 10000000;
    for(int p=1;p <= 100;p++){
        int vit = 0;
        for(int i=0;i < n;i++){
            vit += (p-home[i])*(p-home[i]);
        }
        ans = min(ans,vit);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
import java.util.*;

class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0;i<n-1;i++){
            int tmp = sc.nextInt();
            a[tmp-1]++;
        }

        for(int i=0;i<n;i++){
            System.out.println(a[i]);
        }
    }
}


Measured memory_bytes: 55920
#include <iostream>
#include <utility>
#include <stdint.h>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  uint16_t X, Y, Z, K;
  cin >> X >> Y >> Z >> K;

  vector<uint64_t> A(X),B(Y),C(Z);
  for (int ix=0; ix<X; ++ix)
    cin >> A[ix];
  for (int iy=0; iy<Y; ++iy)
    cin >> B[iy];
  for (int iz=0; iz<Z; ++iz)
    cin >> C[iz];

  sort(A.begin(),A.end(), greater<uint64_t>());
  sort(B.begin(),B.end(), greater<uint64_t>());
  sort(C.begin(),C.end(), greater<uint64_t>());

  vector<uint64_t> D;
  uint64_t minD = 0;
  for (auto a : A) {
    for (auto b : B) {
      for (auto c : C) {
	uint64_t sum = a+b+c;
	if (sum>minD)
	  D.push_back(sum);
	if (D.size() > K+1000) {
	  sort(D.begin(),D.end(), greater<uint64_t>());
	  D.erase(D.begin()+K, D.end());
	  minD = D[K];
	}
      }
    }
  }

  sort(D.begin(),D.end(), greater<uint64_t>());

  for (int ii=0; ii<K; ++ii)
    cout << D[ii] << endl;

  return 0;
}


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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;
typedef queue<int> qi;

int main(){
    S s;
    cin >> s;
    vc c(s.size());
    rp(i,s.size()){
        c.at(i)=s.at(i);
    }
    sort(c);
    unique(c);
    vi ans1(c.size());
    rp(i,c.size()){
        ans1.at(i)=0;
        rp(j,s.size()){
            int cnt=0;
            while(j<s.size()&&s.at(j)!=c.at(i)){
                j++;
                cnt++;
            }
            ans1.at(i)=max(ans1.at(i),cnt);
        }
    }
    sort(ans1);
    cout << (ans1.at(0)>s.size()/2?s.size()/2:ans1.at(0)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
#include<functional>
#include<cmath>
#include<vector>
#define pii pair<int,int>
#define ll long long
#define lowbit(x) x&-x
using namespace std;
using std::min;
using std::max;
using std::swap;
using std::sort;
using std::reverse;
using std::random_shuffle;
using std::lower_bound;
using std::upper_bound;
using std::unique;
using std::vector;
const int N=100000+7;
const ll mod=1000000000+7;
int n,m,rb[N],ho[N];
ll c[N];
pair<int,int> p[N];
int tmp[N],t1,t2;
void read(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		scanf("%d",&rb[i]);
	for(int i=1;i<=m;i++)
		scanf("%d",&ho[i]);
}
bool rule(pii a,pii b){
	if(a.first!=b.first)return a.first<b.first;
	else return a.second>b.second;
}
ll add(ll a,ll b){
	a+=b;
	return a>=mod?a-mod:a;
}
void add(int x,ll v){
	for(int i=x;i<=t2;i+=i&-i)
		c[i]=add(c[i],v);
}
ll query(int x){
	ll sum=0;
	for(int i=x;i;i-=i&-i)
		sum=add(sum,c[i]);
	return sum;
}
void init(){
	int lst,nxt=ho[1],top=1;
	for(int i=1;i<=n;i++){
		if(rb[i]>ho[1]&&rb[i]<ho[m]){
			while(rb[i]>nxt){
				lst=nxt;
				nxt=ho[++top];
			}
			if(rb[i]==lst||rb[i]==nxt)continue;
			int ld=rb[i]-lst,rd=nxt-rb[i];
			p[++t1]=make_pair(ld,rd);
			tmp[++t2]=rd;
		}
	}
	
	/*for(int i=1;i<=t1;i++)
		printf("%d %d\n",p[i].first,p[i].second);
	printf("\n");*/
		
	sort(tmp+1,tmp+1+t2);
	t2=unique(tmp+1,tmp+1+t2)-(tmp+1);
	for(int i=1;i<=t1;i++)
		p[i].second=lower_bound(tmp+1,tmp+1+t2,p[i].second)-tmp;
	sort(p+1,p+1+t1,rule);
	t1=unique(p+1,p+1+t1)-(p+1);
	
	/*for(int i=1;i<=t1;i++)
		printf("%d %d\n",p[i].first,p[i].second);*/
		
}
void work(){
	ll ans=1;
	for(int i=1;i<=t1;i++){
		ll s=query(p[i].second-1)+1;
		ans=(ans+s)%mod;
		add(p[i].second,s);
	}
	printf("%lld\n",ans);
}
int main(){
	//freopen("1.txt","r",stdin);
	read();
	init();
	work();
	return 0;
}
/*
4 1
1 2 4 5
3

*/
/*
4 5
2 5 7 11
1 3 6 9 13

*/
/*
3 4
2 5 10
1 3 7 13

*/

Measured memory_bytes: 2560
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			long n = in.nextLong(), x = in.nextLong();
			long ans = n + f(n - x, x);
			out.println(ans);
		}

		long f(long a, long b) {
			if (a > b) {
				long t = b;
				b = a;
				a = t;
			}
			if (b % a == 0) return 2*(b/a)*a - a;
			return 2*(b/a)*a + f(a, b % a);
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

	static long max(long... n) {
		long ret = n[0];
		for (int i = 0; i < n.length; i++) {
			ret = Math.max(ret, n[i]);
		}
		return ret;
	}

	static int max(int... n) {
		int ret = n[0];
		for (int i = 0; i < n.length; i++) {
			ret = Math.max(ret, n[i]);
		}
		return ret;
	}

	static long min(long... n) {
		long ret = n[0];
		for (int i = 0; i < n.length; i++) {
			ret = Math.min(ret, n[i]);
		}
		return ret;
	}

	static int min(int... n) {
		int ret = n[0];
		for (int i = 0; i < n.length; i++) {
			ret = Math.min(ret, n[i]);
		}
		return ret;
	}
}


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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout << i << endl
using namespace std;
int main(){
  int n, ans;
  int k, p;
  cin >> n;

  REP(i, n){
      cin >> k >> p;
      ans = k % p;

      if(ans == 0) ans = p;
      cout << ans << endl;
    }
}


Measured memory_bytes: 3064
n = int(input())
p = [int(input()) for _ in range(n)]
s = [0] * n
for i in range(n):
    s[p[i] - 1] = i
ans = 0
m = s[0]
c = 0
for i in s:
    if i >= m:
        c += 1
    else:
        ans = max(ans, c)
        c = 1
    m = i
ans = max(ans, c)
print(n - ans)

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  int check = 1;
  int count = 0;
  
  for (int i = 0; i < N; i++) {
    if (vec.at(i) == check) {
      check += 1;
    }
    else {
      count++;
    }
  }
  
  if (count != N) {
    cout << count << endl;
  }
  
  else {
    cout << -1 << endl;
  }
}


Measured memory_bytes: 1024
S=input()
n=0
if len(S)%2==0:
    for i in range (0,int((len(S))/2)):
        if S[i]!=S[-i-1]:
            n+=1
else:
    for i in range (0,int(((len(S))+1)/2)):
        if S[i]!=S[-i-1]:
            n+=1
print(n)

Measured memory_bytes: 3060
N = int( input())
H = [ list( map( int, input().split())) for _ in range(N)]
dp = [ [0]*3 for _ in range(N)]
dp[0][0], dp[0][1], dp[0][2] = H[0]
for i in range(1,N):
    a, b, c = H[i]
    dp[i][0] = max( dp[i-1][1]+a, dp[i-1][2]+a)
    dp[i][1] = max( dp[i-1][0]+b, dp[i-1][2]+b)
    dp[i][2] = max( dp[i-1][0]+c, dp[i-1][1]+c)
print( max( dp[-1]))


Measured memory_bytes: 47344
import java.io.*;
import java.util.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		
		int[] list = new int[10];
		
		for (int i = 0; i < 10; i++)
			list[i] = Integer.parseInt(br.readLine());
		Arrays.sort(list);
		System.out.println(list[list.length - 1]);
		System.out.println(list[list.length - 2]);
		System.out.println(list[list.length - 3]);
	}
	
}

Measured memory_bytes: 9368
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

void SieveEratosthenes(long long n, vector<bool>& isPrime) {
    if (n+1 > isPrime.size()) isPrime.resize(n+1, true);
    isPrime[0] = isPrime[1] = false;

    for(long long i = 2; i*i <= n; ++i)
        if(isPrime[i])
            for(long long j = 2; i*j <= n; ++j)
                isPrime[i*j] = false;
}

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

    Int Q; cin >> Q;
    const Int N = 100001;
    vector<bool> isPrime(N, true);
    vector<Int> subsum(N, 0);

    SieveEratosthenes(N, isPrime);

    rep(i, 1, N) {
        subsum[i] = subsum[i-1];
        if (i%2 == 1 and isPrime[i] and isPrime[(i+1)/2])
            subsum[i]++;
    }

    rep(i, 0, Q) {
        Int r, l; cin >> l >> r;
        cout << subsum[r] - subsum[l-1] << endl;
    }
}


Measured memory_bytes: 1408
#include <iostream>

using namespace std;
typedef long long ll;

int main(){
    ll x, a, b;
    cin >> x >> a >> b;
    if(b <= a){
        cout << "delicious" << endl;
    }else if(b - a <= x){
        cout << "safe" << endl;
    }else{
        cout << "dangerous" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;

int main()
{
	int a, b, c, t;
	cin >> a >> b >> c;
	
	if (a > b) {
		t = a;
		a = b;
		b = t;
	}
	if (b > c) {
		t = b;
		b = c;
		c = t;
	}
	if (a > b) {
		t = a;
		a = b;
		b = t;
	}
	cout << a << " " << b << " " << c << endl;
	
	return 0;	
}

Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	long long n, i, j, k, a, b, s, id, pp;
	cin >> n;
	vector<vector<int>> adj(n + 1);
	for (i = 0; i < n - 1; i++) {
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	vector<long long> c(n);
	vector<long long> ans(n + 1);
	for (i = 0; i < n; i++) cin >> c[i];

	sort(c.rbegin(), c.rend());
	queue<int> q;
	q.push(1);
	vector<bool> used(n + 1, false);
	used[1] = true;
	pp = 0;

	while (!q.empty()) {
		id = q.front();
		q.pop();
		ans[id] = c[pp++];

		for (auto p : adj[id]) {
			if (!used[p]) {
				used[p] = true;
				q.push(p);
			}
		}
	}

	s = 0;
	for (i = 1; i < n; i++) s += c[i];

	cout << s << "\n";
	for (i = 1; i <= n; i++) cout << ans[i] << " ";
	cout << "\n";

	return 0;
}



Measured memory_bytes: 1272
local A, B, C, K = io.read("*n", "*n", "*n", "*n")

local K_rem = K
local function add(card, card_num)
	if card < K_rem then
		K_rem = K_rem - card
		return card * card_num
	else
		local val = K_rem * card_num
		K_rem = 0
		return val
	end
end

local result = add(A, 1)
result = result + add(B, 0)
result = result + add(C, -1)

print(result)

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define All(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
template<class T> T gcd(T a,T b) {return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b) {return a/gcd(a,b)*b; }
template<class T> bool isPrime(T num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (T i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

using namespace std;

int a,b,c;
int n,m,cnt;
ll ans;
string s,t;

main()
{
        cin>>n>>m;
        vpii p(n+10);
        p[0].second=1;
        each(&it,p)it.first=true;

        vi v(m);
        each(&it,v)
        {
                cin>>it;
                p[it].first=false;
        }

        rep(i,n)
        {
                if(!p[i].first)continue;

                p[i+1].second=(p[i+1].second+p[i].second%mod)%mod;
                p[i+2].second=(p[i+2].second+p[i].second%mod)%mod;
        }

        //each(it,p)printf("%d %d %d\n",cnt++,it.first,it.second);

        cout<<p[n].second<<endl;
}

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

int N, M;
vector<vector<int> > G;

int dp[100100];

int rec(int v){
	if(dp[v] != -1) return dp[v];

	int res = 0;
	for(auto nextv : G[v]){
		res = max(res, rec(nextv)+1);
	}
	return dp[v] = res;
}

int main() {
	cin >> N >> M;
	G.assign(N, vector<int>());
	for(int i=0; i<M; i++){
		int x, y;
		cin >> x >> y;
        x--;
        y--;
		G[x].push_back(y);
	}
	for(int i=0; i<N; i++){
		dp[i] = -1;
	}
	int ans=0;
	for(int i=0; i<N; i++){
		ans = max(ans, rec(i));
	}

	cout << ans << endl;

}


Measured memory_bytes: 8192
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.A
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var (N, X, T) = Read3Longs();
            if (N % X == 0)
            {
                return N / X * T;
            }
            return N / X * T + T;
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 28144
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
const int mx = 100005;
int n;
long long a[mx], s, hf, ans;

int main(){
	scanf("%d", &n);
	rep(i,n){
		scanf("%lld", a+i);
		s += a[i];
		if(i%2) hf += a[i]*2;
	}
	ans = s - hf;
	rep(i,n){
		printf("%lld%s", ans, i == n-1 ? "\n" : " ");
		ans = a[i]*2 - ans;
	}
}

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


int main(){
    int64_t K,amari,cnt;
    cin >> K;
    amari = 0;
    cnt = 0;
    while((amari != 0 || cnt == 0) && cnt <= 1000001){
        amari = (amari*10+7)%K;
        cnt++;
    }
    if(cnt == 1000002){
        cout << -1 << endl;
    }else{
        cout << cnt << endl;
    }
}

Measured memory_bytes: 3624
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		int min = 1000000, max = -1000000;
		long sum= 0;
		for (int i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		}
		
		for (int k = 0; k < n; k++) {
			sum += a[k];
			if(min > a[k]) {
				min = a[k];
			}
			if(max < a[k]) {
				max = a[k];
			}
		}
		System.out.println(min + " " + max +" " + sum);
	}
}


Measured memory_bytes: 41404
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string b = Console.ReadLine();
            int A = int.Parse(b);
            string an;
            if (A < 1200) { an = "ABC"; }
            else if (A < 2800) { an = "ARC"; }
            else { an = "AGC"; }
            Console.Write(an);
        }
    }
}

Measured memory_bytes: 11092
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        final int n = sc.nextInt();
        final int k = sc.nextInt();

        final int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
        }

        final double[] evs = new double[1001];
        for (int i = 1; i <= 1000; i++) {
            evs[i] = getExpectedValue(i);
        }

        double ans = Double.MIN_VALUE;
        final double[] sum = new double[n];
        sum[0] = evs[p[0]];
        for (int i = 1; i < n; i++) {
            sum[i] = evs[p[i]] + sum[i-1];
            if (i >= k) {
                ans = Math.max(ans, sum[i] - sum[i - k]);
            }
        }

        if (n == k) {
            ans = Math.max(ans, sum[n-1]);
        }

        System.out.println(ans);
    }

    private static double getExpectedValue(final int max) {
        double result = 0;
        for (double j = 1; j <= max; j++) {
            result += j;
        }
        return result / max;
    }
}


Measured memory_bytes: 87884
#include <stdio.h>

int main(){
  int a, b, k, i;
  scanf("%d %d %d", &a, &b, &k);
  if((b-a+1)/2 < k){
    for(i=a;i<=b;i++){
      printf("%d\n", i);
    }
  } else {
    for(i=a;i<=a+k-1;i++){
      printf("%d\n", i);
    }
    for(i=b-k+1;i<=b;i++){
      printf("%d\n", i);
    }
  }
  return 0;
}

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

#define VARNAME(x) #x
#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v)
{
    for (auto& e : v) {
        is >> e;
    }
    return is;
}

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


constexpr ll MOD = (ll)1e9 + 7LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 10;


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    int Q;
    cin >> N >> Q;
    for (int q = 0; q < Q; q++) {
        ll v, w;
        cin >> v >> w;
        if (N == 1) {
            cout << min(v, w) << endl;
        } else {
            v--, w--;
            while (v != w) {
                if (v < w) {
                    w = (w - 1) / N;
                } else {
                    v = (v - 1) / N;
                }
            }
            cout << v + 1 << endl;
        }
    }
    return 0;
}


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

using namespace std;

using ll = long long;

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> x(n), y(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i];
  }
  vector<ll> sx(x), sy(y);
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  ll ans = (x[n - 1] - x[0]) * (y[n - 1] - y[0]);
  for (int x_i = 0; x_i < n; ++x_i) {
    for (int x_j = x_i + 1; x_j < n; ++x_j) {
      for (int y_i = 0; y_i < n; ++y_i) {
        for (int y_j = y_i + 1; y_j < n; ++y_j) {
          int count = 0;
          for (int i = 0; i < n; ++i) {
            if (x[x_i] <= sx[i] && x[x_j] >= sx[i] && y[y_i] <= sy[i] &&
                y[y_j] >= sy[i]) {
              ++count;
            }
          }
          if (count >= k) {
            ll ret = (x[x_j] - x[x_i]) * (y[y_j] - y[y_i]);
            if (ret)
              ans = min(ans, ret);
          }
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        long[] a = new long[n];
        long ans = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
        }
        Arrays.sort(a);
        long[][] b = new long[m][2];
        for (int i = 0; i < m; i++) {
            b[i][0] = sc.nextLong();
            b[i][1] = sc.nextLong();
        }
        Arrays.sort(b, (x, y) -> Long.compare(y[1], x[1]));
        boolean end = false;
        int idx = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < b[i][0]; j++) {
                if(idx <= n-1 && a[idx] < b[i][1]){
                    a[idx] = b[i][1];
                    idx++;
                }else{
                    end = true;
                    break;
                }
            }
            if(end) break;
        }
        for (int i = 0; i < n; i++) ans += a[i];
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 98288
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;


int main()
{
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; ++i)
  {
    cin >> h[i];
  }

  if (n == 1){
    cout << "Yes" << endl;
    return 0;
  }

  for (int i = n - 2; i >= 0; i--)
  {
    if (h[i] <= h[i + 1])
    {
    }
    else if (h[i] - h[i + 1] == 1)
    {
      h[i] -= 1;
    }
    else
    {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 640
def solve(prev, r, dic):
    d = 0
    t = r
    stack = []
    stack += [[prev, r, d]]
    while stack:
        prev, r, d1 = stack.pop(-1)
        if r in dic:
            for vtx, cost in dic[r]:
                if vtx == prev:
                    continue
                stack += [[r, vtx, d1 + cost]]
                if d < d1 + cost:
                    d = d1 + cost
                    t = vtx
    return d, t

line = input()
n = int(line)
edge = {}
for _ in range(0, n - 1):
    line = input()
    s, t, d = list(map(int, line.split()))
    if s not in edge:
        edge[s] = [[t, d]]
    else:
        edge[s] += [[t, d]]
    if t not in edge:
        edge[t] = [[s, d]]
    else:
        edge[t] += [[s, d]]
r1, t1 = solve(-1, 0, edge)
r2, t2 = solve(-1, t1, edge)
print(r2)


Measured memory_bytes: 45496
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = replicateM 5 readInt >>= print . minimum . map ( solve 0 ) . permutations

solve t [a] = t + a
solve t (a:as) = solve ( t + a' ) as
	where
		a' = ( a + 9 ) `div` 10 * 10

Measured memory_bytes: 508
n=int(input())
s=input()
lw=0
re=s.count('E')
l=[]
for i in range(n):
  if s[i]=='W':
    x=lw+re
    lw+=1
  else:
    x=lw+(re-1)
    re-=1
  l.append(x)
print(min(l))

Measured memory_bytes: 15520
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <numeric>
#include <math.h>

#define user spaesk
#define lli long long int
#define ld long double
#define ff first
#define ss second
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

typedef vector<vector<lli> > matrix ;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;
const int NN = 5e3 + 6;

void solve()
{

    lli a, b;
    cin>>a>>b;
    if(a <= 0 and b >= 0) {
        cout<<"Zero";
        return ;
    }
    else if(a > 0 and b > 0) {
        cout<<"Positive";
    }
    else {
        lli x = b - a + 1;
        if(x & 1) {
            cout<<"Negative";
        }
        else {
            cout<<"Positive";
        }
    }
    cout<<"\n";
    return ;
}

/*
*/

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

    int t = 1;
//    cin>>t;
    while(t --)
    {
        solve();
    }
    return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i, m, n) for(int i = (int)m; i < (int)n; i++)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;


/*FUNCs=================================================*/



/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    ll n, m, answer; cin >> n >> m;
    priority_queue<ll> a;
    rep(i,n){
        ll p; cin >> p;
        a.push(p);
    }

    while(m > 0){
        ll p = a.top();  a.pop();
        a.push(p/2);
        m--;
    }

    while(a.size() > 0){
        answer += a.top();
        a.pop();
    }
    cout << answer << '\n';
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{

	int N;
	cin >> N;
	vec(A);
	fx(N) {
		vecp(A);
	}
	map<int, int> K;
	if (A[0]!=0) {
		ce(0)
		return 0;
	}
	K[0] = 1;
	int zero = 2;
	fx(N-1) {
		if (A[x+1]==0) {
			K[0]++;
			zero--;
			if (zero<0) {
				ce(0);
				return 0;
			}
		}
		else {
			K[A[x + 1] - 1]--;
			if (K[A[x + 1] - 1]<0) {
				ce(0);
				return 0;
			}
			K[A[x + 1]]++;
		}
	}

	ll ans = 1;
	map<int, ll> L;
	L[0] = 1;
	zero = 1;
	fx(N-1) {
		if (A[x+1]==0) {
			zero++;
		}
		else {
			ans *= L[A[x + 1] - 1];
			ans %= MOD;
			L[A[x + 1] - 1]--;
		}
		L[A[x+1]]++;
	}

	if (zero==1) {
		ce((ans * 3) % MOD)
	}
	else if (zero==2) {
		ce((ans * 6) % MOD)
	}
	else {
		ce((ans * 6) % MOD)
	}
    return 0;
}



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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

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

struct SegTree {
  int size;
  vector<ll> pos;
  SegTree(ll N) { size = 1; while(size<N) size<<=1; pos.resize(2*size,0); }
  ll operator[](const ll &x) const { return pos[x+size]; }

  void build() { per(i,size) operate(i); }
  void set(ll x, const ll v) { pos[x+size] = v; }
  void update(ll x, const ll v) { set(x,v); x+=size; while (x>>=1) operate(x); }
  ll query(ll a, ll b) {
    ll L = 0, R = 0;
    for (a+=size, b+=size; a<b; a>>=1, b>>=1) {
      if (a&1) { L = q(L,pos[a]); a++; }
      if (b&1) { b--; R = q(R,pos[b]); }
    }
    return q(L,R);
  }
  void operate(ll i) { pos[i] = pos[i*2] + pos[i*2+1]; }
  ll q(ll x, ll y) { return x + y; }
};

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

struct query { 
  ll l, r, t, i; 
  bool operator< (const query &x) const { return r<x.r||(r==x.r&&(t<x.t||(t==x.t&&l<x.l))); };
};

int main() {
  ll N, Q; cin >> N >> Q;
  ll c[N]; rep(i,N) { cin >> c[i]; c[i]--; }

  vector<query> q(Q);
  ll l[Q], r[Q]; rep(i,Q) { cin >> l[i] >> r[i]; l[i]--; r[i]--; }
  rep(i,Q) q[i] = {l[i], r[i], 2, i};
  vector<ll> pre(N,-1);
  rep(i,N) {
    if (pre[c[i]]!=-1) q.push_back({pre[c[i]], i, 1, -1});
    pre[c[i]] = i;
  }
  sort(all(q));


  // for (auto x: q) cout << x.l << "-" << x.r << " " << x.t << " " << x.i << endl;

  ll result[Q] = {};
  SegTree st(N);
  for (auto x: q) {
    if (x.t==1) st.update(x.l, st[x.l]+1);
    else result[x.i] = x.r-x.l+1 - st.query(x.l,x.r+1);
  }
  rep(i,Q) cout << result[i] << endl;
  return 0;
}

Measured memory_bytes: 62128
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;

int main(){
  int n; cin >> n;
  vector<vector<int>> count(10,vector<int>(10,0)); //count[i][j] = iで始まりjで終わる数字の数
  rep(i,n){
    int a = i+1;
    string s = to_string(a);
    int start = s.at(0) - '0';
    int end = s.at(s.size()-1) - '0';
    count.at(start).at(end)++;
  }
  int ans = 0;
  rep(i,10) rep(j,10) ans+= count[i][j] * count[j][i];
  cout << ans << endl;
}


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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define Sort(x) sort(x.begin(), x.end())
#define Sort_rev(x) sort(x.begin(), x.end(), greater<int>())
#define ALL(v) (v).begin(), (v).end()

// π M_PI
// deg = rad*180/M_PI

const ll MOD = 1e9 + 7;

ll Mod(ll a, ll mod) {
    return (a%mod + mod)%mod;
}

ll pow_mod(ll x, ll n, ll mod) {
    ll res = 1;
    while(n > 0) {
        if (n & 1) {
            res = res*x%mod;
        }
        x = x*x%mod;
        n >>= 1;
    }
    return res;
}

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}

ll modinv(ll a, ll mod) {
    ll x, y;
    extGCD(a, mod, x, y);
    return Mod(x, mod);
}

ll nCr_mod(ll n, ll r, ll mod) {
    if ( n == r || n == 1 ) {
        return 1;
    }
    r = min(r, n-r);
    if ( r == 1 ) {
        return n;
    } else {
        ll n_to_n_r = n;
        ll r_to_1 = r;
        rep2(i, r-1) {
            n_to_n_r *= n-i;
            n_to_n_r %= mod;
            r_to_1 *= r-i;
            r_to_1 %= mod;
        }
        // r_to_1 = pow_mod(r_to_1, mod-2, mod);
        r_to_1 = modinv(r_to_1, MOD);
        return n_to_n_r*r_to_1%mod;
    }
}

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    if ( n == 2 ) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = pow_mod(2, n, MOD)-1;
    ans = Mod(ans-nCr_mod(n, a, MOD), MOD);
    ans = Mod(ans-nCr_mod(n, b, MOD), MOD);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
const int N=2e5+10;
const ll INF_ll=4611686018427387903;
int n,q[N],head,tail;ll c,h[N],dp[N];
inline ll GetY(int x,int y){return dp[y]-dp[x]+h[y]*h[y]-h[x]*h[x];}
inline ll GetX(int x,int y){return h[y]-h[x];}
inline ll Calc(int j,int i){return dp[j]+(h[j]-h[i])*(h[j]-h[i])+c;}
int main(){
	scanf("%d%lld",&n,&c);
	for(register int i=1;i<=n;i++)scanf("%lld",&h[i]);
	for(register int i=2;i<=n;i++)dp[i]=INF_ll;q[head=tail=1]=1;
	for(register int i=2;i<=n;i++){
		while(head<tail&&GetY(q[head],q[head+1])<=2ll*h[i]*GetX(q[head],q[head+1]))head++;
		dp[i]=Calc(q[head],i);
		while(head<tail&&GetY(q[tail-1],q[tail])*GetX(q[tail],i)>=GetY(q[tail],i)*GetX(q[tail-1],q[tail]))tail--;
		q[++tail]=i;
	}
//		for(register int j=1;j<i;j++)
//			dp[i]=min(dp[i],dp[j]+(h[j]-h[i])*(h[j]-h[i])+c);
	printf("%lld\n",dp[n]);
	return 0;
}
/*
j1<j2&&j1 youyu j2
dp[j1]+h[j1]*h[j1]-2*h[j1]*h[i]<dp[j2]+h[j2]*h[j2]-2*h[j2]*h[i]
2*h[i]*(h[j2]-h[j1])<dp[j2]-dp[j1]+h[j2]*h[j2]-h[j1]*h[j1]
dp[j2]-dp[j1]+h[j2]*h[j2]-h[j1]*h[j1]
------------------------------------- > 2*h[i]
             h[j2]-h[j1]
*/

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

string s;
int x,a,b,i,kurang,kiri,kanan,idx;

int main(){
    cin>>a>>b;
    cin>>s;
    kurang=0;
    for(i=0;i<s.length();i++){
        if(s[i]=='-'){idx=i; kurang++;}
    }
    if(kurang!=1){printf("No\n");}
    else{
        for(i=0;i<s.length();i++){
            if(i<idx){kiri++;}
            else if(i>idx){kanan++;}
        }
        if(a==kiri && b==kanan){printf("Yes\n");}
        else{printf("No\n");}
    }
}



Measured memory_bytes: 256
#include <cstdio>
#include<algorithm>
using namespace std;
int main()
{
    int n,i,j,k,s;
    scanf("%d",&n);
    int a[2][n],b[n];
    for(i=0;i<2;i++)
        for(j=0;j<n;j++)
        scanf("%d",&a[i][j]);
    for(k=0;k<n;k++)
    {
        s=0;
        for(i=k;i>=0;i--)
            s+=a[0][i];
        for(j=k;j<n;j++)
            s+=a[1][j];
        b[k]=s;
    }
    sort(b,b+n);
    printf("%d\n",b[k-1]);
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main() {
	int A;
	int B;
	int C;
	cin >> A >> B >> C;
	int a;
	int b;
	int c;
	a = A - B;
	b = A - C;
	c = B - C;
	if (A == B&&B == C) {
		cout << "No" << endl;
	}
	else {
		if (a == 0 || b == 0 || c == 0) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 3104
n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = [list(map(int,input().split())) for i in range(m)]

for i in a:
    bc.append([1,i])
bc.sort(key=lambda x:x[1],reverse=True)
#print(bc)
ans = 0
for i in bc:
    d = min(i[0],n)
 #   print(d)
    ans += i[1] * d
    n -= d
print(ans)

Measured memory_bytes: 99644
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;

signed main(){
  int n;
  cin >> n;
  vint A(n);
  bool judge = false;
  rep(i,n) cin >> A[i];
  int ans = 0;
  rep(i,n){
    if(A[i] % 2 == 1 && judge){
      ans++;
      judge = false;
    }
    else if(A[i] % 2 == 1) judge = true;
    if(A[i] == 0) judge = false; 
    ans += A[i]/2;
    //cout << ans << endl;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);

#define N 4e7
#define nl "\n"
#define f first
#define s second
#define pi acos(-1.0)
#define MOD 1000000007
#define pb push_back
#define vector<int> VI;
#define vector<long long> VII;

typedef long long ll;
typedef double db;

using namespace std;

int main()
{
    io;
    //freopen("in.txt" , "r" , stdin);
    //freopen("out.txt" , "w" , stdout);

    ///Let the showdown begin

    string s;
    cin >> s;

    int cnt;

    if(s[0] =='R' && s[1] == 'R' && s[2] == 'R')
        cnt = 3;
    else if((s[0] =='R' && s[1] == 'R' && s[2] == 'S') || (s[0] =='S' && s[1] == 'R' && s[2] == 'R'))
        cnt = 2;
    else if((s[0] =='S' && s[1] == 'S' && s[2] == 'S'))
        cnt = 0;
    else
        cnt = 1;

    cout << cnt << nl;

    ///Happily DONE
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

#define rep(i, n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

template<class T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

template<class T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }


int main() {
    int n;
    cin>>n;
    string s;
    cin>>s;


    if(n%2){cout<<"No"<<endl;return 0;}
    bool f = true;

    for(int i=0;i<n/2;i++){
        if(s[i]!=s[i+n/2]){
            f=false;
            break;
        }
    }

    if(f){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
	int R;
    cin >> R;
    cout << setprecision(15) << R * 2 * M_PI << endl;
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
int inf=1000001000;
ll INF=1e18;
ll mod=1000000007;
ll MOD=INF;


int main() {
  int h,w,m;
  cin >> h >> w >> m;
  vector<pair<int,int>> a(h),b(w);
  rep(i,h) a[i]=mk(0,i);
  rep(i,w) b[i]=mk(0,i);
  set<pair<int,int>> s;
  rep(i,m){
      int f,g;
      cin >> f >> g;
      f--;
      g--;
      s.insert(mk(f,g));
      a[f].first++;
      b[g].first++;
  }
  sort(all(a));
  sort(all(b));
  reverse(all(a));
  reverse(all(b));
  int x=a[0].first;
  int y=b[0].first;
  bool t=true;
  rep(i,h){
      if (!t) break;
      if (a[i].first!=x) break;
      rep(j,w){
          if (b[j].first!=y) break;
          if (s.find(mk(a[i].second,b[j].second))==s.end()){
              t=false;
              break;
          }
      }
  }
  if (t) cout << x+y-1 << endl;
  else cout << x+y << endl;
}


Measured memory_bytes: 22008
s = input()
t = input()
cnt = 1
for _ in range(len(s)):
    a = s[len(s)-1]
    b = [s[i] for i in range(len(s)-1)]
    bb = "".join(b)
    s = a+bb
    if s == t:
        cnt *= 0

print("No") if cnt else print("Yes")

Measured memory_bytes: 3060
#include <stdio.h>

int dp[50];

int fibo(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fibo(n - 1) + fibo(n - 2);
}

int main(){
  int n,i;
  for(i = 0;i < 50;i++) dp[i] = -1;
  scanf("%d",&n);
  printf("%d\n",fibo(n));
  return 0;
}

Measured memory_bytes: 596
fun main(args: Array<String>) {
    abc148e()
}

fun abc148e() {
    val n = readLine()!!.toLong()

    if (n % 2 != 0L) return println(0)

    var answer = 0L
    var curr = n / 2
    while (curr > 0) {
        answer += curr / 5
        curr /= 5
    }

    println(answer)
}


Measured memory_bytes: 31708
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,ans=INT_MAX;
    cin>>n;
    int k;
    cin>>k;
    int arr[k];
    for(int i=0;i<k;i++)cin>>arr[i];
    for(int i=0;i<k;i++)
    {
        int l=arr[i];
        int r=arr[(i+k-1)%k];
        if(l>r)r+=n;
        ans=min(ans,r-l);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
  int h,w,ch,cw,n=0;
  string ans="";
  cin>>h>>w;
  bool c[w];
  rep(i,w)c[i]=false;
  rep(i,(h-1)*w){
    cw=i%w;
    ch=i/w;
  //  cout<<"b:"<<ch<<","<<cw<<endl;
    int t;
    cin>>t;
    if(c[cw])t++;
    if (t%2!=0) {ans+=to_string(ch+1)+" "+to_string(cw+1)+" "+to_string(ch+2)+" "+to_string(cw+1)+"\n";n++;}
    c[cw]=(t%2!=0);
  }
  bool f=false;
  rep(i,w-1){
    cw=i%w;

      int t;
      cin>>t;
      if(c[cw])t++;
      if(f)t++;
      if (t%2!=0) {ans+=to_string(h)+" "+to_string(cw+1)+" "+to_string(h)+" "+to_string(cw+2)+"\n";n++;}
      f=(t%2!=0);
  }
  cout<<n<<endl<<ans;
  return 0;
}


Measured memory_bytes: 4228