akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

const long long MOD = (long long)1e9 + 7;

long long mod_pow(long long x_, long long y_){
    if(y_ == 0) return 1;
    long long res = mod_pow(x_ * x_ % MOD, y_ / 2);
    if(y_ & 1) res =  x_ * res % MOD;
    return res;
}

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    vector<ll> p(60);
    for(int i = 0; i < 60; i++){
        ll x = 0, y = 0;
        for(int j = 0; j < n; j++){
            if(((a[j] >> i) & 1) == 1){
                x++;
            }else{
                y++;
            }
        }
        p[i] = x * y;
        p[i] %= MOD;
    }
    ll ans = 0, d = 1;
    for(int i = 0; i < 60; i++){
        ans += d * p[i];
        ans %= MOD;
        d *= 2;
        d %= MOD;
    }
    cout << ans << endl;
    return 0;
}


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

#define ll long long
#define mod 1000000007
#define IO_fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main(){
    IO_fast
    string s, t;
    cin >> s >> t;
    int mincount = t.size();
    for(int i = 0 ; i<=s.size()-t.size() ; i++){
        int count = 0;
        for(int j = 0 ; j<t.size() ; j++){
            if(s[i+j]!=t[j]) count++;
        }
        if(count<mincount) mincount = count;
    }
    cout << mincount << endl;
    return 0;
}


Measured memory_bytes: 3656
n, m = gets.split.map(&:to_i)

a = Array.new
b = Array.new

n.times{
  a.push(gets.split.map(&:to_i))
}

m.times{
  b.push(gets.to_i)
}


c = Array.new



n.times{|i|
  sum = 0
  m.times{|j|
    sum += a[i][j]*b[j]
  }
  c.push(sum)
}

puts c



Measured memory_bytes: 9012
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <tuple>
#include <cassert>
#include <memory>
using namespace std;
typedef long long ll;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

ll N,S;
ll A[3010];
ll MOD = 998244353LL;

// i: 何番目か, j:合計, k: 0-Lが未確定, 1-Lが確定R未確定, 2-LとRが確定
ll dp[3010][7010][3];

int main ()
{
    cin >> N >> S;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    dp[0][0][0] = 1LL;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= S; j++) {
            (dp[i + 1][j][0] += dp[i][j][0]) %= MOD;
            (dp[i + 1][j + A[i]][1] += dp[i][j][0] * (i + 1)) %= MOD;
            (dp[i + 1][j + A[i]][2] += dp[i][j][0] * (i + 1) * (N - i)) %= MOD;

            (dp[i + 1][j][1] += dp[i][j][1]) %= MOD;
            (dp[i + 1][j + A[i]][1] += dp[i][j][1]) %= MOD;
            (dp[i + 1][j + A[i]][2] += dp[i][j][1] * (N - i)) %= MOD;

            (dp[i + 1][j][2] += dp[i][j][2]) %= MOD;
        }
    }

    cout << dp[N][S][2] << endl;

    return 0;
}


Measured memory_bytes: 492800
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define MX 10000000000
#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

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

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
	{
		return gcd(b, a % b);
	}
}
ll a[200005], s[200005];
map<ll, ll>m;
void solve()
{
	ll n, k;
	cin >> n >> k;
	for (ll i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	ll sz = 0;
	ll sol = 0;
	if (k == 1)
	{
		cout << "0";
		return;
	}
	m[0]++;
	for (ll i = 1; i <= n; i++)
	{
		s[i] = s[i - 1] + a[i];
		sol = sol + m[(s[i] - i) % k];
		sz++;
		m[(s[i] - i) % k]++;
		if (sz == (k - 1))
		{
			m[(s[i - (k - 1)] - (i - (k - 1))) % k]--;
			sz--;
		}
	}
	cout << sol;

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



Measured memory_bytes: 15872
#include<iostream>
using namespace std;
int main(){
  int h,w;
  while(true){
    cin >> h >> w;
    if(h==0&&w==0) break;
    for(int i = 0;i < h;i++){
      for(int j = 0;j < w;j++){
    if(i%2 == 0 && j%2 == 0 || i%2 == 1 && j%2 == 1){
      cout << "#";
    }else{
      cout << ".";
    }
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
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; }
typedef long long ll;

const long long INF = 1LL << 60;
typedef pair<int, int> P;

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

    vector<P> eval(N);
    rep(i, N) {
        cin >> eval[i].first >> eval[i].second;
    }

    sort(eval.begin(), eval.end());
    priority_queue<int> que;

    ll ans = 0;
    int index = 0;
    repd(cnt, 1, M + 1) {
        repd(i, index, N) {
            if (eval[i].first == cnt) que.push(eval[i].second);
            if (eval[i].first != cnt) {
                index = i;
                break;
            }
        }
        if (!que.empty()) {
            ans += que.top();
            que.pop();
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1788
//file_name:ABC67_C.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


int main() {
    int n;
    scanf("%d",&n);
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
        if(i>0){
            a[i]+=a[i-1];
        }
    }


    ll ans = 1000000000000;

    rep(i,n-1){
        ans = min(ans,abs(a[n-1]-a[i]-a[i]));
    }

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



Measured memory_bytes: 1792
def solve():
    n = int(input())
    if n == 1:
        print(1)
        return
    elif n == 2:
        print(2)
        return
    ans = []
    anssum = 0
    for i in range(1, n):
        ans.append(str(i))
        anssum += i
        if anssum >= n:
            if anssum == n:
                print("\n".join(ans))
            else:
                ans.remove(str(anssum - n))
                print("\n".join(ans))
            return
    print("\n".join(ans))

if __name__=="__main__":
    solve()

Measured memory_bytes: 39920
/*An anomaly, I'm Muhammad Ali
  'Cause I know one day I'm gonna be the*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const  int mod = 1000000007;
void add(ll& a, ll b)
{
    a+=b;
    while(a>=mod)
        a-=mod;
    while(a<0)
        a+=mod;
    
}
void sub(ll& a, ll b)
{
	a-=b;
	while(a<0)
		a+=mod;
	while(a>=mod)
		a-=mod;
}
void mul(ll& a, ll b)
{
	a = (a*b)%mod;
}
ll binexpomodulo(ll x, ll y)
{
	ll res =1;
	x%=mod;
	if(!x)
		return 0;
	while(y)
	{
		if(y&1)
		{
			mul(res, x);
		}
		mul(x,x);
		y>>=1;
	}
	return res;
}
ll nCrInOr(ll n, ll r)
{
	ll res = 1 ;
	if(r>n-r)
		r = n-r;
	ll rin = 1;
	for(ll i = 1; i <=r ; i++)
		rin = (rin*i)%mod;
	rin = binexpomodulo(rin,mod-2);
	for(ll i = 1; i <= r; i++)
		res = (res*(n-i+1))%mod;
	res = (res*rin)%mod;
	return res;
}

int main()
{
	ll n,a,b;
	cin>>n>>a>>b;
	ll ans = binexpomodulo(2LL, n) - 1;
	sub(ans,nCrInOr(n,a));
	sub(ans,nCrInOr(n,b));
	cout<<ans<<endl;
  	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    double sum=0;
    rep(i,n)sum+=(double)1/a[i];
    sum=1/sum;
    cout<<fixed<<setprecision(6)<<sum<<endl;
}


Measured memory_bytes: 3728
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

ll f(ll b, ll n) {
    ll ret = 0;
    while(n > 0) {
        ret += n % b;
        n /= b;
    }
    return ret;
}

vll div(ll n) {
    vll ret;
    ret.push_back(1);
    for(ll i = 2; i * i <= n; i++) {
        ll b = 1;
        ll m = ret.size();
        while(n % i == 0) {
            b *= i;
            for(ll i = 0; i < m; i++) {
                ret.push_back(b * ret[i]);
            }
            n /= i;
        }
    }
    ll m = ret.size();
    if(n > 1) {
        for(ll i = 0; i < m; i++) {
            ret.push_back(n * ret[i]);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}

void solve() {
    ll n, s;
    cin >> n >> s;
    ll b = 2;
    while(b * b <= n) {
        if(f(b, n) == s) {
            cout << b << endl;
            return;
        }
        b++;
    }
    if(n - s < 0) {
        cout << -1 << endl;
        return;
    }
    else if(n == s) {
        cout << n + 1 << endl;
        return;
    }
    vll v = div(n - s);
    sort(v.begin(), v.end(), greater<ll>());
    for(auto i : v) {
        ll bb = (n - s) / i + 1;
        if(!(bb >= b)) continue;
        if(!(0 <= i && i <= bb - 1)) continue;
        if(!(0 <= (s - i) && (s - i) <= bb - 1)) continue;
        cout << bb << endl;
        return;
    }
    cout << -1 << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cstring>
#include <queue>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <bitset>

using namespace std;

//#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

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

//static const ll MOD = 1000000007;
//static const ll INF = 100000000;

int main() {
    // input
    ll N;
    vector<string> S;
    cin >> N;
    for (ll i = 0; i < N; i++) {
        string s;
        cin >> s;
        S.emplace_back(s);
    }

    // process
    sort(S.begin(), S.end());
    vector<string> vote_name;
    vector<ll> voted_num;
    ll current_number = 0;

    vote_name.emplace_back(S[0]);
    voted_num.emplace_back(1);
    for (ll i = 1; i < N; i++) {
        if (S[i] == vote_name[current_number]) {
            voted_num[current_number]++;
        } else {
            vote_name.emplace_back(S[i]);
            voted_num.emplace_back(1);
            current_number++;
        }
    }

    ll max = *max_element(voted_num.begin(), voted_num.end());

    for (ll i = 0; i < voted_num.size(); i++) {
        if (voted_num[i] == max) {
            cout << vote_name[i] << endl;
        }
    }

    return 0;
}

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

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 400+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 998244353;

int n,a[maxn],b[maxn],f[maxn][maxn],fac[maxn],ifac[maxn];

int qpow(int a,int x) {
    int res=1;
    for(;x;x>>=1,a=1ll*a*a%mod) if(x&1) res=1ll*res*a%mod;
    return res;
}

void gen() {
    fac[0]=ifac[0]=1;
    for(int i=1;i<maxn;i++) fac[i]=1ll*fac[i-1]*i%mod;
    ifac[maxn-1]=qpow(fac[maxn-1],mod-2);
    for(int i=maxn-2;i;i--) ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
}

int main() {
    gen();
    read(n);int s=0;
    for(int i=1;i<=n;i++) read(a[i]),read(b[i]),s+=a[i];
    f[0][0]=mod-1;
    int ss=0,tt=0;
    for(int i=1;i<=n;i++) {
        ss+=a[i],tt+=b[i];
        for(int j=ss;j>=a[i];j--) {
            for(int k=0;k<=tt;k++) {
                int w=1;
                for(int x=0;x<b[i]&&x<=k;x++) {
                    f[j][k]=(f[j][k]-1ll*f[j-a[i]][k-x]*w%mod*ifac[x]%mod+mod)%mod;
                    w=1ll*w*a[i]%mod;
                }
            }
        }
    }int ans=0;
    for(int i=1;i<=ss;i++) {
        int r=qpow(i,mod-2),w=1ll*r*ss%mod;
        for(int j=0;j<=tt;j++,w=1ll*w*r%mod)
            ans=(ans+1ll*f[i][j]*fac[j]%mod*w%mod)%mod;//,printf("%d %d %d\n",i,j,f[i][j]);
    }
    write((ans+mod)%mod);
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,m;
    cin>>n>>m;
    vector<string> s,t;
    for(int i=0;i<n;i++){
    string ss;
    cin>>ss;
    s.push_back(ss);
    }
    for(int i=0;i<m;i++){
        string ss;
        cin>>ss;
        t.push_back(ss);
    }
    for(int i=0;i<n-m+1;i++){
        for(int j=0;j<n-m+1;j++){
            bool ok=true;
            for(int k=0;k<m;k++){
                for(int kk=0;kk<m;kk++){
                    if(s[i+k][j+kk]!=t[k][kk]){ok=false;break;}
                }
            }
            if(ok){cout<<"Yes"<<endl;return 0;}
        }
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())

parent = [-1] * N


def get_group_root(x):
    if parent[x] < 0:
        return x
    return get_group_root(parent[x])


for i in range(0, M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1

    groupA = get_group_root(A)
    groupB = get_group_root(B)

    if groupA == groupB:
        continue
    elif parent[groupA] < parent[groupB]:
        parent[groupB] = A
        parent[groupA] -= 1
    else:
        parent[groupA] = B
        parent[groupB] -= 1


def check(x):
    return x < 0


print(sum(list(map(check, parent))) - 1)


Measured memory_bytes: 13436
#include<bits/stdc++.h>
		#include <bitset>
		using namespace std;
		#define ll long long 
		#define ld long double
		#define MOD 1000000007
		#define mod9 1000000009
		#define mod 1000003
		#define fast ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
		#define mp make_pair
		#define pb push_back
		#define ct ll t;cin>>t;while(t--)
		#define bi begin()
		#define ei end()
		#define fi first 
		#define se second   	
		bool isPrime(ll n) 
		{ 
			// Corner case 
			if (n <= 1) 
				return false; 
			
			// Check from 2 to n-1 
			for (ll i = 2; i*i <= n; i++) 
				if (n % i == 0) 
					return false; 
			
			return true; 
		}
		long long binpow(long long a, long long b) {
			long long res = 1;
			while (b > 0) {
				if (b & 1)
					res = (res%mod) * (a%mod);
				a = (a%mod) * (a%mod);
				b >>= 1;
			}
			return res%mod;
		}

		bool compare(const pair<ll,ll>&a,const pair<ll,ll>&b)
		{
			return (a.se<b.se);
		}
		ll lcm(ll a,ll b)
		{
			return(a*b)/__gcd(a,b);
		}
		// vector<ll>s;
		void SieveOfEratosthenes() 
		{  
			ll n=10005;
			bool prime[1000005]; 
			memset(prime, true, sizeof(prime)); 
			// s[0]=1;
			// s[1]=1;
			for (int p=2; p*p<=n; p++) 
			{ 
				
				if (prime[p] == true) 
				{   
					for (int i=p*p; i<=n; i += p) {
						prime[i] = false; 
						// s[i]=1;
						}
				} 
			} 
			for(ll i=2;i<10005;i++)
			{
				if(prime[i])
				{
					// s.pb(i);
				}
			}
		} 
		void eea(ll a, ll b, ll & x, ll & y) {
		if (a == 0) {
			x = 0;
			y = 1;
			return ;
		}
		ll x1, y1;
		eea(b % a, a, x1, y1);
		x = y1 - (b / a) * x1;
		y = x1;
		return ;
	}
	ll modinverse(ll a,ll m)
	{
		ll x, y;
		eea(a, m, x, y);
		if (__gcd(a,m) != 1) {
		return -1;
		}
	else {
		x = (x % m + m) % m;
		cout << x << endl;
		return x;
	}
	}
		ll fact[1000007]={0};
		ll expo(ll x, ll y) {ll res=1;x=x%MOD;while(y>0){if(y&1)res=(1ll*res*x)%MOD;
		y=y>>1;x=(1ll*x*x)%MOD;} return res;}
		void facto() {fact[0]=1;fact[1]=1;for(ll i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%MOD;}
		ll npr(ll n,ll r) {facto(); ll res=1; res=fact[n]; res=(res*(expo(fact[n-r],MOD-2)))%MOD; return res; }
		ll ncr(ll n,ll r){ ll res=1; if(r>n-r)r=n-r; for(ll i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res;}
			
				
		int main()
		{
			fast
			ll n,m;
			cin>>n>>m;
			ll s=0,a;
			while(m--)
			{
				cin>>a;
				s+=a;
			}
			if(s>n)
			{
				cout<<"-1\n";
			}
			else
			{
				cout<<n-s<<"\n";
			}
			}

 

Measured memory_bytes: 3628
input = STDIN.read.split("\n").map{|l| l.split(" ").map{|i| i.to_i}}

N = input[0][0]
H = input[1]

INF = 1000000

BAG = {
}

def jump(i)
  if BAG.key?(i)
    return BAG[i]
  end

  if i == 0
    return 0
  end

  cost1 = INF
  cost2 = INF
  if i-1 >= 0
    cost1 = (H[i]-H[i-1]).abs
    cost1 += jump(i-1)
  end
  if i-2 >= 0
    cost2 = (H[i]-H[i-2]).abs
    cost2 += jump(i-2)
  end

  cost = [cost1, cost2].min
  BAG[i] = cost
  return cost
end

for i in 0..N-1 do
  c = jump(i)
end
puts c


Measured memory_bytes: 17532
import sys
readline = sys.stdin.readline

def f(a, b):
    return (1+(-(-a//b)-1).bit_length())//2

N = int(readline())
A = list(map(int, readline().split()))

dpr = [0]*N
Ar = A[:]
cnt = 0
for i in range(1, N):
    res = 0
    idx = i-1
    while cnt <= idx:
        k = f(Ar[idx+1], Ar[idx])
        if k:
            Ar[idx] *= 4**k
            res += k
        idx -= 1
        if not k:
            break
    else:
        dpr[i] += cnt*k
    dpr[i] += dpr[i-1] + res
    while cnt < i:
        if Ar[cnt] < Ar[cnt+1]*4:
            cnt += 1
        else:
            break

dpl = [0]*N
Al = A[:]
cnt = N-1
for i in range(N-2, -1, -1):
    res = 0
    idx = i+1
    while cnt >= idx:
        k = f(Al[idx-1], Al[idx])
        if k:
            Al[idx] *= 4**k
            res += k
        idx += 1
        if not k:
            break
    else:
        dpl[i] += (N-1-cnt)*k
    dpl[i] += dpl[i+1] + res
    while cnt > i:
        if Al[cnt] < Al[cnt-1]*4:
            cnt -= 1
        else:
            break
dpl = [2*dpl[i] for i in range(N)]
dpr = [0] + [i+1+2*dpr[i] for i in range(N)]
inf = 10**20
ans = inf
for i in range(N):
    ans = min(ans, dpr[i] + dpl[i])
print(ans)

Measured memory_bytes: 109136
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int n,i;
	ll s=0ll,l,m=-INFLL;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> l;
		s += l;
		m = max(m,l);
	}
	s -= m;
	cout << ((s>m)?"Yes":"No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,p,j,a[5];
    for(i=1;i<=5;i++)
    {
        cin>>a[i];
    }
    for(j=1;j<=5;j++)
    {
        if(a[j]==0)
        {
           p=j;
        }
    }
    cout<<p;
}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>
#include <map>
 
using namespace std;
typedef long long int ll;

ll MOD = 1000000007;
 
int main(){

    string S;
    cin >> S;

    vector<vector<ll > > dp(S.length() + 1, vector<ll >(13, 0));

    dp[0][0] = 1;

    for(ll i = 0; i < S.length(); i++){

        //0~9までを入れたとき前からのMODがどう変化するか
        for(ll j = 0; j < 10; j++){
            //？ではなく数字が書かれているときは数字分の遷移しか考えない
            if(S[i] != '?' && (S[i] - '0') != j ){
                continue;
            }
            for(ll h = 0; h < 13; h++){
                dp[i + 1][(h * 10 + j) % 13] += dp[i][h];
            }
        }

        //答えが超えないように割っておく
        for(ll j = 0; j < 13; j++){
            dp[i + 1][j] %= MOD;
        }
    }
 
    cout << dp[S.length()][5] << endl;

}  

Measured memory_bytes: 13696
/***
*	author  :_shamim
*	created : 05.05.2020
*
***/

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <list>
#include <set>
#include <queue>
#include <iterator>
#include <bitset>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#define ll             long long
#define _              ios_base::sync_with_stdio(0);cin.tie(0);
#define loop           for(i=0;i<n;i++)
#define pb             push_back
#define tc()           int t;cin>>t;while(t--)          

using namespace std;

ll i,j,temp;

int main()
{_
	
	int N,pos,neg;
	cin>>N;

	cout<<"ABC"<<N<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long A,B,C,D,E,F,G,H,I,J,K,L,M,N,T,W,X,Y;
  string S;
  cin >>  N >> M;
  A=0;
  
  vector<long long> vec(N);
  for (int i=0;i<N;i++) {cin >> vec.at(i);A+=vec.at(i);}
  
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  //cout << vec[0] << vec[1];
  F=0;
  for (int j=0;j<M;j++) {if (vec.at(j)*4*M<A) {F=1;}}
  if (F==0) {cout << "Yes" << endl;} else {cout << "No" << endl;}
  
  
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/agc005/tasks/agc005_a

# 'ST'を抜け。
# 文字列を連長圧縮、先頭は必ずSを、最後には必ずTになるようにする(0個を許容)
# そしたらSTSTSTSTの文字数なので二個ずつabs(n_s-n_t)を取っていけばよい。ただしTが先になくなるときは、Sの余りを次のSに移し替えなければ行けない
# とかいろいろ考えたけどおとなしくstackで実装
# ここでは何文字STができたかを数える


X = input()

# おとなしくstackで実装し直す
stack = []
n_poped = 0
for x in X:
    if x == 'S':
        stack.append(1)
    elif x == 'T':
        if stack:
            stack.pop()
            n_poped += 2

print(len(X) - n_poped)


Measured memory_bytes: 4328
a, b, k = [int(x) for x in input().split()]
b += 1

k_temp = b - a
if k > k_temp:
    k = k_temp

l = k
if k + l > b - a:
    l = b - a - k

ans = [x for x in range(a, a + k)]
ans.extend(range(b - l, b))
print(' '.join([str(x) for x in ans]))


Measured memory_bytes: 3060
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

#a = list(map(int, input().split()))

#####################################


#4:40
def nu(x):
    return ord(x)-ord('a')
s=input()

if(s[0]==s[1]):
    print(1,2)
    exit()

for i in range(len(s)-2):
    if(s[i]==s[i+1]):
        print(i+1,i+2)
        exit()
    if(s[i]==s[i+2]):
        print(i+1,i+3)
        exit()
        
print("-1 -1")

Measured memory_bytes: 39536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int N=6666;
ll n,k;
ll c[N][N];
ll dp[N];
ll C(ll n,ll m)
{
    if(c[n][m]) return c[n][m];
    if(m==0||n==m) return 1;
    if(m==1) return n;
    return c[n][m]=(C(n-1,m-1)+C(n-1,m))%mod;
}
int main()
{
    scanf("%lld%lld",&n,&k);
    int s=n-k;
    for(int i=1;i<=s;i++)
        dp[i]=C(s-1,i-1);
    for(int i=1;i<=k;i++)
    {
        if(i>n-k+1)
        {
            printf("0\n");
            continue;
        }
        ll ans = 1;
        ans = C(k-1,i-1) * C(n-k+1,i) % mod;
        printf("%lld\n",ans);
    }
}

Measured memory_bytes: 102912
//#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cstring>
#include <cassert>

using namespace std;

#ifdef LOCAL_DEBUG
#include <local_debug.h>
#define DEBUG(x...) {                                       \
   cerr << "\e[91m";                                        \
   cerr << __LINE__ << ": " << #x << " = "; DBG::_print(x); \
   cerr <<"\e[39m";                                         \
}
#else
#define DEBUG(x...)
#endif

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;



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

   int N, K;
   cin >> N >> K;

   vector<int> P(N);
   REP(i, N)
      cin >> P[i];

   sort(P.begin(), P.end());

   int res = 0;
   REP(i, K)
      res += P[i];

   cout << res << endl;

   return 0;
}


Measured memory_bytes: 3596
import numpy as np
N,M=list(map(int,input().split()))
H=list(map(int,input().split()))
F=[0]*len(H)
for i in range(M):
  A,B=list(map(int,input().split()))
  if(H[A-1]<H[B-1]):
    F[A-1]=1
  elif(H[A-1]>H[B-1]):
    F[B-1]=1
  else:
    F[B-1]=1
    F[A-1]=1
print(F.count(0))

Measured memory_bytes: 38608
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f

using namespace std;
using namespace __gnu_pbds;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<pair<int,int>,null_type, less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>   ordered_set;
const int N=1e5+100, mod=1e9+7;

int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	string s,t; int ct=0;
	cin>>s>>t;
	for(int i=0;i<3;i++)ct+=(s[i]==t[i]);
	cout<<ct;
}




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

int main() {
  int N;
  cin >> N;
  
  vector<char> cap(N);
  
  for(int i=0; i<N;i++){
   cin >> cap.at(i);
  }
  
  int red=0, blue=0;
  
  for(int i=0; i<N;i++){
   if(cap.at(i)=='R') {
     red +=1;
   }else{
    blue +=1; 
   }
  }
  
  if(red>blue){
   cout<<"Yes"<<endl; 
  }
  else{
   cout<<"No"<<endl; 
  }
}

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

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0; i<n; i++)
    cin >> v[i];
    int minv,maxv;
    minv = v[0];
    maxv = v[1]-v[0];
    for(int i=1; i<n; i++){
        maxv = max(maxv,v[i]-minv);
        minv = min(minv,v[i]);
    }
    cout << maxv << endl;
}


Measured memory_bytes: 3616
N=int(input())
X=list(map(int,input().split()))
Y=[X[i] for i in range(N)]
Y.sort()

a=Y[int((N-1)/2)]
b=Y[int((N+1)/2)]

for i in range(N):
    if X[i]<a:
        print(b)
    elif X[i]>b:
        print(a)
    else:
        if X[i]==a:
            print(b)
        elif X[i]==b:
            print(a)


Measured memory_bytes: 25224
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


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

  vector<vector<int>> used(100010, vector<int>(30, 0));
  REP(i, N){
    int s, t, c;
    cin >> s >> t >> c;
    used[s][c-1]++;
    used[t+1][c-1]--;
  }

  int ans = 0;
  REP(i, 100000){
    int ret = 0;
    REP(j, C){
      used[i+1][j] += used[i][j];
      if(used[i+1][j]) ret++;
    }
    chmax(ans, ret);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 27648
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
    string field;
    cin >> field;
    int height = 0;
    stack<pair<int, int>> downs;
    vector<pair<pair<int, int>, int>> pools;
    int sum_vol = 0;
    for (int i = 0; i < field.size(); i++) {
        switch (field[i]) {
        case '/':
            if (downs.empty()) {
                continue;
            } else {
                int left = downs.top().first;
                downs.pop();
                pair<pair<int, int>, int> p(make_pair(left, i), i - left);
                sum_vol += i - left;
                while (!pools.empty()
                       && left < pools.back().first.first
                       && pools.back().first.second < i) {
                    int vol = pools.back().second;
                    pools.pop_back();
                    p.second += vol;
                }
                pools.push_back(p);
            }
            break;
        case '\\':
            downs.push(make_pair(i, height--));
            break;
        case '_':
            break;
        }
    }
    sort(begin(pools), end(pools));
    cout << sum_vol << endl;
    cout << pools.size();
    for (auto p : pools) {
        cout << " " << p.second;
    }
    cout << endl;
}

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

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

const long long MOD = 1000000007;

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


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define mp make_pair
#define pb push_back
#define sqr(x) (x)*(x)
#define matrix vector < vector<int> >

using namespace std;

const double eps = 1e-9;
const double PI = acos(-1.0);
const int INF = int (1e9+7);
const int mod = int (1e9+7);
const int N = int (2e5+7);    

int n, k, ans, a[N];
vector <int> g[N];

int dfs(int v, int p = 1) {
	int maxi = 0;
	for(int to: g[v]) 
		maxi = max(maxi, dfs(to, v));
	if(maxi == k - 1 && p != 1) 
		ans ++, maxi = -1;
	return maxi + 1;
}

int main () { 
   	//freopen("peacefulsets.in", "r", stdin);
   	//freopen("peacefulsets.out", "w", stdout);  
   	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> k;
	for(int i = 1; i <= n; i ++) {
		cin >> a[i];
		if(i != 1)
			g[a[i]].pb(i);
	}
	if(a[1] != 1)
		a[1] = 1, ans ++;
	dfs(1);
	cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 13184
#include<stdio.h>
int main(){
  char tenki[3];
  int i=0,flag=0;
  scanf("%s",tenki);
   if(tenki[0]=='R'&&tenki[1]=='R'&&tenki[2]=='R'){
    flag=3;}
  else if(tenki[0]=='R'&&tenki[1]=='R'){
    flag=2;}
  else if(tenki[1]=='R'&&tenki[2]=='R'){
    flag=2;}
  else if(tenki[0]=='S'&&tenki[1]=='S'&&tenki[2]=='S'){
    flag=0;}
  else{
    flag=1;}
  printf("%d",flag);
  return 0;}


Measured memory_bytes: 1736
#include <vector>

class union_find
{
private:
	std::vector<int>parent;
	std::vector<int>rank;
public:
	union_find(int siz)
	{
		parent.resize(siz);
		rank.resize(siz);
		for (int i = 0; i < siz; ++i)
		{
			parent[i] = i;
			rank[i] = 0;
		}
	}
	void unite(int x, int y)
	{
		int xr = find(x);
		int yr = find(y);
		if (rank[xr] > rank[yr])
		{
			parent[yr] = xr;
		}
		else if (rank[xr] > rank[yr])
		{
			parent[xr] = yr;
		}
		else if (xr != yr)
		{
			parent[yr] = xr;
			++rank[xr];
		}
	}
	int find(int x)
	{
		if (parent[x] == x)
		{
			return x;
		}
		else
		{
			return parent[x] = find(parent[x]);
		}
	}
	bool check(int x, int y)
	{
		return find(x) == find(y);
	}
};

int n;
int q;

#include <cstdio>

int main()
{
	scanf("%d", &n);
	scanf("%d", &q);
	union_find uf(n);
	for (int i = 0; i < q; ++i)
	{
		int c, x, y;
		scanf("%d %d %d", &c, &x, &y);
		if (c == 0)
		{
			uf.unite(x, y);
		}
		else
		{
			if (uf.check(x, y))
			{
				printf("1\n");
			}
			else
			{
				printf("0\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2756
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

const ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}
int main() {
	int h, w, i, j;
	char a[111][111], ans[111][111];
	cin >> h >> w;
	for (i = 0; i < h; i++)
		cin >> a[i];
	for (i = 0; i < h + 2; i++){
		for (j = 0; j < w + 2; j++)
			ans[i][j] = '#';
      ans[i][w+2]='\0';
    }
	for (i = 0; i < h; i++)
		for (j = 0; j < w; j++)
			ans[i + 1][j + 1] = a[i][j];
	for (i = 0; i < h+2; i++)
		cout << ans[i] << endl;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int main(){
  map<string,int>data;
  int N,M;
  cin>>N;
  for(int i=0;i<N;i++){
    string tmp;
    cin>>tmp;
    data[tmp]++;
  }
  cin>>M;
  for(int i=0;i<M;i++){
    string tmp;
    cin>>tmp;
    if(data[tmp]>0)data[tmp]--;
  }
  int ans=0;
  for(auto a:data){
    auto value=a.second;
    ans=max(ans,value);
  }
  cout<<ans<<endl;


}

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

public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
                    
        str = br.readLine();
        String[] nums = str.split("\\s");

        double a = (Double.parseDouble(nums[2]) - Double.parseDouble(nums[0]));
        double b = (Double.parseDouble(nums[3]) - Double.parseDouble(nums[1]));

        double ans = Math.sqrt((Math.pow(a,2) + Math.pow(b,2)));
        
        System.out.println(ans);
        
        br.close();
        
    }

}



Measured memory_bytes: 24420
object Main extends App {
	val s = scala.io.StdIn.readLine.toList.toArray

	var ans = 0
	val L1 = Array('A', 'C', 'G', 'T')

	for(i<-0 until s.size){
		var j = i
		var tp = 0
		while(j < s.size){
			if(L1.contains(s(j))){
				j = j + 1
				tp = tp + 1
			}else{
				j = 100
			}
		}

		ans = math.max(ans, tp)
	}

	println(ans)


}

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

int n, m;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    vector<int> a(n);
    for (auto& i : a) cin >> i;
    sort(a.begin(), a.end());
	
	vector<pair<ll, ll>> pairs(m);
	for (auto& i : pairs) cin >> i.second >> i.first;
	sort(pairs.begin(), pairs.end());
	
	ll sum = 0, added = 0;
	int ai = n - 1, pi = m - 1;
	while (added < n) {
		if (pi >= 0 && ai >= 0) {
			if (pairs[pi].first >= a[ai]) {
				ll chosen = min(n - added, pairs[pi].second);
				sum += chosen * pairs[pi].first;
				added += chosen;
				pi--;				
			} else {
				sum += a[ai];
				ai--;
				added++;
			}
		} else if (pi >= 0) {
			int chosen = min(n - added, pairs[pi].second);
			sum += chosen * pairs[pi].first;
			added += chosen;
			pi--;
		} else {
			sum += a[ai];
			ai--;
			added++;
		}
	}
	cout << sum;
    return 0;
}


Measured memory_bytes: 2176
// g++ -std=c++14

/*

Today might be the chance to grasp the chance to let your talent bloom.
May be tomorrow, the day after, or next year...
May be even when you are 30. I'm not sure if physique has anything to do with it
but if you think that it will never come, it probably never will.

- Tooru Oikawa.

*/


#include<bits/stdc++.h>

typedef long long ll;
typedef long double lld;
using namespace std;

#define endl "\n"
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define all(c) c.begin(),c.end()
#define inf 1000000000000000001
#define pii pair<int, int>
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
ll l=v.size();for(ll i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template <typename T>
ostream &operator<<(ostream &out, set<T> const &v) {
    for (auto i = v.begin(); i != v.end(); i++)
        out << (*i) << ' ';
    return out;
}
template <typename T, typename V>
ostream &operator<<(ostream &out, map<T, V> const &v) {
    for (auto i = v.begin(); i != v.end(); i++)
        out << "\n" << (i->first) <<  ":"  << (i->second);
    return out;
}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

#define int ll


int solve() {
    string s;
    cin >> s;
    int n = s.size();
    if (s[0] == s[n - 1]) {
        if (n & 1) {
            cout << "Second\n";
        } else {
            cout << "First\n";
        }
    } else {
        int cnt = 0;
        int curr = 0;
        for (int i = 0; i < n; i++) {
            // tr(i, s[i], s[curr], cnt);
            if (s[i] != s[curr]) {
                cnt++;
            } else {
                if (curr == 0) curr = n - 1;
                else curr = 0;
            }
        }   
        // tr(cnt); 
        if (cnt & 1) {
            cout << "First\n";
        } else {
            cout << "Second\n";
        }
    }
    
}

int32_t main(){ _
    int t;
    // cin >> t;
    t = 1;
    while (t--) solve();
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define maxn 1200000
typedef long long LL;
const LL mod = 1000000007;
LL A[maxn], B[maxn];
void no(){
	cout << 0;
	exit(0);
}
int main(){
	int N, M;
	cin >> N >> M;
	for(int i = 1; i <= N; i += 1){
		int k;
		cin >> k;
		if(A[k]) no();
		A[k] = i;
	}
	for(int i = 1; i <= M; i += 1){
		int k;
		cin >> k;
		if(B[k]) no();
		B[k] = i;
	}
	LL ans = 1, sum = 0, row = 0, coj = 0;
	for(int i = N * M; i; i -= 1){
		if(A[i] == 0 && B[i] == 0){
			ans = ans * sum % mod;
			sum -= 1;
		}
		else if(A[i] == 0){
			ans = ans * row % mod;
			coj += 1;
			sum += row - 1;
		}
		else if(B[i] == 0){
			ans = ans * coj % mod;
			row += 1;
			sum += coj - 1;
		}
		else{
			sum += row + coj;
			row += 1;
			coj += 1;
		}
	}
	cout << ans;
}

Measured memory_bytes: 4352
/*
AizuOnline A0084
Search Engine
*/
#include <stdio.h>
#include <string.h>
char buffer[1025];

main()
{
   char *p;
   int  len;
   int  flag;
  
  while(fgets(buffer,1024,stdin))
    { flag = 0;
      p = strtok(buffer," ,.");

      while(p)
        {
          len = strlen(p);
          if(len > 2 && len < 7)
            {  if(flag)
                 printf(" ");
               printf("%s",p);
               flag=1;
            }
          p=strtok(NULL," ,.");
        }
      printf("\n");
    }


return(0);
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  sort(v.rbegin(), v.rend());
  int sum = 0;
  for (int i = 0; i < k; i++) {
    sum += v[i];
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
/**
 * The man who codes no bugs
 * McCheng is the man studying Maths in CUHK with IQ200
 * @author McCheng
 */

#include <bits/stdc++.h>
using namespace std;

class ACalc {
public:
    static constexpr int kStressCount = 0;
    static void generateTest(ostream& test) {}
	void solve(istream& cin, ostream& cout) {
        long long a;
cin>>a;
cout<<a+a*a+a*a*a;
	}
};

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream &in(cin);
    ostream &out(cout);
    out << fixed;
    out.precision(20);
    ACalc solver;
    solver.solve(in, out);
}


Measured memory_bytes: 3608
def resolve():
    import math
    n,k = map(int, input().split())
    a = list(map(int, input().split()))
    r = max(a)
    l = 0
    def cuttimes(p, cutter):
        return math.ceil(p/cutter)-1

    while r-l > 1:
        mid = (r+l)//2
        cut = 0
        for i in range(n):
            cut += cuttimes(a[i], mid)

        if cut <= k:
            r = mid
        else:
            l = mid
    print(r)

resolve()

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

int main(){
  int n,y;
  cin >> n >> y;
  
  bool can = false;
  
  int a,b,c;
  for(a = 0; a <= n; a++){
    for(b = 0; a+b <= n; b++){
      c = n - a - b;
      if(10000*a + 5000*b + 1000*c == y){
        can = true;
        cout << a << " " << b << " " << c;
        break;
      }
    }
    if(can){
      break;
    }
  }
  if(!can){
    cout << "-1 -1 -1" << endl;
  }
}

Measured memory_bytes: 256
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 200000
typedef long long i64;

int q;

int input() {
	if (scanf("%d", &q) < 0) return 0;
	return 1;
}

void init() {
}

int solve() {
	i64 sa=0, sb=0;
	multiset<int> l, u;
	int left, right, first=1;
	for (int i=0; i<q; i++) {
		int op;
		scanf("%d", &op);
		if (op==1) {
			int a, b;
			scanf("%d %d", &a, &b);	
			sb += b;
			if (!first) {
				if (a < left) sa += left-a;
				else if (a > right) sa += a-right;
			}
			first = 0;
			if (u.size() > l.size()) {
				if (a <= *u.begin()) {
					l.insert(a);
				}
				else {
					u.insert(a);
					l.insert(*u.begin());
					u.erase(u.begin());
				}
				left = *l.rbegin();
				right = *u.begin();
			}
			else {
				if (l.size()==0 || a >= *l.rbegin()) {
					u.insert(a);
				}
				else {
					auto p = --l.end();
					u.insert(*p);
					l.erase(p);
					l.insert(a);
				}
				left = right = *u.begin();
			}
		}
		else {
			//printf("%lld %lld\n", sa, sb);
			printf("%d %lld\n", left, sa + sb);
		}
	}
	return 1;
}

void output(int ans) {
}

void cleanup() {
}

int main() {
	//precalc();
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}




Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n,m;
    vector <int> T;
    int p,x,tmp,sum=0;
    cin >> n;
    FOR(i,0,n){
        cin >> tmp;
        sum+= tmp;
        T.push_back(tmp);
    }
    cin >> m;
    FOR(i,0,m){
        cin >> p >>x;
        cout << sum-T[p-1]+x << endl;
    }
    return 0;
}

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

typedef long long ll;
int main()
{
	ll x, y;
	cin >> x >> y;

	ll cnt = 0;
	ll z = 0;
	while (z <= y) {
		z = x * 2;
		cnt++;
		x = z;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256