akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

int main()
{
	int N; std::cin >> N;
	std::vector<int> T(N);
	for(int n=0; n<N; n++)
	{
		std::cin >> T[n];
	}
	int M; std::cin >> M;
	std::vector<std::pair<int , int> > drink(M);
	for(int m=0; m<M; m++)
	{
		std::cin >> drink[m].first;
		std::cin >> drink[m].second;
		drink[m].first--;
	}

	int sum0 = 0;
	for(auto &x : T)
	{
		sum0 += x;
	}

	for(auto &d : drink)
	{
		int sum = sum0;
		sum = sum - T[d.first] + d.second;
		std::cout << sum << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
#  --*-coding:utf-8-*--

def main():
    N = int(input())
    B = list(map(int, input().split()))

    if N == 2:
        print(B[0]*2)
    else:
        print(sum(min(B[i], B[i+1]) for i in range(N-2)) + B[0]+B[-1])



if __name__ == '__main__':
    main()



Measured memory_bytes: 3060
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 15000 + 1;

int n;

void print_odd(int n)
{
    int x = 3;
    while(n --) {
        printf("%d ", x);
        x += 6;
    }
}
void print_even(int n)
{
    int x = 2;
    while(n --) {
        printf("%d ", x);
        x += 2;
    }
}

void solve()
{
    cin >> n;
    if (n == 3) {
        cout << 2 << ' ' << 5 << ' ' << 63 << endl;
        return;
    }

    int odd, even;
    if (n <= N) {
        even = (n - 1) / 3 * 3;
        odd = n - even;
        if (odd % 2) {
            odd ++;
            even --;
        }
    } else {
        even = 15000;
        odd = n - even;
        if (odd % 2) {
            odd ++;
            even --;
        }
    }
    print_even(even);
    print_odd(odd);
    printf("\n");
}

int main()
{
    solve();
    return 0;
}



Measured memory_bytes: 384
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}

fn gcd(mut a: u64, mut b: u64) -> u64 {
    if a == 0 {
        return b;
    } else if b == 0 {
        return a;
    }
    if a > b {
        a = a % b;
    } else {
        b = b % a;
    }
    gcd(a, b)
}
fn lcm(a: u64, b: u64) -> u64 {
    (a / gcd(a, b))*b
}

fn main() {
    let n: u64;
    let mut ans = 1;
    input!(n);
    for z in 0..n {
        let t: u64;
        input!(t);
        ans = lcm(ans, t);
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define int long long int
#define mod 1000000007
#define inf 1e18
#define fo(i,y,n,inc)	for(int i=y;i<n+y;i+=inc)
#define cin(t) int t;cin>>t
#define w(t) while(t--)
#define nl cout<<endl;
#define pb push_back
#define ft(i) (i&(-1*i))
#define arrIn(arr,size)		for(int i=0;i<size;i++){cin>>arr[i];}
#define arrOut(arr,size,seperater)	for(int i=0;i<size;i++){cout<<arr[i]<<seperater;}
using namespace std;

int max(int a, int b) {
	if (a > b)
		return a;
	return b;
}

int min(int a, int b) {
	if (a < b)
		return a;
	return b;
}

void fastIO() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

}


string s, k;
int dp[3005][3005];

int getLen(int i, int j) {

	if (i >= s.length() || j >= k.length() ) {
		return 0;
	}

	if (dp[i][j] != -1)	return dp[i][j];

	if (s[i] == k[j])		dp[i][j] = 1 + getLen(i + 1, j + 1);

	dp[i][j] = max(dp[i][j], max(getLen(i + 1, j), getLen(i, j + 1)));

	return dp[i][j];
}

string getLcs(int len) {
	string ans = "";
	int i, j;
	i = j = 0;

	while (i < s.length() && j < k.length()) {

		if (s[i] == k[j]) {
			ans += s[i];
			i++; j++;
			len--;
		}
		else {
			if (dp[i][j + 1] > dp[i + 1][j]) {
				j++;
			}
			else {
				i++;
			}
		}
	}

	return ans;

}

void solve() {
	int len = getLen(0, 0);
	cout << getLcs(len);
	nl;

	return;
}

int32_t main() {

	// fastIO();

	memset(dp, -1, sizeof(dp));

	cin >> s;
	cin >> k;

	solve();

	return 0;
}

// cout << "Case #" << i << ": " << answer << endl;

Measured memory_bytes: 71040
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()
#define pb push_back

#define error(x) cout << #x << " = " << x << endl

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

const int N = 2e5 + 20, LG = 20, MASK = (1 << LG);
int n, v, m, a[N];
int dpL[MASK], dpR[MASK];
int L[N][LG], R[N][LG];
vector <int> vec;

int sum[N];
bool flag;

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

	cin >> n >> v;
	
	for (int i = 0; i < n; i++) cin >> a[i];

	while (v) {
		vec.pb(v);
		v /= 2;
	}
	vec.pb(0);

	reverse(vec.begin(), vec.end());

	m = _sz(vec);

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (i && a[i] - a[i - 1] <= vec[j]) L[i][j] = L[i - 1][j];
			else L[i][j] = i;
		}
	}

	for (int i = n - 1; i >= 0; i--)
	{
		for (int j = 0; j < m; j++)
		{
			if (i < n - 1 && a[i + 1] - a[i] <= vec[j]) R[i][j] = R[i + 1][j];
			else R[i][j] = i;
		}
	}

	for (int mask = 0; mask < (1 << m); mask++)
		dpL[mask] = 0, dpR[mask] = n - 1;

	for (int mask = 0; mask < (1 << m); mask++)
	{
		for (int i = 0; i < m; i++)
		{
			if (mask >> i & 1) continue;

			int nmask = mask | (1 << i);

			if (dpL[mask] == n) dpL[nmask] = n;
			else 
			{
				int k = dpL[mask];
				k = R[k][i] + 1;

				dpL[nmask] = max(dpL[nmask], k);
			}

			if (dpR[mask] == -1) dpR[nmask] = -1;
			else
			{
				int k = dpR[mask];
				k = L[k][i] - 1;

				dpR[nmask] = min(dpR[nmask], k);
			}
		}
	}

	for (int mask = 0; mask < (1 << (m - 1)); mask++)
	{
		int m1 = mask, m2 = ((1 << (m - 1)) - 1) ^ m1;

		int l = dpL[m1], r = dpR[m2];

		if (r < l) flag = 1;
		else if (R[l][m - 1] >= r) sum[l]++, sum[r + 1]--;
	}

	for (int i = 1; i < n; i++) sum[i] += sum[i - 1];

	for (int i = 0; i < n; i++)
		cout << (flag || sum[i]? "Possible" : "Impossible") << '\n';
}


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


const int Interval = 512;
struct SqrtDecomp{
  typedef long long Type;
  const int n;
  vector<Type> arr,buc;
  const Type ide;

  Type func(Type a,Type b){
    return min(a,b);
  }

  Type update_func(Type a,Type x){
    return x;
  }

  SqrtDecomp(const vector<Type>& init,const Type& ide_) : n(init.size()),ide(ide_),arr(init),buc((int)init.size() / Interval + 10,ide_){
    for(int i = 0;i < n;i++){
      buc[i / Interval] = func(buc[i / Interval],arr[i]);
    }
  }

  Type get_inter(int l,int r){
    Type res = ide;
    while(l < r){
      if(l % Interval == 0 && l + Interval <= r){
        res = func(res , buc[l / Interval]);
        l += Interval;
      }
      else{
        res = func(res , arr[l]);
        l++;
      }
    }
    return res;
  }

  void update(int idx,const Type& x){
    arr[idx] = update_func(arr[idx] , x);
    buc[idx / Interval] = ide;
    int start = idx - idx % Interval;
    int end = min(start + Interval , (int)arr.size());
    for(int i = start;i < end;i++){
      buc[idx / Interval] = func(buc[idx / Interval],arr[i]);
    }
  }
};
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
int main(){
  int n,q;
  cin >> n >> q;
  SqrtDecomp srd(vector<i64>(n,(1LL << 31) - 1),(1LL << 31) - 1);
  vector<i64> ans;
  for(int i = 0;i < q;i++){
    i64 com,x,y;
    cin >> com >> x >> y;
    if(com == 0){
      srd.update(x,y);
    }
    else{
      ans.push_back(srd.get_inter(x,y + 1));
    }
  }

  for(int i = 0;i < ans.size();i++){
    cout << ans[i] << endl;
  }
}



Measured memory_bytes: 4596
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

constexpr int MOD = int(1e9) + 7;

int N;
string s;
i64 memo[100010][5];

char chr[] = { 'A', 'B', 'C', '~'};

i64 dp(int idx, int nxt) {
    if (idx >= N) {
        if (nxt >= 3) return 1;
        else return 0;
    }

    i64 &ret = memo[idx][nxt];
    if (~ret) return ret;

    ret = 0;

    char first, last;
    if (s[idx] == '?') {
        first = 'A';
        last = 'C';
    } else {
        first = last = s[idx];
    }

    reps(ch, first, last) {
        ret += dp(idx+1, nxt);
        ret %= MOD;
        // trace(idx, nxt, char(ch), ret);
        if (nxt < 3 && ch == chr[nxt]) {
            ret += dp(idx+1, nxt+1);
            ret %= MOD;
        }
    }

    return ret;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    read(s);
    N = s.length();

    memset(memo, -1, sizeof(memo));

    print(dp(0, 0));

    return 0;
}


Measured memory_bytes: 13776
// In the name of GOD
#include<bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

#define     IOS         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	setprecn(x) cout<<fixed<<setprecision(x);
#define 	ll          long long int
#define 	pb          push_back
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	mod         1000000007
#define 	inf         10000000000000007
#define 	rep(i,n)    for(ll i=0;i<n;i++)
#define 	repe(i,a,b) for(ll i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search

ll power(ll a,ll b,ll m=mod)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2,m);
	if(b%2==0)
		return((c%m)*(c%m))%m;
	return ((((c%m)*(c%m))%m)*(a%m))%m;
}

/********************************************************/
//	d.erase(unique(all(d)), d.end());



int main()
{
	IOS;
	ll n,k,m,i,j,c=0,cs=0,t;
	t=1;

	// cin>>t;
	string s;
	while(t--)
	{
		ll x,y;
		cin>>n>>x>>y;
		x--;y--;
		// n=s.length();
		ll dp[n][n],dist[n];
		memset(dist,0,sizeof dist);
		memset(dp,-1,sizeof dp);
		rep(i,n)
		{
			rep(j,n)
			{
				if(i==j || dp[j][i]!=-1) continue;
				dp[i][j]=abs(i-j);
				ll p=min(i,j),q=max(i,j);
				dp[i][j]=min(dp[i][j],abs(i-x)+1+abs(y-j));
				dist[dp[i][j]]++;
			}
		}
		repe(i,1,n)
			cout<<dist[i]<<"\n";
	}
	return 0;
}

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

using namespace std;

int n, h[100003], memo[100003] = {0};
int dp(int a)
{
    int best = 1000000000;
    if (memo[a] > 0)
        return memo[a] - 1;
    if (a == n - 2 || a == n - 3)
    {
        return abs(h[a] - h[n - 1]);
    }
    best = min(abs(h[a] - h[a + 1]) + dp(a + 1), abs(h[a] - h[a + 2]) + dp(a + 2));
    memo[a] = best + 1;
    return best;
}

int main(void)
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &h[i]);
    }
    int m;
    m = dp(0);
    printf("%d\n", m);
    
}


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

#define fl(k, n) for(int i = k; i < n; i++)
#define flr(k, n) for(int i = n - 1; i >= k; i--)
#define vi vector<int>
#define vp vector<pair<int, int>>
#define mp make_pair
#define ll long long

using namespace std;

int binary_search(vector<int> nums, int target_val){
  int begin = 0;
  int end = nums.size();
  int mid;

  while(begin <= end){
    mid = begin + (end - begin) / 2;
    if(nums[mid] == target_val)
      return mid;
    else if(nums[mid] <= target_val && nums[mid + 1] > target_val)
      return mid;
    else if(nums[mid] > target_val)
      end = mid - 1;
    else
      begin = mid + 1;
  }

  if(begin == 0)
    return -1;
  else 
    return nums.size();
}

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

  int n;
  cin >> n;

  vector<vi> nums(n, vi(3));
  fl(0, n)
    cin >> nums[i][0] >> nums[i][1] >> nums[i][2];

  //cout <<"No segmentation faults til here" << endl;

  vector<vi> happ(n, vi(3));
  happ[0][0] = nums[0][0];
  happ[0][1] = nums[0][1];
  happ[0][2] = nums[0][2];

  //cout <<"No segmentation faults til here" << endl;

  fl(1, n){
    for(int j = 0; j < 3; j++){
      int max_hap = 0;
      for (int k = 0; k < 3; k++){
        if(k == j)
          continue;
        int hap = happ[i - 1][k] + nums[i][j];
        max_hap = max(max_hap, hap);
      }
      happ[i][j] = max_hap;
    }
  }

  /*
  fl(0, n){
    cout << happ[i][0] << " " << happ[i][1] << " " << happ[i][2] << "\n";
  }
  */

  int max_hap = max(happ[n - 1][0], happ[n - 1][1]);
  max_hap = max(happ[n - 1][2], max_hap);

  cout << max_hap << "\n";
}

Measured memory_bytes: 14244
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_mut)]
#![allow(unused_assignments)]
use proconio::input;
use proconio::marker::*;
use std::collections::*;
use std::cmp::*;
use std::mem::swap;
use std::f64::consts::*;

const MOD: u64 = 1000000007;
const INF: usize = std::usize::MAX / 4;

fn main() {
    input! {
        N: usize,
        K: usize,
        C: usize,
        S: Chars,
    }

    let mut L = vec![0; N + 1];
    let mut R = vec![0; N + 1];

    let mut now = 1;
    while now <= N {
        if S[now - 1] == 'o' {
            L[now] += 1;
            now += C + 1;
        } else {
            now += 1;
        }
    }
    for i in 0..N {
        L[i + 1] += L[i];
    }

    now = 1;
    while now <= N {
        if S[N - now] == 'o' {
            R[N - now] += 1;
            now += C + 1;
        } else {
            now += 1;
        }
    }
    for i in (0..N).rev() {
        R[i] += R[i + 1];
    }

    for i in 1..N+1 {
        if S[i - 1] == 'o' && L[i] + R[i] == K && L[i] != L[i - 1] && R[i] != R[i - 1] {
            println!("{}", i);
        }
    }
}


Measured memory_bytes: 6276
import sys

for line in sys.stdin:
  if line == '\r' or line == '\n':
    break
  slist = list(line)
  slist.pop()
  while True:
    for i in range(len(slist)):
      if slist[i] == ' ' or slist[i] == '.' or slist[i] == ',':
        continue
      elif slist[i] == 'z':
        slist[i] = 'a'
      else:
        slist[i] = chr(ord(slist[i]) + 1)
    s = ''.join(slist)
    if "the" in s or "this" in s or "that" in s:
      print(s)
      break

Measured memory_bytes: 5568
#include <bits/stdc++.h>
#define fs first
#define sc second
#define mx 100005
#define mod 1000000007
#define pii pair<int, int>
#define ll long long
#define mkp make_pair
#define all(a) a.begin(),a.end()
using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	ll ara[n+64];
	memset(ara, 0, sizeof ara);

	for(int i = 0; i<n; i++){
		scanf("%lld", &ara[i]);
	}
	if(n < 64) n = 64;
	int lim = 61;
	ll ans = 0;
	for(int i = 0; i<lim; i++){
		int c = 0;
		for(int j = 0; j<n; j++){
			if(ara[j]&(1ll<<i)) c++;
		}
		if(c & 1){
			for(int j = 0; j<n; j++){
				ara[j] = ara[j]&(~(1ll<<i));
			}
			ans |= (1ll << i);
		}
	}
	ll basis[62];
	memset(basis, 0, sizeof basis);
	for(int i = lim-1, k = 0; i>=0; i--, k++){
		for(int j = k; j<n; j++){
			if(ara[j]&(1ll<<i)){
				swap(ara[j], ara[k]);
				break;
			}
		}
		if((ara[k]&(1ll<<i)) == 0) {
			k--;
			continue;
		}
		
		for(int j = 0; j<n; j++){
			if(j != k && (ara[j]&(1ll<<i))){
				ara[j] ^= ara[k];
			}
		}
		// for(int j = 0; j<n; j++){
		// 	cout << k << " " << bitset<5>(ara[j]) << endl;

		// }
		// cout << endl;
		// cout << endl;
	}
	
	ll nw = 0;
	for(int i = 0; i<lim; i++){
		if(nw^(ara[i]) > nw) nw ^= ara[i];
	}
	printf("%lld\n", 2ll*nw+ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define MOD 1000000007
//#define int long long  
signed main(){
    int N,X;
    int m[104];
    int ms=0;
    int Ans=0;
    int mn=810114514;
    cin >> N >> X;
    REP(i,N){
        cin >> m[i];
        ms+=m[i];
        mn=min(mn,m[i]);
    }
    Ans+=N;
    X-=ms;
    Ans+=(X/mn);
    cout << Ans << endl;
	return 0;
}

Measured memory_bytes: 256
import math

A, B, C, X, Y = map(int, input().split())

if A + B < C * 2:
    p = A * X + B * Y
else:
    if X > Y:
        p = Y * C * 2
        if A > C * 2:
            p += math.ceil((X - Y) * 2) * C
        else:
            p += (X - Y) * A
    else:
        p = X * C * 2
        if B > C * 2:
            p += math.ceil((Y - X) * 2) * C
        else:
            p += (Y - X) * B

print(p)

Measured memory_bytes: 3060
use std::io::prelude::*;

fn main() {
    let mut input_str = String::new();
    std::io::stdin().read_to_string(&mut input_str).unwrap();

    let input_parts = input_str.split_whitespace().collect::<Vec<_>>();
    let mut input_parts_it = input_parts.iter().cloned();
    let mut next = || input_parts_it.next().unwrap();

    let a: i64 = next().parse().unwrap();
    let b: i64 = next().parse().unwrap();
    let c: i64 = next().parse().unwrap();

    if a +b + c >= 22 {
        println!("bust");
    } else {
        println!("win");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define chmin(x,y) if(x>y)x=y
#define chmax(x,y) if(x<y)x=y
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const ll inf=100100100100;
const int INF=1001001001;
const int mod=1000000007;
int main(){
    int a,b,c,d,e,k;cin>>a>>b>>c>>d>>e>>k;
    if(e-a>k)cout<<":("<<endl;
    else cout<<"Yay!"<<endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		int n = 0;
	    double avg = 0;
		  
		while((n = Integer.parseInt(input.readLine())) != 0){
		  String line = input.readLine();
		  String[] str = line.split(" ");
		  double[] data = new double[n];
		  
		  double sum = 0 , scat = 0 , dev = 0;
		  for(int i = 0 ; i < n ; i ++){
			  data[i] = Double.parseDouble(str[i]);
			  sum += data[i];
			  avg = sum / (double)n ;
		  }
		  for(int j = 0 ; j < n ; j++){
			  scat += Math.pow(avg - data[j], 2); 
		  }
		  
		  dev = Math.sqrt(scat/(double)n);
		  sb.append(dev + "\n");
		  
		}
		System.out.print(sb);
		
	}

}

Measured memory_bytes: 19364
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    multiset<int> se;
    for(auto v:a){
        if(se.lower_bound(v)!=se.begin()){
            se.erase(prev(se.lower_bound(v)));
        }
        se.insert(v);
    }
    cout<<se.size()<<endl;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int x1,y1,x2,y2,d;
    cin>>x1>>y1>>x2>>y2;
    int dx=x2-x1, dy=y2-y1;
    int x3=x2-dy, y3=y2+dx;
    int x4=x3-dx, y4=y3-dy;
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
    


    return 0;
}


Measured memory_bytes: 3608
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;

class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer(br.readLine(), " ");
    int A = Integer.parseInt(st.nextToken());
    int B = Integer.parseInt(st.nextToken());
    int ans = (A + B) % 24;
    System.out.println(ans);
  }
}


Measured memory_bytes: 21076
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

ll x, k, d;

ll solve() {
    if ((ld)abs(x)/d >= k) {
        return abs(x) - d*k;
    }
    x = abs(x);
    ll n = (x - x % d) / d;
    if (n % 2 == k % 2) return x % d;
    return d - x%d;
}

void input() {
    cin >> x >> k >> d;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 3140
using System;

namespace _2_D
{
    class Program
    {
        static void Main(string[] args)
        {
            var WHxyr = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var W = WHxyr[0];
            var H = WHxyr[1];
            var x = WHxyr[2];
            var y = WHxyr[3];
            var r = WHxyr[4];
            if((r<=x && x<=W-r) && (r<=y && y<= H-r))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}



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

#define endl '\n'
using namespace std;
using ll = long long;

const int N = 1003;
const int M = 20004;

struct Block
{
    ll w, s, v;
    bool operator < (const Block &that)
    {
        return this->w + this->s < that.w + that.s;
//        return this->w <= that.s && this->s < that.w;
    }
};

int n;
Block arr[N];
ll dp[N][M];

void init();
void process();

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    init();
    process();
    cout.flush();
    return 0;
}

void init()
{
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> arr[i].w >> arr[i].s >> arr[i].v;
    sort(arr+1, arr+1+n);
}

void process()
{
    for(int i = 1; i <= n; i++)
    {
        for(int j = 0; j < M; j++)
        {
            dp[i][j] = dp[i-1][j];
            if(j-arr[i].w >= 0 && arr[i].s >= j-arr[i].w) 
                dp[i][j] = max(dp[i][j], dp[i-1][j-arr[i].w]+arr[i].v);
        }
        /*
        for(int j = 0; j < M; j++)
        {
            dp[i][j] = max(dp[i][j], dp[i-1][j]);
            if(j <= arr[i].s && j+arr[i].w < M) 
                dp[i][j+arr[i].w] = max(dp[i][j+arr[i].w], dp[i-1][j]+arr[i].v);
        }
        */
    }
    ll ans = 0;
    for(int i = 0; i < M; i++) ans = max(ans, dp[n][i]);
    cout << ans << endl;
}



Measured memory_bytes: 156544
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    string s;
    cin >> s;
    ll n=s.size();
    ll ans=0;
    vector <string> out;
    for(ll i=1;i<pow(2,n-1);i++)
    {
        ll prev=-1;
        for(ll j=0;j<n-1;j++)
        {
            if(1<<j & i)
            {
                //ans+=stoi(s.substr(prev,j));
                
                out.push_back(s.substr(prev+1,j-prev));
                prev=j;
            }
        }
        out.push_back(s.substr(prev+1,n-prev));
        //ans+=stoi(s.substr(prev,n-1));
    }
    //cout << out.size();
    for(ll i=0;i<out.size();i++)
    {
        ans+= stoll(out[i]);
    }
    ans+=stoll(s);
    cout << ans<<"\n";
}


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

int search_root(int *parent, int v)
{

  if(parent[v] != v) 
    {
      parent[v] = search_root(parent, parent[v]);
      return parent[v];
    }
  else
    return v;

}

int unite(int *parent, int v1, int v2)
{
  int r1 = search_root(parent, v1);
  int r2 = search_root(parent, v2);
    
  if(r1 != r2)
    {
      parent[r1] = r2;
      return true;
    }

  else
    return false;
}

int main(int argc, char **argv)
{
  int Vnum,Enum,i;

  std::cin >> Vnum >> Enum;

  int *parent, *s, *t;
  s = new int[Enum];
  t = new int[Enum];
  parent = new int[Enum];
  std::pair<int,int> w[Enum];
  
  for(i=0; i<Enum; i++)
    {
      std::cin >> s[i] >> t[i] >> w[i].first;
      w[i].second = i;
    }

  std::sort(w, w+Enum);

  for(i=0; i<Vnum; i++)
    parent[i]=i;
      
  int sum = 0;

  for(i=0; i<Enum; i++)
    {
      if(unite(parent, s[w[i].second], t[w[i].second]))
	sum += w[i].first;
    }
      
  std::cout << sum << std::endl;

  return 0;
}


Measured memory_bytes: 4672
#include<stdio.h>
#include<string.h>

int main(void)
{
  int n,i,l;
  char s[10000];

  scanf("%d",&n);
  scanf("%s",s);

  l=strlen(s);

  for(i=0;i<l;i++){
    s[i]=s[i]+n;
    if(s[i]>90)s[i]=s[i]-26;
  }
  printf("%s",s);


  return 0;
}

Measured memory_bytes: 128
x1,y1,x2,y2 = list(map(int,input().split()))
x3 = x2 - y2 + y1
y3 = y2 + x2 - x1
x4 = x1 - y2 + y1
y4 = y1 + x2 - x1
print('{} {} {} {}'.format(x3,y3,x4,y4))


Measured memory_bytes: 2940
#define _USE_MATH_DEFINES
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <numeric>
#include <array>
#include <float.h>
#include <map>
#include <iomanip>

using namespace std;

using ULL = unsigned long long;

int main() {
  int K, S;
  ULL num = 0;
  cin >> K >> S;
  //if (K == S)num += 3;
  for (int x = 0; x < K + 1 ; ++x) {
    for (int y = 0; y < K + 1; ++y) {
        auto z = S - x - y;
        if (z >= 0 && z <= K) {
          ++num;
        }
        else if (x != 0 && y != 0 && z == 0)++num;
      }
    
  }
  cout << num << endl;
  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, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
using vbvb = vector<vector<bool>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 1000000007;
const int inf = 1001001001;



int main(void) {
  int n;
  string s;
  cin >> n >> s;
  vivi rgb(2);
  set<int> b;
  rep(i,n){
    if(s[i]=='R')rgb[0].push_back(i);
    else if(s[i]=='G')rgb[1].push_back(i);
    else b.insert(i);
  }
  ll cnt = 0;
  //cout << rgb[0].size() << " " << rgb[1].size() << endl;
  rep(i,rgb[0].size())rep(j,rgb[1].size()){
    int p = rgb[0][i];
    int q = rgb[1][j];
    int r = abs(p-q);
    int ad = b.size();
    if(b.count(min(p,q)-r))ad--;
    if(b.count(max(p,q)+r))ad--;
    if(r%2==0 && b.count(max(p,q)-r/2))ad--;
    cnt += ad;
  }
  cout << cnt << endl;
  
}






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

int main(){
    //input
    long long N, M;
    cin >> N >> M;
    long long a[M], b[M];
    long long i, j;
    for(j = 0; j < M; j++){
        cin >> a[j] >> b[j];
    }

    //calc
    long long s[N];
    for(i = 0; i < N; i++){
        s[i] = i+1;
    }
    long long counta = 0;
    bool countif;
    do{
        countif = 1;
        for(i = 1; i < N; i++){
            for(j = 0; j < M; j++){
                if((s[i-1]==a[j] && s[i]==b[j]) || (s[i-1]==b[j] && s[i]==a[j])){
                    break;
                }
            }
            if(j==M){
                countif = 0;
            }
        }
        if(countif){
            counta++;
        }
    }while(next_permutation(s+1, s+N));

    //output
    cout << counta << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 504
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int n,k,a[MAXN];
int main()
{
    scanf("%d",&n);
    printf("%d\n",180*(n-2));
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int N, A = 0, B = 0;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) cin >> vec.at(i);
  
  sort(vec.begin(), vec.end());
  
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) A += vec.at(i);
    else B += vec.at(i);
  }
  
  cout << max(A, B) - min(A, B) << endl;
}

Measured memory_bytes: 256
import copy
from collections import deque

def getlist():
	return list(map(int, input().split()))

L = []
N = int(input())
for i in range(N):
	x, y = getlist()
	L.append([x, y])

L = sorted(L)

ans = float("inf")
for i in range(N):
	for j in range(i, N):
		LL = copy.copy(L)
		Q = deque(LL)
		p = L[j][0] - L[i][0]
		q = L[j][1] - L[i][1]
		c = 1
		xx, yy = Q.popleft()

		while Q:
			if [xx + p, yy + q] in Q:
				Q.remove([xx + p, yy + q])
				xx, yy = xx + p, yy + q
			else:
				xx, yy = Q.popleft()
				c += 1

		if c < ans:
			ans = c

print(ans)

Measured memory_bytes: 3444
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll N,A[100007],B[100007];

int main(){
    COMinit();
    cin >> N;
    ll l,r;
    rep(i,N+1){
        cin >> A[i];
        if(B[A[i]]==0){
            B[A[i]]=i+1;
        }
        else{
            l=B[A[i]];
            r=i+1;
        }
    }
    Rep(i,1,N+2){
        cout << (COM(N+1,i)-COM(l+N-r,i-1)+MOD)%MOD << endl;
    }
}

Measured memory_bytes: 14720
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl

class mint {
    long long x;
public:
    mint(long long x=0) : x((x%MOD+MOD)%MOD) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};
/* -- template -- */

struct UnionFind {
    vector<int> par;
    vector<ll> siz;
    UnionFind(int N) : par(N), siz(N, 1LL) {
        for(int i = 0; i < N; ++i) {
            par[i] = i;
        }
    }
    int root(int x) {
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        siz[ry] += siz[rx];
        par[rx] = ry;
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    ll size(int x) {
        return siz[root(x)];
    }
};
const int MAX_N = 1000001;
int cntA[MAX_N], cntB[MAX_N];

ll primeFactorization(ll x, int cnt[]) {
    cnt[1] = 1;
    for(ll i = 2LL; i * i <= x; ++i) {
        if(x % i == 0){
            ++cnt[i];
            x /= i;
            i = 1LL;
        }
    }
    if(x < MAX_N)
        ++cnt[x];
    return x;
}
void solve(ll A, ll B) {
    ll a = primeFactorization(A, cntA);
    ll b = primeFactorization(B, cntB);
    int ans = 0;
    rep(i, MAX_N)
        if(cntA[i] > 0 && cntB[i] > 0)++ans;
    if(a == b && a >= MAX_N)
        cout << ans + 1 << endl;
    else
        cout << ans << endl;
}

int main() {
    ll A, B; cin >> A >> B;
    solve(A, B);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int n;
long long x;
set<long long> s;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(s.find(x)==s.end())
        {
            s.insert(x);
        }
        else
            s.erase(x);
    }
    cout<<s.size();
}



Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる





int main() {
  int n,m;
  cin>>n>>m;

  vector<ll> p(n);
  rep(i,n){
    cin>>p[i];
  }

  sort(all(p));

  vector<pair<ll,ll>> q(m);
  rep(i,m){
    cin>>q[i].se>>q[i].fi;
  }

  sort(all(q));
  reverse(all(q));

  ll now=0;
  rep(i,n){
    chmax(p[i],q[now].fi);
    q[now].se--;
    if(q[now].se==0) now++;
    if(now==m) break;
  }

  ll ans=0;
  rep(i,n){
    ans+=p[i];
  }

  cout << ans << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

#define MAX_N 200001

long long par2[MAX_N]; // 親
long long rankuf2[MAX_N]; // 木の深さ
// n要素で初期化
void init2(long long n) {
	for (long long i = 0; i < n; i++) {
		par2[i] = i;
    rankuf2[i] = 0;
	}
}
// 木の根を求める
long long find2(long long x) {
	if (par2[x] == x) {
		return x;
	} else {
		return par2[x] = find2(par2[x]);
	}
}
// xとyの属する集合を併合
void unite2(long long x, long long y) {
	x = find2(x);
	y = find2(y);
	if (x == y) return;
	if (rankuf2[x] < rankuf2[y]) {
		par2[x] = y;
	} else {
		par2[y] = x;
		if (rankuf2[x] == rankuf2[y]) rankuf2[x]++;
	}
}
// xとyが同じ集合に属するか否か
bool same2(long long x, long long y) {
	return find2(x) == find2(y);
}

long long par[MAX_N]; // 親
long long rankuf[MAX_N]; // 木の深さ
// n要素で初期化
void init(long long n) {
	for (long long i = 0; i < n; i++) {
		par[i] = i;
    rankuf[i] = 0;
	}
}
// 木の根を求める
long long find(long long x) {
	if (par[x] == x) {
		return x;
	} else {
		return par[x] = find(par[x]);
	}
}
// xとyの属する集合を併合
void unite(long long x, long long y) {
	x = find(x);
	y = find(y);
	if (x == y) return;
	if (rankuf[x] < rankuf[y]) {
		par[x] = y;
	} else {
		par[y] = x;
		if (rankuf[x] == rankuf[y]) rankuf[x]++;
	}
}
// xとyが同じ集合に属するか否か
bool same(long long x, long long y) {
	return find(x) == find(y);
}

int main(){	
	long long K;
	long long N;
	long long L;
	scanf("%lld",&N);
	scanf("%lld",&K);
	init(N+1);
	init2(N+1);
	vector<long long> q(K-1+1);
	vector<long long> p(K-1+1);
	scanf("%lld",&L);
	vector<long long> r(L-1+1);
	vector<long long> s(L-1+1);
	for(int i = 0 ; i <= K-1 ; i++){
		scanf("%lld",&p[i]);
		scanf("%lld",&q[i]);
		unite(p[i]-1, q[i]-1);
	}
	for(int i = 0 ; i <= L-1 ; i++){
		scanf("%lld",&r[i]);
		scanf("%lld",&s[i]);
		unite2(r[i]-1, s[i]-1);
	}
	map<P, ll> m;
	rep(i, N) {
		m[P(find(i), find2(i))]++;
	}
	ll cnt = 0;
	rep(i, N-1) {
		cout << m[P(find(i), find2(i))] << " ";
	}
	cout << m[P(find(N-1), find2(N-1))] << endl;
	return 0;
}



Measured memory_bytes: 21248
#include<stdio.h>
#include<string.h>
int main()
{
	char s[105],t[105],x[205];
    int n,i;
	scanf("%s",s);
	scanf("%s",t);
	n=strlen(s);
  for(i=0;i<n;i++)
   {
       x[i]=t[i];
       x[i+n]=t[i];
   }
  
   int f=1;
   int j;
   for(i=0;i<n;i++)
   {
   	f=1;
   	for(j=0;j<n;j++)
   	if(x[j+i]!=s[j])
   	     f=0;
   	if(f)  break;
   
    }
   if(f)
   printf("Yes\n");
   else
	 printf("No\n");
}


Measured memory_bytes: 128
n,m = map(int,input().split())
mod = 10**9+7
rng = 500100
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
  finv.append(pow(fctr[i],mod-2,mod))
def cmb(n,k):
  if n<0 or k<0:
    return 0
  else:
    return fctr[n]*finv[n-k]*finv[k]%mod
ans = 0
for i in range(n+1):
  if i%2 == 0:
    ans += fctr[m-i]*finv[m-n]*cmb(n,i)
  else:
    ans -= fctr[m-i]*finv[m-n]*cmb(n,i)
  ans %= mod
print(ans*fctr[m]*finv[m-n]%mod)

Measured memory_bytes: 159024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			cout << v[i][j] << "   ";
		}
		cout << endl;
	}
}




int main(){//
	int N;
	cin >> N;
	vector<ll> A(N), B(N), C(N);
	for(int i=0; i<N; i++) cin >> A[i];
	for(int i=0; i<N; i++) cin >> B[i];
	for(int i=0; i<N; i++) cin >> C[i];
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	sort(C.begin(), C.end());

	ll ans = 0;
	for(int b=0; b<N; b++){
		auto iter = lower_bound(A.begin(), A.end(), B[b]);
		auto num_a = iter - A.begin();

		auto iter2 = upper_bound(C.begin(), C.end(), B[b]);
		auto index = iter2 - C.begin();
		auto num_c = C.size() - index;
		//cout << " index: " << index << " num_c: " << num_c << endl;
		ans += num_a * num_c;
	}

	cout << ans << endl;

}


Measured memory_bytes: 2560
n = int(input())
A = list(map(int,input().split()))
S = [0] * (n + 1)

from collections import defaultdict
dic = defaultdict(int)
for i in range(len(A)):
  S[i+1] = S[i] + A[i]
for s in S:
  dic[s] += 1
from scipy.special import comb
ans = 0
for k, v in dic.items():
  if v > 1:
    ans += comb(v, 2, exact=True)

print(int(ans))

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

int N, X;
int L[101];
long long D[102];
void solve()
{
	int cnt = 0;
	if(D[0] <= X)
		cnt++;
	for(int i = 1; i <= N; i++){
		D[i] = D[i-1] + L[i-1];
		if(D[i] <= X)
			cnt++;
	}
	cout << cnt << endl;
}
int main()
{
	cin >> N >> X;
	for(int i = 0; i < N; i++)
		cin >> L[i];
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>

template<typename T> bool chmax(T &a,T b){
    if(a<b){
        a=b;
        return true;
    }
    return false;
}

template<typename T> bool chmin(T &a,T b){
    if(a>b){
        a=b;
        return true;
    }
    return false;
}

using namespace std;
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=1001001000;
const ll LLMAX=1010010010010010000;

bool comp(vll a,vll b){
    return a[0]>b[0];
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N;
    cin>>N;
    vvll A(N,vll(2));
    for(ll i=0;i<N;i++){
        cin>>A[i][0];
        A[i][1]=i;
    }
    
    sort(A.begin(),A.end(),comp);
    
    vvll dp(N+1,vll(N+1,0));
    
    for(ll i=0;i<N;i++){
        if(i==0){
            dp[1][0]=A[i][0]*(A[i][1]-0);
            dp[0][1]=A[i][0]*(N-1-A[i][1]);
        }else{
            for(ll j=0;j<=i;j++){
                chmax(dp[j+1][i-j],dp[j][i-j]+A[i][0]*(A[i][1]-j));
                chmax(dp[j][i-j+1],dp[j][i-j]+A[i][0]*(N-1-(i-j)-A[i][1]));
            }
        }
    }
    
    ll ans=0;
    for(ll i=0;i<=N;i++){
        chmax(ans,dp[i][N-i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 34616
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  char a[n+2][m+2];
  for(int i=0;i<=n+1;i++){
    if(i==0||i==n+1){
      for(int j=0;j<m+2;j++){
        cout << "#";
      }
      cout << endl;
    }
    else{
      cout << "#";
      for(int jj=1;jj<=m;jj++){
        cin >> a[i][jj];
        cout << a[i][jj];
      }
      cout << "#" << endl;
    }
  }
}


Measured memory_bytes: 256