akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using i128 = boost::multiprecision::int128_t;
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int fLog2(const int x) { return 31-__builtin_clz(x); } // floor(log2(x))
inline int fLog2(const ll x) { return 63-__builtin_clzll(x); }
inline int cLog2(const int x) { return (x == 1) ? 0 : 32-__builtin_clz(x-1); } // ceil(log2(x))
inline int cLog2(const ll x) { return (x == 1) ? 0 : 64-__builtin_clzll(x-1); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


int main() {
  ll n, m, k; cin >> n >> m >> k;
  Vll a(n), b(m); cin >> a >> b;

  Vll sa(n+1), sb(m+1);
  rep(i, n) sa[i+1] = sa[i] + a[i];
  rep(i, m) sb[i+1] = sb[i] + b[i];

  int ans = 0;
  rep(i, n+1) {
    if (sa[i] > k) break;
    auto it = upper_bound(all(sb), k-sa[i]);
    int j;
    if (it == sb.end()) j = m;
    else j = it - sb.begin() - 1;
    chmax(ans, i+j);
  } 

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 9460
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
int main()
{
    ll t1,t2,a1,a2,b1,b2;
    cin>>t1>>t2>>a1>>a2>>b1>>b2;
    if(a1*t1+a2*t2==b1*t1+b2*t2)
    {
        cout<<"infinity";
        return 0;
    }
    ll c1=(a1-b1)*t1,c2=(a2-b2)*t2;
    if(c1>=0&&c2>=0)
    {
        cout<<"0";
        return 0;
    }
    if(c1<=0&&c2<=0)
    {
        cout<<"0";
        return 0;
    }

        if(abs(c1)>abs(c2))
        {
            cout<<"0";
            return 0;
        }
        else cout<<(2LL*(c1/(-(c1+c2))))+1-(c1%(c1+c2)==0)<<'\n';
        return 0;


}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;  
#define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update> 
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
int main()
{
    fastIO;
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    ll dp[n+1]={0};
    dp[2]=abs(a[1]-a[0]);
    for(int i=3;i<=n;i++)
    {
        dp[i]=min(dp[i-1]+abs(a[i-2]-a[i-1]),dp[i-2]+abs(a[i-3]-a[i-1]));
    }
    cout<<dp[n]<<endl;
}

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

/*should use ::toupper/lower as its defined in global scope, not std*/

#define pb push_back
#define eb emplace_back
#define res reserve

#define pii pair<int, int>
#define mp make_pair
#define f first
#define s second

#define pq priority_queue<int, vector<int>, greater<int>>

#define mt make_tuple

#define endl << "\n" 
#define bigint __int128_t; // Not available in all contest systems
#define rr return
#define cc continue

#define feq(a, b) (abs(a - b) < 1e-9)

using ll = long long;

using namespace __gnu_pbds;
using namespace std;

typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ll INF = 1e17; 
const int MOD = 1e9 + 7;

#define madd(a, b) ((int(a) % MOD + int(b) % MOD) % MOD)
#define msub(a, b) ((int(a) % MOD - int(b) % MOD) % MOD)
#define mmul(a, b) ((int(a) % MOD * int(b) % MOD) % MOD)

#define ue(u, v, g) g[u].eb(v), g[v].eb(u)

const int mxN = (int)1e7 + 10000;

int k;
string s;

void solve() {

	cin >> k;
	cin >> s;

	if(s.size() <= k) {
		cout << s endl;
	} else {
		cout << s.substr(0, k) << "..." endl;
	}

}

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int t;
	//cin >> t;
	t = 1;

	while(t--) {
		solve();
	}

}

Measured memory_bytes: 3656
# データ構造: Union Find (素集合データ構造)
#  前提
#    グラフ（頂点と辺からなる集合）上の各頂点が、どの連結成分に属しているかを管理するときに使う
#    具体的には、各連結成分ごとに適当な1点を親として、同じ連結成分に属する他の点が子になるように配置する
#  できること
#    1, ある頂点の親を返す (つまり、どの連結成分に属するかがわかる)
#    2, 新たな辺が与えられた時、必要なら連結成分の統合を行う

# 以下、事前準備。(本処理は42行目から)
# 上記1,2を実現する関数を作成する。

# 0, 前提
# par = [-1 for _ in range(n)]
#  配列parの要素par[i]には、
#    頂点iが子の場合に 親頂点の番号
#    頂点iが親の場合に 属する連結成分の頂点数を格納する。(区別のため負数として表記)
#  例: par = [2, 2, -3, -1, 5, -1]
#    点0,1,2からなる連結成分、点3からなる連結成分、点4,5からなる連結成分がある場合。

# 1, 頂点xの親を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
      
# 2, 頂点xとyが属する連結成分を結合する
def unite(x,y):
    x = find(x)
    y = find(y) 
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

# 以下、本処理
# 求めるもの：各連結成分の頂点数のうち、最大のもの
n, m = map(int,input().split())
par = [-1 for _ in range(n)]
 
for _ in range(m): #各辺について
  a, b = map(int,input().split())
  a -= 1
  b -= 1
  unite(a,b) #辺の両端(頂点aとb)が統合される
  
print(-min(par))
# 各連結成分の頂点数は、配列parの中に負数として記録されている。
# 連結成分の最大の頂点数を求めたければ、そのminをとって-1倍すればよい。


Measured memory_bytes: 86888
#include<iostream>
using namespace std;
int main()
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    char s[n];
    int count=0;
    for(int i=0;i<n;i++){
        cin >> s[i];
    }
    for(int i=0;i<n;i++){
        if(i>0&&s[i]=='L'){
            if(s[i-1]=='L'){
                count++;
            }
        }else if(i<n-1&&s[i]=='R'){
            if(s[i+1]=='R'){
                count++;
            }
        }
    }
    count += k*2;
    if(count > n-1){
        count = n-1;
    }
    cout << count;
}

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

def solve():
    N = int(readline())

    ans = ''

    alphas = [chr(i + ord('a')) for i in range(26)]

    while N > 0:
        r = N % 26
        if r == 0:
            ans = alphas[-1] + ans
            N = N // 26 - 1
        else:
            ans = alphas[r - 1] + ans
            N = N // 26
    
    print(ans)


solve()

Measured memory_bytes: 61744
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define pb(x) pop_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sum(x) accumulate(all(x),0)
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()

void solve(){
 ll n;
  cin >> n;
  vll a(n),b(n);
  rep(i,0,n) cin >> a[i];
  rep(i,0,n) {
    cin >> b[i];
    if(b[i]<a[i]) {
      cout << -1 << endl;
      return; 
    }
  }
  priority_queue<P> q;
  rep(i,0,n) if(b[i]>a[i]) q.push(P(b[i],i));
  ll ans=0;
  while(q.size()){
   P p=q.top();
    q.pop();
   ll i=p.se;
   ll x=b[(i+n-1)%n];
   ll y=b[(i+1)%n]; 
   ll cnt=(b[i]-1)/(x+y);
   chmin(cnt,(b[i]-a[i]-1)/(x+y)+1); 
   b[i]-=cnt*(x+y);
   ans+=cnt;
    if(cnt==0) break;
    if(b[i]>a[i]) q.push(P(b[i],i)); 
  }
  
  ll f=1;
  rep(i,0,n) if(b[i]!=a[i]) f=0; 
  cout << (f?ans:-1) << endl;
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}

Measured memory_bytes: 10532
#include <iostream>
#include <vector>
using namespace std;
#define rep(n) for (int i = 0; i < (n); ++i)
typedef long long ll;
int main()
{
    int n;
    cin >> n;
    vector<ll> v(n);
    rep(n) cin >> v[i];
    ll min = v[n - 1], max = v[n - 1];
    bool ok = true;
    rep(n)
    {
        ll now = v[n - 1 - i];
        if (now <= min)
            max = min = now;
        if (now > max)
            max = now;
        if (max - min > 1)
        {
            ok = false;
            break;
        }
    }
    cout << ((ok) ? "Yes" : "No");
}

Measured memory_bytes: 1024
while True:
    x,y = raw_input().split()
    x,y = map(int,(x,y))
    if x == 0 and y == 0:
        break
    if x > y:
        x,y = map(str,(x,y))
        print y + " " + x
    else:
        x,y = map(str,(x,y))
        print x + " " + y

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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
	string C1, C2, C3;
  	C1 = a[0];
  	C2 = b[0];
  	C3 = c[0];
  cout << C1 + C2 + C3 << endl;
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


int main()
{
    int X;
    cin >> X;

    for(long long a = 0; a <= 3e+3; ++a){
        for(long long b = 0; b <= 3e+3; ++b){
            if(a*a*a*a*a - b*b*b*b*b == X){
                cout << a << " " << b << endl;
                return 0;
            }else if(a*a*a*a*a + b*b*b*b*b == X){
                cout << a << " " << -b << endl;
                return 0;
            }
        }
    }

    return 0;
}

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

#define rep(i,a,b) for(int i = a; i < b; i++)

int n;
int x[24], y[24], r[24], c[24];
int dp[1 << 24];
int ans;

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

    bool flag[n];
    rep(i,0,n) flag[i] = true;

    rep(i,0,n) {
        if ((s >> i) & 1) {
            flag[i] = false;
            continue;
        }
        rep(j,i+1,n) {
            if ((s >> j) & 1 ) {
                flag[j] = false;
            }

            int d1 = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
            int d2 = (r[i] + r[j]) * (r[i] + r[j]);
            if (d1 < d2) {
                flag[j] = false;
            } 
        }
    }

    int res = 0;
    rep(i,0,n) {
        if (!flag[i]) continue;
        rep(j,i+1,n) {
            if (!flag[j]) continue;
            if (c[i] != c[j]) continue;
            int ns = s | (1 << i) | (1 << j);
            res = max(res, rec(ns) + 2);
        }
    }
    dp[s] = res;
    return res;
}

int main() {
    while (true) {
        cin >> n;
        if (n == 0) break;
        rep(i,0,n) cin >> x[i] >> y[i] >> r[i] >> c[i];
        rep(s,0,1<<n) dp[s] = -1;
        ans = rec(0);
        cout << ans << endl;
    }
}


Measured memory_bytes: 68556
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    def nCr(com_n, com_r):
        return fac[com_n] * inv[com_r] * inv[com_n - com_r] % md

    n, k = MI()
    aa = LI()

    md = 10 ** 9 + 7
    n_max = n
    fac = [1] * (n_max + 1)
    inv = [1] * (n_max + 1)
    for i in range(2, n_max + 1): fac[i] = fac[i - 1] * i % md
    inv[n_max] = pow(fac[n_max], md - 2, md)
    for i in range(n_max - 1, 1, -1): inv[i] = inv[i + 1] * (i + 1) % md

    cnt = Counter(aa)
    allp = nCr(n, k)
    pa = 10 ** 10
    ans = 0
    l = 0
    for a, c in sorted(cnt.items()):
        if pa == 10 ** 10:
            pa = a
            l += c
            continue
        d = a - pa
        if l >= k and n - l >= k:
            ans += d * (allp - nCr(l, k) - nCr(n - l, k))
        elif l >= k:
            ans += d * (allp - nCr(l, k))
        elif n - l >= k:
            ans += d * (allp - nCr(n - l, k))
        else:
            ans += d * allp
        ans %= md
        l += c
        pa = a
    print(ans)

main()


Measured memory_bytes: 29284
#include<bits/stdc++.h>
#define IL inline
#define _ 200005
#define ll long long
using namespace std;

IL int gi(){
	int data=0,fu=1; char ch=0; while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')fu=-1,ch=getchar();
	while('0'<=ch&&ch<='9')data=(data<<1)+(data<<3)+(ch^48),ch=getchar(); return data*fu;
}
#define mod 1000000007

int n,X[_],V[_],f[_],lp[_],rp[_],bit[_],vov,xox; struct Point{int x,v; }p[_]; vector<int>vec[_]; 
IL int Query(int x){++x; int ret=0; while(x<=vov+1)ret=(ret+bit[x])%mod,x+=(x&-x); return ret; }
IL void Insert(int x,int fv){++x; while(x)bit[x]=(bit[x]+fv)%mod,x-=(x&-x); return; }
IL bool cmp(Point i,Point j){return i.x<j.x; }
int main(){
	n=gi();
	for(int i=1;i<=n;++i)p[i].x=gi(),p[i].v=gi(),X[++xox]=p[i].x,V[++vov]=p[i].v;
	sort(X+1,X+xox+1); xox=unique(X+1,X+xox+1)-X-1; 
	sort(V+1,V+vov+1); vov=unique(V+1,V+vov+1)-V-1;
	sort(p+1,p+n+1,cmp);
	for(int i=1;i<=n;++i){
		p[i].x=lower_bound(X+1,X+xox+1,p[i].x)-X;
		p[i].v=lower_bound(V+1,V+vov+1,p[i].v)-V; 
	}
	for(int i=1,v=-mod;i<=n;++i)v=max(v,p[i].v),rp[i]=v;
	for(int i=n,v= mod;i>=1;--i)v=min(v,p[i].v),lp[i]=v;
	for(int i=1;i<=n;++i)vec[rp[i]].push_back(lp[i]);
	Insert(0,1);
	for(int i=1;i<=vov;++i){
		for(auto l:vec[i])f[i]=Query(l-1),Insert(i,f[i]);
	}
	cout<<Query(vov)<<endl; return 0; 
}


Measured memory_bytes: 17408
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c<=32)c=_buff.get();return c;}
ll qpow(ll x,ll k){return k==0?1:1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
ll n;
int a[20],an;
int main()
{
	cin>>n;
	int ans=0,sum=0;
	while(n)
	{
		a[an++]=n%10;
		sum+=n%10;
		n/=10;
	}
	ans=sum;
	for(int i=0;i<an;i++)
	{
		sum-=a[i];
		if(a[i]>0)
		{
			ans=max(ans,sum+a[i]-1+i*9);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

s=SI()
k=I()
n=len(s)
strs=[]
for i in range(n):
    for j in range(1,k+1):
        strs.append(s[i:i+j])
print(sorted(list(set(strs)))[k-1])

Measured memory_bytes: 5480
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
	ios::sync_with_stdio(false);
	int a, b, c;
	cin >> a >> b >> c;
	int x = min(a - b, c);
	cout << (c - x) << endl;
}

Measured memory_bytes: 764
#include <stdio.h>

int main(void){
    int N;
    scanf("%d", &N);
    int d[N];
    for(int i = 0; i < N; i++){
        scanf("%d", &d[i]);
    }
    int count = N;
    for(int i = 0; i < N; i++){
        if(d[i] == 0) continue;
        for(int j = i+1; j < N; j++){
            if(d[i] == d[j]){
                count -= 1;
                d[j] = 0;
            }
        }
    }
    printf("%d\n", count);
    return 0; 
}

Measured memory_bytes: 128
#include <stdio.h>
#define N 101
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define NIL -1
#define INF (1<<21)

int n,a[N][N];

void dijkstra(void)
{
  int i,j,u,v,min;
  int d[N],color[N];

  for(i=0;i<n;i++){
    d[i]=INF;
    color[i]=WHITE;
  }
  d[0]=0;
  color[0]=GRAY;

  while(1){
    min=INF;
    u=NIL;
    for(i=0;i<n;i++){
      if(color[i]!=BLACK && d[i]<min){
        min=d[i];
        u=i;
      }
    }
      if(u==NIL) break;
      color[u]=BLACK;
    
    for(v=0;v<n;v++){
      if(color[v]!=BLACK && a[u][v]!=INF){
        if(d[u]+a[u][v]<d[v]){
          d[v]=d[u]+a[u][v];
          color[v]=GRAY;
        }
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d %d\n",i,(d[i]==INF ? -1:d[i]));
  }
}
int main(){
  int i,j,u,k,v,c;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      a[i][j]=INF;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d %d",&v,&c);
      a[u][v]=c;
    }
  }
  dijkstra();

  return 0;
}




Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
#define intl long long int

vector<vector<intl> > dp(103,vector<intl>(1e5+2,-1));

intl fun(intl n,intl m,vector<pair<intl,intl> > &ar){
    // printf("n m are %lld %lld\n",n,m);
    if(dp[n][m]!=-1){
        return dp[n][m];
    }
    if(n==1){
        if(m>=ar[n-1].first){
            return ar[n-1].second;
        }
        else{
            return 0;
        }
    }
    if(m>=ar[n-1].first){
        dp[n-1][m-ar[n-1].first]=fun(n-1,m-ar[n-1].first,ar);
        // dp[n-1][m-ar[n-1].first]+=ar[n-1].second;
        dp[n-1][m]=fun(n-1,m,ar);
        dp[n][m] = max(dp[n - 1][m], ar[n - 1].second + dp[n - 1][m - ar[n - 1].first]);
    }
    else{
        dp[n][m]=fun(n-1,m,ar);
        // dp[n][m]=0;
    }
    return dp[n][m];
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    intl i,j,n,m,k;
    cin>>n>>m;
    vector<pair<intl,intl> > ar(n);
    for(i=0;i<n;i++){
        cin>>ar[i].first>>ar[i].second;
    }
    // sort(ar.begin(),ar.end());
    cout<<fun(n,m,ar)<<"\n";
}

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

int main() {
    int n, k, ans = 1;
    cin >> n >> k;

    for (int i = 0; i < n; i++) {
        if (ans * 2 <= ans + k) {
            ans *= 2;
        } else {
            ans += k;
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
// 2018/07/10 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

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

	int v[100];
	int w[100];
	for(int i=0; i<N; i++){
		cin >> v[i] >> w[i];
	}

	int DP[101][10001];

	for(int j=0; j<=W; j++){
		DP[0][j] = 0;
	}

	for(int i=1; i<=N; i++){
		for(int j=0; j<=W; j++){
			if(j<w[i-1]){
				DP[i][j] = DP[i-1][j];
			}
			else{
				DP[i][j] = max(DP[i-1][j], DP[i-1][j-w[i-1]]+v[i-1]);
			}
		}
	}

	cout << DP[N][W] << endl;

	return 0;
}



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

using namespace std;



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

    if(m!=1) {

        vector<long long> x(m);
        vector<long long> dx(m,0);

        for (long long i = 0; i < m; i++) {
            cin >> x.at(i);
        }

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

        for (long long i = 1; i < m; i++) {
            dx.at(i) = abs(x.at(i) - x.at(i - 1));
        }

        sort(dx.begin(), dx.end(), greater<long long>());

        if(m>=(n-1)){
            for (long long i = 0; i < (n - 1); i++) {
                dx.at(i) = 0;
            }
        }else{
            for (long long i = 0; i < m; i++) {
                dx.at(i) = 0;
            }
        }

        long long sum = 0;
        for (long long i = 0; i < m; i++) {
            sum += dx.at(i);
        }

        cout << sum << endl;

    }else{
        cout<<0<<endl;
    }

}


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

int main()
{
	int ans,n,k,cntl,cntr;
	int l[120000];
	int r[120000];
	string a;
	cin >> n;
	cin >> k;
	cntl = 0;
	cntr = 0;
	ans = 0;
	getline(cin,a);
	getline(cin,a);
	if (a[0] == '1') {
		l[0] = 0;
		cntl++;
	}
	else {
		l[0] = 0;
		cntl++;
		r[0] = 0;
		cntr++;
	}
	for (int i = 1; i < n; i++) {		
		if (a[i] == '1'&&a[i - 1] == '0') {
			l[cntl] = i; cntl++;
		}
		if (a[i] == '0'&&a[i - 1] == '1') {
			r[cntr] = i; cntr++;
		}
	}
	if (a[n - 1] == '0') {
		l[cntl] = n;
		cntl++;
		r[cntr] = n;
		cntr++;
	}
	else {
		r[cntr] = n;
		cntr++;
	}
	if (k >= cntl) ans = n;
	else for (int i = 0; i +k < cntl; i++) {
		if ((r[i + k] - l[i]) > ans)ans = r[i + k] - l[i];
	}
	cout << ans;
}


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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 1010;
const ll INF = 1LL << 60;

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



// Main Code

ll gcd(ll x, ll y)
{
  if(y == 0) return x;
  return gcd(y, x%y);
}
ll lcm(ll x, ll y)
{
  return (x / gcd(x, y)) * y;
}

int main()
{
	ll a, b;
	cin>>a>>b;
	cout<<lcm(a, b)<<endl;
}


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

using namespace std;
using ll = long long;

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

	int r = 0, b = 0;
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == 'R') { ++r; }
		if (s[i] == 'B') { ++b; }
	}

	if (r > b) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;
int main()
{
    // 文字列の入力
    int N;
	cin >> N;
	
	static int A[200001];
	int S = 0;
	for(int i = 0; i < N; i++) {
		cin >> A[i];
		S = S ^ A[i];
	}
	
	for(int i = 0; i < N; i++) {
		printf("%d ", S ^ A[i]);
	}
	printf("\n");

	
    return 0;
}

Measured memory_bytes: 4520
//B - Garbage Collector
#include<iostream>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

int main()
{
	ll N, X, x;
	cin >> N >> X;
	ll sum[N + 1];
	sum[0] = 0;
	for (ll i = 1; i <= N; i++) {
		cin >> x;
		sum[i] = sum[i - 1] + x;
	}

	ll ans = INF;
	for (ll k = 1; k <= N; k++) {
		ll i = N;
		ll E = (N + k)*X + sum[i] * 5;
		i -= k * 2;
		while (i > 0) {
			E += sum[i] * 2;
			i -= k;
			if (E < 0) {
				E = INF;
				break;
			}
		}
		ans = min(ans, E);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
#define eps 1e-8
#define INF 0x3f3f3f3f
#define pb push_back
#define endl '\n'
#define IO ios::sync_with_stdio(false)
using namespace std;
const ll maxn = 2e6 + 5;
const ll mod = 1e9 + 7;
ll inv[maxn],fec[maxn],k;
string str;
ll qpow(ll a,ll b){
    ll res = 1;
    while(b){
        if(b&1)res = res * a % mod;
        b >>= 1;
        a = a * a % mod;
    }
    return res;
}
ll C(ll n,ll m){
    if(m == 0 || n == m)return 1;
    else return fec[n] * inv[m] % mod * inv[n - m] % mod;
}
int main(){
    IO;
    ll ans = 0;
    fec[0] = 1;
    for(ll i = 1; i <= maxn; i++)
        fec[i] = i * fec[i - 1] % mod;
    inv[maxn] = qpow(fec[maxn],mod - 2);
    for(ll i = maxn - 1; i >= 0; i--)
        inv[i] = (i + 1) * inv[i + 1] % mod;
    cin >> k >> str;
    ll len = str.size() + k,slen = str.size();
    for(ll i = slen; i <= len; i++)
        ans = (ans + (C(i - 1,slen - 1) * qpow(25,i - slen) % mod * qpow(26,len - i) % mod)) % mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 35556
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    for i in range (H):
        for j in range (W):
            if (i+j)%2==0:
                print('#',end='')
            else:
                print('.',end='')
        print()
    print()
    



Measured memory_bytes: 7008
#include <stdio.h>

int main()
{
 int ans[4][3][10] = {0}, b, f, r, v, i, n;

 scanf("%d\n", &n);
 for(i = 0; i < n; i++)
 {
     scanf("%d %d %d %d\n", &b, &f, &r, &v);
     ans[b - 1][f - 1][r - 1] += v;
 }

 for(b = 0; b < 4; b++)
 {
     for(f = 0; f < 3; f++)
     {
         for(r = 0; r < 10; r++)
         {
             printf(" %d", ans[b][f][r]);
         }
         printf("\n");
     }
     if(b < 3) printf("####################\n");
 }

 return 0;
}

Measured memory_bytes: 616
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    val Array(a, b, k) = sc.nextLine.split(" ").map(_.toInt)


    @annotation.tailrec
    def go(n: Int, k: Int, gcdVal: Int): Unit = {
      if (gcdVal % n == 0) {
        if (k == 1) {
          println(n)
          n
        }
        else go(n - 1, k - 1, gcdVal)
      }
      else go(n - 1, k, gcdVal)
    }


    def gcd(x: Int, y: Int): Int = {
      if (y == 0) x
      else gcd(y, x % y)
    }

    val gcdVal: Int = gcd(a, b)

    go(gcdVal, k, gcdVal)
  }
}

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

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2")

using namespace std;

#define f first
#define s second
#define mp make_pair
#define all(x) x.begin(), x.end()
#define MOD 1000000007
#define EPS 1e-9
#define X real()
#define Y imag()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
using point = pair<double, double>;
using Vector = complex<double>;

int main() {

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

	cin >> n;

	cout << (n + 1) / 2 << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  
  int ans = 0;
  bool fin = true;
  if(n > 9) ans += 9;
  else ans += n;
  if(n < 100) fin = false;
  
  if(fin){
    if(n > 999) ans += 900;
    else ans += n - 99;
  }
  if(n < 10000) fin = false;
  
  if(fin){
    if(n > 99999) ans += 90000;
    else ans += n - 9999;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
_isPrime = function(n) {
  if (n < 2) {
    return false
  }
  for (var i = 2; i*i <= n; i++) {
    if (n % i === 0) {
      return false
    }
  }
  return true
}

inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
x = inp.shift() * 1
while (true) {
    if (_isPrime(x)) {
        break;
    }
    x++
}
console.log(x)


Measured memory_bytes: 21064
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
#define f first
#define s second
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug(...) cout << " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " << endl

using ld = long double;
using ll = long long;
using pii = pair <int,int>;
using pll = pair <ll,ll>;
using vi = vector <int>;
using vll = vector <ll>;
using vpii = vector <pii>;
using vpll = vector<pll>;
using vs = vector <string>;

const int mod = 1e9 + 7;

int main(){
  fastio;

  int n;
  cin >> n;
  vll vet(n+1);

  for(int i=1;i<=n;i++)
    cin >> vet[i];
  
  vll pref(n+1,0);

  for(int i=1;i<=n;i++){
    pref[i] = pref[i-1] + vet[i];
    pref[i] %= mod;
  }

  
  ll ans = 0;

  for(int i=1;i<n;i++){
    ans += vet[i]*(pref[n]-pref[i]);
    ans %= mod;
  }

  if(ans < 0)
    ans += mod;
    
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6352
#include<cstdio>
#include<cmath>
using namespace std;
int n,a[100001],x,ans;
int gcd(int a,int b)
{
	return b==0?a:gcd(b,a%b);
}
int main()
{
	scanf("%d%d",&n,&x);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		a[i]=abs(a[i]-x);
	}
	ans=a[1];
	for(int i=1;i<=n;i++) ans=gcd(ans,a[i]);
	printf("%d",ans);
	return 0;
}


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

#define ll long long 
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define REP(i,n) for (int i=0; i<(n); i++)
#define RREP(i,n) for (int i=(n-1); i>=0; i--)
#define ALL(x) x.begin(),x.end()
#define SZ(x) x.size()
#define MNTO(a,b) a = min(a,(__typeof__(a))(b))
#define MXTO(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define debug(x) cerr<<#x<<" is "<<x<<endl

using namespace std;

const int maxn = 2e5+5;
const int intinf = 1<<29;
const ll inf = 1ll<<60;


void GG(){cout<<"No\n"; exit(0);}


int a[maxn];


int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n; cin>>n;
    REP(i,n){
    	cin>>a[i];
    }
    int j = 0;
    int tt = 0;
    ll re = 0;
    REP(i,n){
    	if (i) {
    		tt -= a[i-1];
    	}
    	//debug(tt);
    	while (j<n&&((a[j]&tt)==0)){
    		tt += a[j]; j++; 
    	}
    	//cout<<i<<" to "<<j-1<<endl;
    	re += j-i;
    }
    cout<<re<<'\n';
}

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

int main() {

	int N, M, K;
	cin >> N >> M >> K;
	vector<int> A(N);
	vector<int> B(M);
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < M; i++) cin >> B[i];

	int ans;

	long long time = 0;
	int cntb = 1;
	while (cntb <= M) {
		if (time + B[cntb - 1] <= K) {
			time += B[cntb - 1];
			cntb++;
		}
		else break;
	}
	cntb--;
	ans = cntb;

	for (int cnta = 1; cnta <= N; cnta++) {
		time += A[cnta - 1];
		while (time > K && cntb > 0) {
			time -= B[cntb - 1];
			cntb--;
		}
		if (time > K && cntb == 0) break;
		ans = max(ans, cnta + cntb);
	}

	cout << ans << endl;

	return 0;
}

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



int n, k;
vector<double> a;

bool c(double m){
  int cnt = 0;
  for(int i=0; i<n; i++){
    cnt = cnt + (int)(a[i]/m);
    if(m*(int)(a[i]/m) == a[i]){
      cnt--;
    }
  }
  return cnt > k;
}

int main(){
  cin >> n >> k;
  a.resize(n, 0);
  for(int i=0; i<n; i++)
    cin >> a[i];

  if(k == 0){
    int ans = 0;
    for(int i=0; i<n; i++)
      ans = max(ans, (int)a[i]);
    cout << ans << endl;
    return 0;
  }

  double s = 0, t = 1000000002;
  for(int i=0; i<1000; i++){
    double mid = (s + t) / 2.0;

    if(c(mid))  s = mid;
    else  t = mid;
  }

  int ans = (int)(s);
  if(s-(double)(int)s)ans++;

  cout << ans << endl;

  return 0;
}


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

int main()
{
  int N;
  string S;
  cin >> N >> S;
  if (N % 2 != 0)
    cout << "No" << endl;
  else
  {
    int point = N / 2;
    string substr = S.substr(0, point);
    string substr2 = S.substr(point, point);
    if (substr == substr2)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(ll i=0;i<n;i++) cin>>a[i];
    ll dp[k+1]={0};
    for(ll i=1;i<=k;i++)
    {
        for(ll j=0;j<n;j++)
        {
            if(i>=a[j] && dp[i-a[j]]==0)
            {
                dp[i]=1;
                break;

            }
        }
    }
    if(dp[k]) cout<<"First";
    else cout<<"Second";
}


Measured memory_bytes: 4404
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int r = sc.nextInt();
		int s = sc.nextInt();
		int p = sc.nextInt();
		String t = sc.next();

		int rNum = 0;
		int sNum = 0;
		int pNum = 0;

		char[] own = new char[k];

		for (int i = 0; i < k; i++) {
			char com = t.charAt(i);
			if (com == 'r') {
				pNum++;
				own[i] = 'p';
			} else if (com == 's') {
				rNum++;
				own[i] = 'r';
			} else {
				sNum++;
				own[i] = 's';
			}
		}
		for (int i = k; i < n; i++) {
			char com = t.charAt(i);
			char kBefore = own[i % k];
			if (com == 'r') {
				if (kBefore == 'p') {
					own[i % k] = 'd';
					continue;
				}
				pNum++;
				own[i % k] = 'p';
			} else if (com == 's') {
				if (kBefore == 'r') {
					own[i % k] = 'd';
					continue;
				}
				rNum++;
				own[i % k] = 'r';
			} else {
				if (kBefore == 's') {
					own[i % k] = 'd';
					continue;
				}
				sNum++;
				own[i % k] = 's';
			}
		}
		long score = rNum * r + sNum * s + pNum * p;
		System.out.println(score);
	}

}

Measured memory_bytes: 26380
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <climits>
#define ll long long
#define MAX 25 * 1e13
#define N  200010

#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define EB(X) emplace_back(X)
#define REP(i,a) for(int i=0;i<(a);++i)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
#define VI vector<int>;

using namespace std;
int MOD = 1000000007;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,n;
  cin >> n >> a >> b;
  ll ret = 0;
  ll sum = a + b;
  ret += (n/sum) * a;
  ll rm = n % sum;
  ret += rm > a ? a : rm;
  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto S = readln.chomp;
    auto N = S.length.to!int;

    if (S.map!(s => s == S[0]).all) {
        writeln(N);
        return;
    }

    int ans = 1000000;
    foreach (i; 0..N-1) if (S[i] != S[i+1]) ans = min(ans, max(i+1,N-i-1));

    ans.writeln;
}


Measured memory_bytes: 2428
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		int addNum = (int) Arrays.stream(s.split("")).filter(e -> e.equals("+")).count();
		addNum -= (4 - addNum);

		System.out.println(addNum);

		sc.close();
	}
}

Measured memory_bytes: 27860
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

const int INF=1001001001;

int main() {
  int64_t N,D;
  cin>>N>>D;
  int cnt=0;
  for(int i=0;i<N;i++){
    int64_t x,y;
    cin>>x>>y;
    int64_t dis=x*x+y*y;
    if(dis<=D*D){cnt++;}
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define All(v) v.begin(), v.end()
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;

const int MAX_N = (int)1e5 + 5;
map<lint, lint> mp;

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int N, M; cin >> N >> M;
    for(int i=0;i<N;i++){
        int a; cin >> a;
        mp[-a]++;
    }
    for(int i=0;i<M;i++){
        int b, c; cin >> b >> c;
        mp[-c] += b;
    }
    lint cnt = 0;
    lint ans = 0;
    for(auto p : mp){
        lint k = min(N-cnt, p.second);
        ans += -p.first * k;
        cnt += k;
        if(cnt==N) break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12800
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	#N,K = inputMap()
	HH = inputInt()
	ans = 0

	H = []
	sin = []
	H.append(HH)

	cnte = 1
	flg = False
	while True:
		#print(cnte)
		if cnte % 2 == 1:
			sin = []
			for i,val in enumerate(H):
				if val <= 1:
					ans += 2**(cnte-1)
					continue
				else:
					flg = True
					ans += 2**(cnte-1)
					sin.append(val//2)
					#sin.append(val//2)
			if flg == False:
				print(ans)
				sys.exit()
			else:
				flg = False

		else:
			H = []
			for i,val in enumerate(sin):
				if val <= 1:
					#print("ss")
					ans += 2**(cnte-1)
					continue
				else:
					flg = True
					ans += 2**(cnte-1)
					H.append(val//2)
					#H.append(val//2)
			if flg == False:
				print(ans)
				sys.exit()
			else:
				flg = False

		cnte += 1

	#print(ans)




if __name__ == "__main__":
	main()


Measured memory_bytes: 38256
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element {
        return self.maxElement()!
    }
    func min() -> Element {
        return self.minElement()!
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/



/*************** メインプログラム ***************/

let input = readIntSplit(by: " ")
let (H, W) = (input[0], input[1])
for _ in 0..<H {
    let s = readLine()!
    print(s)
    print(s)
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,x,y;
    cin>>n>>k>>x>>y;
    int minimum;
    minimum=min(n,k);
    int ans;
    ans=minimum*x;
    n-=minimum;
    ans+=n*y;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define LL long long
int main(){
	LL a,b;
	scanf("%lld%lld",&a,&b);
	if(a*b<=0)return puts("Zero"),0;
	if(a>0)return puts("Positive"),0;
	if((b-a+1)&1)return puts("Negative"),0;
	puts("Positive");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 10000000;

class MaxFlow {
	struct edge {
		int to, cap, rev;
		edge(int to_, int cap_, int rev_) : to(to_), cap(cap_), rev(rev_) {};
	};

	int V;
	vector<vector<edge>> G;
	vector<int> level;
	vector<int> iter;

	void BFS(int s) {
		fill(level.begin(), level.end(), -1);
		queue<int> que;
		level[s] = 0;
		que.push(s);
		while (!que.empty()) {
			int v = que.front(); que.pop();
			for (size_t i = 0; i < G[v].size(); i++) {
				edge &e = G[v][i];
				if (e.cap > 0 && level[e.to] < 0) {
					level[e.to] = level[v] + 1;
					que.push(e.to);
				}
			}
		}
	}

	int DFS(int v, int t, int f) {
		if (v == t) return f;
		for (int &i = iter[v]; i < (int)G[v].size(); i++) {
			edge &e = G[v][i];
			if (e.cap > 0 && level[v] < level[e.to]) {
				int d = DFS(e.to, t, min(f, e.cap));
				if (d > 0) {
					e.cap -= d;
					G[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}

public:
	MaxFlow(int _V) : V(_V), G(_V), level(_V), iter(_V) {}
	void add(int from, int to, int cap) {
		G[from].push_back(edge(to, cap, G[to].size()));
		G[to].push_back(edge(from, 0, G[from].size() - 1));
	}
	int Dinic(int s, int t) {
		int flow = 0;
		while (true) {
			BFS(s);
			if (level[t] < 0) return flow;
			fill(iter.begin(), iter.end(), 0);
			int f;
			while ((f = DFS(s, t, INF)) > 0) {
				flow += f;
			}
		}
	}
};

int main()
{
	cin.sync_with_stdio(false);
	int n, m;
	while (cin >> n >> m, n | m) {
		vector<int> u(m), v(m);
		for (int i = 0; i < m; i++) {
			cin >> u[i] >> v[i]; u[i]--; v[i]--;
		}
		int mi, ma;
		int l = 0, r = 50;
		while (l + 1 < r) {
			int c = (l + r) / 2;
			MaxFlow mf(n + m + 2);
			for (int i = 0; i < n; i++) {
				mf.add(n + m, i, c);
			}
			for (int i = 0; i < m; i++) {
				mf.add(u[i], n + i, 1);
				mf.add(v[i], n + i, 1);
				mf.add(n + i, n + m + 1, 1);
			}
			if (mf.Dinic(n + m, n + m + 1) == n * c) {
				l = c;
			}
			else {
				r = c;
			}
		}
		mi = l;
		l = 0, r = 100;
		while (l + 1 < r) {
			int c = (l + r) / 2;
			MaxFlow mf(n + m + 2);
			for (int i = 0; i < n; i++) {
				mf.add(n + m, i, c);
			}
			for (int i = 0; i < m; i++) {
				mf.add(u[i], n + i, 1);
				mf.add(v[i], n + i, 1);
				mf.add(n + i, n + m + 1, 1);
			}
			if (mf.Dinic(n + m, n + m + 1) == m) {
				r = c;
			}
			else {
				l = c;
			}
		}
		ma = r;
		cout << mi << ' ' << ma << endl;
	}
	return 0;
}

Measured memory_bytes: 3596
def swap(A, i, j):
    tmp = A[i]
    A[i] = A[j]
    A[j] = tmp



def bubble_sort(A, n):
    count = 0
    for i in range(0, n):
        for j in range(n-1, i, -1):
                if A[j] < A[j-1]:
                    swap(A, j, j-1)
                    count += 1
    return A, count

n = int(input())
A = [int(x) for x in input().split()]

s_A, count = bubble_sort(A, n)

print(" ".join([str(x) for x in s_A]))
print(count)


Measured memory_bytes: 5608
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <map>
#include <set>
#include <list>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

/////////////////////////////////////////////////////

ll N,K,a[1010];

ll ba[1010][1010];
vector<ll> bt;

ll i,j,k,ans;
int main(){
    scanf("%lld%lld", &N,&K);
    fornum(i,0,N){
        scanf("%lld", &a[i]);
    }
    fornum(i,0,N){
        ll ann = 0;
        fornum(j,i,N){
            ann += a[j];
            bt.push_back(ann);
            //printf("%lld ", ann);
        }
    }
    for (i = 40; i >= 0;i--){
        ll ct = 0;
        fornum(j,0,bt.size()){
            ll btn = bt[j];
            if((btn|ans)!=btn||(btn&ans)!=ans)
                continue;
            if(btn&((ll)1<<i))
                ct++;
        }
        if(ct>=K){
            ans |= (ll)1 << i;
        }
    }

    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 6512
def is_prime(n):
    """
    Assumes that n is a positive natural number
    """
    # We know 1 is not a prime number
    if n == 1:
        return False

    i = 2
    # This will loop from 2 to int(sqrt(x))
    while i*i <= n:
        # Check if i divides x without leaving a remainder
        if n % i == 0:
            # This means that n has a factor in between 2 and sqrt(n)
            # So it is not a prime number
            return False
        i += 1
    # If we did not find any factor in the above loop,
    # then n is a prime number
    return True

x = int(input())
if x % 2 == 0 and x != 2:
  x += 1
while not is_prime(x):
  x += 2
print(x)


Measured memory_bytes: 38640