akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second > b.second; }

int main() {
    int n,a,x,ok=0;cin>>n>>x;
    rep(i,n){
        cin>>a;
        if(a>=x)
        ok++;
    }
    cout<<ok<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
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/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
const string tr="abcdefghijklmnopqrstuvwxyz";
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
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(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll llpow(ll n,ll i){ll cnt=n;  for(ll j=0;j<i-1;j++){n*=cnt;}return n;}
bool is_prime(long long N) {if (N == 1) return false;for (long long i = 2; i * i <= N; ++i) {if (N % i == 0) return false;}return true;}
int digit(ll N) {int ans = 0;while (N) {++ans;N /= 10;}return ans;}

int main() {
  ll N;
  cin >> N;
  ll res = MX;
  for (ll A = 1; A * A <= N; ++A) {
    if (N % A == 0) {
      ll B = N / A;
      ll cnt = max(digit(A),digit(B));
      res = min(res, cnt);
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const ll LINF = 1e18;
const double EPS = 1e-9;


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

  ll n,k;
  cin>>n>>k;
  P pr[n];
  rep(i,n) cin>>pr[i].second>>pr[i].first;
  sort(pr, pr + n, greater<>());
  ll use[n + 1];
  rep(i,n+1) use[i] = 0;
  ll ans = 0, cnt = 0;
  rep(i,k) {
    ans += pr[i].first;
    if(!use[pr[i].second]) {
      cnt++;
    }
    use[pr[i].second]++;
  }
  ans += cnt * cnt;
  ll sans = ans;
  ll p = k-1;
  for(ll i = k; i < n; i++) {
    if(use[pr[i].second] == 0) {
      while(p >= 0) {
        if(use[pr[p].second] > 1) {
          sans = sans - pr[p].first + pr[i].first;
          use[pr[p].second]--;
          use[pr[i].second]++;
          cnt++;
          sans += cnt * cnt - (cnt - 1) * (cnt - 1);
          ans = max(ans, sans);
          p--;
          break;
        }
        p--;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2560
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

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

  cout << count(s.begin(), s.end(), '2') << endl;
  return 0;
}

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

class edge{
public:
    ll x, y, w;
};

int main(){
    ll n, m, p;
    cin >> n >> m >> p;
    edge e[m];
    for(ll i = 0 ; i < m ; i++){
        cin >> e[i].x >> e[i].y >> e[i].w;
        e[i].w -= p;
    }
    ll arr[n+1];
    for(ll i = 0 ; i <= n ; i++){
        arr[i] = INT_MIN;
    }
    arr[1] = 0;
    for(ll i = 1 ; i <= 2 * n ; i++){
        for(ll j = 0 ; j < m ; j++){
            ll x = e[j].x, y = e[j].y, w = e[j].w;
            if(arr[x] == INT_MIN){
                continue;
            }
            if(arr[x] + w > arr[y]){
                arr[y] = arr[x] + w;
                if(i > n){
                    arr[y] = INT_MAX;
                }
            }
        }
    }
    if(arr[n] == INT_MAX || arr[n] == INT_MIN){
        cout << -1 << endl;
        return 0;
    }
    cout << max((ll)0, arr[n]) << endl;

}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>


int main()
{
	int N, M;
	std::unordered_map<int, std::vector<long>> A;

	std::cin >> N >> M;
	for (int i = 0; i < N; ++i) {
		int a;
		long b;
		std::cin >> a >> b;
		A[a].push_back(b);
	}

	long result = 0;
	std::priority_queue<long> possible;
	for (int i = M - 1; i >= 0; --i) {
		int rest = M - i;
		auto it = A.find(rest);
		if (it != A.end()) {
			for (auto b : it->second) {
				possible.push(b);
			}
		}
		if (!possible.empty()) {
			result += possible.top();
			possible.pop();
		}
	}

	std::cout << result << "\n";
}


Measured memory_bytes: 8868
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int MAX_N = 100000;
ll N;
ll dp[MAX_N+1];

ll rec(ll n) {
  if (dp[n] != 0) return dp[n];

  if (n < 6) return dp[n] = n;

  ll res = 1e18;
  int i = 6;
  while(i <= n) i *= 6;
  res = min(res, rec(n-(i/6))+1);

  i = 9;
  while(i <= n) i *= 9;
  res = min(res, rec(n-(i/9))+1);

  return res;
}


int main() {
  cin >> N;

  cout << rec(N) << endl;
}


Measured memory_bytes: 256
'use strict';
function main(input) {
  const N = parseInt(input);
  let distance = N - 1;
  for (let a = 2; a <= Math.sqrt(N); ++a) {
    let b = N / a;
    if (Number.isInteger(b) && a+b-2 < distance) {
      distance = a+b-2;
    }
  }
  console.log(distance);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

int main() {
    int N, K, t;
    int d[110];
    int A[110] = {};

    cin >> N >> K;
    for (int i = 0; i < K; i++) {
        cin >> d[i];
        for (int j = 0; j < d[i]; j++) {
            cin >> t;
            A[t-1] = 1;
        }
    }

    int ans = 0;
    for (int i = 0; i < N; i++) if (A[i] == 0) ans++;
    cout << ans << endl;

}

Measured memory_bytes: 3548
unittest
{
	assert( [ "4 5" ].parse.expand.solve == 10 );
	assert( [ "7 3" ].parse.expand.solve == 11 );
	assert( [ "1000000000 1000000000" ].parse.expand.solve == 500000000000000000 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto hw = input.front.split.to!( long[] );
	return tuple( hw[ 0 ], hw[ 1 ] );
}

auto solve( long h, long w )
{
	if( h == 1 || w == 1 ) return 1;
	else                   return ( ( w + 1 ) / 2 ) * ( ( h + 1 ) / 2 ) + ( w / 2 ) * ( h / 2 );
}


Measured memory_bytes: 256
a=int(input())
b=list(map(int,input().split()))
c=0
for i in range(a-2):
  if b[i]<b[i+1] and b[i+1]<b[i+2] or b[i]>b[i+1] and b[i+1]>b[i+2]:
    c+=1
print(c)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long;
const ll MOD = 1e9+7; int INF=INT_MAX; ll LLINF = 1LL << 60;
const vector<int> d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vector<int> d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> d4x = {1, 0, -1, 0}; vector<int> d4y = {0, 1, 0, -1};

//

int main(){
    int k; cin>>k;
    ll sum=0;
    for(int i=1; i<=k; i++){
        for(int j=1; j<=k; j++){
            for(int l=1; l<=k; l++){
                sum+=__gcd(i,__gcd(j,l));
            }
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 3632
S = input()
T = input()
s = []
t = []
if len(S) + 1 == len(T):
    for i in range(len(S)):
        s.append(S[i])
        t.append(T[i])
    if s == t:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 9116
import heapq as hq
from math import ceil
N, H = map(int, input().split())
A = 0
B = []
for i in range(N):
  a, b = map(int, input().split())
  A = max(A, a)
  hq.heappush(B, -b)

ans = 0
while H > 0 and B:
  b = -hq.heappop(B)
  if b > A:
    H -= b
    ans += 1
  else:
    break

if H > 0:
  ans += ceil(H / A)

print(ans)

Measured memory_bytes: 7192
#include <iostream>

using namespace std;
using ll = long long;
const ll MAX = 1000010;
const ll mod = 1000000007;
ll fact[MAX],inv[MAX],fi[MAX];
void fii(){
    inv[1] = 1;
    for(int i=2;i<=MAX;i++){
        inv[i] = mod - mod/i*inv[mod%i]%mod;
    }
    fact[0] = 1; fact[1] = 1; fi[0] = 1; fi[1] = 1;
    for(int i=2;i<=MAX;i++){
        fact[i] = fact[i-1]*i%mod;
        fi[i] = fi[i-1]*inv[i]%mod;
    }
}

ll nck(int n, int k){
    if(k>n) return 0;
    return fact[n]*fi[n-k]%mod*fi[k]%mod;
}

ll dp[1000010],ans = 0;
int main(){
    int i,n;
    cin >> n;
    fii(); dp[0] = 0;
    for(i=1;i<n;i++){
        dp[i] = nck(i-1,n-1-i)*fact[i]%mod*fact[n-1-i]%mod;
        
    }
    for(i=1;i<n;i++){
        (ans += (mod + dp[i]-dp[i-1])%mod*i) %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 31488
#include <iostream>
#include <vector>
#include <algorithm>

#define int long long

using namespace std;

int save, res;
vector<pair<int, int> > g;

signed main()
{
	int n, cnt = 0;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		int x, y;
		cin >> x >> y;

		cnt += (x == y);

		if (x <= y)
		{
			save += y - x;
			res += x;
		}
		else
		{
			g.push_back({ x, y });
		}
	}

	if (cnt == n)
	{
		cout << 0 << endl;
		return 0;
	}

	int miny = (int)1e9 + 5;
	for (pair<int, int> p : g)
	{
		miny = min(miny, p.second);
		res += p.first;
	}

	res -= miny;
	cout << res << endl;
	return 0;
}

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

int main() {

    int s1s2s3, ans = 0;
    cin >> s1s2s3;              // 例：101
    
    // 1桁目の余りを求める
    ans += s1s2s3 % 10;         // 101 % 10 = 1
    
    // 1桁目を無くす
    s1s2s3 /= 10;               // 101 / 10 = 10
    
    // 2桁目の余りを求める
    ans += s1s2s3 % 10;         // 10 % 10 = 0
    
    // 2桁目を無くす
    s1s2s3 /= 10;               // 10 / 10 = 1
    
    // 2桁目の余りを求める
    ans += s1s2s3 % 10;         // 1 % 10 = 1
    
    cout << ans << endl;

}

Measured memory_bytes: 256
#配列の準備
# ンプット分を数値型に変換後、スプリットで各変数に持たせる

a,b,c,d=map(int,input().split())
# abs関数で引数を絶対値とする。

if abs(c-a)>d:
  if abs(a-b)>d or abs(b-c)>d:
    print("No")
  else:
    print("Yes")
else:
  print("Yes")

Measured memory_bytes: 8952
#include <stdio.h>
#include <string.h>
int main(){
	int n;
	int taro = 0;
	int hanako = 0;
	char str_t[101];
	char str_h[101];
	int i;
	int judge;
	scanf("%d", &n);
	for(i = 0;i < n; i++){
		scanf("%s %s", str_t, str_h);
		judge = strcmp(str_t, str_h);
		if(judge > 0) taro+=3;
		else if(judge < 0) hanako += 3;
		else {
			taro++;
			hanako++;
		}
	}
	printf("%d %d\n", taro, hanako);

	return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    vector<int> a(3);
    cin>>a[0]>>a[1]>>a[2];
    sort(a.begin(),a.end());
    int ans=0,k;
    k=(a[2]-a[1])/2;
    ans+=k;
    a[1]+=2*k;
    k=(a[2]-a[0])/2;
    ans+=k;
    a[0]+=2*k;
    if (a[1]==a[2])
    {
        if (a[0]!=a[1])
            ans+=2;
    }
    else
    {
        if (a[0]==a[2])
            ans+=2;
        else
            ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int maxArray;

/* 配列の要素を順番に出力 */
void printOut(int *numericArray)
{
    int count;
    for (count = 0; count < maxArray; count++) {
        if (count > 0) {
            printf(" ");
        }
        printf("%d",numericArray[count]);
    }
    printf("\n");
}

/* 挿入ソート */
void insertionSort(int *numericArray)
{
    int count, currentReference, insertedValue;

    for (count = 1; count < maxArray; count++) {
        insertedValue = numericArray[count];
        currentReference = count - 1;
        while (currentReference >= 0 && numericArray[currentReference] > insertedValue) {
            numericArray[currentReference + 1] = numericArray[currentReference];
            currentReference--;
        }
        numericArray[currentReference + 1] = insertedValue;
        printOut(numericArray);
    }
}

int main(void)
{
    int count;

    scanf("%d",&maxArray);
    int numericArray[maxArray];

    for (count = 0; count < maxArray; count++) {
        scanf("%d", &numericArray[count]);
    }

    printOut(numericArray);
    insertionSort(numericArray);

    return 0;
}



Measured memory_bytes: 2124
#include <iostream>
#include <map>
#include <vector>
#include <string>

#define _ << " " <<
#define debug(x) #x << " = " << (x)

using ll = long long;

const int maxn = 350;
int map[maxn][maxn];
using pii = std::pair<int, int>;

int prefix[maxn][maxn];
std::map<int, std::vector<pii>> find_points(int l, int r, int t, int b)
{
	std::map<int, std::vector<pii>> points;
	for (int i = t; i <= b; i++)
	{
		for (int j = l; j <= r; j++)
		{
			if (map[i][j] > 0)
				points[j].push_back({i, map[i][j]});
		}
	}

	return points;
}

void fill_simple(int l, int r, int t, int b, int c)
{
	for (int i = t; i <= b; i++)
	{
		for (int j = l; j <= r; j++)
		{
			if (map[i][j] == 0)
				map[i][j] = c;
		}
	}
}

const ll inf = 0x3f3f3f3f;
void fill(int l, int r, int t, int b)
{
	if (l > r || t > b)
		return;

	auto points = find_points(l, r, t, b);
	points[r + 1].push_back({t, inf});

	int last_col = l;
	auto it = points.begin();
	while (it != points.end())
	{
		if (it->second.front().first == inf)
			break;


		int next_col = std::next(it)->first - 1;

		it->second.push_back({b + 1, inf});
		int last_row = t;

		auto it2 = it->second.begin();
		while (it2 != it->second.end())
		{
			if (it2->second == inf)
				break;

			int next_row = std::next(it2)->first - 1;
			fill_simple(last_col, next_col, last_row, next_row, it2->second);
			last_row = next_row + 1;
			++it2;
		}

		last_col = next_col + 1;
		++it;
	}
}

int main()
{
	int n, m, k;
	std::cin >> n >> m >> k;
    int count = 1;
	for (int i = 0; i < n; i++) {
        std::string level;
        std::cin >> level;
        for (int j = 0; j < m; j++)
        {
            if (level[j] != '.')
                map[i][j] = count++;
        }
	}

    fill(0, m, 0, n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++)
            std::cout << map[i][j] << " ";
        std::cout << "\n";
	}
}

Measured memory_bytes: 2048
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T>
inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T>
inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T>
T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

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

	if (ceil((double)c / b) > ceil((double)a / d)) {
		cout << "No" << endl;
	}
	else cout << "Yes" << endl;
}


Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <algorithm>
#include <unordered_map>

using namespace std;

int main()
{
	const int MAX_N = 100000;
	const string okMessage = "Yes";
	const string badMessage = "No";

	int n;
	cin >> n;
	int h[MAX_N];
	for (int i = 0; i < n; i++)
		cin >> h[i];

	for (int i = 1; i < n; i++)
	{
		if (h[i] < h[i - 1])
		{
			cout << badMessage;
			return 0;
		}
		else
		{
			if (h[i] != h[i - 1])
				h[i] -= 1;
		}
	}

	cout << okMessage;

	return 0;
}


Measured memory_bytes: 640
import sys
import bisect

N = int(sys.stdin.readline())
L = [int(x) for x in sys.stdin.readline().split()]
L.sort()

answer = 0

for i in range(len(L)-2):
    for j in range(i+1, len(L)-1):
        answer += bisect.bisect_left(L, L[i]+L[j])-j-1

print(answer)


Measured memory_bytes: 44588
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pdd pair<double, double>
#define V vector<int>
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define db(x) cout << #x << "=" << (x) << endl
#define db2(x, y) cout << #x << "=" << (x) << " " << #y << "=" << (y) << endl
#define db3(x, y, z) cout << #x << "=" << (x) << " " << #y << "=" << (y) << " " << #z << "=" << (z) << endl

using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 7;
const double eps = 1e-9;

int a[maxn];
int main()
{
    #ifdef AFei
    freopen("in.txt", "r", stdin);
    #endif

    int N, M, Q;
    cin >> N >> M >> Q;
    for(int x, i = 0; i < Q; ++ i)
    {
        scanf("%d", &x);
        a[x-1] ++;
    }
    for(int i = 0; i < N; ++ i)
    {
        if(Q-a[i] < M)
            puts("Yes");
        else
            puts("No");
    }

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main() {
    constexpr double PI = 3.1415926535897932;
    double r;
    cin >> r;
    cout << fixed << setprecision(16) << PI * pow(r, 2) << ' ' << 2 * PI * r << endl;
}



Measured memory_bytes: 3272
////////////////////////
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
namespace my {
char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }
ll gcd(ll a, ll b) {
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll lcm(ll a, ll b) { return a * b / my::gcd(a, b); }
vector<pair<ll, ll>> primeFac(ll n) {
  vector<pair<ll, ll>> ret;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) continue;
    ll exp = 0;
    while (n % i == 0) {
      n /= i;
      exp++;
    }
    ret.push_back(make_pair(i, exp));
  }
  if (n != 1) ret.push_back(make_pair(n, 1));
  return ret;
}
}  // namespace my
////////////////////////

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

  int rall = 0;
  for (auto &si : s) {
    if (si == 'R') rall++;
  }
  int ans = 0;
  for (int i = 0; i < rall; i++) {
    if (s.at(i) != 'R') ans++;
  }

  cout << ans << endl;
}

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

int dp[2][140][20000][3],nxtind[20000][10];

signed main(){
	string s;
	cin >> s;
	int n = s.length(),sum = 0,prod = 1;
	for(int i = 0;i < n;i++){
		sum += s[i] - '0';
		prod *= s[i] - '0' + 1;
	}
	set<int> st;
	st.insert(1);
	for(int i = 0;i < n;i++){
		set<int> nxt;
		for(int v : st){
			for(int j = 1;j <= 10;j++) nxt.insert(v * j);
		}
		st.swap(nxt);
	}
	vector<int> vec(st.begin(),st.end());
	for(int i = 0;i < vec.size();i++){
		for(int j = 0;j < 10;j++){
			auto it = lower_bound(vec.begin(),vec.end(),vec[i] * (j + 1));
			if(*it == vec[i] * (j + 1)) nxtind[i][j] = it - vec.begin();
			else nxtind[i][j] = -1;
		}
	}
	dp[0][0][0][1] = 1;
	for(int i = 0;i < n;i++){
		int _i = i % 2;
		for(int j = 0;j <= (i + 1) * 9;j++){
			for(int k = 0;k < vec.size();k++){
				for(int l = 0;l < 3;l++) dp[!_i][j][k][l] = 0;
			}
		}
		for(int j = 0;j <= i * 9;j++){
			for(int k = 0;k < vec.size();k++){
				for(int l = 0;l < 10;l++){
					if(nxtind[k][l] == -1) continue;
					int dest;
					if(s[i] - '0' == l) dest = 1;
					else if(s[i] - '0' > l) dest = 0;
					else dest = 2;
					dp[!_i][j + l][nxtind[k][l]][dest] += dp[_i][j][k][1];
					dp[!_i][j + l][nxtind[k][l]][0] += dp[_i][j][k][0];
					dp[!_i][j + l][nxtind[k][l]][2] += dp[_i][j][k][2];
				}
			}
		}
	}
	int ans = 0,prodind = lower_bound(vec.begin(),vec.end(),prod) - vec.begin();
	for(int i = 0;i <= n * 9;i++){
		for(int j = 0;j < vec.size();j++){
			for(int k = 0;k < 3;k++){
				if(i < sum || (i == sum && j < prodind) || (i == sum && j == prodind && !k)) ans += dp[n % 2][i][j][k];
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 113960
#include <bits/stdc++.h>
#define typeof(x) __typeof__(x)
#define int long long int
#define double long double
#define mod(x) ((x % MOD) + MOD) % MOD
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define RREP(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) (UB(c,x)-LB(c,x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (s).find(e)!=(s).end()
#define PB push_back
#define MP make_pair
#define vec vector
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define NL cerr << endl;

using namespace std;

typedef pair<int,int> P;
struct edge { int from, to; int cost; };
ostream& operator << (ostream& s, const edge& e) {
   s << "(" << e.from << "->" << e.to << ": " << e.cost << ")";
   return s;
}
bool operator< (const edge &edge1, const edge &edge2){
   return edge1.cost < edge2.cost;
};

const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const pair<T1,T2>& p) {
   s << "(" << p.first << "," << p.second << ")";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const map<T1,T2>& m) {
   s << "{";
   for (auto i = m.begin(); i != m.end(); ++i) {
      s << i->first << ":" << i->second;
      if (next(i) != m.end()) s << ", ";
   }
   s << "}";
   return s;
}

signed main()
{
   int H, W, N; cin >> H >> W >> N;
   vec<int> a(N), b(N);
   REP(i, 0, N) {
      cin >> a[i] >> b[i];
      a[i]--; b[i]--;
   }

   map<P, int> count;

   REP(i, 0, N) {
      REP(dx, -1, 2) {
         REP(dy, -1, 2) {
            double x = a[i] + dx;
            double y = b[i] + dy;
            if (0 < x && x < H-1 && 0 < y && y < W-1) {
               count[MP(x, y)]++;
            }
         }
      }
   }

   map<int, int> ans;
   EACH(i, count) {
      ans[i->second]++;
   }

   int sum = 0;
   REP(i, 1, 10) {
      sum += ans[i];
   }
   cout << (H-2)*(W-2) - sum << endl;
   REP(i, 1, 10) {
      cout << ans[i] << endl;
   }

   return 0;
}


Measured memory_bytes: 58112
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;


int n, q;
string s;
vector<char> t, d;

bool calcr(int idx){
    if(idx == n) return true;
    int now = idx;
    rep(i, 0, q){
        if(t[i] == s[now]){
            if(d[i] == 'L') now--;
            else now++;
        }
        if(now == -1) return false;
        if(now == n) return true;
    }
    return false;
}

bool calcl(int idx){
    if(idx == -1) return true;
    int now = idx;
    rep(i, 0, q){
        if(t[i] == s[now]){
            if(d[i] == 'L') now--;
            else now++;
        }
        if(now == n) return false;
        if(now == -1) return true;
    }
    return false;
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> n >> q >> s;
    t.resize(q); d.resize(q);
    rep(i, 0, q){
        cin >> t[i] >> d[i];
    } 
    if(calcr(0)){
        cout << 0 << endl;
        return 0;
    }
    if(calcl(n - 1)){
        cout << 0 << endl;
        return 0;
    }
    int rng = 0, rok = n;
    while(rok - rng > 1){
        int mid = (rok + rng) / 2;
        if(calcr(mid)) rok = mid;
        else rng = mid;
    }
    int lng = n - 1, lok = -1;
    while(lng - lok > 1){
        int mid = (lok + lng) / 2;
        if(calcl(mid)) lok = mid;
        else lng = mid;
    }
    cout << rng - lng + 1 << endl;
}

Measured memory_bytes: 976
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll g = c / __gcd(c, d) * d;
  ll ans = (b - a + 1) - (b / c - a / c) - (b / d - a / d) + (b / g - a / g);
  if (a % c == 0) ans--;
  if (a % d == 0) ans--;
  if (a % g == 0) ans++;
  cout << ans << "\n";
  return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int main() {
  string str; cin >> str;
  int ans, cnt = 0;
  for (int i = 0; i < str.length(); i++) {
    if (str[i] == '0') {
      cnt--;
    } else {
      cnt++;
    }
  }
  ans = str.length() - abs(cnt);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
h=int(input())
w=int(input())
n=int(input())

ans=0
count=0
i=0
while i<min(w,h):
	count+=max(w,h)
	ans+=1
	i+=1
	if count>=n:
		break

if count<n:
	j=0
	while j<max(w,h):
		ans+=1
		count+=min(w,h)
		j+=1
		if count>=n:
			break
print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
  int A,B;
  scanf("%d %d",&A,&B);
  if(A <= 8 && B <= 8)
    printf("Yay!\n");
  else
    printf(":(\n");
  return 0;
}


Measured memory_bytes: 128
st = input().split()
AB = input().split()
U = input()
s = st[0]
t = st[1]
A = int(AB[0])
B = int(AB[1])

if s == U:
    A = A - 1

if t == U:
    B = B - 1

print(str(A) + " " + str(B))


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] r = new int[4];
        for (;;) {
            int[] l = new int[] { sc.nextInt(), sc.nextInt(), sc.nextInt() };
            Arrays.sort(l);
            if (l[0] + l[1] <= l[2]) {
                for (int i = 0; i < 4; i++) {
                    System.out.print(r[i] + (i == 3 ? "\n" : " "));
                }
                break;
            }
            r[0]++;
            int a = l[0] * l[0] + l[1] * l[1];
            int b = l[2] * l[2];
            if (a == b) {
                r[1]++;
            } else if (a > b) {
                r[2]++;
            } else {
                r[3]++;
            }
        }

    }
}


Measured memory_bytes: 26396
#include<iostream>
#include<string>
#include<algorithm>
#include<set>

using namespace std;
#if 0
http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=774095#1
#endif


int n;
string s[100000];



int main(){
  cin >> n;
  int cnt = 0;
  for(int i = 0; i < n; ++i){
    typedef set<string>set_t;
    set_t A;
    cin >> s[i];
    
    for(int j = 0; j < s[i].size(); ++j){
      string l = s[i].substr(0, j);
      string r = s[i].substr(j);
      A.insert(l + r);
      A.insert(r + l);
      reverse(l.begin(), l.end());
      A.insert(l + r);
      A.insert(r + l);
      reverse(r.begin(), r.end());
      A.insert(l + r);
      A.insert(r + l);
      reverse(l.begin(), l.end());
      A.insert(l + r);
      A.insert(r + l);
    }
    cout << A.size() << endl;
  }
}


Measured memory_bytes: 3968
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)


func main()  {
	sc.Scan()
	in := sc.Text()
	cols := strings.Split(in, "")

	for _, c := range cols {
		if c == "1" {
			fmt.Print( 9)
		} else if c == "9" {
			fmt.Print( 1)
		} else {
			fmt.Print(c)
		}
	}
	fmt.Println()
}


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

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

void solve(int n, int m, int a){
	vector<PP> v;
	for(int i=0; i<m; ++i){
		int h, p, q;
		cin >> h >> p >> q;
		v.push_back(PP(h, P(p, q)));
	}
	sort(v.begin(), v.end());
	vector<int> w;
	for(int i=0; i<n; ++i)
		w.push_back(i+1);
	for(int i=0; i<m; ++i)
		swap(w[v[i].second.first-1], w[v[i].second.second-1]);
	cout << w[a-1] << "\n";
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(1){
		int n, m, a;
		cin >> n >> m >> a;
		if(n+m+a==0) return 0;
		solve(n, m, a);
	}
}


Measured memory_bytes: 3204
#include <iostream>                        
#include <cmath>                           
using namespace std;                       
                                           
int main(void){                            
 long int n,a,b,c,d,e,min;                 
  cin >> n;                                
  cin >> a;min = a;                        
  cin >> b;if(b < min) min =b;             
  cin >> c;if(c < min) min = c;            
  cin >> d;if(d < min) min = d;            
  cin >> e;if(e < min) min = e;            
  cout <<  4 + (n+min-1)/min<< endl;       
  return 0;                                
}                                          
                                           
                                           
                                           

Measured memory_bytes: 256
import sys
# import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

def z_algorithm(s: list):
    n = len(s)
    if n == 0: return []
    z = [-1] * n
    z[0] = 0; j = 0
    for i in range(1, n):
        k = z[i] = 0 if j + z[j] <= i else min(j + z[j] - i, z[i - j])
        while i + k < n and s[k] == s[i + k]: k += 1
        z[i] = k
        if j + z[j] < i + z[i]: j = i
    z[0] = n
    return z

def z_algorithm2(s: str):
    n = len(s)
    s2 = list(map(ord, s))
    return z_algorithm(s2)

def Main():
    n = read_int()
    s = read_str()
    ans = 0
    for i in range(n):
        lcp = z_algorithm2(s[i:])
        for j, x in enumerate(lcp):
            ans = max(ans, min(j, x))
    print(ans)

if __name__ == '__main__':
    Main()

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

int main(){

    int n;
    int ans=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        int check=i;
        int digit=0;
        while(check>0){
            check/=10;
            digit++;
        }
        if(digit%2==1) ans++;

    }

    cout<<ans<<endl;




    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>

#define EPS 1e-9

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

    double a, b, c, d, e, f;
    while(std::cin >> a >> b >> c >> d >> e >> f){
        double x = std::round(1000*(c*e-b*f)/(a*e-b*d))/1000;
        double y = std::round(1000*(a*f-c*d)/(a*e-b*d))/1000;
        std::cout << std::fixed << std::setprecision(3) << ((std::fabs(x)<EPS)?0:x) << " " << ((std::fabs(y)<EPS)?0:y) << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 3340
count = int(input())
primeCount = 0
for i in range(count):
    num = int(input())
    beki = num**(1/2)
    if beki%1 == 0:
        chkmax = beki//1
    else:
        chkmax = beki//1 + 1
    chkmax = int(chkmax)

    flag = True
    for i in range(2,chkmax+1):
        if num%i == 0:
            flag = False
            break

    if flag or num == 2:
        primeCount += 1

print(primeCount)



Measured memory_bytes: 5700
n = int(input())
l = [0]*10010


for i in range(1, 100):
    for j in range(1, 100):
        for k in range(1, 100):
            ref = i**2 + j**2 + k**2 + i*j + j*k + i*k
            if ref <= 10000:
                l[ref - 1] += 1

for i in l[:n]:
    print(i)

Measured memory_bytes: 9140
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int d;
int c[27];
int s[366][27];
int calc(vector<int> t){
    int last[26]={};
    vector<int> ret(d);
    int ans=0;
    for(int i=0; i<d; i++){
        ans+=s[i][t[i]];
        last[t[i]]=i+1;
        for(int j=0; j<26; j++){
            ans-=c[j]*(i+1-last[j]);
        }
        ret[i]=ans;
    }
    return ans;
}
int main()
{
    cin>>d;
    for(int i=0; i<26; i++) cin>>c[i];
    for(int i=0; i<d; i++) for(int j=0; j<26; j++) cin>>s[i][j];
    vector<int> t(d);
    int last[26]={};
    for(int i=0; i<d; i++){
        int kmx=0, mx=-1e9;
        for(int k=0; k<26; k++){
            int sum=s[i][k];
            int myon=last[k];
            last[k]=i+1;
            for(int j=0; j<26; j++){
                sum-=c[j]*(i+1-last[j]);
            }
            last[k]=myon;
            if(mx<sum) kmx=k, mx=sum;
        }
        t[i]=kmx;
        last[kmx]=i+1;
    }
    for(int i=0; i<d; i++){
        cout<<t[i]+1<<endl;
    }
	return 0;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define  ll  long long
#define rep(k, n)  for(int i=k; i<n;  i++)
#define rep2(k,n)   for(int j=k; j<n;  j++)
using namespace std;

int main(){
    int ans;
    string s;
    string list[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    cin >> s;

    rep(0,7){
        if(s == list[i]){
            ans = i;
        }
    }
    cout << 7-ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		String[] a = new String[h];
		for (int i = 0; i < h; i++) {
			a[i] = sc.next();
		}
		
		for (int i = 0; i < w + 2; i++) {
			System.out.print("#");
		}
		System.out.println();
		for (int i = 0; i < h; i++) {
			System.out.print("#");
			System.out.print(a[i]);
			System.out.println("#");
		}
		for (int i = 0; i < w + 2; i++) {
			System.out.print("#");
		}
		System.out.println();
	}

	public static void main(String[] args) {
		new Main().run();
	}
}
	

Measured memory_bytes: 21716
// #include <bits/stdc++.h>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<map>
#include<set>
#include<vector>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<string>
#include<tuple>
using namespace std;
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
long N,M,A,B,C,n;
cpp_int sum;
map<long,long,greater<long>>m;
inline void solve(void){
  in(N,M);
  rep(i,N){
    in(A);
    m[A]++;
  }
  rep(i,M){
    in(B,C);
    m[C]+=B;
  }
  for(auto e:m){
    if(n+e.sd<=N){
      sum+=e.ft*min(e.sd,N);
      n+=min(e.sd,N);
    }else{
      sum+=e.ft*(N-n);
      break;
    }
  }
  out(sum);
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
// *st.find_by_order(index), 0-based
// order_of_key(e)

const int mx=3077;
ll val[mx][mx], r,c,v, dp[mx][mx][7];

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int R,C,K; cin>>R>>C>>K;
	for (int i=0; i<K; i++)
		cin>>r>>c>>v, val[r][c]=v;
	ll ret=0;
	for (int i=1; i<=R; i++)
		for (int j=1; j<=C; j++)
			for (int k=1; k<=3; k++)
				dp[i][j][k]=max({dp[i-1][j][3]+val[i][j],dp[i][j-1][k-1]+val[i][j],dp[i][j-1][k]}), ret=max(ret,dp[i][j][k]);
	cout<<ret<<"\n";
	return 0;
}

Measured memory_bytes: 579688
#include <cstring>
#include <cassert>
#include <utility>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <bitset>
#include <chrono>
#include <cstdlib>
#include <functional>
#include <tuple>
#include <climits>
#include <limits>
#include <deque>
#include <list>
#include <array>
#include <stack>
#include <queue>
#include <random>
#include <complex>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
 
#define init ios::sync_with_stdio(0); cin.tie(NULL);cout.tie(NULL);
#define setpr(x) cout << setprecision((x))
#define PI atan(1)*4
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define in insert
#define er erase
#define mk(a , b) { min((a) , (b)) , max((a) , (b)) }
#define flush cout.flush()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endc "\n"
#define MOD 998244353
#define mod(x) (x) %= MOD
 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;

// #define int ll
 
ll gcd(ll a, ll b){
    while(true){
        if(a>b)
            swap(a,b);
        if (a == 0) 
            return b; 
        ll p = b % a  , q = a;
        a = p;
        b = q;
    }
}
 
ll powerMod(ll x,ll y){
    ll res = 1;
    x %= MOD;
    while(y > 0){
        if(y & 1)res = (res*x)%MOD;
        y = y >> 1;
        x = (x * x)%MOD;
    }
    return res%MOD;
}
 
string binary(ll s) {
    string res = "";
    while(s != 0) {
        res += (char)('0' + s % 2);
        s /= 2;
    }
    reverse(res.begin() , res.end());
    return res;
}


//  =========     /\       /|    |====/|
//      |        /  \       |    |   / |
//      |       /____\      |    |  /  |
//      |      /      \     |    | /   |
//  ========= /        \  =====  |/====|  
//  code

int32_t main(){
    init;
    ll n,s,i,j,k,l,p;
    cin >> n >> s;
    vector<ll> a(n);
    vector< vector<ll> >dp(n + 1 , vector<ll>(s + 1 , 0LL));

    for(auto &i : a)cin >> i;

    for(i = p = 0LL; i < n; i++){
        dp[i + 1] = dp[i];
        if(a[i] <= s)
            mod( dp[i + 1][a[i]] += i + 1LL );
        for(j = 0LL; j <= s - a[i]; j++){
            mod( dp[i + 1][j + a[i]] += dp[i][j] );
        }
        mod (p += dp[i + 1][s]);
    }
    cout << p << endc;
    return 0;
}

Measured memory_bytes: 70784
<?php
fscanf(STDIN, "%d %d", $n, $k);
$x = 0;
$m = $n;
if ($n >= $k) {
	$x = ($n - $k + 1) / $n;
	$m = $k - 1;
}
$p = 0.5;
while ($k > 1) {
	$k *= 0.5;
	$k1 = (int) ceil($k);
	if ($m >= $k1) {
		$x += ($m - $k1 + 1) / $n * $p;
		$m = $k1 - 1;
	}
	$p *= 0.5;
}
echo $x;

Measured memory_bytes: 4604
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;
typedef long long ll;
int main(){
    int N; cin >> N;
    vector<pair<int, int>> P;
    int A[1000000] = {};
    int Max = 0;
    for(int i = 0; i < N; i++){
        int a; cin >> a; A[a]++;
        Max = max(Max, a);
    }
    for(int i = 0; i <= Max; i++){
        if(A[i] != 0){
            P.push_back(make_pair(i, A[i]));
        }
    }
    sort(P.begin(), P.end());
    int ans = N;
    int f=0, l=P.size()-1;
    while(P[f].second <= 1){
        if(0 <= f && f < P.size()){
            f++;
        }
        else break;
    }
    while(P[l].second <= 1){
        if(0 < l && l < P.size()){
            l--;
        }
        else break;
    }
    if(f == P.size() && l == 0){
        cout << ans << endl;
        return 0;
    }

    while(f <= l){
        if(f < 0 || P.size() <= f) break;
        if(l < 0 || P.size() <= l) break;
        if(f+1 < l){
            P[f].second--;
            P[l].second--;
            ans -= 2;
            while(P[f].second <= 1 && f <= l){
                f++;
            }
            while(P[l].second <= 1 && f <= l){
                l--;
            }
        }
        else if(f < l){
            int tmp = P[f].second + P[l].second;
            if(tmp % 2 == 0){
                int use = tmp - 2;
                ans -= use;
            }
            else{  
                int use = tmp - 1;
                ans -= use;

            }
            break;
        }
        else if(f == l){
            if(P[f].second % 2 == 0){
                int use = P[f].second - 2;
                ans -= use;
                ans -= 2;
            }
            else{
                int use = P[f].second -1;
                ans -= use;
            }
            break;
        }
        //cout << ans << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5240
$d = [[[-1, -1], [0, -1], [1, -1], [1, 0], [0, 1], [-1, 0]],
      [ [-1, 0], [0, -1],  [1, 0], [1, 1], [0, 1], [-1, 1]]]
     
def bfs(fld, w, h)
 
  fld
end

w, h = gets.split.map(&:to_i)
fld = (h+2).times.map{ [false]*(w+2) }
(1..h).each do |i|
  gets.split(" ").each_with_index{ |e, idx| fld[i][idx+1] = true if e == "1" }
end

#bfs
prt = (h+2).times.map{ [false]*(w+2) }
arr = []
arr << [0, 0]
prt[0][0] = true
until arr.empty?
  y, x = arr.pop
  $d[y%2].each do |dy, dx|
    u = y + dy; v = x + dx
    next if u < 0 || u > h+1 || v < 0 || v > w+1
    if !fld[u][v] && !prt[u][v]
      prt[u][v] = true
      arr << [u, v]
    end
  end
end
(1..h).each do |k|
  (1..w).each do |m|
    fld[k][m] = true unless prt[k][m]
  end
end

sum = 0
(1..h).each do |i|
  (1..w).each do |j|
    if fld[i][j]
      $d[i%2].each do |y, x|
        sum += 1 if !fld[i+y][j+x]
      end
    end
  end
end
p sum

Measured memory_bytes: 8928
#include<iostream>
using namespace std;
int main(){
	int a,b;
	cin>>a;
	cin>>b;
	if(a<b){
		cout<<"a < b"<<endl;
	}
	else if(a>b){
		cout<<"a > b"<<endl;
	}
	else if(a==b){
		cout<<"a == b"<<endl;
	}
}

Measured memory_bytes: 1156