akhauriyash/Code-Regression huggingface dataset:
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;

ll power(ll a, ll b){
    if(b<1) return 1;
    if(b==1) return a;
    if(b%2!=0) return a * power(a, b-1) % MOD;
    ll t = power(a, b/2) % MOD;
    return t * t % MOD;
}

ll nCr(ll n, ll r){
    ll X=1, Y=1;
    for (ll i = 0; i < r; ++i) {
        X *= n-i; X%=MOD;
        Y *= i+1; Y%=MOD;
    }

    ll ans = X;
    ans *= power(Y, MOD-2);
    ans %= MOD;
    return ans;
}

int main(void){

    ll X,Y; cin>>X>>Y;
    ll n=(2*X-Y)/3, m=(2*Y-X)/3;
    if((X+Y)%3!=0){
        cout<<0<<endl;
        return 0;
    }
    if(n<0 || m<0){
        cout<<0<<endl;
        return 0;
    }
    
    cout<<nCr(n+m, n)<<endl;
}

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

struct StNode
{
  StNode* m_poParnt;
  StNode* m_poLeft;
  StNode* m_poRigt;
  int m_nKey;

  StNode(int nNo) :
    m_poParnt(nullptr), m_poLeft(nullptr), m_poRigt(nullptr), m_nKey(nNo)
  { }
};

void fnPreOrder(StNode* poNode)
{
  if (poNode == nullptr)  return;

  cout << " " << poNode->m_nKey;
  fnPreOrder(poNode->m_poLeft);
  fnPreOrder(poNode->m_poRigt);
}

void fnInOrder(StNode* poNode)
{
  if (poNode == nullptr)  return;

  fnInOrder(poNode->m_poLeft);
  cout << " " << poNode->m_nKey;
  fnInOrder(poNode->m_poRigt);
}

int fnFind(StNode* poRoot, int nNo)
{
  StNode* poNode = poRoot;
  while (poNode != nullptr)
    if (nNo == poNode->m_nKey)
      return 1;
    else if (nNo < poNode->m_nKey)
      poNode = poNode->m_poLeft;
    else
      poNode = poNode->m_poRigt;

  return 0;
}

void fnInsert(StNode*& rpoRoot, StNode* poNewNod)
{
  StNode* poParnt = nullptr;
  StNode* poNode = rpoRoot;

  while (poNode != nullptr)
  {
    poParnt = poNode;
    if (poNewNod->m_nKey < poNode->m_nKey)
      poNode = poNode->m_poLeft;
    else
      poNode = poNode->m_poRigt;
  }

  poNewNod->m_poParnt = poParnt;
  if (poParnt == nullptr)
    rpoRoot = poNewNod;
  else if (poNewNod->m_nKey < poParnt->m_nKey)
    poParnt->m_poLeft = poNewNod;
  else
    poParnt->m_poRigt = poNewNod;
}

void fnBinSchTree(StNode*& rpoRoot)
{
  int nMaxSiz;
  cin >> nMaxSiz;

  for (int i = 0; i < nMaxSiz; ++i)
  {
    string sCmd;
    cin >> sCmd;
    if (sCmd[0] == 'i')
    {
      int nNo;
      cin >> nNo;
      StNode* poNewNod = new StNode(nNo);
      fnInsert(rpoRoot, poNewNod);
    }
    if (sCmd[0] == 'f')
    {
      int nNo;
      cin >> nNo;
      if (fnFind(rpoRoot, nNo))
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
    if (sCmd[0] == 'p')
    {
      fnInOrder(rpoRoot);
      cout << endl;
      fnPreOrder(rpoRoot);
      cout << endl;
    }
  }
}

void fnPstOrder(StNode* poNode)
{
  if (poNode == nullptr)  return;

  fnPstOrder(poNode->m_poLeft);
  fnPstOrder(poNode->m_poRigt);
  delete poNode;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  StNode* poRoot = nullptr;

  fnBinSchTree(poRoot);
//fnPstOrder(poRoot);
  return 0;
}

Measured memory_bytes: 21852
#include <algorithm>
#include <iostream>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    int N, M;
    cin >> N;
    map<string, int> counts;
    for (int i = 0; i < N; ++i)
    {
        string si;
        cin >> si;
        ++counts[si];
    }
    cin >> M;
    multiset<string> reds;
    for (int i = 0; i < M; ++i)
    {
        string ti;
        cin >> ti;
        --counts[ti];
    }
    int max = 0;
    for (const auto &kvp : counts)
    {
        int score = kvp.second;
        if (score > max)
        {
            max = score;
        }
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<ll> par;
//     vector<ll> siz;
    
//     UnionFind(ll N): par(N), siz(N,1) {
//         for (ll i=0;i<N;i++) par[i] = i;
//     }

//     ll root(ll x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         if (rx == ry) return;
//         // if (siz[rx] < siz[ry]) swap(rx,ry);
//         par[rx] = ry;
//         siz[ry] += siz[rx];
//     }

//     bool same(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         return rx == ry;
//     }

//     ll size(ll x) {
//         return siz[root(x)];
//     }
// };

//     vector<ll> par;
//     vector<ll> siz;
    
//     UnionFind(ll N): par(N), siz(N,1LL) {
//         for (ll i=0;i<N;i++) par[i] = i;
//     }

//     ll root(ll x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//         siz[ry] += siz[rx];
//     }

//     bool same(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         return rx == ry;
//     }

//     ll size(ll x) {
//         return siz[root(x)];
//     }
// };

int main(void) {
    int N;
    cin >> N;
    switch (N%10)
    {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
        cout << "hon" << endl;
        break;
    case 0:
    case 1:
    case 6:
    case 8:
        cout << "pon" << endl;
        break;
    case 3:
        cout << "bon" << endl;
        break;
    default:
        break;
    }

    return 0;
}


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

// function that calculates the sum of each digit
int findSumOfDigits(int n) {
	int sum = 0;
	while (n > 0) {	// until n becomes 0
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, a, b;
	cin >> n >> a >> b;
	int total = 0;
	for (int i = 1; i <= n; i++) {
		int sum = findSumOfDigits(i);
		if (sum >= a && sum <= b) {
			total += i;
		}
	}		
	cout << total << '\n';
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    
    int a,b;
    cin >> a >> b;
    
    if (a == 2 && b == 3 || a == 3 && b == 2){
        cout << '1' << endl;
    }
    else if (a == 1 && b == 3 || a == 3 && b == 1){
        cout << '2' << endl;
    }
    
    else cout << '3' << endl;
    
}


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

using namespace std;

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

    int ans = 0;
    bool flag = false;
    while (true){
        for (int i = 0; i < N; i++){
            if (A[i] % 2 == 1){
                flag = true;
                break;
            } else {
                A[i] /= 2;
            }
        }
        if (flag){
            break;
        }else{
            ans += 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import collections
#nを素因数分解したリストを返す
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n //= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

N = int(input())
if N == 1:
    print(0)
else:
    A = prime_decomposition(N)

    c = collections.Counter(A)
    values, counts = zip(*c.most_common())


    cnt = 0
    for i in range(len(counts)):
        for j in range(10,0,-1):
            if counts[i] >= j * (j + 1)//2:
                cnt += j
                break
    print(cnt)

Measured memory_bytes: 9464
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define PI 3.14159265358979323846
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef long double ld;
typedef string st;
const ll MOD = 1e9 + 7 ;
const ll INF=1e14;
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
ll mpow(ll a,ll b,ll p=MOD){a=a%p;ll res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const ll N=1005;
ll stringToInt( string s )
{
   ll result = 0;                               // to hold the integer result

   for ( ll i = 0; i <(ll)s.size(); i++ )          // loop through characters of string
   {
      ll digit = s[i] - '0';
      result = 10 * result + digit;
   }

   return result;
}

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

      ll n;
      cin>>n;
      queue<string> s;
      s.push("3");
      s.push("7");
      s.push("5");
      ll ans=0;
      map<string,bool> vis;
      while(!s.empty()){
        string o=s.front();
        s.pop();
        if(vis[o]) continue;
        vis[o]=true;
        ll cnt[3]={0};
        forn(i,o.length()){
        	if(o[i]=='3') cnt[0]++;
        	else if(o[i]=='7') cnt[1]++;
        	else cnt[2]++;
        }
        bool f=true;
        forn(i,3){
        	if(cnt[i]==0) f=false;
        }
        ll num=stringToInt(o);
        if(num>n){
        	continue;
        }
        else if(f){
        //	cout<<o<<" ";
        	ans++;
        }
        s.push(o+'3');
        s.push(o+'7');
        s.push(o+'5');
        s.push('3'+o);
        s.push('7'+o);
        s.push('5'+o);
      }
      cout<<ans;
}
/* If today were the last day of my life,would I want to do what I'm about to do today? */

Measured memory_bytes: 11136
from math import ceil

def BinarySearch(x):
    ans = sum([ceil(a/x)-1 for a in A])
    if ans <= K:
        return True
    else:
        return False

N,K = map(int,input().split())
A = list(map(int,input().split()))

r = max(A)
l = 0
eps = 10**-6

while abs(r-l) > eps:

    m = (r+l)/2

    if BinarySearch(m):
        r = m
    else:
        l = m

print(ceil(r)) 


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

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

using namespace std;
typedef int64_t ll;

const int64_t MOD = 1000000007;
int64_t frac[400000];

ll inv(ll a,ll p = MOD){
  return ( a == 1 ? 1 : (1 - p*inv(p%a,a)) / a + p );
}

ll cmb(ll a, ll b) {
  ll res = frac[a] * inv(frac[b]);
  res %= MOD;
  res *= inv(frac[a-b]);
  res %= MOD;
  return res;
}

ll ci(ll a, ll b) {
  if (b == 0) return 1;
  int64_t res = cmb(a+b, b) + MOD - cmb(a+b, b-1);
  res %= MOD;
  return res;
}

ll calc(ll n,ll k1, ll m, ll k2) {
  ll v1 = ci(n+k1,k1);
  ll v2 = ci(m+k2,k2);
  ll res = v1 * v2;
  res %= MOD;
  res *= cmb(n+k1*2+m+k2*2, n+k1*2);
  res %= MOD;
  return res;
}

int main() {
  frac[0] = 1;
  REP(i,399999) {
    frac[i+1] = frac[i] * (i+1);
    frac[i+1] %= MOD;
  }
  ll n,m,k;
  cin>>n>>m>>k;
  ll sum = 0;
  REP(i,k+1) {
    sum += calc(n,i,m,k-i);
    sum %= MOD;
  }
  cout << sum << endl;
  return 0;
}

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

int main()
{
    long long n,m;
    cin>>n>>m;
    if(n==1&&m==1)
        printf("0\n");
    else{
        printf("%lld\n",(n*(n-1)+m*(m-1))/2);
    }
}


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

int main()
{
    string search_string = "ABC";
    int N; string S; cin >> N >> S;
    S += "|";

    int x = S.find(search_string) + 1;
    int ans = 0;
    while (x) {
        ans++;
        S = S.substr(x);
        x = S.find(search_string) + 1;
    }

    cout << ans << endl;
}


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


int main(){
  int K;
  cin >> K;
  string S;
  cin >> S;
  if(S.size()<=K){
    cout << S << endl;
  }else{
    cout << S.substr(0, K) << "..." << endl;
  }
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> PDL;
typedef pair<LD, LD> PDD;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
//typedef boost::multiprecision::cpp_int bigint;

template<class T>
void in(T& x) {
	cin >> x;
}

template<class T1,class T2>
void in(pair<T1, T2>& p) {
	in(p.first);
	in(p.second);
}

template<class T>
void in(vector<T>& v,LL st=-1,LL en=-1) {
	if (st == -1) {
		st = 0;
		en = v.size() - 1;
	}
	for (LL n = st; n <= en; n++) {
		in(v[n]);
	}
}

void modinvs(long long N, vector<long long>& inv, vector<long long>& sinv, long long mod = 1e9 + 7) {
	inv.resize(N + 1);
	sinv.resize(N + 1);
	inv[1] = 1;
	sinv[0] = 1;
	sinv[1] = 1;
	for (int n = 2; n <= N; n++) {
		inv[n] = mod - (inv[mod % n] * (mod / n)) % mod;
		sinv[n] = (sinv[n - 1] * inv[n]) % mod;
	}
}

LL modpow(LL base, LL p) {
	if (p == 0)return 1;
	if (p == 1)return base;
	LL temp = modpow(base, p / 2);
	temp = (temp * temp) % MOD;
	if (p & 1)temp = (temp * base) % MOD;
	return temp;
}

LL st(LL en,LL st = 1) {
	LL ans = st;
	for (LL n = st+1; n <= en; n++) {
		ans = (ans * n) % MOD;
	}
	return ans;
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL N, A, B;
	cin >> N >> A >> B;
	LL ans = modpow(2, N);
	LL tempa = st(N, N - A + 1);
	LL tempaa = st(A);
	tempaa = modpow(tempaa, MOD - 2);
	tempa = (tempa * tempaa) % MOD;
	LL tempb = st(N, N - B + 1);
	LL tempbb = st(B);
	tempbb = modpow(tempbb, MOD - 2);
	tempb = (tempb * tempbb) % MOD;
	ans -= (tempa + tempb + 1);
	ans %= MOD;
	if (ans < 0)ans += MOD;
	cout << ans << "\n";
	return 0;
}

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

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 

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

    int N, M; cin >> N >> M;
    vector<int> f(N+1, 0);
    
    int a, b;
	bool possible = false;
    rep(i, M) {
        cin >> a >> b;
		if ((a == 1 && (f[b] |= 1) == 3)
		 || (b == N && (f[a] |= 2) == 3)
		) {
			possible = true;
			break;
        }
    }
    cout << (possible ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
/**
******************* Author:Bisnu sarkar ****************************
**/
/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/
#define fRead(x)       freopen(x,"r",stdin)
#define fWrite(x)      freopen (x,"w",stdout)
#define ull            unsigned long long
#define ll             long long
#define pii            pair<int,int>
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';
#define sz(s)          (int)s.size()
#define all(s)         s.begin(),s.end()
#define IO             ios_base::sync_with_stdio(false),cin.tie(NULL);  
#define what_is(x)     cerr << #x << " is " << x << endl;
///*....Debugger....*///
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ", ";
  err(++it, args...);
}
///*....Input....*///
template <typename T> inline void Int(T &n) {
  n = 0; int f = 1; register int ch = getchar();
  for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
  n = n * f;
}
 
template <typename T, typename TT> inline void Int(T &n, TT &m) { Int(n); Int(m); }
template <typename T, typename TT, typename TTT> inline void Int(T &n, TT &m, TTT &l) { Int(n, m); Int(l);}
double ind(){double x; scanf("%lf",&x);return x;}

///*....Bitmask....*///
int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}

int dx[8]= {1,0,-1,0,-1,-1,1,1};
int dy[8]= {0,1,0,-1,-1,1,-1,1};

///*....Constraints....*///
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);
const double eps=1e-9;


int main()
{
    int t=1,te=0;
    //Int(t);
    while(t--){
      int k;
      Int(k);
      string s;
      cin>>s;

      if(sz(s) <= k){
        cout<<s<<endl;
      }
      else{
        for(int i=0;i<k;++i){
          cout<<s[i];
        }
        cout<<"..."<<endl;
      }

        //printf("Case %d: ",++te);
    }
    return 0;
}






Measured memory_bytes: 3544
/*5_3 hightierra*/
#include <stdio.h>
#define limit 100

int main(void){
    int row,col,i,j;
    scanf("%d %d",&row,&col);

    int rowjudge[100]={0},coljudge[100]={0};
    char matrix[row][col];

    // 入力（初期化）
    for(i=0; i<row; i++){
        for(j=0; j<col; j++){
            scanf(" %c",&matrix[i][j]);
        }
    }

    // 各行、各列に黒が１つでもあるかを判別
    for(i=0; i<row; i++){
        for(j=0; j<col; j++){
            if(matrix[i][j]=='#'){
                rowjudge[i]=1;
            }
        }
    }
    for(j=0; j<col; j++){
        for(i=0; i<row; i++){
            if(matrix[i][j]=='#'){
                coljudge[j]=1;
            }
        }
    }

    // 黒が１つでもある行と列の重なる要素のみを出力
    for(i=0; i<row; i++){
        for(j=0; j<col; j++){
            if(rowjudge[i]==1 && coljudge[j]==1){
                printf("%c",matrix[i][j]);
            }
        }
        if(rowjudge[i]==1){
            printf("\n");
        }
    }
    return 0;
}

Measured memory_bytes: 128
using System;


class AOJ
{

    public static void Main(){


        while (true)
        {

            string ss = Console.ReadLine();

            if (ss == null) break;

            string[] s = ss.Split(' ');

            int c = int.Parse(s[0]) + int.Parse(s[1]);

            int digit = 0;

            do
            {
                c /= 10;
                digit++;
            } while (c != 0);

            Console.WriteLine(digit);
        }

    }
}

Measured memory_bytes: 5628
S = gets.chomp.split('').map(&:to_i)

answer = (S.length + 1) / 2
bit = S[answer - 1]

(S.length - answer).times do |i|
    l = (S.length - 2) / 2 - i
    r = (S.length + 1) / 2 + i
    if S[l] == bit && S[r] == bit
        answer += 1
    else
        break
    end
end

print answer

Measured memory_bytes: 9724
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>


using namespace std;

int main() {
    long long int A, B;
    cin >> A >> B;

    cout << A * B;

    return 0;

}



Measured memory_bytes: 3196
#include<iostream>
#include<vector>
using namespace std;
int count=0;
void move(int x,int y,vector<vector<char> > &room,int w,int h){
    count++;
    if(x>0){
        if(room[x-1][y]=='.'){
            room[x-1][y]='@';
            move(x-1,y,room,w,h);
        }
    }
    if(x<h-1){
        if(room[x+1][y]=='.'){
            room[x+1][y]='@';
            move(x+1,y,room,w,h);
        }
    }
    if(y<w-1){
        if(room[x][y+1]=='.'){
            room[x][y+1]='@';
            move(x,y+1,room,w,h);
        }
    }
    if(y>0){
        if(room[x][y-1]=='.'){
            room[x][y-1]='@';
            move(x,y-1,room,w,h);
        }
    }
}

int main(void){
    int w=1,h=1,x,y;
    vector<vector<char> > room;
    while(w|h){
        count=0;
        room.clear();
        cin>>w;
        cin>>h;
        if((w|h)==0)break;
        room.resize(h);
        for(int i=0;i<h;i++){
            room[i].resize(w);
        }
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cin>>room[i][j];
                if(room[i][j]=='@'){
                    x=i;y=j;
                }
            }
        }
        move(x,y,room,w,h);
        cout<<count<<endl;
    }
    return 0;
}


Measured memory_bytes: 3120
import math
def judge(max_d,x):
    if x<=max_d:
        return x
    else:
        return 1

def main():
    n,m = map(int,input().split())
    max_d = m//n
    sq = math.floor((math.sqrt(m)))
    ans = 1
    for i in range(1,sq):
        if m%i==0:
            x1 = judge(max_d,i)
            x2 = judge(max_d,m//i)
            x = max(x1,x2)
            ans = max(ans,x)
        else:
            pass
    print(ans) 
if __name__ == '__main__':
    main()

Measured memory_bytes: 38896
// ABC_	B

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

int cunt(int N) 
{
	int ans = 0;
	while (N % 2 == 0)
	{
		ans++;
		N /= 2;

	}

	return  ans;
}


int main()
{
	int N;
	int ans =0;
	int dis;
	int num = 1;
	cin >> N;

	for (size_t i = 2; i <= N; i++)
	{
		dis = cunt(i);
		//cout << i << ":" << cunt(i) << endl;
		if (ans < dis)
		{
			num = i;
			ans = dis;
		}
	}
	cout << num <<endl;


	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
#include <math.h>
using namespace std;
int main(){
    long long int n,sum=0,f=0,ans1=0,ans2=0;
    cin>>n;
    vector<long long int>a(10000000);
    vector<long long int>b(10000000);
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i]=a[i];
    }
    f=-1;
    for(int i=0;i<n;i++){
        sum+=a[i];
        if(f*sum>0){

        }
        else{
            ans1+=abs(sum)+1;
            sum=f;
            a[i]+=f*(abs(sum)+1);
        }
        f*=-1;
    }
    sum=0;
    f=1;
    for(int i=0;i<n;i++){
        sum+=b[i];
        if(f*sum>0){

        }
        else{
            ans2+=abs(sum)+1;
            sum=f;
            b[i]+=f*(abs(sum)+1);
        }
        f*=-1;
    }
    if(ans2<ans1){
        ans1=ans2;
    }
    cout<<ans1<<endl;    
    return 0;
}


Measured memory_bytes: 159520
#include <stdio.h>
#include <stdlib.h>
#define NMAX 100000

int A[NMAX];
int partition(int q,int r){
  int x,i,j,tmp;
  x=A[r];
  i=q-1;
  for(j=q;j<r;j++){
    if(A[j]<=x){
      i=i+1;
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
    }
  }
  tmp=A[i+1];
  A[i+1]=A[r];
  A[r]=tmp;
  return i+1;
}
int main(){
int n,i=0,j;
int x,y,tmp,q;
scanf("%d",&n);
for(i=0;i<n;i++){
    scanf("%d",&A[i]);
}

q=partition(0,n-1);

for(i=0;i<n;i++){
  if(i)printf(" ");
  if(i==q)printf("[");
  printf("%d",A[i]);
  if(i==q)printf("]");
}
printf("\n");
  return 0;
}



Measured memory_bytes: 2116
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
    string s;
    cin >> s;
    
    int ans = 700;
    
    for(int i = 0; i < 3; i++){
        if(s[i] == 'o'){
            ans += 100;
        }
    }
    
    cout << ans << endl;
}

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

int main()
{
    //cout << "aaaaa" << endl;

    char m[1002][1002];
    int h,w;


   cin >> h >> w;

    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            cin >> m[i][j];
        }
    }

   int dp[1002][1002];

    dp[0][0] = 1;

    for(int j = 1; j < w; j++)
        {
            if(dp[0][j-1] == 1 && m[0][j] == '.')
                dp[0][j] = 1;
            else
                dp[0][j] = 0;
        }

     for(int j = 1; j < h; j++)
        {

            if(dp[j-1][0] == 1 && m[j][0] == '.')
            {

                dp[j][0] = 1;
            }

            else
                dp[h][0] = 0;
        }

    for(int i = 1; i < h; i++)
    {
        for(int j = 1; j < w; j++)
        {
            if(m[i][j] == '.')
                dp[i][j] = (dp[i-1][j] + dp[i][j-1])%(1000000007);

            else
            {
                dp[i][j] = 0;
            }
        }
    }



    cout << dp[h-1][w-1] << endl;

    return 0;
}


Measured memory_bytes: 5120
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

const int mod = 1e9 + 7;

// O(N * K^2)

void add_self(int& a, int b) {
    a += b;
    if(a >= mod) {
        a -= mod;
    }
}
void sub_self(int& a, int b) {
    a -= b;
    if(a < 0) {
        a += mod;
    }
}

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    vector<int> dp(k + 1);
    // dp[i] - the number of ways such that we used i candies so far
    dp[0] = 1;
    for(int child = 0; child < n; ++child) {
        int up_to;
        scanf("%d", &up_to);
        vector<int> fake(k + 1);
        for(int used = k; used >= 0; --used) {
            int tmp = dp[used];
            int L = used + 1;
            int R = used + min(up_to, k - used);
            if(L <= R) {
                add_self(fake[L], tmp);
                if(R + 1 <= k) {
                    sub_self(fake[R+1], tmp);
                }
            }
            //~ for(int i = L; i <= R; ++i) {
                //~ add_self(dp[i], tmp);
            //~ }
        }
        int prefix_sum = 0;
        for(int i = 0; i <= k; ++i) {
            add_self(prefix_sum, fake[i]);
            add_self(dp[i], prefix_sum);
        }
    }
    printf("%d\n", dp[k]);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;

int cnt = 0;

void merge(vector<int>& s, int left, int mid, int right) {
  int n1 = mid - left, n2 = right - mid;
  vector<int> l(n1 + 1), r(n2 + 1);
  rep(i, n1) l[i] = s[left + i];
  rep(i, n2) r[i] = s[mid + i];
  l[n1] = INF;
  r[n2] = INF;

  int i = 0, j = 0;
  FOR(k, left, right) {
    cnt++;
    if (l[i] <= r[j]) {
      s[k] = l[i];
      i++;
    }
    else {
      s[k] = r[j];
      j++;
    }
  }
}

void mergeSort(vector<int>& s, int left, int right) {
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    mergeSort(s, left, mid);
    mergeSort(s, mid, right);
    merge(s, left, mid, right);
  }

}

int main() {
  int n;
  cin >> n;
  vector<int> s(n);
  rep(i, n) cin >> s[i];

  mergeSort(s, 0, n);

  rep(i, n) {
    if (i) cout << " ";
    cout << s[i];
  }
  cout << endl;
  cout << cnt << endl;

  
  return 0;
}


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

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'

mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

int main(){ _
	ll a, b, c, k;	
	cin >> a >> b >> c >> k;
	ll ans = 0;
	ll t;
	t = min(a, k);
	ans += t;
	k -= t;

	t = min(b, k);
	k -= t;

	t = min(c, k);
	ans -= t;
	k -= t;
	
	cout << ans << endl;

	exit(0);
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <ctype.h>

int main(void){
	
	char ch;
	while(1){
		scanf("%c",&ch);
		if(isupper(ch)!=0){
			ch=tolower(ch);
			printf("%c",ch);
		}else if(islower(ch)!=0){
			ch=toupper(ch);
			printf("%c",ch);
		}else{
			printf("%c",ch);
		}
		if(ch=='\n') break;
	}
	return 0;
}



Measured memory_bytes: 2096
n,m=map(int,input().split())
f=lambda x:int(x)-1
l=[[] for _ in range(n)]
for i in range(m):
  a,b=map(f,input().split())
  l[a].append(b)
  l[b].append(a)
m=0  
visit=set()
for i in range(n):
  if i in visit:
    continue
  queue=[i]
  visit.add(i)
  cnt=1
  while len(queue)>0:
    now=queue.pop(0)
    for j in l[now]:
      if j not in visit:
        visit.add(j)
        queue.append(j)
        cnt+=1
  m=max(m,cnt)
print(m)

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

using lint = long long;
const int MAXN = 6005;
const int INF = 1e5;

int N;
int A[MAXN];

int ans = 0;
int base = 0;
int nxt[MAXN];
int dp[MAXN][MAXN];

inline int Cost(int a, int b, int c) {
  return A[a] == A[b] && A[b] == A[c];
}

inline void Transition(int i, int j, int cur) {
  if (cur > 3 * N) return;
  if (cur == 3 * N) {
    ans = max(ans, dp[i][j] + Cost(i, j, cur));
    return;
  }
  dp[cur + 0][cur + 1] = max(dp[cur + 0][cur + 1], dp[i][j] + Cost(i, j, cur + 2));
  dp[cur + 0][cur + 2] = max(dp[cur + 0][cur + 2], dp[i][j] + Cost(i, j, cur + 1));
  dp[cur + 1][cur + 2] = max(dp[cur + 1][cur + 2], dp[i][j] + Cost(i, j, cur + 0));

  dp[i][cur + 0] = max(dp[i][cur + 0], dp[i][j] + Cost(j, cur + 1, cur + 2));
  dp[i][cur + 1] = max(dp[i][cur + 1], dp[i][j] + Cost(j, cur + 0, cur + 2));
  dp[i][cur + 2] = max(dp[i][cur + 2], dp[i][j] + Cost(j, cur + 0, cur + 1));

  dp[j][cur + 0] = max(dp[j][cur + 0], dp[i][j] + Cost(i, cur + 1, cur + 2));
  dp[j][cur + 1] = max(dp[j][cur + 1], dp[i][j] + Cost(i, cur + 0, cur + 2));
  dp[j][cur + 2] = max(dp[j][cur + 2], dp[i][j] + Cost(i, cur + 0, cur + 1));
}

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

  cin >> N;
  for (int i = 1; i <= 3 * N; i++) {
    cin >> A[i];
  }

  while (true) {
    bool change = false;
    for (int i = 3; i + 2 <= 3 * N; i += 3) {
      if (A[i] == A[i + 1] && A[i + 1] == A[i + 2]) {
        base += 1;
        for (int j = i + 3; j <= 3 * N; j++) {
          A[j - 3] = A[j];
        }
        N -= 1;
        change = true;
        break;
      }
    }
    if (!change) {
      break;
    }
  }
  
  vector<int> last(3 * N + 1, 3 * N + 1);
  for (int i = 3 * N; i > 0; i--) {
    nxt[i] = last[A[i]];
    last[A[i]] = i;
  }
  for (int i = 0; i < MAXN; i++) {
    for (int j = 0; j < MAXN; j++) {
      dp[i][j] = -INF;
    }
  }
  dp[1][2] = 0;
  for (int i = 1; i <= 3 * N; i++) {
    for (int j = i + 1; j <= 3 * N; j++) {
      Transition(i, j, (j + 3) / 3 * 3);
      // Find next occurrence of A[i]
      if (j / 3 * 3 < nxt[i] / 3 * 3) {
        Transition(i, j, nxt[i] / 3 * 3);
      }
      // Find next occurrence of A[j]
      if (j / 3 * 3 < nxt[j] / 3 * 3) {
        Transition(i, j, nxt[j] / 3 * 3);
      }
    }
  }

  cout << ans + base << "\n";
  return 0;
}


Measured memory_bytes: 144540
#include <iostream>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    string s;
    cin >> s;
    int n = s.length();
    int cur = -1, ans = n/2;
    while(ans < n) {
        ans++;
        if (s[ans-1] == s[n-ans] && (cur == -1 || cur == s[ans-1]-'0')) {
            cur = s[ans-1] - '0';
        }
        else {
            ans--;
            break;
        }
    }
    cout << ans;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
vector<int> v1[1000001];
vector<int> v[100001];
void build(int node, int L, int R)
{
    
    for(int i = L; i <= R; i++)
    {
        for(int j = 0; j < v[i].size(); j++)
        {
            v1[node].push_back(v[i][j]);
        }
    }
    sort(v1[node].begin(), v1[node].end());
    if(L >= R)return ;
    build(2*node, L, (L+R)/2);
    build(2*node+1, (L+R)/2 + 1, R);
}

int query(int node, int L, int R, int l, int r)
{
    if(L > R || L > r || R < l) return 0;
    int ans = 0;
    if(L >= l && R <= r)
    {
        int idx = upper_bound(v1[node].begin(), v1[node].end(), r-1) - v1[node].begin();
        ans += v1[node].size() - idx;
        return ans;
    }
    int a = query(node*2, L, (L+R)/2, l, r);
    int b = query(node*2+1, (L+R)/2 + 1, R, l, r);
    return (a+b);
}
int main()
{
    int n, m;
    cin >> n >> m;
    
    for(int i = 0; i < n; i++)
    {
        int l ,r;
        cin >> l >> r;
        v[l].push_back(r);
    }
    
    build(1, 1, m);
    // for(int i = 0; i < v1[1].size(); i++)cout << v1[1][i] << " ";
    for(int d = 1; d <= m; d++)
    {
        int ans = 0;
        for(int i = d; i <= m; i+=d)
        {
            ans += query(1, 1, m, i-d+1, i);
        }
        cout << ans << "\n";
    }
    return 0;
}

Measured memory_bytes: 56944
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

int n,m,k,p;
int arr[200005];
vector<int> v;

int main() {
  memset(arr, 0, sizeof arr);
  m = 0;

  scanf("%d%d",&n,&k);
  for (int i=0; i<n; i++) {
    scanf("%d",&p);
    if (arr[p] == 0) ++m;
    ++arr[p];
  }

  if (m <= k) {
    printf("0\n");
  } else {
    for (int i=0; i<=n; i++) {
      if (arr[i] > 0) v.push_back(arr[i]);
    }

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

    int sum = 0;
    for (int i=0; i<m-k; i++) {
      sum += v[i];
    }
    printf("%d\n", sum);

  }

}

Measured memory_bytes: 2168
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue,copy
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])
def sortx(x,n,k):
    if k == 0:x.sort(key=lambda y:y[1,n])
    else:x.sort(reversed=True, key=lambda y:y[1,n])
def graph():
    n,m=inpm()
    g=[[] for _ in range(n)]
    for _ in range(n-1):
        a,b=inpm()
        a-=1
        b-=1
        g[a].append(b)
        g[b].append(a)
    return n,m,g

def graphm():
    n=inp()
    g=[[] for _ in range(n)]
    for _ in range(n-1):
        a,b,w=inpm()
        a-=1
        b-=1
        g[a].append((b,w))
        g[b].append((a,w))
    return n,g

def main():
    n,g=graphm()
    que=[0]
    ans=[-1 for _ in range(n)]
    ans[0]=0
    while len(que)>0:
        x=que.pop(0)
        for i in range(len(g[x])):
            go=g[x][i][0]
            if ans[go]==-1:
                que.append(go)
                if g[x][i][1]%2==0:
                    ans[go]=ans[x]
                else:
                    ans[go]=1-ans[x]
    print(*ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 69164
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,m = LI()
    aa = [LI() for _ in range(m)]
    s,t = LI()
    e = collections.defaultdict(set)
    for a,b in aa:
        e[a].add(b)

    def search(s):
        d = collections.defaultdict(lambda: inf)
        d[(s,0)] = 0
        q = []
        heapq.heappush(q, (0, (s,0)))
        v = collections.defaultdict(bool)
        while len(q):
            k, u = heapq.heappop(q)
            if v[u]:
                continue
            v[u] = True
            uk = (k+1)
            kk = (k+1) % 3

            for uu in e[u[0]]:
                uv = (uu, kk)
                if v[uv]:
                    continue
                if d[uv] > uk:
                    d[uv] = uk
                    heapq.heappush(q, (uk, uv))

        return d

    d = search(s)
    r = d[(t,0)]
    if r == inf:
        return -1

    return r // 3


print(main())



Measured memory_bytes: 114840
#from operator import itemgetter
#from collections import Counter
#import heapq
N = int(input())
#N, M = map(int, input().split())
#A = list(map(lambda x: int(x)*(-1), input().split()))
#A = [int(input()) for i in range(N)]
#C = [list(map(int, input().split())) for i in range()]

import itertools
import math
l = []
answer = 0

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a 

for i in range(N):
    l.append(i+1)
p = itertools.combinations_with_replacement(l, 3)
for i in p:
    a = list(i)
    g = gcd(a[0], a[1])
    ans = gcd(g, a[2])
    if a[0] == a[1] == a[2]:
        answer += ans
    elif (a[0] == a[1] and a[0] !=a[2]) or (a[0] == a[2] and a[0] !=a[1]) or (a[1] == a[2] and a[1] !=a[0]):
        answer += ans*3
    else:
        answer += ans*6
print(answer)

Measured memory_bytes: 9248
from itertools import permutations
n = int(input())
a = tuple(map(int ,input().split()))
b = tuple(map(int ,input().split()))

np = [i for i in range(1, n+1)]
p = list(permutations(np))
ai = p.index(a)
bi = p.index(b)
print(abs(ai-bi))

Measured memory_bytes: 8052
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcd(long long a,long long b){return a*b / gcd(a,b) / gcd(a,b);}


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

	vector<int> cnt(N+1);
	int s = (int)sqrt(N) + 1;
	for(int x=1; x<=s; x++)
	{
		for(int y=1; y<=s; y++)
		{
			for(int z=1; z<=s; z++)
			{
				int result = x*x + y*y + z*z + x*y + y*z + z*x;
				if(result > N)
				{
					break;
				}

				cnt[result]++;
			}
		}
	}

	for(int i=1; i<=N; i++)
	{
		cout<<cnt[i]<<endl;
	}
}

Measured memory_bytes: 3624
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
template <typename T> T max(T, T);
int gcd(int a, int b);

int main() {
    // source
    ll n, m;
    cin >> n >> m;
    ll a[n];
    rep(i, n) { cin >> a[i]; }

    vector<pair<ll, ll>> p(m);
    ll b, c;
    rep(i, m) {
        cin >> b >> c;
        p.push_back(make_pair(c, b));
    }

    sort(a, a + n, greater<ll>());
    sort(p.rbegin(), p.rend());

    ll num = n;
    ll a_index = 0;
    ll p_index = 0;
    ll ans = 0;

    while (num > 0) {
        if (a[a_index] >= p[p_index].first) {
            ans += a[a_index];
            a_index++;
            num--;
        } else {

            if (p[p_index].second > num) {
                ans += p[p_index].first * num;
                num = 0;
            } else {
                ans += p[p_index].first * p[p_index].second;
                num -= p[p_index].second;
            }

            p_index++;
        }
    }

    cout << ans << endl;

    return 0;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T max(T a, T b) {

    if (a > b) {
        return a;
    } else {
        return b;
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

void solve(){
    int N;
    cin >> N;
    if (N == 1) {
        cout << "Hello World" << endl;
    }else{
        int a,b;
        cin >> a >> b;
        cout << a+b << endl;
    }

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 764
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let mut a: Vec<bool> = vec![false; n + 1];
    for i in 1..n + 1 {
        let ai: u8 = scan(tokens);
        a[i] = ai == 1;
    }
    let mut b: Vec<usize> = Vec::new();
    for i in (1..n + 1).rev() {
        if a[i] {
            b.push(i);
            let mut j = 1;
            while j * j < i {
                if i % j == 0 {
                    a[j] ^= true;
                    a[i / j] ^= true;
                }
                j += 1;
            }
            if j * j == i {
                a[j] ^= true;
            }
        }
    }
    println!("{}", b.len());
    for i in 0..b.len() {
        if i > 0 {
            print!(" ");
        }
        print!("{}", b[i]);
    }
    println!("");
}


Measured memory_bytes: 7164
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(ll i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll,ll> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    bool sw[4][100001] = {}; // s:true w:false
    rep (i, 4) rep (j, 2) sw[i][j] = !!(i & (1 << j));
    rep (i, 4) {
        rep (j, n - 2) sw[i][j + 2] = sw[i][j] ^ sw[i][j + 1] ^ (s[(j + 1) % n] == 'o');
        if (sw[i][n - 2] ^ sw[i][n - 1] ^ (s[n - 1] == 'o') == sw[i][0]
            && sw[i][n - 1] ^ sw[i][0] ^ (s[0] == 'o') == sw[i][1]) {
                rep (k, n) cout << (sw[i][k] ? 'S' : 'W');
                cout << "\n";
                return 0;
        }
    }
    cout << "-1\n";
    return 0;
}

Measured memory_bytes: 976
/*  -*- coding: utf-8 -*-
 *
 * f.cc: F - Tree and Constraints
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 50;
const int MAX_M = 20;
const int MBITS = 1 << MAX_M;
const int BN = 16;
const int BBITS = 1 << BN;
const int BMSK = BBITS - 1;

/* typedef */

typedef long long ll;
typedef vector<int> vi;
typedef queue<int> qi;

/* global variables */

int bnums[BBITS];
vi nbrs[MAX_N];
int ps[MAX_N], ds[MAX_N];
ll ebits[MAX_N], pbits[MAX_M];

/* subroutines */

int bitnum(ll bits) {
  return
    bnums[bits & BMSK] +
    bnums[(bits >> BN) & BMSK] +
    bnums[(bits >> (BN * 2)) & BMSK] +
    bnums[(bits >> (BN * 3)) & BMSK];
}

/* main */

int main() {
  bnums[0] = 0;
  for (int bits = 1, msb = 1; bits < BBITS; bits++) {
    if ((msb << 1) <= bits) msb <<= 1;
    bnums[bits] = bnums[bits ^ msb] + 1;
  }

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

  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--, b--;
    nbrs[a].push_back(b);
    nbrs[b].push_back(a);
  }

  ps[0] = -1, ds[0] = 0, ebits[0] = 0;
  qi q;
  q.push(0);

  while (! q.empty()) {
    int u = q.front(); q.pop();
    int up = ps[u], vd = ds[u] + 1;
    ll uebits = ebits[u];
    vi &nbru = nbrs[u];

    for (vi::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
      int v = *vit;
      if (v != up) {
	ps[v] = u, ds[v] = vd;
	ebits[v] = uebits | (1LL << v);
	q.push(v);
      }
    }
  }

  int m;
  scanf("%d", &m);
  int mbits = 1 << m;

  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--, v--;
    pbits[i] = ebits[u] ^ ebits[v];
  }

  ll sum = 0;
  for (int bits = 0; bits < mbits; bits++) {
    int c = 0;
    ll pb = 0;
    for (int i = 0, bi = 1; i < m; i++, bi <<= 1)
      if (bits & bi) c++, pb |= pbits[i];

    sum += (1LL << (n - 1 - bitnum(pb))) * ((c & 1) ? -1 : 1);
  }

  printf("%lld\n", sum);
  return 0;
}


Measured memory_bytes: 512