akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
#define AMAX 100001
 
 
struct card{
  char mark;
  int value;
  int cnt;
};
 
card a[AMAX];
int partion(int q, int r){
  int x = a[r].value;
  int i = q-1;
  for(int j = q; j < r; j++){
    if(a[j].value <= x){
      i = i + 1;
      swap(a[i],a[j]);
    }
  }
  swap(a[i+1],a[r]);
  return i+1;
}
 
 
void quicksort(int p, int r){
 
  if(p < r){
    int q;
    q = partion(p,r);
    quicksort(p,q-1);
    quicksort(q+1,r);
  }
}
 
int main(){
 
  int n;
  scanf("%d",&n);
 
  for(int i = 0; i < n; i++){
    scanf(" %c %d",&a[i].mark,&a[i].value);
    a[i].cnt = i;
  }
 
  quicksort(0,n-1);
  int junge = 0;
 
  for(int i = 1; i < n; i++){
    if(a[i-1].value == a[i].value&&a[i-1].cnt>a[i].cnt)junge=1;
  }
  if(junge == 1) printf("Not stable\n");
  else  printf("Stable\n");
 
  for(int i = 0; i < n; i++){
    printf("%c %d\n",a[i].mark,a[i].value);
  }
 
}

Measured memory_bytes: 2368
A = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
for i in range(3):
    A[i][0], A[i][1], A[i][2] = list(map(int, input().split()))
N = int(input())
B = [0] * N
for i in range(N):
    B[i] = list(map(int, input().split()))

for n in range(N):
    for i in range(3):
        for j in range(3):
            if A[j][i] == B[n][0]:
                A[j][i] = 0

if (A[0][0] == A[0][1] and A[0][1] == A[0][2]) or (A[1][0] == A[1][1] and A[1][1] == A[1][2]) or (
        A[2][0] == A[2][1] and A[2][1] == A[2][2]) or (A[0][0] == A[1][0] and A[1][0] == A[2][0]) or (
        A[0][1] == A[1][1] and A[1][1] == A[2][1]) or (A[0][2] == A[1][2] and A[1][2] == A[2][2]) or (
        A[0][0] == A[1][1] and A[1][1] == A[2][2]) or (A[0][2] == A[1][1] and A[1][1] == A[2][0]):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38256
n = gets.to_i
taro = {"score" => 0, "card" => ""}
hanako = {"score" => 0, "card" => ""}

for i in 1..n
  taro["card"], hanako["card"] = gets.split(" ")
  hanako["score"] += 3 if taro["card"] < hanako["card"]
  taro["score"] += 3 if taro["card"] > hanako["card"]
  if taro["card"] == hanako["card"]
    taro["score"] += 1; hanako["score"] += 1
  end
end

puts "#{taro["score"]} #{hanako["score"]}"

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

using namespace std;

typedef long long ll;

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 (a>b) { a=b; return 1; } return 0; }

const ll MOD = 998244353;
const ll max_n = 202020;
ll fact[max_n];
bool fact_init = false;

ll pow(ll a, ll b){
	if(b == 0) return 1;
	if(b % 2 == 1) return a * pow(a, b - 1) % MOD;

	ll d = pow(a, b / 2) % MOD;
	return d * d % MOD;
}

ll comb(ll n, ll k){
	if(!fact_init){
		fact[0] = 1;
		fact[1] = 1;

		for(ll i = 2; i < max_n; i++){
			fact[i] = fact[i-1] * i;
			fact[i] %= MOD;
		}

		fact_init = true;
	}

	ll ret = fact[n];
	ret *= pow(fact[k],MOD-2);
	ret %= MOD;
	ret *= pow(fact[n-k],MOD-2);
	ret %= MOD;
	return ret;

	// X^(-1) = X^(p-2) (mod p) (Fermat's little theorem)
}

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

	ll n, m, k;
	cin >> n >> m >> k;

	ll ans = 0;
	for(ll i = 0; i <= k; i++){
		ll t = comb(n-1, i);
		t *= m;
		t %= MOD;
		t *= pow(m - 1, n - 1 - i);
		t %= MOD;

		ans += t;
		ans %= MOD;
	}

	cout << ans << endl;
}


Measured memory_bytes: 5176
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int result(0);
	string arg;
	cin >> arg;
	
	for (int i2(0), n2(arg.length()); i2 < n2; ++i2)
	{
		if ('A' <= arg[i2] && arg[i2] <= 'Z') { arg[i2] = arg[i2] - 'A' + 'a'; }
	}

	while(1)
	{
		string tmp;
		cin >> tmp;
		
		if (tmp == "END_OF_TEXT")
		{
			cout << result << endl;
			return 0;
		}

		for (int i2(0), n2(tmp.length()); i2 < n2; ++i2)
		{
			if ('A' <= tmp[i2] && tmp[i2] <= 'Z') { tmp[i2] = tmp[i2] - 'A' + 'a'; }
		}
		
		if (tmp == arg) { ++result; }
	}
}

Measured memory_bytes: 3180
#include<stdio.h>
#define MAX 100000
#define N -1

typedef struct{
  int p,l,r;
}Node;

Node T[MAX];
int n;

void Pre(int x){
  if(x==N)return;
  printf(" %d",x);
  Pre(T[x].l);
  Pre(T[x].r);
}

void In(int x){
  if(x==N)return;
  In(T[x].l);
  printf(" %d",x);
  In(T[x].r);
}

void Post(int x){
  if(x==N)return;
  Post(T[x].l);
  Post(T[x].r);
  printf(" %d",x);
}

int main(){
  int i;
  scanf("%d",&n);
  for(i=0;i<n;i++)T[i].p=T[i].l=T[i].r=N;
  for(i=0;i<n;i++){
  int current,left,right;
  scanf("%d %d %d",&current,&left,&right);
  T[current].l=left;
  T[current].r=right;
  if(left!=N)T[left].p=current;
  if(right!=N)T[right].p=current;
}
  int r;
  for(i=0;i<n;i++)if(T[i].p==N)r=i;
  printf("Preorder\n");
  Pre(r);
  printf("\n");
  printf("Inorder\n");
  In(r);
  printf("\n");
  printf("Postorder\n");
  Post(r);
  printf("\n");
  return 0;
}



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

signed main(void)
{
	string s;
	cin >> s;

	if ((s[0] == s[1] && s[1] == s[2]) || \
			(s[1] == s[2] && s[2] == s[3]))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import math

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
n = int(input())
a = list(map(int, input().split()))
a.sort()
mid = a[-1] / 2
ans = 10 ** 9
l = 0
for i in range(n):
    if ans > abs(mid - a[i]):
        ans = abs(mid - a[i])
        l = a[i]
print(a[-1], l)


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

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define F0R(i, n) for (int i = 0; i < (n); i++)
#define print(x) cout << x << '\n'
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;

const int MAX_N = 1e5 + 100;
int N;
int dp[MAX_N];
int h[MAX_N];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> N;
    for (int i = 0; i < N; i++)
        cin >> h[i+1];

    dp[1] = 0;
    dp[2]= abs(h[2]- h[1]);

    for (int i = 3; i < N+1; i++)
        dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]));
    
    cout << dp[N]<<endl;
    return 0;
}

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

#define loop(i,n) for(int i=1;i<=n;i++)
int a[102];

int main(){
  int n,m;
  cin>>n>>m;
  loop(i,n)cin>>a[i];

  loop(k,m){
    loop(i,n-1){
      if(a[i]%k>a[i+1]%k)swap(a[i],a[i+1]);
    }
  }

  loop(i,n)cout<<a[i]<<endl;
  return 0;
}

Measured memory_bytes: 3076
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
li = []
for i in range(n):
    li.append(ni())
sli = sorted(li)
for i in range(n):
    if sli[-1] != li[i]:
        print(sli[-1])
    else:
        print(sli[-2])


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

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.length()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>())

int main(){
	string s;
	cin >> s;
	int count = 0;
	SREP(i,s){
		if(s[i]=='o') count++;
	}
	cout << 700+(100*count) << endl;
}


Measured memory_bytes: 256
N = gets.to_i
h = []
h = gets.split.map(&:to_i)

d = []
d[0] = 0
low = 0
1.upto (N-1) do |i|
  d[i] = h[i] - h[i-1]
  # 2以上減少したらNo確定
  if d[i] <= -2
    puts "No"
    exit
  end
  # 1だけ減少した場合
  if d[i] == -1
    low += 1
    if low >= 2
      puts "No"
      exit
    end
  elsif d[i] >= 1
    low = 0
  end
end
puts "Yes"

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

namespace CP
{
    class Atria
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            string s = ReadLine();
            for (int i = 0; i < s.Length; i++)
            {
                if ('A' <= s[i] + n&& s[i] + n <= 'Z')
                {
                    Write((char)(s[i] + n));
                }
                else
                {
                    Write((char)(s[i] + n - ('Z' - 'A' + 1)));
                }
            }
            Write("\n");
        }
    }
}


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

int main(){
    int h, w;
    string s[402];

    cin >> h >> w;
    s[0] = s[h+1] = "";
    for(int j=0;j<=w+1;++j){
        s[0].push_back('X');
        s[h+1].push_back('X');
    }
    for(int i=1;i<=h;++i){
        string t;
        cin >> t;
        s[i] = "X" + t + "X";
    }

    int64_t ans = 0;
    constexpr int d[4] = {-500, -1, 1, 500};
    for(int i=1;i<=h;++i){
        for(int j=1;j<=w;++j){
            if(s[i][j] == 'X') continue;
            int64_t cnt[2] = {0, 0};
            queue<pair<char, int>> q;
            q.emplace(s[i][j], i*500+j);
            ++cnt[s[i][j] == '#'];
            s[i][j] = 'X';
            while(!q.empty()){
                char c = q.front().first;
                int x = q.front().second;
                q.pop();
                for(int k=0;k<4;++k){
                    int ii = (x+d[k]) / 500, jj = (x+d[k]) % 500;
                    char cc = s[ii][jj];
                    if(cc == (c=='.' ? '#' : '.')){
                        q.emplace(cc, x+d[k]);
                        ++cnt[cc == '#'];
                        s[ii][jj] = 'X';
                    }
                }
            }
            ans += cnt[0] * cnt[1];
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
s = input()
len_s = len(s)
ans=0
def dfs(x,len_x,i=0):
        global ans
        if i < len_x:
                dfs(x,len_x,i=i+1)
                x=x[:i+1] + "+" + x[i+1:]
                dfs(x,len_x + 1,i=i+2)
                ans+=sum([int(k) for k in x.split("+")])
dfs(s,len_s-1)
print(ans+int(s))

Measured memory_bytes: 3064
# coding: utf-8

num = int(input().rstrip())

md = 1000000000 + 7

cnt = {}


def prime_devide(n):
    current = n

    ret = {}
    div = 2
    while current > 1:
        if current % div == 0:
            ret[div] = 0
            while current % div == 0:
                ret[div] += 1
                current = int(current / div)
        div += 1
    return ret


if num == 1:
    print(1)

else:
    for i in range(2, num + 1):
        tmp = prime_devide(i)
        for k, v in tmp.items():
            if k in cnt:
                cnt[k] += v
            else:
                cnt[k] = v
    ans = 1
    for k, v in cnt.items():
        ans *= (v + 1)
        ans = ans % md
    ans = ans % md
    print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;
const int mod = 1000000007;

int main(){
  int n;
  cin >> n;
  vector<int> a(n+1);
  for(int i=1; i<=n; i++){
    cin >> a[i];
  }
  if(n%2 == 0){
    for(int i=n; i>=2; i-=2){
      cout << a[i] << " ";
    }
    for(int i=1; i<n; i+=2){
      cout << a[i] << " ";
    }
    cout << endl;
  }else{
    for(int i=n; i>=1; i-=2){
      cout << a[i] << " ";
    }
    for(int i=2; i<n; i+=2){
      cout << a[i] << " ";
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

vector<int> init(int size){
  vector<int> par(size,-1);
  return par;
}

int root(int x, vector<int>& par){
  if(par[x] < 0){
    return x;
  }else{
    return par[x] = root(par[x],par);
  }
}

bool same(int x, int y, vector<int>& par){
  return root(x, par) == root(y, par);
}

void unite(int x, int y, vector<int>& par){
  x = root(x, par), y = root(y, par);
  if(same(x,y, par))return;
  par[x] += par[y];
  par[y] = x;
}

int size(int x, vector<int>& par){
  return -par[root(x, par)];
}

int pow(int x, int n){
  if(n == 0)return 1;
  if(n % 2 == 0)return pow(x * x % MOD, n/2);
  else return x * pow(x, n-1) % MOD;
}

int n;vector<int> v[110000];int c[110000],ans[110000];pair<int,int> dig[110000];
int cind,ansM;

void f(int ver){
  //cout << "ver : " << ver << endl;
  vector<int> next;
  for(int nver : v[ver]){
    if(ans[nver] != -1)continue;
  //cout << "nver : " << nver << " " << cind << endl;
    next.push_back(nver);
    ans[nver] = c[cind];
    ansM += c[cind];
    cind++;
  }
  for(int nver : next){
    f(nver);
  }
}

signed main(){  
  int n,l;cin>>n>>l;
  int sum = 0, ans, diff = INF;
  rep(i,n){
    sum += l+i;
  }
  rep(i,n){
    if(diff > abs(sum-l-i-sum)){
      diff = abs(sum-l-i-sum);ans = sum-l-i;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4224
A, B = map(int, input().split())

def main():
    d = B-A
    if d==0:
        return A
    elif d==1:
        return A^B
    elif A%2==1:
        if B%2==1:
            if d%4==0:
                return A
            else:
                return A^1
        else:
            if d%4==1:
                return A^B
            else:
                return A^1^B
    else:
        if B%2==1:
            if d%4==1:
                return 1
            else:
                return 0
        else:
            if d%4==0:
                return B
            else:
                return 1^B

print(main())

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

int main() {
    int k;
    string s;

    cin >> k;
    cin >> s;

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

    return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n;
    cin>>n;
    set<int> st;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        st.insert(a);
    }
    int ans=st.size();
    if(ans%2==0)ans--;
    cout<<ans<<endl;
}


Measured memory_bytes: 4992
a,b = list(map(int,input().split()))
ad,bd = [],[]
for i in range(1,int(a**(1/2)) + 1):
    if a%i == 0:
        ad.append(i)
        ad.append(a//i)
for i in range(1,int(b**(1/2)) + 1):
    if b%i == 0:
        bd.append(i)
        bd.append(b//i)
cd = list(set(ad) & set(bd))
ans = []
def prime(n):
    if all(n%i!=0 for i in range(2,int(n**(1/2))+1)):
        return True
    else:
        return False
for num in cd:
    if prime(num):
        ans.append(num)
print(len(ans))

Measured memory_bytes: 5176
S = input()
T = input()

d_S = [[] for _ in range(26)]
d_T = [[] for _ in range(26)]

for i in range(len(S)):
    d_S[ord(S[i])-97].append(i)
    d_T[ord(T[i])-97].append(i)

for i in range(26):
    tmp = ""
    for j in d_S[i]:
        if tmp == "":
            tmp = T[j]
        else:
            if tmp != T[j]:
                print("No")
                break
    else:
        continue
    break
else:
    for i in range(26):
        tmp = ""
        for j in d_T[i]:
            if tmp == "":
                tmp = S[j]
            else:
                if tmp != S[j]:
                    print("No")
                    break
        else:
            continue
        break
    else:
        print("Yes")


Measured memory_bytes: 14512
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>
#include <cmath>
#include <numeric>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define rrep(i, n) for (int i=(int)n-1;i>=0;--i)
#define rrep1(i, n) for (int i=n;i>=1;--i)
#define range(i, l, r) for (int i=l;i<(int)r;++i)
#define rrange(i, l, r) for (int i=(int)r-1;i>=(int)l;--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

const int inf = 10000;

int N, M;
vector<int> G[1010];
int pre[1010][1010];
int dist[1010][1010];

int find_cycle(int k)
{
	memset(pre[k], -1, sizeof(pre[k]));
	queue<int> q;
	q.push(k);
	dist[k][k] = 0;

	while (q.size()) {
		int cur = q.front(); q.pop();

		if (dist[k][k] != 0 and cur == k) {
			return dist[k][k];
		}

		for (int &nxt : G[cur]) {
			if (pre[k][nxt] != -1) continue;

			pre[k][nxt] = cur;
			dist[k][nxt] = dist[k][cur] + 1;
			q.push(nxt);
		}
	}
	
	return inf;
}

signed main()
{
	cin >> N >> M;

	rep(i, M) {
		int a, b; cin >> a >> b;
		--a, --b;
		G[a].PB(b);
	}

	int mn = inf;
	int idx = -1;

	rep(i, N) {
		if (chmin(mn, find_cycle(i))) {
			idx = i;
		}
	}

	if (mn == inf) {
		cout << -1 << endl;
		return 0;
	}

	cout << mn << endl;

	int cur = idx;
	while (true) {
		printf("%lld\n", cur + 1);
		cur = pre[idx][cur];

		if (cur == idx) break;
	}
}



Measured memory_bytes: 16128
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<algorithm>
using namespace std;

int main(){
    int n;
    long long mod=1e9+7;
    cin>>n;
    vector<long long>d(1000);
    long long ans=1;
    for(int i=2;i<=n;i++){
        int x=i;
        for(int j=2;j<=x;j++){
            while(x%j==0){
                x/=j;
                d[j]++;
            }
        }
    }
    for(int i=0;i<=1000;i++){
        ans*=(d[i]+1);
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int64_t MAXN = 200000;
int64_t N, cnt = 0;
string S;
vector<int64_t> W(MAXN, 0), B(MAXN, 0); // 累積和を取る

int64_t dfs(int64_t idx, int64_t cnt, bool rW)
{
  if (idx < 0)
    return cnt;
  if (rW) // 右が白 => iも白でなければNG
  {
    if (S.at(idx) == '#')
      return dfs(idx - 1, cnt + 1, true); // 黒ならばひっくり返す。rW = trueのまま。
    else
      return dfs(idx - 1, cnt, true); // 右が白、idxも白 -> そのまま。
  }
  else // iが白ならば、黒に変える or そのまま
  {
    if (S.at(idx) == '.')
    {
      int64_t ret1, ret2;
      ret1 = B.at(idx) + cnt;              // idx以前の黒を全てひっくり返す。
      ret2 = dfs(idx - 1, cnt + 1, false); // idxの白を黒にひっくり返す。
      return min(ret1, ret2);
    }
    else // 右が黒 => iも黒ならばそのまま
    {
      return dfs(idx - 1, cnt, false);
    }
  }
}

int main()
{
  cin >> N >> S;
  for (int i = 0; i < N; i++)
  {
    if (i != 0)
    {
      W.at(i) += W.at(i - 1);
      B.at(i) += B.at(i - 1);
    }
    S.at(i) == '.' ? W.at(i)++ : B.at(i)++;
  }
  cout << dfs(N - 1, 0, false) << endl;
}

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

#define ll long long

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

	set <string>s ;
    int n;
    cin >> n;
    for(int i=0; i<n; ++i){
        string s1;
        cin >> s1;
        s.insert(s1);
    }
    cout << s.size();
    

	return 0;
}


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

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

    if (N % 2 == 0){
        for (int i=0; i<N/2; i++){
            if (S[i] != S[i+N/2]){
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
int main(){
    ll n;cin>>n;
    ll d;cin>>d;
    double x,y,rj=0;
    for(int i=0;i<n;i++){
        cin>>x>>y;
        if(sqrt((x*x)+(y*y))<=d){
            rj++;
        }
    }
    cout << rj<<endl;
}


Measured memory_bytes: 3824
#include<iostream>
#include<iomanip>
#include<math.h>
using namespace std;

int main(){
    int N,K;
    int N1,N2;
    cin >> N >> K;
    N1=min(N,K);
    N2=max(0,N-K);

    double ans=0.0;

    for(int i=1; i<=N; i++){
        if( i < K ){
            int alpha = (int) ceil(log2((double) K/i));
            //cout << "i alpha " << i << " " << alpha << endl;
            ans += 1.0/pow(2,alpha)/(double) N;
        }else{
            ans += 1.0/(double) N;
        }
    }

    cout << setprecision(15) << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl "\n"
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl

#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;

mp::cpp_int A, B, ans;
string b;
int main() {
	cin >> A >> b;
	b.erase(b.length()-3, 1);
	string str = to_string(stoi(b));
	B.assign(str);
	ans = (A*B)/100;
	cout << ans << endl;
    return 0;
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];a[i]--;
    }
    int count = 0;
    int now = 0;
    vector<bool> kita(n, false);
    while(true){
        if(kita[now]){
            cout << -1 << endl;
            break;
        }
        kita[now] = true;
        if(now == 1){
            cout << count << endl;
            break;
        }
        now = a[now];
        count++;
    }
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
//<<setprecision(30)
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
  double R; cin>>R;
  double pi = 6.28318530717958623200;
  cout<<R*pi<<endl;
}


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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

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

const int N = 333;
int n,m,a[N][N];

int ind[N], cnt[N];
bool in[N];
bool check(int k) {
    forn(i,n) ind[i] = 0;
    forn(i,m) in[i] = true;
    while (true) {
        fill_n(cnt, m, 0);
        forn(i,n) {
            while (ind[i] < m && !in[a[i][ind[i]]]) ind[i]++;
            if (ind[i] >= m) return false;
            cnt[a[i][ind[i]]]++;
        }
        bool ok = true;
        forn(i,m) if (cnt[i] > k) {
            in[i] = false;
            ok = false;
        }
        if (ok) return true;
    }
    return false;
}

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

    cin >> n >> m;
    forn(i,n) forn(j,m) cin >> a[i][j], a[i][j]--;

    int lo = 0, hi = n+2;
    while (lo+1 < hi) {
        int mi = (lo+hi)/2;
        if (check(mi)) hi = mi; else lo = mi;
    }
    cout << hi << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define all(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
const int mod = 1e9+7;

int main() {
    int n;
    cin >> n;
    int a[n];
    int b1= 0, b2 = 0, b4 = 0;
    rep(i, n) {
        cin >> a[i];
        if (a[i] % 2 == 1) {
            b1++;
        } else if (a[i] % 4 == 0) {
            b4++;
        } else {
            b2++;
        }
    }
    if (b2 == 0) {
        if (b1 <= b4 + 1) cout << "Yes" << endl;
        else cout << "No" << endl;
    } else {
        if (b1 <= b4) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 3984
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstring>
#include <tuple>
#include <utility>
#include <list>
#include <cmath>

using namespace std;

typedef long long LL;
typedef vector<int> Array;
typedef pair<int, int> P;

const int INF = 1 << 29;
const LL MOD = 100000;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(c) (c).begin(), (c).end()

struct edge{ int to, cost; edge(int t, int c) :to(t), cost(c){} };

int dxk[] = { 1, 1, 1, 0, -1, 0 };
int dxg[] = { 0, 1, 0, -1, -1, -1 };
int dy[] = { -1, 0, 1, 1, 0, -1 };

int bitcount(int a)
{
	int ret = 0;
	while (a != 0) { ret++; a = (a - 1) & a; }
	return ret;
}

vector<int> topoSort(vector<vector<edge>>& graph)
{
	vector<int> visited(graph.size());
	vector<int> order;
	function<bool(int)> visit = [&](int node)
	{
		if (visited[node] == 1) return false;
		visited[node] = 1;
		for (const auto& e : graph[node]) if (visited[e.to] != 2)
			if(!visit(e.to)) return false;
		order.push_back(node);
		visited[node] = 2;
		return true;
	};
	for (int i = 0; i < graph.size(); i++) if (visited[i] == 0)
	{
		if (!visit(i)) return move(vector<int>());
	}
	reverse(order.begin(), order.end());
	return move(order);
}

int main()
{
	int n, m;
	while (cin >> n >> m && n)
	{
		vector<vector<bool>> hasEdge(n, vector<bool>(n, false));
		vector<vector<edge>> graph(n);
		rep(i, m)
		{
			int w, l; cin >> w >> l;
			w--; l--;
			graph[w].push_back(edge(l, 1));
			hasEdge[w][l] = true;
		}
		auto vec = topoSort(graph);
		rep(i, n)
		{
			cout << vec[i] + 1 << endl;
		}
		bool ans = true;
		rep(i, n - 1)
		{
			ans = ans && hasEdge[vec[i]][vec[i + 1]];
		}
		cout << (int)!ans << endl;
	}

	return 0;
}

Measured memory_bytes: 6048
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int H,W;
vector <vector <char> > a;





int main()
{

	cin >> H >> W;

	a.resize(H);

	REP(i,H){
		a[i].resize(W);
	}

	REP(i,H){
		REP(j,W){
			cin >> a[i][j];
		}
	}
	REP(i,W+2){
		cout << "#";
	}
	cout << endl;

	REP(i,H){
		cout << "#";
		REP(j,W){
			cout << a[i][j];
		}
		cout << "#" << endl;
	}

	REP(i,W+2){
		cout << "#";
	}
	cout << endl;

}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        char[] t = sc.next().toCharArray();
        int ans = 0;
        for (int i = 0; i < s.length; i++) {
            if (s[i] != t[i]) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 42132
#include <iostream>

using namespace std;
long long gcd(long long a, long long b){
	if(a<b) swap(a,b);
	if(b==0) return a;
	return gcd(a%b,b);
}
int main(){
	long long a,b;
	cin >> a >> b;
	if(b%a==0){
		cout << -1 << endl;
	}else{
		long long i;
		for(i=0;i<=a - 1;i++){
			long long j = i + b;
			if(j/a + j%a<1 + i){
				cout << j << endl;
				return 0;
			}
		}
		cout << -1 << endl;
	}
}


Measured memory_bytes: 3112
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <map>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

static const ll M = 1000000;
ll f[M] = {};
map<ll, ll> mp;
ll MOD = 1e9 + 7;

void fact() {
	f[0] = 1;
	rep(i, 1, M) f[i] = f[i - 1] * i % MOD;
}

void factorization(ll m) {
	ll t = m;
	for (int i = 2; t != 1; i++) {
		while (!(t % i)) {
			mp[i]++;
			t /= i;
		}
	}
}

ll pow(ll e, ll x) {
	if (x == 0)return 1;
	if (x == 1)return e;

	ll t = pow(e, x / 2);
	if (x & 1) {
		return (((t *t) % MOD)* e) % MOD;
	}
	else {
		return (t * t) % MOD;
	}
}

ll nCr(ll n, ll r) {
	return ((f[n] * pow(f[r], MOD - 2) % MOD) * pow(f[n - r], MOD - 2) % MOD);
}

int main() {
	ll h, w, a, b; cin >> h >> w >> a >> b;
	fact();

	ll ans = 0;

	rep(B, b, w) {
		ll x = nCr(h - a - 1 + B, B) % MOD;
		ll y = nCr(a - 1 + w - 1 - B, w - 1 - B) % MOD;
		ans = (ans + x * y %MOD) % MOD;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 8064
from sys import stdin

while True:
    h, w = (int(n) for n in stdin.readline().rstrip().split())
    if h == w == 0:
        break

    for n in range(h):
        if n in {0, h - 1}:
            print('#' * w)
            continue

        print('#' + '.' * (w - 2) + '#')

    print()



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

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

    vector<long long int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }

    vector<long long int> dp1(n,1);// ---
    vector<long long int> dp2(n,0);// +++

    vector<long long int> b2 = a;
    stack<long long int> st2;// critical points (order not inverted even after the multiplication by 4)
    st2.push(n-1);

    for(int i=n-2; i>=0;i--){
        dp2[i] += dp2[i+1];

        while(b2[i] > b2[i+1]){
            b2[i+1] *= 4;

            // then, need to multiply 4 to a[i+1] ~ a[j] to keep the order unchanged
            int j = st2.top(); st2.pop();
            if(j != i+1) b2[j] *= 4;

            dp2[i] += (j-(i+1)+1) * 2;

            if(j == n-1 || b2[j] * 4 <= b2[j+1]) st2.push(j);
        }

        if(b2[i] * 4 <= b2[i+1]) st2.push(i);
    }

    vector<long long int> b1 = a;
    stack<long long int> st1;
    b1[0] *= -2;
    st1.push(0);

    for(int i=1; i<n;i++){
        b1[i] *= -2;
        dp1[i] += dp1[i-1];

        while(b1[i-1] > b1[i]){
            b1[i-1] *= 4;

            // then, need to multiply 4 to a[j] ~ a[i-1] to keep the order unchanged
            int j = st1.top(); st1.pop();
            if(j != i-1) b1[j] *= 4;

            dp1[i] += ((i-1)-j+1) * 2;

            if(j == 0 || b1[j-1] <= b1[j] * 4) st1.push(j);
        }
        if(b1[i-1] <= b1[i] * 4) st1.push(i);
    }

    long long int ans = dp2[0];// ++...+
    for(int i=0; i+1<n; i++){
        ans = min(ans, dp1[i] + dp2[i+1]);// -+...+ ~ -...-+
    }
    ans = min(ans, dp1[n-1]);// --...-
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11180
#include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

char in[33];
int n,deg[26];
bool v[26];
vi e[26];

void dfs(int c){
  v[c]=1;
  fr(i,e[c])if(!v[*i])dfs(*i);
}
int main()
{
  while(scanf("%d",&n),n){
    rep(i,26)e[i].clear(),deg[i]=0,v[i]=1;
    int a,b;
    rep(i,n){
      scanf("%s",in);
      a=in[0]-'a'; b=in[strlen(in)-1]-'a';
      e[a].pb(b);
      deg[a]++; deg[b]--; v[a]=v[b]=0;
    }
    dfs(a);
    rep(i,26)if(!v[i]||deg[i]!=0){
      puts("NG"); goto END;
    }
    puts("OK"); END:;
  }
  return 0;
}

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

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

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

int dp[500][500];

int solve(){
  int n,m,q;cin>>n>>m>>q;

  int l,r;
  vvi x(n); vvi y(n);
  rep(i, m){
    cin>>l>>r; l--;r--;
    x[l].pb(r); y[r].pb(l);
  }
  rep(i, n){ sort(all(x[i])); sort(all(y[i])); }
  dump(x); dump(y);

  dp[0][n-1] = m;

  rep(i, 1, n){
    dp[i][n-1] = dp[i-1][n-1] - sz(x[i-1]);
  }

  rep(i, n){
    rrep(j, n-1){
      dp[i][j] = dp[i][j+1];
      int dif = sz(y[j+1]) - (lower_bound(all(y[j+1]), i) - y[j+1].begin());
      dp[i][j] -= dif;
    }
  }

  dump_2d(dp, n, n);

  rep(i, q){
    cin>>l>>r; l--;r--;
    cout << dp[l][r] << endl;
  }

  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 7936
#include <bits/stdc++.h>
#define int long long

using namespace std;
const int MN = 1e5+7;

int dp[107][MN];

signed main()
{
    int n, W, w[107], v[107];
    cin >> n >> W;
    for(int i = 0; i < n; i++){
        cin >> w[i];
        cin >> v[i];
    }
    for(int x = 0; x <= W; x++){
        if(x >= w[0])dp[0][x] = v[0];
        else dp[0][x] = 0;
    }
    //cout << dp[0][W] << ' ';
    for(int i = 1; i < n; i++){
        for(int x = 0; x <= W; x++){
            if(x >= w[i]){
                dp[i][x] = max(dp[i-1][x], dp[i-1][x-w[i]] + v[i]);
            }
            else{
                dp[i][x] = dp[i-1][x];
            }
        }
        //cout << dp[i][W] << ' ';
    }
    cout << dp[n-1][W];
}


Measured memory_bytes: 80128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll;
const int maxn = 1000005;
const int maxm = maxn*2;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

ll dp[405][405];
ll a[405],b[405];
ll p[405][405];
ll sum[405][405];
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i = 1;i<=n;i++) cin>>a[i];
    for(int i = 1;i<=n;i++) cin>>b[i];
    for(int i = 1;i<=400;i++) {
        p[i][0] = 1;
        for(int j = 1;j<=400;j++) p[i][j] = p[i][j-1]*i%mod;
    }
    for(int i = 1;i<=400;i++) {
        for(int j = 0;j<=400;j++) {
            sum[i][j] = (sum[i][j] + sum[i-1][j] + p[i][j]) % mod;
        }
    }
    dp[0][0] = 1;
    for(int i = 1;i<=n;i++) {
        for(int j = 0;j<=m;j++){
            for(int k = 0;k<=j;k++){
                dp[i][j] = (dp[i][j] + dp[i-1][j-k]*(sum[b[i]][k]-sum[a[i]-1][k])%mod+mod)%mod;
            }
        }
    }
    cout<<dp[n][m]<<'\n';
    return 0;
}


Measured memory_bytes: 4096
#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::io::{self, Write};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
     };
    ($next:expr, isize1) => {
        read_value!($next, isize) - 1
     };
     ($next:expr, $t:ty) => {
         $next().parse::<$t>().expect("Parse error")
    };
}
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[allow(dead_code)]
const MOD: u64 = 1000000007;
#[allow(dead_code)]
fn to_num(c: char) -> i64 {
    c as i64 - 48
}

use std::io::*;
use std::str::FromStr;
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
fn read_char() -> char {
    let s: String = read();
    s.chars().collect::<Vec<char>>()[0]
}


fn main() {
    let c = read_char();
    let ans = match c  {
        'a' | 'i' | 'u' | 'e' | 'o' => "vowel",
        _ => "consonant",
    };
    println!("{}", ans);
}

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

using namespace std;

/*

        Bismillahir Rahmanir Rahim
        Problem :
        Problem Link :
        Topics :
        Solver : Masud Parves
        I Love Code More than Sharks Love Blood <3
*/


#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define SZ(a)           (int)a.size()
#define all(a)  a.begin(), a.end()
#define allr(a)  a.rbegin(), a.rend()


#define sf(a)           scanf("%d",&a)
#define sff(a,b)        scanf("%d %d",&a,&b)
#define sfff(a,b,c)     scanf("%d %d %d",&a,&b,&c)

#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)

#define CIN ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define TEST_CASE(t) for(int zz=1 ; zz<=t ; zz++)
#define PRINT_CASE printf("Case %d: ",zz)
#define Debug(x)            cout<<#x " = "<<(x)<<endl
#define NOT_VISITED 0
#define IS_VISITED 1
#define WHITE 0
#define GRAY 1
#define BLACK 2



int fx[4]= {1,-1,0,0};
int fy[4]= {0,0,1,-1};

/*-----------------------Bitmask------------------*/
//int Set(int N,int pos){return N=N  (1<<pos);}
//int Reset(int N,int pos){return N= N & ~(1<<pos);}
//bool Check(int N,int pos){return (bool)(N & (1<<pos));}
/*------------------------------------------------*/


const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9+7;
const int maxn = (int)2e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<int, ll> pill;

int n,m;
int adj[10][10];
bool visited[10];

int dfs(int u){
    bool allNodeVisited=true;

    for(int i=1 ; i<=n ; i++){
        if(visited[i]==false){
            allNodeVisited=false;
        }
    }

    if(allNodeVisited){
        return 1;
    }


    int res=0;
    f1(i,n){
        if(adj[u][i]==0 || visited[i]) continue;
        if(adj[u][i] && !visited[i])
            {
                visited[i]=true;
                res+=dfs(i);
                visited[i]=false;
            }

    }
    return res;

}


int main() {
    CIN
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> n >> m;

    f0(i,m){
        int a,b;
        cin >> a >> b;
        adj[a][b]=adj[b][a]=1;
    }

    visited[1]=true;
    cout << dfs(1) << endl;



    return 0;
}


Measured memory_bytes: 256
//QWsin
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=nxt[i])
#define repvc(i,vc) for(int i=0,Sz=vc.size();i<Sz;++i)
using namespace std;
inline int read()
{
	char ch=getchar();int ret=0,f=1;
	while(ch<'0' || ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	for(;ch>='0' && ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret*f;
}

inline void print(string name,int *arr,int len){
	rep(i,1,len) printf("%s[%d]=%d\n",name.c_str(),i,arr[i]);puts("");
}
inline void print(string name,int a){
	printf("%s=%d\n",name.c_str(),a);puts("");
}

typedef long long ll;
const int INF=1<<30;

const int maxn=100000+10;

struct Node{
	int t,val;
	Node(int t=0,int val=0):t(t),val(val){}
	bool operator < (const Node &rhs)const{
		return t>rhs.t;	
	}
}arr[maxn];


priority_queue<int>q;

int main()
{
	int n,m;cin>>n>>m;
	int a,b;
	rep(i,1,n)
	{
		scanf("%d%d",&a,&b);
		arr[i]=Node(m-a,b);
	}
	sort(arr+1,arr+n+1);
	
	int ans=0;
	int cur=1;
	for(int i=m-1;i>=0;--i)
	{
		while(cur<=n && arr[cur].t>=i){
			q.push(arr[cur].val);	
			++cur;
		}
		if(!q.empty()){ans+=q.top();q.pop();}
	}
	cout<<ans<<endl;
	return 0;
}


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

typedef long long ll;

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

// chmax, chmin
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; }

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    vector<ll> num(5,0);
    REP(i,N){
        cin >> S[i];
        //cout << S[i][0] << endl;
        
        if ( S[i][0] == 'M' ) num[0] = num[0] + 1;
        else if ( S[i][0] == 'A' ) num[1] = num[1] + 1;
        else if ( S[i][0] == 'R' ) num[2] = num[2] + 1;
        else if ( S[i][0] == 'C' ) num[3] = num[3] + 1;
        else if ( S[i][0] == 'H' ) num[4] = num[4] + 1;
    }
    
    ll ans = 0;
    for ( int i = 0; i < 3; ++i){
        for ( int j = i + 1; j < 4; ++j){
            for ( int k = j + 1; k < 5; ++k){
                ans = ans + (num[i] * num[j] * num[k]);
            }
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 6336
<?php
fscanf(STDIN, "%d", $n);
$a = explode(' ', fgets(STDIN));
$a[$n] = 0;

$before = 0;
for ($i = 0; $i <= $n; $i++) {
	$sum += abs($a[$i] - $before);
	$before = $a[$i];
}
$before = 0;
for ($i = 0; $i < $n; $i++) {
	$current = (int)$a[$i];
	$after = (int)$a[$i + 1];
	if ($before <= $after) {
		if ($current < $before) {
			$external = 2 * ($before - $current);
		} elseif ($current > $after) {
			$external = 2 * ($current - $after);
		} else {
			$external = 0;
		}
	}
	if ($before > $after) {
		if ($current > $before) {
			$external = 2 * ($current - $before);
		} elseif ($current < $after) {
			$external = 2 * ($after - $current);
		} else {
			$external = 0;
		}
	}
	echo $sum - $external, "\n";
	$before = $current;
}

Measured memory_bytes: 13940
/* Generated by powerful Codeforces Tool
 * You can download the binary file in here https://github.com/xalanq/cf-tool (Windows, macOS, Linux)
 * Author: alireza_kaviani
 * Time: 2020-06-20 17:09:28
**/
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define sep                         ' '
#define endl                        '\n'
#define SZ(x)                       ll(x.size())

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 300 + 10;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 998244353; // 1e9 + 9;

ll n , m , ans , dp[MAXN][MAXN][MAXN];
vector<int> vec;
string s;

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

    cin >> s >> m; n = SZ(s); s = "." + s + "0";
    m = min(m , 305ll);
    for(int i = 1 , cnt = 0 ; i <= n + 1 ; i++){
        if(s[i] == '0'){
            vec.push_back(cnt); cnt = 0;
        }
        if(s[i] == '1') cnt++;
    }
    vec.push_back(0);
    reverse(all(vec));
    dp[0][0][0] = 1;
    // dp[tedad 0][tedad opreation][jam]
    for(int i = 1 ; i < SZ(vec) ; i++){
        //cout << i << sep << vec[i] << endl;
        for(int j = 0 ; j <= m ; j++){
            ll cur = 0;
            for(int k = n ; k >= 0 ; k--){
                cur += dp[i - 1][j][k];
                dp[i][j][k] = (dp[i][j][k] + cur) % MOD;
                for(int l = 1 ; l <= vec[i] ; l++){
                    if(j + l < MAXN && k + l < MAXN)    dp[i][j + l][k + l] = (dp[i][j + l][k + l] + dp[i - 1][j][k]) % MOD;
                }
            }
        }
        //for(int j = 0 ; j <= m ; j++)   for(int k = n ; k >= 0 ; k--)   cout << i << sep << j << sep << k << sep << dp[i][j][k] << endl;
    }
    for(int i = 0 ; i <= m ; i++)   ans += dp[SZ(vec) - 1][i][0];
    cout << ans % MOD << endl;

    return 0;
}
/*

*/


Measured memory_bytes: 116220
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    map<int, int> cnt;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        cnt[x]++;
    }
    int res = 0;
    for (auto item : cnt) {
        if (item.second < item.first)
            res += item.second;
        else
            res += item.second - item.first;
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 4736