akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<string, ii> sii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<sii> vsii;

// void dp(sp_1, sp_2.....)
// {
// 	if()//exit statement
// 	if()//using the memoization technique
// 	ll ans = //default/dummy answer
// 	//recursions
// 			//max/min
// 	return memo[][].. = ans;

// }
bool sorty(pair<string, ii> a, pair<string, ii> b)
{
	if(a.first==b.first)
		return (a.second.first> b.second.first);
	else
		return a.first<b.first;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
 	cout.tie(NULL);
 	//memset(memo, -1/0, sizeof memo);
 	ll n, p;
 	string s;
 	cin>>n;
 	vsii a(n);
 	for(int i = 0 ; i < n ; i++)
 	{
 		cin>>s>>p;
 		ii ind = make_pair(p,i+1);
 		a[i] = make_pair(s,ind);
 	}
 	sort(a.begin(), a.end(), sorty);
 	for(auto& it : a)
 		cout<<it.second.second<<endl;
	return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
mn=a[0]
mm=a[0]+1
mx=a[-1]
bool=1
b=[mx+1 for _ in range(len(a)-1)]
if mx<k:
  print("IMPOSSIBLE")
  exit()
if k in a:
  print("POSSIBLE")
  exit()
while bool==1:
  a=list(set(a))
  a.sort()
  b=[mx+1 for _ in range(len(a)-1)]
  p=a[0]
  for i in range(1,len(a)):
    x=a[i]
    b[i-1]=x-p
    if x>p:
      mm=min(mm,x-p)
    p=x
  if mm==mn:
    bool=0
  else:
    mn=mm
  b=[x for x in b if x!=0]
  a.extend(b)

#print(a,mn,mx,b)
if mn==1:
  print("POSSIBLE")
  exit()
elif (mx-k)%mn==0:
  print("POSSIBLE")
  exit()
else:
  print("IMPOSSIBLE")
  exit()



print(a,mn,mx,b)

Measured memory_bytes: 22796
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int x[maxn], y[maxn];
int main(){
	int n, m; cin >> n >> m;
	for(int i = 0; i < n; i++) cin >> x[i] >> y[i];
	for(int i = 0; i < m; i++) cin >> x[i + n] >> y[i + n];
	for(int i = 0; i < n; i++){
		int best = abs(x[i] - x[n]) + abs(y[i] - y[n]);
		for(int j = 0; j < m; j++) best = min(best, abs(x[i] - x[n + j]) + abs(y[i] - y[n + j]));
		for(int j = 0; j < m; j++) if(best == abs(x[i] - x[n + j]) + abs(y[i] - y[n + j])) {
			cout << j + 1 << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

#include <functional>

template<typename T>
class SegmentTreeAllOne {
    using Func = function<T(T, T)>;

public:
    vector<T> data;
    int n;
    T init;
    Func update_func;
    SegmentTreeAllOne(int _n, T _init, Func up) {
        init = _init;
        update_func = up;
        for (n = 1; n < _n; n *= 2)
            ;
        data.resize(2 * n - 1, init);
    }
    void update(int l, int r, T val) {
        for (l += n - 1, r += n - 1; l < r; l = l / 2, r = (r - 1) / 2) {
            if (!(l & 1)) {
                data[l] = update_func(data[l], val);
            }
            if (!(r & 1)) {
                data[r - 1] = update_func(data[r - 1], val);
            }
        }
    }
    T query(int pos) {
        pos += n - 1;
        T res = data[pos];
        while (pos > 0) {
            pos = (pos - 1) / 2;
            res = update_func(res, data[pos]);
        }
        return res;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, k, q;
    cin >> n >> k >> q;
    auto SUM = [&](ll a, ll b) {
        return a + b;
    };
    SegmentTreeAllOne<ll> segtree(n, 0, SUM);
    REP(i, 0, q) {
        int a;
        cin >> a;
        a--;
        segtree.update(0, a, 1);
        segtree.update(a + 1, n, 1);
    }
    REP(i, 0, n) {
        int g = k - segtree.query(i);
        if (g > 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 2688
n = int(input())
aa = [0] + list(map(int,input().split())) + [0]

comp = 0
for i in range(len(aa)-1):  
  comp += abs(aa[i+1]-aa[i])

shortcut = [0] * n
for i in range(1,n+1):
  shortcut[i-1] = abs(aa[i]-aa[i-1]) + abs(aa[i+1]-aa[i]) - abs(aa[i+1]-aa[i-1])  
  
for i in range(n):
  print(comp - shortcut[i])  

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

#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

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

    vector<ll> a(3*n);
    
    rep(i, 3*n)cin >> a[i];

    vector<ll> plus(3*n, 0);
    priority_queue<ll, vector<ll>, greater<ll>> plus_que;
    rep(i, n){
        plus[i+1] = plus[i] + a[i];
        plus_que.push(a[i]);
    }

    for(ll i = n; i < 2*n; ++i){
        ll top = plus_que.top();
        if(a[i] > top){
            plus[i+1] = plus[i] - top + a[i];
            plus_que.pop();
            plus_que.push(a[i]);
        }
        else plus[i+1] = plus[i];
    }


    vector<ll> minus(3*n, 0);
    priority_queue<ll> minus_que;
    rep(i, n){
        minus[i+1] = minus[i] + a[3*n-1-i];
        minus_que.push(a[3*n-1-i]);
    }
    
    for(ll i = n; i < 2*n; ++i){
        ll top = minus_que.top();
        if(a[3*n-1-i] < top){
            minus[i+1] = minus[i] - top + a[3*n-1-i];
            minus_que.pop();
            minus_que.push(a[3*n-1-i]);
        }
        else minus[i+1] = minus[i];
    }

    ll ans = -1*LINF;
    for(ll i = n; i <= 2*n; ++i){
        ans = max(ans, plus[i] - minus[3*n-i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 9588
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    vector<int>a;
    vector<int>b;
    cin>>n;
    for(int i =0;i<n;i++)
    {
        int x;
        cin>>x;
         a.push_back(x);

    }
    cin>>m;
    for(int i =0;i<m;i++)
    {
        int x;
        cin>>x;
         b.push_back(x);

    }
    int cnt = 0,l,r;
    for(int i = 0;i<m;i++)
    {
        int k = b[i];
        l = 0;
        r = n-1;
        while(l<=r)
        {
            int mi = l+((r-l)/2);
            if(a[mi] == k)
                {
                    cnt++;
                }
            if(a[mi]< k)
                l = mi+1;
            else
                r = mi-1;
        }
    }
    if(cnt == m)
        cout<<1<<endl;
    else
        cout<<0<<endl;
    return 0;
}



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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 N, K;
	cin >> N >> K;
	int64 zero = 0;
	vector<int64> A(N), mA, pA;
	REP(i, N) {
	  cin >> A[i];
	  if (A[i] < 0) mA.push_back(A[i]);
	  else if (A[i] > 0) pA.push_back(A[i]);
	  else zero++;
	}
	sort(all(pA));
	sort(all(mA), greater<int64>());
	if (K <= mA.size() * pA.size()) {
	  int64 l = -INF_LL-1, r = 0, m;
	  while (r - l > 1) {
	    m = (l + r) / 2;
	    int64 cnt = 0;
//	    cout << "    ";
	    REP(i, mA.size()) {
	      int64 ot = abs(m+mA[i]+1) / abs(mA[i]);
	      cnt += pA.size() - (lower_bound(all(pA), ot) - pA.begin());
//	      cout << ot << " ";
	    }
//	    cout << endl;
//	    cout << m << " " << cnt << endl;
	    if (K <= cnt) {
	      r = m;
	    } else {
	      l = m;
	    }
	  }
	  cout << r << endl;
	} else if (K <= mA.size() * pA.size() + zero * (N-zero) + (zero * (zero - 1))/2) {
	  cout << 0 << endl;
	} else {
//	  cout << pA.size() << " " << mA.size() << " " << zero << endl;
	  K -= mA.size() * pA.size() + zero * (N-zero) + (zero * (zero - 1))/2;
//	  cout << K << endl;
    int64 l = 0, r = INF_LL+1, m;
    REP(i, mA.size()) mA[i] *= -1;
    while (r-l > 1) {
      m = (l + r) / 2;
      int64 cnt = 0;
      REP(i, mA.size()) {
//        cout << "(" << mA[i] << " " << m/mA[i] << ") ";
        cnt += upper_bound(all(mA), m/mA[i]) - mA.begin() - (m/mA[i] >= mA[i]);
      }
//      cout << endl;

      REP(i, pA.size()) {
//        cout << "(" << pA[i] << " " << m/pA[i] << ") ";
        cnt += upper_bound(all(pA), m/pA[i]) - pA.begin() - (m/pA[i] >= pA[i]);
      }
      cnt /= 2;
//      cout << endl;
//      cout << m << " " << cnt << endl;
      if (K <= cnt) {
        r = m;
      } else {
        l = m;
      }
    }
    cout << r << endl;
	}
}


Measured memory_bytes: 3956
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
s=sum(b)
t=a[0]
for e in a[1:]:
    if e-1==t:
        s+=c[t-1]
    t=e
print(s)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define fast {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
typedef long long int ll;
typedef string S;
#define M 1e18
#define AS 1000005
#define in(x)  cin>>x
#define o(x)  cout<<x
#define sp cout<<' '
#define nw cout<<endl
#define rt return
#define fr(i,a,n) for(ll i=a;i<=n;i++)
#define frm(i,a,n) for(ll i=n;i>=a;i--)
#define P pair<ll,ll>
#define vc vector<ll>
#define pb push_back
#define MP map<ll,ll>
bool sortin(const pair<ll,ll> &e,const pair<ll,ll> &f){return (e.first<f.first);}
bool POT(ll x){return x && (!(x&(x-1)));}
ll i,j,k,l,m,n,p,q,r,a,b,c,x,y,z,ts,mn=1e18,mod=1e9+7;
ll ar[AS],br[AS],xr[AS],tem[AS];
ll board[500][500];
int main()
{
    fast;
    in(n);
    while(n--)
    {
        in(p);
        m=max(m,p);
        c+=m-p;
    }
    o(c);
}


Measured memory_bytes: 3656
#include <stdio.h>

int face[7][7][4] = {
{{0},{0},{0},{0},{0},{0},{0}},
{{0},{0},{0,1,2,3},{0,1,3,5},{0,1,4,2},{0,1,5,4},{0}},
{{0},{0,2,1,4},{0},{0,2,3,1},{0,2,4,6},{0},{0,2,6,3}},
{{0},{0,3,1,2},{0,3,2,6},{0},{0},{0,3,5,1},{0,3,6,5}},
{{0},{0,4,1,5},{0,4,2,1},{0},{0},{0,4,5,6},{0,4,6,2}},
{{0},{0,5,1,3},{0},{0,5,3,6},{0,5,4,1},{0},{0,5,6,4}},
{{0},{0},{0,6,2,4},{0,6,3,2},{0,6,4,5},{0,6,5,3},{0}}};
int assign[7];

int main()
{
	int q, i, t, f;

	for (i = 1; i <= 6; i++) scanf("%d", assign+i);
	scanf("%d", &q);
	while (q--) {
		scanf("%d%d", &t, &f);
		for (i = 1; i <= 6; i++) {
			if (assign[i] == t) t = i;
			if (assign[i] == f) f = i;
		}
		printf("%d\n", assign[face[t][f][3]]);
	}
	return 0;
}


Measured memory_bytes: 2040
#include<bits/stdc++.h>
    #include<vector>
    #define REP(i,n) for(int i=0;i<n;i++)
    #define V vector
    #define VI vector<int>
    #define VVI vector<vector<int>>
    #define M 1000000007
     
    using namespace std;
     
    int main(void){
        int N;
        cin>>N;
        VI h(N);
        VI dp(N);
        REP(i,N)cin>>h[i];
        dp[0]=0;
        dp[1]=abs(h[1]-h[0]);
     
        for(int i=2;i<N;i++){
                dp[i]=min(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2]);
        }
        cout<<dp[N-1]<<endl;
    }

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

using namespace std;
typedef long long ll;

int main() {
  ll N; cin >> N;
  vector<ll> H(N);
  for (ll j=0; j < N; ++j) cin >> H[j];
  ll mm = H[0];
  ll ans = 0;
  for (ll j=0; j < N; ++j) {
    if (H[j] >= mm) {
      ans += 1;
    }
    mm = max(mm, H[j]);
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> C(N), S(N), F(N);
    for(int i=0; i<N-1; i++) cin >> C[i] >> S[i] >> F[i];
    
    for(int i=0; i<N; i++){
        int s=0;
        int cnt=0;
        if(i==N-1){ cout << s << endl; continue; }
        for(int j=i; j<N-1; j++){
            if(cnt==0){
                s += S[j];
                s += C[j];
                cnt++;
            }
            else {
                if(s%F[j]==0 && s>=S[j]){
                    s += C[j];
                }
                else {
                    if(s<S[j]){
                        s += S[j]-s;
                    }
                    while(s%F[j]!=0){
                        s++;
                    }
                    s += C[j];
                }
            }
        }
        cout << s << endl;
    }
}


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

int main(){
  int i,j,cnt=0;
  int h,w;
  cin>>h>>w;
  string s[h][w];
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      cin>>s[i][j];
    }
  }
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(s[i][j]=="snuke"){
        cout<<(char)(j+'A')<<i+1;
      }
    }
  }
}

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

int func(string s, string t)
{
  int ans = 0;
  for (char c = 'a'; c <= 'z'; c++) {
    bool founds = false, foundt = false;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == c) {
        founds = true;
      }
    }
    for (int i = 0; i < t.length(); i++) {
      if (t[i] == c) {
        foundt = true;
      }
    }

    if (founds && foundt) {
      ans++;
    }
  }
  return ans;
}

int main(void) {
  int N;
  string s;
  cin >> N >> s;
  int ans = 0;
  for (int i = 0; i <= N; i++) {
    int tmp = func(s.substr(0,i),
                   s.substr(i));
    ans = max(ans, tmp);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
N, M = gets.split.map(&:to_i)
edge_list = M.times.map { gets.split.map(&:to_i) }
graph = Array.new(N) { [] }
indegree = Array.new(N) { 0 }
edge_list.each do |(u, v)|
  u -= 1; v -= 1
  graph[u].push(v)
  indegree[v] += 1
end

dp = Array.new(N) { 0 }
queue = []
indegree.each.with_index do |c, v|
  queue.push(v) if c == 0
end
while !queue.empty?
  v = queue.shift
  (graph[v]).each do |v2|
    indegree[v2] -= 1
    if indegree[v2] == 0
      queue.push(v2)
      dp[v2] = dp[v] + 1 if dp[v] + 1 > dp[v2]
    end
  end
end

ans = dp.max
puts ans


Measured memory_bytes: 14460
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    getline(cin,str);
    bool n, s, w, e;
    n = s = w = e = false;
    for(int i = 0; i < str.length(); i++)
        if(str[i] == 'E')
            e = true;
        else if(str[i] == 'W')
            w = true;
        else if(str[i] == 'N')
            n = true;
        else if(str[i] == 'S')
            s = true;
    if((e && w || !e && !w) && (n && s || !n && !s))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
public class Main {
	public static void main(String[] args) {
		java.util.Scanner s = new java.util.Scanner(System.in);
		int h[] = new int[s.nextInt()];
		for(int i=0;i<h.length;i++) {
			h[i]=s.nextInt();
		}
		System.out.println((calc(h)?"Yes":"No"));

	}
	public static boolean calc(int h[] ) {
		h[0]--;
		for(int i=1;i<h.length;i++) {
			if(h[i-1]<h[i]) {
				h[i]--;
			}
			else if(h[i-1]>h[i]) {
				return false;
			}
		}
		return true;
	}
}


Measured memory_bytes: 52536
n=int(input())
s=[int(input()) for _ in range(n)]
t=sum(s)
if t%10!=0 or t==0:
  print(t)
else:
  ans=0
  s.sort()
  for i in s:
    if i%10!=0:
      ans=t-i
      break
  print(ans)


Measured memory_bytes: 9020
#include <stdio.h>

int main()
{
    int x,n;
    scanf("%d %d ", &x, &n);
    int p[100];
    for(int i = 0; i < n; i++)
        scanf("%d ", &p[i]);
    int i = 0;
    while(1)
    {
        int f = 0;
        for(int j = 0; j < n; j++)
            if(p[j] == x - i)
                f = 1;
        if(f == 0)
        {
            printf("%d\n",x - i);
            return 0;
        }
        f = 0;
        for(int j = 0; j < n; j++)
            if(p[j] == x + i)
                f = 1;
        if(f == 0)
        {
            printf("%d\n",x + i);
            return 0;
        }
        i++;
    }
    return 0;
}

Measured memory_bytes: 1732
#include<cstdio>

int main(void){
	int x, y, i, ans=2,rx;
	scanf("%d %d", &x, &y);
	if(x>=y){
		ans=y+x;
		for(i=1; i<x; ++i){
			if((double)y*i/x==(int)y*i/x){--ans;}
		}
	}
	else{
		ans=y+x;
		for(i=1; i<y; ++i){
			if((double)x*i/y==(int)x*i/y){
				--ans;
			}
		}
	}
	printf("%d\n", ans);
	return(0);
}


Measured memory_bytes: 2748
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#define rip(i,n) for(int i=0;i<n;i++)
#define ll long long
#define ld long double
#define pi 3.1415926
#define MOD 998244353
#define sec setprecision
using namespace std;
ll gcd(ll a, ll b)
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
ll pow(ll x, ll n,ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return pow(x * x % m, n / 2, m);
	else
		return x * pow(x, n - 1, m) % m;
}
ll pow(ll x, ll n) {
	if (n == 0)
		return 1;
	else if (x == 1)return(1);
	else if (n % 2 == 0)
		return pow(x * x , (n / 2));
	else
		return x * pow(x, n - 1);
}
int ketasuu(ll h) {
	if (h < 0)return(-(ketasuu(-h)));
	else if (h < 10)return(1);
	else return(1 + ketasuu(h / 10));
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void cominit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

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

int main() {
	int k;
	cin >> k;
	string s;
	cin >> s;
	int p = s.size();
	if (p <= k)cout << s << endl;
	else {
		rip(i, k)cout << s[i];
		cout << "..."  << endl;
	}
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int N, M;
    cin >> N >> M;
    vector<vector<int>> graph(N);
    for(int i = 0; i < M; ++i){
        int a, b;
        cin >> a >> b;
        --a, --b;
        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }
    vector<bool> used(N);
    int ans = 0;
    auto dfs = [&](auto&& self, int cur = 0, int cnt = 1) -> void {
        for(int nxt : graph[cur]){
            if(used[nxt])   continue;
            if(cnt == N - 1){
                ++ans;
                return;
            }
            used[nxt] = true;
            self(self, nxt, cnt + 1);
            used[nxt] = false;
        }
    };
    used[0] = true;
    dfs(dfs);
    cout << ans << endl;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int main(){
  i64 A,B,C,X,Y;
  cin >> A >> B >> C >> X >> Y;
  i64 ans = A * X + B * Y;
  ans = min(ans , min(X,Y) * 2 * C + A * (X - min(X,Y)) + B * (Y - min(X,Y)));
  ans = min(ans , max(X,Y) * 2 * C);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main(){

   int h, w;
   vector<int> v_h, v_w;

   cin >> h >> w;

   while(h != 0 && w != 0){
      v_h.push_back(h);
      v_w.push_back(w);

      cin >> h >> w;
   }

   for(int i = 0; i < v_h.size(); i++){
      for(int j = 0; j < v_h[i]; j++){
         for(int k = 0; k < v_w[i]; k++){
            if((j+k) & 1){
               cout << ".";
            }
            else{
               cout << "#";
            }
         }
         cout << endl;
      }
      cout << endl;
   }

   return 0;
}


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

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define all(v)                                    v.begin(),v.end()

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

const int N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;

int n, Q;
int arr[N + 2];


void solve()
{
	int x, y;
	cin >> x >> y;

	lop(i, 0, x + 1)
	{
		int a = 2 * i + (x - i) * 4;
		if ( a == y )
		{
			cout << "Yes" << endl;
			return;
		}
	}
	cout << "No" << endl;
}

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

	int test = 1;
	// cin >> test;
	while (test--)solve();


}





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

int main() {
  int a, b;
  cin >> a >> b;

  int ans = 0;
  rep(i, 0, 1300) {
    int za = i * 0.08;
    int zb = i * 0.10;
    if (a == za && b == zb) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;
constexpr int MOD = 1e9 + 7;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    //cout << fixed << setprecision(6);
    ll n, m; cin >> n >> m;
    cout << (ll)pow(2, m) * (1900*m + 100*(n-m)) << endl;
    return 0;
}

Measured memory_bytes: 4088
n,m,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
x.sort()
y.sort()
for Z in range(-100 ,101,1):
    if X<Z and Z<=Y and x[-1]<y[0] and x[-1]<Z and Z<=y[0]:
        print('No War')
        import sys
        sys.exit()
print('War')


Measured memory_bytes: 3064
n, m, c = gets.split().map(&:to_i)
b = gets.split().map(&:to_i)
a = []

n.times do |i|
  a[i] = gets.split().map(&:to_i)
end

ans = 0

a.each do |i|
  sum = c
  i.each_with_index do |j, index|
    sum += j*b[index]
  end
  ans += 1 if sum > 0
end

puts ans

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
static const int N=100000;

int n,a[N+5];
int t,k;

int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    cin>>t;
    for(int i=0;i<t;i++)
    {
        cin>>k;
        cout<<lower_bound(a, a+n, k)-a<<endl;
    }
    return 0;
}




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

int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  vector<int> c(n);
  for (int i=0 ; i<n ; i++)
    cin >> v.at(i);
  for (int i=0 ; i<n ; i++)
    cin >> c.at(i);
  
  int ans = 0;
  for (int i=0 ; i<n ; i++){
    if (v.at(i) > c.at(i))
      ans += v.at(i) - c.at(i);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3580
import sys
sys.setrecursionlimit(10 ** 7)


class Tree:
    WHITE = -2
    GRAY = -1
    BLACK = 1

    def __init__(self, adj):
        n = len(adj)
        self.adj = adj
        self.colors = [self.WHITE] * n
        self.depths = [-1] * n
        self.depth = 0

    def init(self):
        self.__init__(self.adj)

    def dfs(self, u, c):
        if self.colors[u] >= 0:
            return

        self.colors[u] = self.GRAY
        self.depths[u] = self.depth

        for v in self.adj[u]:
            if self.colors[v] == self.WHITE:
                self.dfs(v, c)

        self.colors[u] = c

from collections import Counter

n, m, k = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
cd = [list(map(int, input().split())) for _ in range(k)]

adj = [[] for _ in range(n)]
for a, b in ab:
    a -= 1
    b -= 1
    adj[a].append(b)
    adj[b].append(a)

tree = Tree(adj)
for i in range(n):
    tree.dfs(i, i)

labels = tree.colors

counter = Counter(labels)

ans = [counter[labels[i]] - 1 for i in range(n)]

for a, b in ab:
    a -= 1
    b -= 1
    if labels[a] == labels[b]:
        ans[a] -= 1
        ans[b] -= 1

for c, d in cd:
    c -= 1
    d -= 1
    if labels[c] == labels[d]:
        ans[c] -= 1
        ans[d] -= 1

print(*ans)


Measured memory_bytes: 379324
#include "bits/stdc++.h"
using namespace std;
int A[1000],B[1000],C[1000];

int main(){
	fill(&C[0],&C[1000],-1);
	int N,M,cnt=0,k=0,hi=0;
	cin >>N>>M;
	for(int i = 0;i < M;i++){
		cin >> A[i]>>B[i];
		if(A[i]<N){
			C[k]=A[i];
			k++;
		}else{
			cnt++;
		}
	}
	if(cnt >= M-1)cout<<0<<endl;
	else{
		cnt = M-1-cnt;
		sort(&C[0],&C[1000]);
		reverse(&C[0],&C[1000]);
		for(int i = 0;i < cnt;i++){
			hi = hi+N-C[i];
		}
		cout <<hi<<endl;
	}
	

		return 0;
}

Measured memory_bytes: 3116
// --------------
// Tejas Pandey  |
// 14 - 06 - 20  |
// Atcoder BC 170|
// --------------

#include <bits/stdc++.h>
using namespace std;
     
#define mod 1000000007
#define vi vector<int>
typedef long long int ll;
     
int main (void){
  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int x,n,k;
  cin >> x >> n;
  int a[107];
  memset(a,0,sizeof(a));
  for(int i = 0;i < n;i++) cin >> k,a[k] = 1;
  int ans = -1,res = -1;
  for(int i = 0;i < 107;i++)
	if(!a[i]){
		if(ans == -1 || abs(x - i) < ans) ans = abs(x - i),res = i;
	}
  if(ans > x) cout << "0";
  else cout << res;
  return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
using namespace std;
using namespace __gnu_pbds;

typedef tree<pair<long long int,long long int>,null_type,less<pair<long long int,long long int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

void go()
{
    int n;
    cin>>n;
    if(n>=30)
        cout<<"Yes";
    else
        cout<<"No";
}
int main()
{
    FIO;
//    int t;
//    cin>>t;
//    while(t--)
        go();
    return 0;
}


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

string res(int n) {
    if(n == 0) return "pairwise coprime";
    else if(n == 1) return "setwise coprime";
    else return "not coprime";
}

const int M = 1e6 + 5;

int64_t gcd(int64_t a, int64_t b) { return a % b ? gcd(b, a % b) : b; }
int64_t lcm(int64_t a, int64_t b){ return a / gcd(a, b) * b; }

vector<int> primeList(int n) {
    vector<bool> isPrime(n + 1, true);
    vector<int> prime;
    if(n >= 0) isPrime[0] = false;
    if(n >= 1) isPrime[1] = false;
    for(int i = 2; i <= n; ++i) {
        if(isPrime[i]) {
            prime.push_back(i);
            for(int j = i * 2; j <= n; j += i) {
                isPrime[j] = false;
            }
        }
    }
    return prime;
}

int main() {
    int N; cin >> N;
    vector<int64_t> A(N);
    vector<int> B(M);
    for(auto &e : A) {
        cin >> e;
        B[e]++;
    }
    sort(A.begin(), A.end());

    int64_t G = 0;
    rep(i, N) G = gcd(G, A[i]);

    auto P = primeList(M);

    bool ng = false;
    for(int i = 2; i < M; ++i) if(B[i] > 1) ng = true;
    for(int i = 2; i * i <= M + 2; ++i) {
        int cnt = 0;
        for(int j = i; j < M; j += i) {
            cnt += B[j];
        }
        if(cnt > 1) ng = true;
    }

    for(auto &i : P) {
        if(i < 1) continue;
        int cnt = 0;
        for(int j = i; j < M; j += i) {
            cnt += B[j];
        }
        if(cnt > 1) ng = true;
    }

    if(G == 1) {
        if(ng) cout << res(1) << '\n';
        else cout << res(0) << '\n';
    } else {
        cout << res(2) << '\n';
    }
    return 0;
}


Measured memory_bytes: 15616
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

n = int(input())
s = input()
ord_a = ord("A")
ans = ""
for c in s:
    i = (ord(c) - ord_a + n)%26
    ans += chr(ord_a + i)

print(ans)


Measured memory_bytes: 41068
#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 all(x) x.begin(),x.end()
#define gll greater<ll>()

ll n;
vll a;
 
void solve(){
 cin >> n;
 a.resize(n);
 multiset<ll> st; 
 rep(i,0,n) {
   cin >> a[i];
   st.insert(a[i]);
 }
  ll res=0; 
  while(!st.empty()){
   auto it=st.end();
    --it;
   ll a=*it;
    st.erase(it);
   ll b=1;
   while(b<=a) b<<=1;
    b-=a;
    auto jt=st.find(b);
   if(jt!=st.end()){
     ++res;  
     st.erase(jt);
   }
  }
 cout << res << endl;
}

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}  

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


int main() {
  ll N; cin >> N;
  ll res = 0;
  for (ll i = 1; i <= N; i++) {
    res += i * (N + 1 - i);
  }
  for (int i = 0; i < N - 1; i++) {
    ll u, v; cin >> u >> v;
    if (u > v) swap(u, v);
    res -= u * (N + 1 - v);
  }
  cout << res << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <cstdlib>
#include <cmath>
using namespace std;

int main()
{
    int n, d;
	cin >> n >> d;
	vector< vector<double> > x(n, vector<double>(d));

	for(int i = 0; i < n; i++) {
		for(int j = 0; j < d; j++) {
			cin >> x[i][j];
		}
	}

	int result = 0;
	for(int i = 0; i < n; i++) {
		for(int j = i+1; j < n; j++) {
			double dist = 0.0;
			for(int k = 0; k < d; k++) {
				dist += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
			}
			dist = sqrt(dist);
			if(dist - (int)dist == 0.0) {
				result++;
			}
		}
	}

	cout << result << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    char S[100];
    cin >> N;
    for (int i = 0; i < N; i++) cin >> S[i];
    int L[4] = {0, 0, 0, 0};
    char C[4] = {'G', 'W', 'Y', 'P'};
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            if (S[i] == C[j])
            {
                L[j]++;
            }
        }
    }
    int cnt = 0;
    for (int i = 0; i < 4; i++)
    {
        if (L[i] != 0) cnt++;
    }
    if (cnt == 3) cout << "Three" << endl;
    else if (cnt == 4) cout << "Four" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 
 
int main() {
	int ans = 0;
	int tmp = 0;
	int n;
	cin >> n;
	priority_queue<int, vector<int>, greater<int> > p;
	priority_queue<int, vector<int> > np;
	REP(i, n){
		cin >> tmp;
		if(tmp > 0) p.push(tmp);
		else np.push(tmp);
	}
	vector<pair<int, int>> seq;
	if(np.size()>0){
		tmp = np.top();
		np.pop();
	}
	else{
		tmp = p.top();
		p.pop();
	}
	while(p.size()>0 || np.size()>0){
		if(p.size() == 1){
			seq.push_back(make_pair(p.top(), tmp));
			tmp = p.top() - tmp;
			p.pop();
		}
		else if(p.size() > 1){
			seq.push_back(make_pair(tmp, p.top()));
			tmp -= p.top();
			p.pop();
		}
		else{
			seq.push_back(make_pair(tmp, np.top()));
			tmp -= np.top();
			np.pop();
		}
	}
	cout << tmp << endl;
	REP(i, n-1) cout << seq[i].first <<" " << seq[i].second << endl;
}

Measured memory_bytes: 3444
while True:
 S = raw_input()
 if S == '0':break
 m = [1] + [0 for i in range(10)]
 d = A = 0
 e = 1
 S = reversed(S)
 for c in S:
  d = (d + int(c) * e) % 11  
  if int(c) != 0:A += m[d]
  m[d] += 1
  e *= -1
 print A


Measured memory_bytes: 4692
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long n,k,q;
  cin >> n >> k >> q;
  vector<long long>point(n,0);
  for(int i=0;i<q;i++){
    int a;
    cin >> a;
    point.at(a-1)++;
  }
  for(int i=0;i<n;i++){
    if(k-q+point.at(i)>0){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 1408
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest._500problems
{
    class CF2016FinalC
    {
        static void Main(string[] args)
        {
            Method(args);
            ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            bool[] bits = new bool[32];
            int[] changeBits = new int[n];
            for (int i = 0; i < n; i++)
            {
                int val = ReadInt();
                int minBit = -1;
                for(int j = 0; j < 32; j++)
                {
                    if ((val & (1 << j)) > 0)
                    {
                        bits[j] = !bits[j];
                        if (minBit == -1) minBit = j;
                    }
                }
                changeBits[i] = minBit;
            }
            Array.Sort(changeBits);
            Array.Reverse(changeBits);
            int cnt = 0;
            for(int i = 0; i < n; i++)
            {
                if (bits[changeBits[i]])
                {
                    for(int j = 0; j <= changeBits[i]; j++)
                    {
                        bits[j] = !bits[j];
                    }
                    cnt++;
                }
            }
            for(int i = 0; i < 32; i++)
            {
                if (bits[i])
                {
                    WriteLine(-1);
                    return;
                }
            }
            WriteLine(cnt);
        }

        private static string Read() { return ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;
long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
    cin>>n;
    ll cntt=1;
    while(1){
      cnt+=cntt;
      cntt++;
      ans++;
      if(cnt>=n)break;
    }
    Cout(ans);
    
       
return 0;
}


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

using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  vector<bool> v(n, true);
  vector<int> h(n);
  for (int i = 0; i < n; i++)
    cin >> h[i];
  for (int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    if (h[a - 1] > h[b - 1])
      v[b - 1] = false;
    else if (h[a - 1] < h[b - 1])
      v[a - 1] = false;
    else
      v[a - 1] = v[b - 1] = false;
  }
  int cnt = 0;
  for (bool b : v)
    cnt += b;
  cout << cnt;
  return 0;
}

Measured memory_bytes: 3788
/*
Author: Racer5x
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
 
// #pragma GCC optimize("O3")
// #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>
#define int         long long
#define double      long double
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MAX         2000000000000000000
#define M           1000000007
using namespace std;
 
signed main()
{
    tezz

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

    vi snuke(n);

    for(int i=0;i<k;i++){
        int d;
        cin>>d;

        for(int j=0;j<d;j++){
            int x;
            cin>>x;

            snuke[x - 1]++;
        }
    }

    int count = 0;
    for(int x:snuke) if(x == 0) count++;

    cout<<count;
} 

Measured memory_bytes: 3664
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[])
{
    int n, m;
    ll ans = 0;
    cin >> n >> m;
    int a[n];
    rep(i, n) cin >> a[i];
    sort(a, a + n);
    pair<int, int> p[m];
    rep(i, m)
    {
        int b, c;
        cin >> b >> c;
        p[i] = {c, b};
    }
    sort(p, p + m, greater<pair<int, int>>());
    int ind = 0;
    bool f = false;
    rep(i, m)
    {
        rep(j, p[i].second)
        {
            if (ind == n)
            {
                f = true;
                break;
            }
            if (a[ind] < p[i].first)
            {
                a[ind] = p[i].first;
            }
            else
            {
                f = true;
                break;
            }
            ind++;
        }
        if (f == true)
        {
            break;
        }
    }
    rep(i, n)
    {
        //cerr << a[i] << endl;
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
  int n, m, c, r;
  uint64_t k, s = 0;
  vector<uint64_t> a;
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++)
  {
    uint64_t t;
    cin >> t;
    s += t;
    if (s <= k)
    {
      a.push_back(s);
    }
  }

  s = 0;
  c = a.size();
  r = a.size();
  for (int i = 1; i <= m; i++)
  {
    uint64_t t;
    cin >> t;
    s += t;
    if (s <= k)
    {
      r = max(r, i);
      for (; c >= 1; c--)
      {
        if (a[c - 1] + s <= k)
        {
          r = max(r, c + i);
          break;
        }
      }
    }
  }
  cout << r << endl;
}


Measured memory_bytes: 5356
#include <bits/stdc++.h>
using namespace std;
string s1, s2;
int dp[3000][3000];
int go(int i, int j)
{
    if (i==s1.size() || j==s2.size())
        return 0;
    if (dp[i][j]!=-1)
        return dp[i][j];
    dp[i][j]=0;
    if (s1[i]==s2[j])
        return dp[i][j]=1+go(i+1, j+1);
    else
        return dp[i][j]=max(go(i, j+1), go(i+1, j));
}
void build(int i, int j)
{
    if (i==s1.size() || j==s2.size())
        return;
    if (s1[i]==s2[j])
    {
        cout << s1[i];
        build(i+1, j+1);
    }
    else
        if (dp[i][j]==go(i+1, j)) /// OR ==dp[i+1][j]
            build(i+1, j);
        else
            build(i, j+1);
}
int main()
{
    cin >> s1 >> s2;
    memset(dp, -1, sizeof dp);
    int n=go(0, 0);
    int a, b;
    for (int i=0 ; i<s1.size() ; i++)
        for (int j=0 ; j<s2.size() ; j++)
            if (dp[i][j]==n)
            {
                a=i, b=j;
                break;
            }
    build(a, b);
    return 0;
}


Measured memory_bytes: 35712
using System;

namespace AtCoder2020Ned
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(" ");

            var one = int.Parse(input[0]);
            var zero = int.Parse(input[1]);
            var minusOne = int.Parse(input[2]);
            var pick = int.Parse(input[3]);

            var currentPicked = 0;
            var sum = 0;

            for (int i = 0; one > 0 && pick > 0; i++)
            {
                sum++;
                one--;
                pick--;
            }
            for (int i = 0; zero > 0 && pick > 0; i++)
            {
                zero--;
                pick--;
            }
            for (int i = 0; minusOne > 0 && pick > 0; i++)
            {
                sum--;
                minusOne--;
                pick--;
            }

            Console.WriteLine(sum);
            Console.Read();
        }
    }
}


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

long long a[100010], b[100010];

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	reverse(a, a + n);
	reverse(b, b + n);
	long long push = 0;
	for (int i = 0; i < n; i++) {
		a[i] += push;
		if (a[i] % b[i] != 0) {
			push += (a[i] / b[i] + 1)*b[i] - a[i];
		}
	}
	cout << push << endl;
	return 0;
}

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

int main()
{
	cin.tie(0);
	cout.tie(0);
	int x,n;
	cin>>x>>n;
	set<int> s;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		s.insert(a);
	}
	int ans=x;
	for(int i=0;i<=100;i++)
	{
		if(s.find(x-i)==s.end())
		{
			ans=x-i;
			break;
		}
		if(s.find(x+i)==s.end())
		{
			ans=x+i;
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;

int tax8(int n)
{
    return (n * 8 / 100);
}

int tax10(int n)
{
    return (n * 10 / 100);
}

int main(int argc, char const *argv[])
{
    int a, b;
    cin >> a >> b;
    rep(i, 100000)
    {
        if (tax8(i) == a && tax10(i) == b)
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define F first
#define S second
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
signed main(){
    int k;
    string s;
    cin>>k>>s;
    int l=s.size();
    if(l<=k)cout<<s<<endl;
    else cout<<s.substr(0,k)<<"..."<<endl;
    return 0;
}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll  pair <long long,long long>
#define ss second
#define ff first
#define inf 9223372036854775807
#define maa 998244353
#define ld long double
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bug(x) cout << #x <<": " << x << '\n';
const ll N=200001 ;
int main()
{
   fast ;
   ld r ;
   cin>>r ;
   ld ans=r*6.28318530717958623200 ;

   cout<<fixed<<setprecision(20)<<ans ;





}


Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n = 0, l = 0, pos[300500], tim[300500], ans = 0;
bool del[300500], fir[300500], sec[300500];
signed main() {
	ios::sync_with_stdio(false);
	cin >> n >> l; ans = n + 1;
	for(int i = 1; i <= n; i++) {
		cin >> pos[i];
	} for(int i = 1; i <= n; i++) {
		cin >> tim[i];
		ans += (tim[i] / (l * 2)) , tim[i] %= (l * 2);
		if(tim[i] == 0) {
			ans--, del[i] = true;
			continue;
		}
		fir[i] = (2 * (l - pos[i]) >= tim[i]);
		sec[i] = (2 * pos[i] >= tim[i]);
		del[i] = not (fir[i] or sec[i]);
	}
	ans -= fir[n];
	int sum = 0, top = 0, pos = n;
	for(int i = 1; i < n; i++) {
		if(del[i]) continue;
		if(not fir[i]) {
			pos = i;
			break;
		}
		if(sec[i]) {
			top++;
		} else {
			if(top) {
				top--, ans--;
			}
		}
	}
	sum += top, top = 0;
	for(int i = n - 1; i >= pos; i--) {
		if(del[i]) continue;
		if(not sec[i]) break;
		if(fir[i]) {
			top++;
		} else {
			if(top) {
				top--, ans--;
			}
		}
	}
	ans -= (sum + top) / 2;
	cout << 2 * l * ans << endl;
	return 0;
}

Measured memory_bytes: 5888
using System;

class TripleDots {
  
  public static void Main(string[] args){
    var k = int.Parse(Console.ReadLine());
    var s = Console.ReadLine();
    
    var result = GetTripleDots(s, k);
    
    Console.WriteLine(result);
  }
  
  private static string GetTripleDots(string s, int k){
    if (k >= s.Length) return s;
    
    var result = s.Substring(0, k) + "...";
    
    return result;
  }
}

Measured memory_bytes: 27488