akhauriyash/Code-Regression huggingface dataset:
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

#[allow(unused)]
use std::cmp::{max, min};
#[allow(unused)]
use std::collections::HashMap;

#[allow(unused)]
fn gcd(x: i64, y: i64) -> i64 {
    if y == 0 {
        x
    } else {
        gcd(y, x % y)
    }
}

#[allow(unused)]
fn lcm(x: i64, y: i64) -> i64 {
    x * y / gcd(x, y)
}

fn main() {
    input! {
        // usize
        // n: usize,
        // vec
        // v: [i64; n],
        n: usize,
        h: [i64; n],
    }

    let mut hr = h;
    let mut dp: Vec<i64> = Vec::with_capacity(n);
    dp.push(0);
    hr.reverse();

    for i in 1..n {
        if hr[i] >= hr[i - 1] {
            let count = dp[i - 1] + 1;
            dp.push(count);
        } else {
            dp.push(0);
        }
    }

    println!("{}", dp.iter().max().unwrap());
}


Measured memory_bytes: 6396
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;

typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// -9.2e-18 <= long long <= 9.2e18
// 0 <= unsigned int <= 4.2e9
// 0 <= unsigned long long <= 18.4e18
// cout << fixed << setprecision(10);

int main() {
    uint N;
    cin >> N;
    vector<llong> A(N, 0);
    for (auto &a: A) cin >> a;
    llong total = 0;
    for (int i=0; i<A.size()-1; ++i) {
        int j = i + 1;
        if (A[i] > A[j]) {
            llong diff = A[i] - A[j];
            //cout << diff << endl;
            A[j] += diff;
            total += diff;
        }
//        else {
//            cout << 0 << endl;
//        }
    }
    cout << total << endl;
}


Measured memory_bytes: 4824
N, K = map(int, input().split())

MOD = 10**9+7
ans = 0

for i in range(K,N+2):
    MIN = i*(i-1)//2
    MAX = N*(N+1)//2 - (N-i)*(N-i+1)//2
    ans += (MAX-MIN+1)
    ans %= MOD

print(ans)

Measured memory_bytes: 9196
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
  int s, w;
  cin >> s >> w;
  if(w >= s) cout << "unsafe" << endl;
  else cout << "safe" << endl;
}


Measured memory_bytes: 3524
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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

    ll N;
    cin >> N;

    FOR(h, 1, 3501) {
        FOR(n, 1, 3501) {
            ll div = 4 * h * n - N * n - N * h;
            ll num = n * h * N;
            if (0 < div && num % div == 0) {
                int w = num / div;
                std::cout << h << " " << n << " " << w << '\n';
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	char a;
	cin>>a;
	if(a=='A'){
		cout<<'T';
	}
	if(a=='T'){
		cout<<'A';
	}
	if(a=='C'){
		cout<<'G';
	}
	if(a=='G'){
		cout<<'C';
	}
}
//FELAROSSO 2019

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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    vector<ll> sum(N + 1);
    for (int i = 0; i < N; i++) {
        sum[i + 1] = sum[i] + A[i];
    }

    map<ll, ll> m;
    for (int i = 0; i < N + 1; i++) {
        m[sum[i]]++;
    }

    ll res = 0;
    for (auto it = m.begin(); it != m.end(); it++) {
        pair<ll, ll> p = *it;
        if (p.second) {
            res += (p.second * (p.second - 1LL)) / 2LL;
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 15872
def main():
    mod = 998244353
    s, k = input().split()
    k, n, o, cnt, z, zero_list = int(k), len(s), s.count("1")+1, 0, 0, []
    for i in range(n):
        if s[i] == "0":
            zero_list.append(cnt)
            cnt = 0
        else:
            cnt += 1
    m = min(o, k+1)

    dp = [[0]*m for _ in [0]*o]
    dp[0][0] = 1

    for i in zero_list:
        dp2 = [[0]*m for _ in [0]*o]
        dp3 = [[0] for _ in [0]*o]
        for x in range(o):
            t = 0
            for y in range(min(m, o-x)):
                t = (t+dp[x+y][y]) % mod
                dp3[x].append(t)
        dp4 = [[0]*m for _ in [0]*o]
        for y in range(m):
            t = dp[0][y]
            for x in range(1, o):
                dp4[x-1][y] = t
                t = (t+dp[x][y]) % mod
            dp4[o-1][y] = t
        for j in range(z+i, o):
            for x in range(min(j-i+1, m)):
                dp2[j][x] = (dp2[j][x]+dp3[j-x-i][min(o, x+1)]) % mod
            for p in range(m):
                dp2[j][p] = (dp2[j][p]+dp4[j][p]-dp4[max(j-i, p-1)][p]) % mod
        z += i
        dp = dp2
    print(sum([sum(i) for i in dp]) % mod)


main()

Measured memory_bytes: 83284
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
using namespace std;

int N;

int K = 0;

void solve(map<pair<int,int>,int>& color,vector<vector<int>>& list){
	vector<int> used(N+1);
	vector<int> col(N+1);
	used[1] = 1;
	queue<int> q;
	q.push(1);
	while(!q.empty()){
		int point = q.front();
		q.pop();
		used[point] = 1;
		int color_num = 1;
		for(int i=0;i<list[point].size();i++){
			if(!used[list[point][i]]){
				q.push(list[point][i]);
				if(color_num==col[point]) color_num++;
				col[list[point][i]] = color_num;
				color[make_pair(list[point][i],point)] = color_num;
				color[make_pair(point,list[point][i])] = color_num;
				if(K<color_num) K=color_num;
				color_num++;
			}
		}
	}
}

int main(){
	cin >> N;

	vector<pair<int,int>> edge; 
	vector<vector<int>> list(N+1);
	map<pair<int,int>,int> color;

	for(int i=1;i<N;i++){
		int a,b;
		cin >> a >> b;
		edge.push_back(make_pair(a,b));
		list[a].emplace_back(b);
		list[b].emplace_back(a);
	}

	solve(color,list);

	cout << K << endl;
	for(int i=0;i<N-1;i++){
		cout << color[edge[i]] << endl;
	}
	return 0;
}


Measured memory_bytes: 20084
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        d: [(u8, u8); n],
    }

    let mut is_found = false;
    for i in 0..n-2 {
        if (d[i].0 == d[i].1) {
            if (d[i+1].0 == d[i+1].1) {
                if (d[i+2].0 == d[i+2].1) {
                    if (!is_found) {
                        println!("Yes");
                        is_found = true;
                    }
                }
            }
        }
    }

    if (!is_found) {
        println!("No");
    }
}


Measured memory_bytes: 2116
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<char> vec(9);
  REP(i,9) cin >> vec[i];
  cout << vec[0] << vec[4] << vec[8] << endl;
  return 0;
}
//templete by private_yusuke

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

string nodeProfileOf(std::vector<int> tree, int no){
    stringstream res;
    
    res <<"node "<<no<<": "
        <<"key = "<<tree[no-1]<<", ";
    if(no!=1)
        res <<"parent key = "<<tree[no/2-1]<<", ";
    if(no*2-1<tree.size())
        res <<"left key = "<<tree[no*2-1]<<", ";
    if(no*2<tree.size())
        res <<"right key = "<<tree[no*2]<<", ";
    res <<"\n";
    
    return res.str();
}

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

    int nb_nodes; cin>>nb_nodes;
    std::vector<int> tree(nb_nodes);
    for(auto& a:tree) cin>>a;
    
    for(int no=1;no<=tree.size();++no){
        cout<<nodeProfileOf(tree, no);
    }
}

Measured memory_bytes: 3228
#include <iostream>
#include <cstdio>
#include <math.h>
#include <algorithm>
using namespace std;
const int MAX_N=200000;
 int N;
 int A[MAX_N],AC[MAX_N],S[MAX_N];
int main(){
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> A[i];
        AC[i]=A[i];
    }
    sort(AC,AC+N,greater<int>());
    for(int j=0;j<N;j++){
        if(AC[0]==A[j]){
            int An=AC[1];
            printf("%d\n",An);
        }else{
            int An=AC[0];
            printf("%d\n",An);
        }
    }
}

Measured memory_bytes: 5212
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <deque>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
typedef long long ll;
typedef map<int,int> mint;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef deque<pair<ll,ll>> dep;
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int inf=1e9+1000;
const int mod=1e9+7;
ll infi=1e18+100;

//x=10111;
//x<<2 = 1011100 (右シフト),x>>2 = 101 (左シフト)
//(x>>2)&1 = 101 & 001 = 1
//iビット目は、(x>>i) & 1 でわかる(x>>i)%2 でもよい

int N;
int A[100003];
mint mp;

int main(){
	cin>>N;
	Rep(i,N) cin>>A[i];
	Rep(i,N) mp[A[i]]++;
	int ans=0;
	Rep(i,N){
		if(mp[A[i]]>0){
			ans++;
			mp[A[i]]=0;
	}
	}
	if(ans%2==0) ans--;
	cout<<ans<<endl;

	
	  return 0;
  }


Measured memory_bytes: 5376
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) (a+b-1)/b //小数点切り上げ
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<lol, lol>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}
//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int x;
  cin >> x;
  if(x >= 30){
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)



int main(){
    ll N;
    cin >> N;
    vector<ll> cnts;
    rep(i, 5){
        ll cnt;
        cin >> cnt;
        cnts.push_back(cnt);
    }
    ll min_cnt = (1L << 62);
    rep(i, cnts.size()){
        min_cnt = min(cnts[i], min_cnt);
    }
    ll ans = (N - min_cnt + min_cnt - 1) / min_cnt + 5;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
int main(){
	int W,aLEFT,bLEFT,bRIGHT,aRIGHT;
	std::cin>>W>>aLEFT>>bLEFT;
	bRIGHT=bLEFT+W;
	aRIGHT=aLEFT+W;
	if(aRIGHT>=bLEFT && bRIGHT>=aLEFT){
		std::cout<<0<<"\n";
		return 0;
	}
	else if(aRIGHT<bLEFT && aLEFT<bRIGHT){
		std::cout<<bLEFT-aRIGHT<<"\n";
		return 0;
	}
	else{
		std::cout<<aLEFT-bRIGHT<<"\n";
		return 0;
	}
}

Measured memory_bytes: 256
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1

//{
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define ins insert
#define aer(v) (v).erase((v).begin(),(v).end()) 

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

int dp[111][222222];

main(){
	int n,ub;cin>>n>>ub;
	int w[n],v[n];rep(i,n)cin>>w[i]>>v[i];
	rep(i,111)rep(j,222222)dp[i][j]=MOD;
	dp[0][0]=0;
	rep(i,n){
		rep(j,222222){
			if(j-v[i]>=0)dp[i+1][j]=min(dp[i][j],dp[i][j-v[i]]+w[i]);
			else dp[i+1][j]=dp[i][j];
		}
	}
	int ans=0;
	rep(i,222222){
		if(dp[n][i]<=ub)ans=max(ans,i);
	}
	dans;
}






Measured memory_bytes: 192896
/*************************************************************************
	> File Name: 3.cpp
	> Author: Knowledge_llz
	> Mail: 925538513@qq.com 
	> Blog: https://blog.csdn.net/Pig_cfbsl 
	> Created Time: 2020/7/13 15:13:56
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define LL long long
using namespace std;
int read(){
	char x=getchar(); int u=0,fg=0;
	while(!isdigit(x)){ if(x=='-') fg=1; x=getchar(); }
	while(isdigit(x)){ u=(u<<3)+(u<<1)+(x^48); x=getchar(); }
	return fg?-u:u;
}
const LL oo=1e15;
int a[2020],b[2020];
LL dp[1<<20];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#endif
	int u,v,n,m;
	n=read(); m=read();
	For(i,1,m){
		a[i]=read(); u=read();
		int s=0;
		while(u--){
			v=read();
			s|=(1<<(v-1));
		}
		b[i]=s;
	}
	For(i,1,1<<n) dp[i]=oo;
	dp[0]=0;
	For(i,1,m) For(j,0,(1<<n)-1){
		dp[j|b[i]]=min(dp[j]+a[i],dp[j|b[i]]);
//		cout<<j<<" "<<dp[j]<<endl;
	}
	if(dp[(1<<n)-1]==oo) dp[(1<<n)-1]=-1;
	cout<<dp[(1<<n)-1];
	return 0;
}


Measured memory_bytes: 3660
n = int(input())
a = []
for i in range(n):
    a.append(list(map(str, input().split())))   
    
taro = []
hanako = []
for i in range(len(a)):
    if a[i][0] > a[i][1]:
        taro.append(3)
    elif a[i][0] == a[i][1]:
        taro.append(1)
        hanako.append(1)
    else:
        hanako.append(3)
print(sum(taro),sum(hanako))

Measured memory_bytes: 5620
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int N,t;
	map<int,bool> m;
	scanf("%d",&N);
	for(int i=0;i<N;i++)
	{
		scanf("%d",&t);
		if(m[t]==false)m[t]=true;
		else m[t]=false;
	}
	ll r=0;
	for(pair<int,bool> i:m)
	{
		if(i.second==true)r++;
	}
	printf("%lld\n",r);
}

Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int K;cin >> K;
    vector<ll> A(K);
    rep(i,K)cin >> A[i];
    ll L=2,R=2;
    for(int i=K-1;i>=0;i--){
        R=(R/A[i])*A[i]+A[i]-1;
        L=((L+(A[i]-1))/A[i])*A[i];
        if(R<L){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << L << " " << R << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main() {
    long long N;
    cin>>N;
    long long A[N];
    long long answer[N]={0};
    //cout<<N<<endl;
    for(long long i=1;i<N;i++)//2から
    {
      //cout<<answer[i]<<endl;
      cin>>A[i];
      answer[A[i]-1]++;
    }
    /*for(long long i=0;i<N;i++)
    {
      answer-=A[i];
    }
    if(answer>=0){
    	cout<<answer<<endl;
    }else{
        cout<<"-1"<<endl;
    }*/
    for(long long i=0;i<N;i++)
    {
      cout<<answer[i]<<endl;
    }
 
    return 0;
}

Measured memory_bytes: 6748
# -*- coding utf-8 -*-
import heapq
MOD = 10 ** 9 + 7

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

AB.sort(key=lambda x: -x[0])

ans = 0
hq = []
for i in range(M + 1):
    while len(AB) != 0 and AB[-1][0] <= i:
        ab = AB.pop()
        ba = [-ab[1], ab[0]]
        heapq.heappush(hq, ba)

    if len(hq) != 0:
        ans += heapq.heappop(hq)[0]

print(-ans)


Measured memory_bytes: 32232
#include<bits/stdc++.h>
#define ll long long
#define pi acos(-1.0)
#define pb push_back
#define vi vector<int>
#define mapii map<int , int>
#define mapci map<char, int>
#define mapsi map<string,int>
#define FOR(i,n) for(int i = 0;i<n;i++)
#define CP(n) cout<<"Case "<<n<<": "
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)
#define MAX 1000007
#define all(x)(x.begin(),x.end())
#define debug(x,c) cout<<x<<": "<<c<<" ";
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
int main()
{
	char c;
	cin>>c;
	if(c>='A' && c<='Z')
		cout<<"A"<<endl;
	else
		cout<<"a"<<endl;
	return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

int main(){
    ll n, x[100];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> x[i];
    }

    ll res = -1, resSum = LONG_LONG_MAX;
    for(int y = 0; y <= 100; y++){
        ll resTmp = 0;
        for(int i = 0; i < n; i++){
            resTmp += (y - x[i]) * (y - x[i]);
        }
        resSum = min(resSum, resTmp);
    }

    cout << resSum << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll A, B; cin >> A >> B;
  cout << (A-1)*(B-1)<<endl;

  return 0;
}



Measured memory_bytes: 384
#include <stdio.h>
int main(void){
    int a, b, i;
    scanf("%d%d", &a, &b);
    if (a <= b){
        for(i = 0; i < b; i++){
            printf("%d", a);
        }
    }else {
        for(i = 0; i < a; i++){
            printf("%d", b);
        }
    }
    printf("\n");
  
}


Measured memory_bytes: 1604
#include <stdio.h>
int main(void){
	
	char w[100];
	
	scanf("%s", w);
	
	if(w[0] == 'S') printf("Cloudy\n");
	if(w[0] == 'C') printf("Rainy\n");
	if(w[0] == 'R') printf("Sunny\n");
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct P {
    bool operator<(const P& p) const {
        return d > p.d;
    }
    int t, d;
};

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

    int n, k;
    cin >> n >> k;

    vector<P> p(n);
    int m = 0;
    for (int i = 0; i < n; i++) {
        int t, d;
        cin >> t >> d;
        t--;

        p[i] = { t, d };
        m = max(m, t);
    }
    sort(p.begin(), p.end());
    m++;

    vector<int> d(n);
    vector<char> a(m);
    int i0 = 0, i1 = 0;
    ll r = 0, s = 0;

    for (int i = 0; i < n; i++) {
        if (a[p[i].t] == 0) {
            a[p[i].t] = 1;
            if (i >= k) {
                if (i1 == 0) break;
                s -= d[--i1];
            }
            i0++;
            s += p[i].d;
        } else {
            if (i < k) s += d[i1++] = p[i].d;
        }
        r = max(r, s + (ll)i0 * i0);
    }

    cout << r << endl;

    return 0;
}

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

int main() {
  
  int N;
  cin >> N;
  for(int i = 0; i < N; i++) {
    int r, t; cin >> r >> t;
    if(t % 30 == 0 && r % 100 == 0)
      cout << (t / 30) * 5 + r / 100 << endl;
    else if(r % 100 == 0)
      cout << (t / 30) * 5 + r / 100 << " " << ((t + 30) / 30) * 5 + r / 100 << endl;
    else if(t % 30 == 0) 
       cout << (t / 30) * 5 + r / 100 << " " << (t / 30) * 5 + r / 100 + 1<< endl;
    else 
      cout << (t / 30) * 5 + r / 100 << " " << (t / 30) * 5 + r / 100 + 1 << " " << ((t  + 30) / 30) * 5 + r / 100 << " " << (((t + 30) / 30) * 5) + r / 100 + 1 << endl;
  }
}

Measured memory_bytes: 1160
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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(b < a){
        a = b;
        return true;
    }
    return false;
}

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

    int n;
    cin >> n;

    string s;
    cin >> s;

    rep(i, s.size()){
        cout << (char)((((s[i] - 'A') + n) % 26) + 'A');
    }
    cout << endl;

    cout << flush;

    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++)
typedef long long int ll;

int main()
{
  int n, x;
  cin >> n >> x;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  
  ll res = 0;
  if(a[0] > x) res += a[0]-x, a[0]=x;
  rep(i,n-1)
  {
    if(a[i+1]+a[i] > x)
    {
      res += a[i] + a[i+1] - x;
      a[i+1] = x - a[i];
    }
  }
  cout << res << endl;
  
  return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define fore(e, u, v) for (int p = e(u), v = e[p].y; p; v = e[p = e[p].nxt].y)
#define ri rd<int>
typedef long long LL;
using namespace std;
const int maxN = 1e5 + 7;

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

int n;
int sz[maxN], mx[maxN], rt, mi;
LL ans = 0;

struct vec {
	static const int maxE = maxN;
	int g[maxN], te;
	struct edge {int y, d, nxt;} e[maxE << 1];
	inline void push(int x, int y, int d) { e[++te] = (edge){y, d, g[x]}; g[x] = te; }
	inline void link(int x, int y, int d) { push(x, y, d), push(y, x, d); }
	inline int& operator () (int x) { return g[x]; }
	inline edge& operator [] (int x) { return e[x]; }
}e;

void dfs(int x, int fa) {
	sz[x] = 1, mx[x] = 0;
	fore (e, x, y) if (y != fa) {
		dfs(y, x);
		ans += 2LL * e[p].d * min(sz[y], n - sz[y]);
		sz[x] += sz[y];
		mx[x] = max(mx[x], sz[y]);
	}
	mx[x] = max(mx[x], n - sz[x]);
	if (mx[x] < mi) mi = mx[x], rt = x;
}

int main() {

	n = ri();
	For (i, 1, n) {
		int x = ri(), y = ri(), z = ri();
		e.link(x, y, z);
	}

	mi = n;
	dfs(1, 0);

	fore (e, rt, y) if (mx[rt] == mx[y]) {
		printf("%lld\n", ans - e[p].d);
		return 0;
	}

	int rr = 1000000007; 
	fore (e, rt, y) rr = min(rr, e[p].d);
	printf("%lld\n", ans - rr);

	return 0;
}

Measured memory_bytes: 7680
#include <bits/stdc++.h>
#define rep(i, a) for (ll i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
  ll n,m;
  cin >> n >> m;
  vector<ll> a(m),b(m);
  vector<ll> v;
  vector<ll> v1;
  rep(i,m){
    cin >> a[i] >> b[i];
    if(a[i] == 1 || b[i] == 1){
      if(a[i] < b[i]){
        v.pb(b[i]);
      }else{
        v.pb(a[i]);
      }
    }
    if(a[i] == n || b[i] == n){
      if(a[i] < b[i]){
        v.pb(a[i]);
      }else{
        v.pb(b[i]);
      }
    }
  }
  sort_1(v);
  rep(i,v.size()){
    if(v[i] == v[i+1]){
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 5492
#include <stdio.h>
int main(void){
    // Here your code !
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    //printf("%d %d %d\n",a,b,c);
    if(a==b){
        printf("%d\n",c);
    }
    else if(a==c){
        printf("%d\n",b);
    }
    else printf("%d\n",a);
    
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>


long solve(long n) {
    long temp = 1;
    for (long i = 1; i*i <= n; ++i) {
        if (n % i == 0 && temp + n/temp > i + n/i) {
            temp = i;
        }
    }
    return temp;
}


int main () {
    long n, m;

    scanf("%ld", &n);
    m = solve(n);
    printf("%ld\n", m + n/m - 2);
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

vector<pair<LL, LL>> prime_gen(LL n){
    vector<pair<LL, LL>> out;
    for(LL i=2; i*i<=n; i++){
        if(n%i!=0){
            continue;
        }
        LL num=0;
        while(n%i==0){
            num++;
            n/=i;
        }
        out.push_back(make_pair(i, num));
    }
    if(n!=1){
        out.push_back(make_pair(n, 1));
    }

    return out;
}

int main(){
    LL n;
    LL ans=0;
    vector<pair<LL, LL>> prime_list;
    cin >> n;
    prime_list = prime_gen(n);
    for(int i=0; i<prime_list.size(); i++){
        LL p=prime_list[i].first;
        LL num=prime_list[i].second;
        LL e=1;
        while(num>=e){
            ans++;
            num-=e;
            e++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
 
using namespace std;
 
#ifdef SG
	#include <debug.h>
#else
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
#endif
 
#define ARG4(_1,_2,_3,_4,...) _4
 
#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)
 
#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)
 
#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())
 
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned char uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;
 
const ld pi = 3.1415926535897932384626433832795l;
 
template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}
 
const int N = 510;
int n, m, h, w;
int a[N][N];
 
int main () {
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);
#ifdef SG
	freopen((problemname + ".in").c_str(), "r", stdin);
//	freopen((problemname + ".out").c_str(), "w", stdout);
#endif
	cin >> n >> m >> h >> w;
	forn(i, n)
		forn(j, m)
			a[i][j] = (n / h) * (m / w) + 1;
	for (int i = h - 1; i < n; i += h)
		for (int j = w - 1; j < m; j += w) 
			a[i][j] = -((n / h) * (m / w) + 1) * (w * h - 1) - 1;
	int sum = 0;
	forn(i, n)
		forn(j, m)
			sum += a[i][j];
	if (sum > 0) {
		puts("Yes");
		forn(i, n) {
			forn(j, m) {
				cout << a[i][j] << ' ';
			}
			cout << endl;
		}
		return 0;
	}
	puts("No");
			
	return 0;
}

Measured memory_bytes: 3072
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

S = gets.chomp

i = 0
first_zero_sum = 0
while i < S.length
  if i % 2 == 0
    first_zero_sum += 1 if S[i] == '0'
  else
    first_zero_sum += 1 if S[i] == '1'
  end
  i += 1
end

i = 0
first_one_sum = 0
while i < S.length
  if i % 2 == 0
    first_one_sum += 1 if S[i] == '1'
  else
    first_one_sum += 1 if S[i] == '0'
  end
  i += 1
end

puts [first_zero_sum, first_one_sum].min


Measured memory_bytes: 14592
#include<iostream>
#include<string>

using namespace std;

int main(){
    string s;int n;
    cin >> n >> s;
    int num = n/2;
    int flg = 0;
    if(n==1){
        flg =1;
    }else if(n%2==1){
        flg=1;
    }else{
        for(int i=0;i<num;i++){
        if(s[i] != s[i+num]){
            flg = 1;
        }
    }
    }
    if(flg == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;



}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){

	int r,g,b;
  	cin >> r >> g >> b;
  	if((r*100+g*10+b)%4==0){
    	cout << "YES" << endl;
    }else{
    	cout << "NO" << endl;
    }
  
}

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

int main()
{
  int N ;
  cin >> N ;
  int H[N+1] ;
  for (int i = 1; i <= N; ++i)
    cin >> H[i];
  int minCost[N+1];         //minCost[i,i+1....N] gives the minimum cost to move from i to N.
  minCost[N] = 0 ;
  minCost[N-1] = abs(H[N]-H[N-1]) ;

  for (int i = N-2; i >= 1; --i)
    minCost[i] = min(abs(H[i+1]-H[i])+minCost[i+1], abs(H[i+2]-H[i])+minCost[i+2]) ;

  cout << minCost[1] << endl ;
  
  return 0 ;

}

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

using namespace std;

typedef pair<long long int, vector<long long int>> PLVL;

int main(){
	long long int N, M, X;
	cin >> N >> M >> X;
	vector<long long int>D(M);
	long long int ans = M;
	for( size_t i = 0; i < M; i++ ){
		cin >> D[i];
		if( D[i] > X ){
			ans = i;
			break;
		}
	}
	cout << min(ans, M - ans) << endl;
}



Measured memory_bytes: 256
import math


n,m = map(int,input().split())
S = []
C = []
for i in range(m):
    s,c = map(int,input().split())
    S.append(s-1)
    C.append(c)

max_value = 10 ** n
min_value = 10 ** (n-1)

if n == 1:
    min_value = 0

def check(s):
    for i in range(len(S)):
        if(int(s[S[i]])!=int(C[i])):
            return False
    return True


def solve():
    for i in range(min_value,max_value):
        s = str(i)
        if check(s):
            return i
    return -1


print(str(solve()))


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

#define each(i, c) for (auto& i : c)

typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9+7;

int main() {
  ll n;
  cin >> n;

  ll pn = 0;
  for (ll i = 0; i < n; ++i) {
    ll p;
    cin >> p;
    pn += (p * ll(pow(10, n-i-1)));
  }

  ll qn = 0;
  for (ll i = 0; i < n; ++i) {
    ll q;
    cin >> q;
    qn += (q * ll(pow(10, n-i-1)));
  }

  vector<ll> v(n);
  for (ll i = 0; i < n; ++i) {
    v[i] = i+1;
  }

  vector<ll> vs;
  do {
    ll val = 0;
    for (ll i = 0; i < n; ++i) {
      val += (v[i] * ll(pow(10, n-i-1)));
    }
    vs.push_back(val);
  } while( next_permutation(v.begin(), v.end()) );
  sort(vs.begin(), vs.end());

  ll a = 0;
  ll b = 0;
  for (ll i = 0; i < vs.size(); ++i) {
    if (vs[i] == pn) {
      a = i+1;
    }
    if (vs[i] == qn) {
      b = i+1;
    }
  }

  cout << abs(a - b) << endl;

  return 0;
}

Measured memory_bytes: 892
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define N 200010
using namespace std;
int a[N], preMin[N];
int main() {
	int n, t, ans = 0, cnt;
	scanf("%d%d", &n, &t);
	preMin[0] = 1000000001;
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		preMin[i] = min(preMin[i - 1], a[i]);
		if (a[i] - preMin[i] > ans) {
			cnt = 1;
			ans = a[i] - preMin[i];
		}
		else if (a[i] - preMin[i] == ans) {
			cnt++;
		}
	}
	
	printf("%d\n", cnt);
}

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

int main() {
    int N;
    cin >> N;
    vector<double> A(N);
    vector<string> JorB(N);
    for(int i=0;i<N;i++){
        cin >> A.at(i);
        cin >> JorB.at(i);
    }

    double money = 0;
    for(int j=0;j<N;j++){
        if(JorB.at(j)=="JPY"){
            money = money + A.at(j);
        }
        else{
            money = money + A.at(j)*380000;
        }
    }
    cout << money << endl;

}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int n,r=0,i,j,k,c;
	scanf("%d",&n);
	if(n<105) r=0;
	else if(n==105) r=1;
	else 
	{
		r=1;
		for(i=107;i<=n;i+=2)
		{
			c=0;
			for(j=1;j*j<i;j++)
			{
				if(j*j==i) c+=1;
				else if(i%j==0) c+=2;
			}
			if(c==8) r++;
		}
	} 
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef long double ld;


int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N,0);
    map<ll,ll> mp;

    rep(i, N){
        ll x;
        cin >> x;
        mp[x]++;
    }

    rep(i, M){
        ll num1, num2;
        cin >> num1 >> num2;
        mp[num2] += num1;
    }

    ll ans = 0;
    ll c = N;
    for (auto p = mp.rbegin(); p != mp.rend(); ++p)
    {
        pair<ll, ll> q = *p;
        ans += q.first * min(c, q.second);
        c -= q.second;
        if (c <= 0)
            break;
    }

    cout << ans << endl;
}

Measured memory_bytes: 16464
#include <stdio.h>
#define MAX 200000
int main(void){
  long long a,b,i;
  char s[MAX + 2];
  scanf("%s",s);
  for(i = a = b = 0;i < MAX && s[i] != '\0';i++){
    a += (s[i] == 'W')*(b += (s[i] == 'B'));
  }
  printf("%lld\n",a);
  return 0;
}



Measured memory_bytes: 384
use std::io::Read;
use std::cmp::min;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let a: Vec<i64> = (0..n).map(|_| it.next().unwrap().parse().unwrap()).collect();
    let mut g = vec![vec![]; n];
    for _ in 1..n {
        let a = it.next().unwrap().parse::<usize>().unwrap() - 1;
        let b = it.next().unwrap().parse::<usize>().unwrap() - 1;
        g[a].push(b);
        g[b].push(a);
    }
    let mut q = vec![];
    let mut stack = vec![(0, 0)];
    while let Some((v, p)) = stack.pop() {
        q.push(v);
        let g = &mut g[v];
        for i in (0..g.len()).rev() {
            if g[i] == p {
                g.swap_remove(i);
                break;
            }
        }
        for &u in g.iter() {
            stack.push((u, v));
        }
    }
    let inf = 10_000_000_000_000i64;
    let mut dp1 = vec![vec![]; n];
    let mut dp2 = vec![vec![]; n];
    for &v in q.iter().rev() {
        dp1[v] = vec![a[v]];
        dp2[v] = vec![a[v]];
        if a[v] < 0 {
            dp1[v][0] = inf;
        }
        for &u in &g[v] {
            let mut next1 = vec![inf; dp1[v].len() + dp1[u].len()];
            let mut next2 = vec![inf; dp2[v].len() + dp2[u].len()];
            for i in 0..dp1[v].len() {
                for j in 0..dp1[u].len() {
                    next1[i + j] = min(next1[i + j], dp1[v][i] + dp1[u][j]);
                    next2[i + j] = min(next2[i + j], dp1[v][i] + dp2[u][j]);
                    next2[i + j] = min(next2[i + j], dp2[v][i] + dp1[u][j]);
                    next2[i + j] = min(next2[i + j], dp2[v][i] + dp2[u][j]);
                    if dp2[u][j] < 0 || dp1[u][j] < inf {
                        next1[i + j + 1] = min(next1[i + j + 1], dp1[v][i]);
                        next2[i + j + 1] = min(next2[i + j + 1], dp2[v][i]);
                    }
                }
            }
            dp1[v] = next1;
            dp2[v] = next2;
            dp1[u].clear();
            dp1[u].shrink_to_fit();
            dp2[u].clear();
            dp2[u].shrink_to_fit();
        }
    }
    for i in 0..n {
        if dp1[0][i] < inf || dp2[0][i] < 0 {
            println!("{}", i);
            return;
        }
    }
}

fn main() {
    run();
}


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

int main() {
  double W, H, x, y;
  cin >> W >> H >> x >> y;
  double ans;
  ans = W*H/2;
  cout << fixed;
  cout << setprecision(10) << ans << " ";
  
  if(W == x*2 && H == y*2) cout << 1 << endl;
  else cout << 0 << endl;
}

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

using namespace std;

long d[1111111], d0[1111111], v[1111111], z[555555];
int main() {
	int n, c = 0, p = 1e9 + 7;
	cin >> n;
	for (int i = 0; i < n; i++) {
		z[i + 1] = z[i];
		long a;
		scanf("%ld", &a);
		c ^= a;
		if (!c) {
			z[i + 1]++;
			if (*d) (*d *= 2) %= p;
			else *d = 1;
			continue;
		}
		if (v[c]) (d0[c] += d[c] * (z[i] - z[v[c]])) %= p;
		else d0[c] = 1;
		(d[c] += d0[c]) %= p;
		v[c] = i + 1;
	}
	if (c) {
		cout << d0[c] << endl;
		return 0;
	}
	while (++c < 1 << 20)
		(*d += d[c]) %= p;
	cout << *d << endl;
	return 0;
}


Measured memory_bytes: 30080
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main(){
    ll A,B;
    cin >> A >> B;
    ll a = 2;
    set<ll> a_cnt;
    set<ll> b_cnt;
    ll A_copy = A;
    ll B_copy = B;
    while(A!=1&&a*a<=A_copy){
        while(A%a==0){
            A/=a;
            a_cnt.insert(a);
        }
        a++;
    }
    a_cnt.insert(1);
    a_cnt.insert(A);
    a = 2;
    while(B!=1&&a*a<=B_copy){
        while(B%a==0){
            B/=a;
            b_cnt.insert(a);
        }
        a++;
    }
    b_cnt.insert(1);
    b_cnt.insert(B);
    ll ans = 0;
    for(ll b:a_cnt){
        if(b_cnt.count(b)){
            ans++;
        }
    }
    cout<<ans<<endl;

    return 0;
}


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


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

  cout << "ABC" + n << endl;
  
  return 0;
}

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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  for(int i = 0; i < N; i++){
    cin >> p.at(i);
  }
  sort(p.begin(), p.end());
  int result = 0;
  for(int i = 0; i < K; i++){
    result += p.at(i);
  }
  cout << result << endl;
}

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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<llll> vllll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define repC3(vari,varj,vark,n)  for(int vari=0;vari<(n)-2;++vari)for(int varj=vari+1;varj<(n)-1;++varj)for(int vark=varj+1;vark<(n);++vark)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }
template<typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template<typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }


ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

const ll half = DIV(1LL, 2LL);

inline ll avg(ll a, ll b) {
    return MUL(ADD(a, b), half);
}

ll solve(int N, int Q, vi& a, vi& qx, vi& qy) {
    vector<vll> dp(N, vll(N, 0));
    rep(i,N) rep(j,N) if (a[i] > a[j]) dp[i][j] = 1;

    rep(q,Q) {
        int x = qx[q], y = qy[q];
        rep(i,N) {
            if (i != x && i != y) {
                dp[x][i] = dp[y][i] = avg(dp[x][i], dp[y][i]);
                dp[i][x] = dp[i][y] = avg(dp[i][x], dp[i][y]);
            }
            dp[x][y] = dp[y][x] = avg(dp[x][y], dp[y][x]);
        }
    }

    ll ans = 0;
    repC2(i,j,N) ans = ADD(ans, dp[i][j]);
    ans = MUL(ans, POW(2, Q));
    return ans;
}

int main() {
    int N,Q; scanf("%d%d", &N, &Q);
    vi a(N);
    rep(i,N) scanf("%d", &a[i]);
    vi x(Q), y(Q);
    rep(i,Q) {
        scanf("%d%d", &x[i], &y[i]);
        --x[i]; --y[i];
    }
    cout << solve(N,Q,a,x,y) << endl;
    return 0;
}


Measured memory_bytes: 72832