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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
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;}
const int MOD = 1000000007;

map<ll, ll> prime_factorization(ll n) {
    map<ll, ll> m;
    ll d = 2;
    ll l = n;
    while (n > 1 && l >= d * d) {
        if (n % d == 0) {
            m[d]++;
            n /= d;
        } else {
            if (d == 2) {
                d++;
            } else {
                d += 2;
            }
        }
    }
    if (n > 1) {
        m[n]++;
    }
    return m;
}

class Combination {
    vector<ll> factorial;
    vector<ll> fact_inverse;
    vector<ll> inverse;
    int mod;

    void init(int size) {
        factorial[0] = 1;
        factorial[1] = 1;
        fact_inverse[0] = 1;
        fact_inverse[1] = 1;
        inverse[1] = 1;

        for (int i = 2; i < size; i++) {
            factorial[i] = factorial[i - 1] * i % mod;
            inverse[i] = mod - inverse[mod % i] * (mod / i) % mod;
            fact_inverse[i] = fact_inverse[i - 1] * inverse[i] % mod;
        }
    }

    public:
        Combination(int size, int m) {
           factorial = vector<ll>(size);
           fact_inverse = vector<ll>(size);
           inverse = vector<ll>(size);
           mod = m;
           init(size);
        }
    
        ll calc(int n, int k) {
            if (n < k) {
                return 0;
            }
            if (n < 0 || k < 0) {
                return 0;
            }
            return factorial[n] * (fact_inverse[k] * fact_inverse[n - k] % mod) % mod;
        }
};

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

    map<ll, ll> pf = prime_factorization(m);
    ll c = 0;
    for (const auto p : pf) {
        c += p.second + 1;
    }
    Combination comb = Combination(c + n, MOD);
    ll t = 1;
    for (const auto p : pf) {
        t = t * comb.calc(p.second + n - 1, p.second) % MOD;
    }
    cout << t << endl;
}


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

int cnt[100010];

int modpow(int x){
    int ans=1;
    for(int i=0;i<x;i++){
        ans=(ans*2)%MOD;
    }
    return ans;
}

int main(){
    int n; cin>>n;
    for(int i=0;i<n;i++){
        int a; cin>>a;
        cnt[a]++;
    }
    int ans=0;
    if(n&1){
        if(cnt[0]==1){
            bool ok=true;
            for(int i=2;i<n;i+=2){
                if(cnt[i]!=2)ok=false;
            }
            if(ok)ans=modpow((n-1)/2);
        }
    }
    else{
        bool ok=true;
        for(int i=1;i<n;i+=2){
            if(cnt[i]!=2)ok=false;
        }
        if(ok)ans=modpow(n/2);
    }
    cout<<ans<<endl;
}


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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define INF 1e18

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef vector < pair<int, int> > vii;
typedef long double ld;
typedef tree<pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, m;
	cin >> n >> m;
	if(n>=2){
		n-=2;
	}
	if(m>2){
		m-=2;
	}
	cout<<n*m << endl;
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
        #pragma comment(linker, "/stack:200000000")
        #pragma GCC optimize("unroll-loops")
         
        #include <algorithm>
        #include <bitset>
        #include <cassert>
        #include <chrono>
        #include <cmath>
        #include <complex>
        #include <cstdio>
        #include <cstdlib>
        #include <cstring>
        #include <ctime>
        #include <deque>
        #include <functional>
        #include <iomanip>
        #include <iostream>
        #include <iterator>
        #include <limits>
        #include <climits>
        #include <list>
        #include <map>
        #include <numeric>
        #include <queue>
        #include <random>
        #include <ratio>
        #include <set>
        #include <sstream>
        #include <stack>
        #include <string>
        #include <unordered_map>
        #include <unordered_set>
        #include <utility>
        #include <vector>
        using namespace std;
         
        typedef long long ll;
        typedef long double LD;
        #define int ll
        #define double LD
        #define pb push_back
        #define mp make_pair
        #define REP(i,n) for (int i = 0; i < n; i++)
        #define loop(i,n) for (int i = 0; i < n; i++)
        #define FOR(i,a,b) for (int i = a; i < b; i++)
        #define REPD(i,n) for (int i = n-1; i >= 0; i--)
        #define FORD(i,a,b) for (int i = a; i >= b; i--)
        #define remax(a,b) a = max(a,b)
        #define remin(a,b) a = min(a,b)
        #define mem(a, b) memset(a, b, sizeof a)
        #define append push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define print(x) cout << (x) << endl
        #define PRECISION(x) cout << fixed << setprecision(x)
        #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
        #define N 1005
        #define pb push_back
        const double PI=acos(-1);
        const int MOD = 1000000007;
        const int FMOD = 998244353;
        const double eps = 1e-9;
         
        mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
  	
  		signed main()
  		{
  			int l,r,d;
			  cin>>l>>r>>d;
			  int ans=0;
			  for(int i=l;i<=r;i++)
			  {
			  	if(i%d==0)
			  	ans++;
				  }	
				  cout<<ans;
		}

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

int main(){
	int N, M;
	cin >> N >> M;
	bool B[N][N];
rep(i,N)rep(j,N)B[i][j]= 0;
	rep(i,M){
		int a, b;
		cin >> a >> b;
		a--; b--;
		B[a][b] = true;
		B[b][a] = true;
	}

	vector<int> G[N];
	rep(i,N){
		repi(j,i+1,N){
			if(!B[i][j]){
				G[i].emplace_back(j);
				G[j].emplace_back(i);
			}
		}
	}

	queue<int> Q;
vector<int> C(N, 0);
bool flag = true;
for(int i = 0; i < N; i++){
    if(C[i])continue;
    C[i] = i + 1;
    Q.emplace(i);
    while(Q.size()){
        int u = Q.front();
        Q.pop();
        for(auto v : G[u]){
            if(C[v] == C[u]){
                flag = false;
            }
            if(C[v] == 0){
                C[v] = -C[u];
                Q.emplace(v);
            }
        }
    }
}
if(!flag){
    cout << -1 << endl;
    return 0;
}
	vector<int> P(N + 1);
	vector<int> W(N + 1);
	rep(i, N){
		if(C[i] < 0)P[-C[i]]++;
		else W[C[i]]++;
	}

	vector<bool> dp(N + 1);
	
	dp[0] = true;
	rep(i, N + 1){
		vector<bool> next(N + 1);
		rep(j, N + 1){
			if(dp[j]){
				next[j + P[i]] = true;
				next[j + W[i]] = true;
			} 
		}
		dp = next;
	}

	int ans = INT_MAX;
	rep(i, N + 1){
		if(dp[i]){
			int t = i;
			int s = N - i;
			ans = min(ans, t * (t - 1) / 2 + s * (s - 1) / 2);
		}
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>   // popen, pclose, fgets
#include <cstdlib> 
using namespace std;
#define rep0(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>;
using ll = long long; //10e19までいける
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll =vector<vvll>;
const double PI=3.14159265358979323846;
//小数点以下を指定したい時　　→→→→  cout << fixed << setprecision()<<答え<<endl;
//int→string
//string→int   int num = atoi(numStr.c_str());

int main() {
    int n,sum=0;cin>>n;
    vi v(n);
    rep0(i,n){
        cin>>v[i];
        sum+=v[i];
    }
    sort(all(v));
    if(sum>2*v[n-1]){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3632
#include <stdio.h>

typedef struct node_t {
	int val;
	struct node_t *next;
} node;

node* new_node(int val) {
	static int it = 0;
	static node pool[500000];
	pool[it] = (node) { val, NULL };
	return &pool[it++];
}

node* st[1000];
node* en[1000];

int main(void)
{
	int n, q, com, s, t, x;
	node *tmp;
	scanf("%d%d", &n, &q);
	while (q--) {
		scanf("%d%d", &com, &t);
		if (com == 0) {
			scanf("%d", &x);
			tmp = new_node(x);
			if (!st[t]) st[t] = en[t] = tmp;
			else en[t]->next = tmp, en[t] = tmp;
		}
		else if (com == 1) {
			tmp = st[t];
			while (tmp) {
				if (tmp->next) printf("%d ", tmp->val);
				else printf("%d", tmp->val);
				tmp = tmp->next;
			}
			puts("");
		}
		else {
			s = t;
			scanf("%d", &t);
			if (!st[t]) st[t] = st[s], en[t] = en[s];
			else en[t]->next = st[s], en[t] = en[s];
			st[s] = en[s] = NULL;
		}
	}
	return 0;
}



Measured memory_bytes: 9504
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(m)]
class UnionFind(object):
    def __init__(self, size):
        self.parent = [i for i in range(size)]
        self.rank = [0 for _ in range(size)]
 
 
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])
 
 
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
 
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
 
    def same(self, x, y):
        return self.find(x) == self.find(y)
def C(x):
    U=UnionFind(n)
    for i in range(m):
        if i==x :
            continue
        U.unite(ab[i][0]-1, ab[i][1]-1)
    for i in range(n):
        for j in range(n):
            if not U.same(i, j):
                return False
    return True
ans=0
for y in range(m):
    if not C(y):
        ans+=1
print(ans)

Measured memory_bytes: 3064
from collections import Counter

N = int(input())

def solve(str_num):
    ans = 0
    if int(str_num or 0) <= N:
        if len(Counter(str_num)) == 3:
            ans += 1
        for n in ("3","5","7"):
            ans += solve(str_num+n)
    return ans

print(solve(""))

Measured memory_bytes: 3316
nm = list(map(int, input().split()))
a = list(map(int, input().split()))
Sum=0
flag=0

for i in range(len(a)):
    Sum+=a[i]

a.sort(reverse=True)

for i in range(nm[1]):
    if a[i]<Sum/(4*nm[1]):
        flag=1
        break

if flag==1:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 3060
/****************************************
	Sahil Gangurde
	Learning through WA, TLE, SIGESV
****************************************/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <utility>
#include <climits>
#include <numeric>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <cassert>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll n;
	cin>>n;
	ll a[n];
	// map<int , int > m;
	for(ll i=0; i<n; i++) {
		cin>>a[i];
		// m.first()
	}
	sort(a, a+n);
	for(ll i=1; i<n; i++) {
		if(a[i]==a[i-1]) {
			cout<<"NO\n";
			return 0;
		}
	}
	cout<<"YES\n";
}


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

int main()
{
    int L, R, d;
    cin >> L >> R >> d;

    int count = 0;
    for (int i = L; i <= R; i++)
    {
        if (i % d == 0)
        {
            count++;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3592
S = input()

ZABC = [[0 for i in range(4)] for j in range(len(S))]
if S[0] == '?':  
    ZABC[0][0] = 3
else:
    ZABC[0][0] = 1
if S[0] == '?' or S[0] == 'A':  
    ZABC[0][1] = 1
else:
    ZABC[0][1] = 0
for i in range(2):
    ZABC[0][i+2] = 0

for i in range(1,len(S)):
    if S[i] == '?':
        q = 3
    else:
        q = 1
    ZABC[i][0] = (ZABC[i-1][0]*q)%1000000007
for i in range(1,len(S)):
    if S[i] == '?':
        q = 3
    else:
        q = 1
    if S[i] == '?' or S[i] == 'A':
        r = 1
    else:
        r = 0
    ZABC[i][1] = (ZABC[i-1][1]*q+ZABC[i-1][0]*r)%1000000007
for i in range(1,len(S)):
    if S[i] == '?':
        q = 3
    else:
        q = 1
    if S[i] == '?' or S[i] == 'B':
        r = 1
    else:
        r = 0
    ZABC[i][2] = (ZABC[i-1][2]*q+ZABC[i-1][1]*r)%1000000007
for i in range(1,len(S)):
    if S[i] == '?':
        q = 3
    else:
        q = 1
    if S[i] == '?' or S[i] == 'C':
        r = 1
    else:
        r = 0
    ZABC[i][3] = (ZABC[i-1][3]*q+ZABC[i-1][2]*r)%1000000007
print(ZABC[len(S)-1][3])

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

using namespace std;

#define int long long

constexpr int INF = 1LL << 60;

constexpr int MAX_N = 100005;

typedef pair<int, int> pii;

int n, t;

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

    cin >> n >> t;
    int mh = 0, tt = t, last = 1;
    for (int i = 1; i <= n; i++) {
        int h;
        cin >> h;
        mh = max(mh, h);

        // cerr << "first last: " << last << " tt: " << tt << endl;

        if (tt <= 0) {
            cout << max(1LL, last) << endl;
            continue;
        }

        last = tt / mh;
        if (h <= tt % mh) last++;
        // cerr << "last: " << last << " tt: " << tt << endl;
        cout << last + 1 << endl;

        tt -= h;
    }
}



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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main()
{
    int N,L;

    cin >> N >> L;
    
    vector<int> a;
    ll minus = INF;
    for(int i = 1;i < N+1;i++)
    {
        a.push_back(L+i-1);
        if(abs(minus) > abs(L+i-1)) minus = L+i-1;
    }
    ll sum = 0;
    rep(i,a.size()) sum += a[i];
    cout << sum-minus << endl;

}


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

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

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

const double eps = 1e-6;

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

const int64 mod = 1e9+7;

int64 calc(const vector<int32>& v){
	vector<int64> dp[3];
	REP(i, 3) dp[i].resize(v.size(), -INF_LL);
	int32 n = v.size();
	assert(*min_element(all(v)) != 0);
	dp[2][0] = 0;
	REP(i, n-1){
		REP(j, 3){
			REP(k, 3){
				int64 num = 0;
				if(k == 0) num = v[i];
				else if(k == 1) num = v[i+1];
				if(v[i] == 1 && j != 2) num = 0;
				if(j == 1 && k == 0) num = 0;
				chmax(dp[k][i+1], dp[j][i]+num-(k == j && j != 2 ? 1 : 0));
			}
		}
	}
	int64 res = 0;
	/*
	REP(i, n){
		REP(j, 3){
			cout << dp[j][i] << " ";
		}
		cout << endl;
	}
	*/
	REP(i, 3){
		res = max(res, dp[i][n-1]);
	}
	return res;
}

int main(void){
	int32 n;
	string s;
	cin >> n >> s;
	vector<int32> v;
	int32 cnt = 0;
	int64 res = 0;
	REP(i, s.size()){
		if(s[i] == '1') cnt++;
		else{
			if(i > 0 && s[i-1] == '0'){
				if(v.size()) res += calc(v);
				v.clear();
			}else{
				if(cnt) v.push_back(cnt);
				cnt = 0;
			}
		}
	}
	if(cnt > 0) v.push_back(cnt);
	if(v.size()) res += calc(v);
	cout << res << endl;
}

Measured memory_bytes: 900
#include<iostream>

int seekKeta(int n){
    int keta = 0;
    while(n != 0){
        n /= 10;
        keta++;
    }
    return keta;
}

int main(void){
    int n;
    std::cin >> n;
    int keta = seekKeta(n);
    int maxketa;
    int ans = 0;
    if(keta % 2 == 0){
        maxketa = keta - 1;
    }else{
        maxketa = keta - 2;
    }
    int cur = 9;
    for(int i = 1; i <= maxketa; i+=2){
        ans += cur;
        cur *= 100;
    }
    int res = 1;
    for(int i = 0; i < keta-1; i++){
        res *= 10;
    }
    if(keta % 2 == 1){
        ans += n - res + 1;
    }

    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 3608
/*
    Author : Nishant Gupta 2.0
*/
#include<bits/stdc++.h>

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 100005
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 1e18
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define MSV(A,a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)

using namespace std;

inline void inp( int &n ) { 
	n=0;    int ch=getcx();int sign=1;   
	while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();} 
	while(  ch >= '0' && ch <= '9' )    
	n = (n<<3)+(n<<1) + ch-'0', ch=getcx();
	n=n*sign;
}

inline void inp1( LL &n ) { 
	n=0;    LL ch=getcx();LL sign=1;   
	while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();} 
	while(  ch >= '0' && ch <= '9' )    
	n = (n<<3)+(n<<1) + ch-'0', ch=getcx();
	n=n*sign;
}

typedef pair<LL, LL> pi; 

struct value {
	LL v = -1;
};

map<LL, value> dp;

LL a, b, c, d, n;
value call(LL num) {
	if(dp[num].v != -1) {
		return dp[num];
	}
	
	if(num == 0) {
		value val;
		val.v = 0;
		dp[num] = val;
		return dp[num];
	}
	
	LL all_d = d * num;
	if(all_d < 0) all_d = INFL;
	
	LL ans = INFL;
	ans = min(ans, all_d);
	if(num % 2 == 0) {
		ans = min(ans, call(num/2).v + a);
	} else {
		LL rem = num % 2;
		ans = min(ans, call(num/2).v + d*rem + a);
		if(num != 1) {
			rem = 2-rem;
			ans = min(ans, call((num+rem)/2).v + d*rem + a); 
		}
	}
	
	if(num % 3 == 0) {
		ans = min(ans, call(num/3).v + b);
	} else {
		LL rem = num % 3;
		ans = min(ans, call(num/3).v + d*rem + b);
		if(num != 1) {
			rem = 3-rem;
			ans = min(ans, call((num+rem)/3).v + d*rem + b); 
		}
	}
	
	if(num % 5 == 0) {
		ans = min(ans, call(num/5).v + c);
	} else {
		LL rem = num % 5;
		ans = min(ans, call(num/5).v + d*rem+c);
		if(num != 1) {
			rem = 5-rem;
			ans = min(ans, call((num+rem)/5).v + d*rem+c); 
		}
	}
	
	value ansv;
	ansv.v = ans;
	dp[num] = ansv;
	return dp[num];
}

int main() {
	int t;
	inp(t);
	
	while(t--) {
		inp1(n);inp1(a);inp1(b);inp1(c);inp1(d);
		value ans = call(n);
		dp.clear();
		cout<<ans.v<<endl;
	}

    return 0;
}



Measured memory_bytes: 4356
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());

		var m = new HashSet<string>();
		var a = new HashSet<string>();
		var r = new HashSet<string>();
		var c = new HashSet<string>();
		var h = new HashSet<string>();
		for (var i = 0; i < n; ++i) {
			var s = Console.ReadLine();
			var initial = s[0];
			if (initial == 'M') {
				m.Add(s);
			} else if (initial == 'A') {
				a.Add(s);
			} else if (initial == 'R') {
				r.Add(s);
			} else if (initial == 'C') {
				c.Add(s);
			} else if (initial == 'H') {
				h.Add(s);
			}
		}

		long answer = 0;

		var counts = Array.ConvertAll(
			Array.FindAll(new[] { m, a, r, c, h }, names => names.Any()),
			names => (long)names.Count);
		if (counts.Length == 3) {
			answer = counts[0] * counts[1] * counts[2];
		} else if (counts.Length == 4) {
			answer = counts[0] * counts[1] * counts[2]
				+ counts[0] * counts[1] * counts[3]
				+ counts[1] * counts[2] * counts[2];
		} else if (counts.Length == 5) {
			answer = counts[0] * counts[1] * counts[2]
				+ counts[0] * counts[1] * counts[3]
				+ counts[0] * counts[1] * counts[4]
				+ counts[0] * counts[2] * counts[3]
				+ counts[0] * counts[2] * counts[4]
				+ counts[0] * counts[3] * counts[4]
				+ counts[1] * counts[2] * counts[3]
				+ counts[1] * counts[2] * counts[4]
				+ counts[1] * counts[3] * counts[4]
				+ counts[2] * counts[3] * counts[4];
		}

		Console.WriteLine(answer);
	}
}


Measured memory_bytes: 30940
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
s  = input()
#  = int(input())
#  = map(int, input().split())
#  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

print('ABC' if s == 'ARC' else 'ARC')


Measured memory_bytes: 9400
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
ll MOD  = 1000000007;
int dx[5] = {-1, 0, 0, 1, 0};
int dy[5] = {0, -1, 1, 0, 0};

void solve(){
    ll N;
    cin >> N;
    vector<ll> A(N+2);
    vector<ll> B(N);
    vector<ll> C(N+2);
    A[0] = 0, A[N+1] = INFL;
    C[0] = 0, C[N+1] = INFL;
    for(int i = 1; i <= N; i++) cin >> A[i];
    for(int i = 0; i < N; i++) cin >> B[i];
    for(int i = 1; i <= N; i++) cin >> C[i];
    sort(A.begin(), A.end());
    sort(C.begin(), C.end());
    ll ans = 0;
    for(int i = 0; i < N; i++){
        ll x = B[i];
        ll down, up;
        ll left = -1, right = N+2, mid;
        while(right - left > 1){
            mid = (left + right) / 2;
            if(A[mid] >= x){
                right = mid;
            }else{
                left = mid;
            }
        }
        down = left;
        
        left = -1, right = N+2;
        while(right - left > 1){
            mid = (left + right) / 2;
            if(C[mid] <= x){
                left = mid;
            }else{
                right = mid;
            }
        }
        up = N - left;
        
        ans += down * up;
    }
    cout << ans << endl;
}

int main(void){
    solve();
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> A(N),B(N),C(N);
  for (int i=0;i<N;i++){
    cin >> A[i];
  }
  for (int i=0;i<N;i++){
    cin >> B[i];
  }
  for (int i=0;i<N-1;i++){
    cin >> C[i];
  }
  int ans=B[N-1];
  for (int i=0;i<N-1;i++){
    if (A[i]+1==A[i+1]){
      ans+=C[A[i]-1];
    }
    ans+=B[i];
  }
  cout << ans << endl;
}
  

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

void parbona() {
    cout << "Impossible" << endl;
    exit(0);
}

int done[MAXN];
int a[MAXN];

int findIdx(int n, int x) {
    for (int i = 1; i <= n; i++) {
        if (done[i]) continue;
        if (a[i]==x) return i;
    }
    return -1;
}

int dst[MAXN];
int makeDo(int n, int x) {
    int i = findIdx(n, x);
    if (i==-1) parbona();
    done[i] = 1;
    dst[x] = i;
}

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

    int mx = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        mx = max(mx, a[i]);
    }

    int d = mx/2;
    if (mx%2==0) makeDo(n, d);
    for (int x = d+1; x <= mx; x++) {
        makeDo(n, x);
        makeDo(n, x);
    }

    for (int i = 1; i <= n; i++) {
        if (done[i]) continue;
        if (a[i] <= d) parbona();
        if (dst[a[i]-1] == 0) parbona();
    }

    cout << "Possible" << endl;

    return 0;
}


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

int main(){
	ios::sync_with_stdio(0);
	cout << setprecision(10) << fixed;
	int n;
	cin >> n;
	map<int, int> cnt;
	bool flag = true;
	for (int i = 0; i < n; ++i){
		int a;
		cin >> a;
		if (cnt.count(a)){
			flag = false;
		}
		cnt[a]++;
	}
	cout << (flag ? "YES" : "NO");
	return 0;
}



Measured memory_bytes: 9600
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include <algorithm>
#include<initializer_list>
using namespace std;
#define ul unsigned long long

#define rup(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define rdn(i, a, b) for(int (i) = (a); (i) > (b); (i)--)

int main() {
	ul a, b, c;
	cin >> a >> b >> c;
	ul ab = a + b;
	ul bc = b + c;
	ul ca = c + a;
	ul min = ab;
	if (min > bc) min = bc;
	if (min > ca) min = ca;
	cout << min;
	return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;



int main() {
    int mx = 100;
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    auto f = [&](){
        vector<int> u(n+1);
        for (int i = 0; i < n; ++i) {
            int l = max(0, i-v[i]), r = min(n, i+v[i]+1);
            u[l]++; u[r]--;
        }
        for (int i = 0; i < n; ++i) {
            v[i] = u[i];
            u[i+1] += u[i];
        }
    };
    for (int i = 0; i < min(k, mx); ++i) {
        f();
    }
    for (int i = 0; i < n; ++i) {
        if(i) printf(" ");
        printf("%d", v[i]);
    }
    puts("");
    return 0;
}

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

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

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

ll dp[100100];
ll sum[100100];
bool used[100100];


int main(){
    int N,M,X; cin >> N >> M >> X;
    int c[N];
    int a[N][M];
    for(int i=0;i<N;i++){
        cin >> c[i];
        for(int j=0;j<M;j++){
            cin >> a[i][j];
        }
    }
    int ans=INF;
    for(int bit=0;bit<(1<<N);bit++){
        int res=0;
        int sum[M]={};
        for(int i=0;i<N;i++){
            if((1<<i)&bit){
                res+=c[i];
                for(int j=0;j<M;j++){
                    sum[j]+=a[i][j];
                }
            }
        }
        bool flag=true;
        for(int i=0;i<M;i++){
            if(sum[i]<X) flag=false;
        }
        if(flag){
            ans=min(ans,res);
        }
    }
    if(ans==INF){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
    
}

Measured memory_bytes: 3616
/**
  *    author:  NEZZ
 **/
 #include <bits/stdc++.h>
 #define rep(i,a,b) for (int i=a;i<b;i++)
 #define rep2(i,a,b) for (int i=a;i>=b;i--)
 #define mod 1000000007
 #define INF  0x3f3f3f3f3f3f3f3f
 #define f first
 #define s second
 #define endl '\n'
 #define ll long long
 #define ii pair <int,int>
 #define pll pair <ll,ll>
 #define vi vector <int>
 #define vl vector <ll>
 #define vvi vector < vi >
 #define vii vector < ii >
 #define vvii vector < vii>
 #define vll vector < ll >
 #define vb  vector <bool>
 #define pb push_back
 #define mk make_pair
 #define sz(a) a.size()
 #define all(a) a.begin(),a.end()
 #define rall(a) a.rbegin(),a.rend()
 #define input freopen("input","r",stdin)
 #define output freopen("output","w",stdout)
 #define fastIO ios_base::sync_with_stdio (0),cin.tie(0)
 #define debug input,output

 using namespace std;
 void affiche (ii t[],int n){ rep (i,0,n) cout<<t[i].s<<" ";cout<<endl;}
 void afficheV (vll t){rep (i,0,sz(t))cout<<t[i]<<" ";cout<<endl;}
int const MAXN=1e5+7;
int main(){
 fastIO;
 ll a,b,c,k;
 cin>>a>>b>>c>>k;
 if (abs(a-b)<1e18){
    if (k%2)
    cout<<b-a;
         else cout<<a-b;
 }

 else cout<<"Unfair";
}



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


int ordena(const void* a, const void* b){
    int x = *((int*)a);
    int y = *((int*)b);

    if(x < y)
        return -1;
    return 1;

}

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

    int v[n];

    for(int i = 0; i < n; ++i){
        scanf("%d", &v[i]);
    }

    qsort(v, n, sizeof(v[0]), ordena);

    printf("%d\n", v[n-1]-v[0]);
 return 0;

}


Measured memory_bytes: 128
import math
import numpy as np
from collections import Counter

N = int(input())

if N == 1:
    print(0)
else:
    xyz_lim = int(math.sqrt(N-2)) - 1

    def f(x, y, z):
        return ((x+y)**2 + (y+z)**2 + (z+x) ** 2) // 2

    cnt = Counter()
    for _x in range(xyz_lim):
        for _y in range(xyz_lim):
            x, y = _x+1, _y+1
            cnt.update([f(x, y, _z+1) for _z in range(xyz_lim)])

    for _n in range(N):
        n = _n + 1
        print(cnt[n])

Measured memory_bytes: 29380
#include <cstdio>

const int MN = 2005;

int N, M, Q, A[MN][MN], B[MN][MN], C[MN][MN];

int main() {
	scanf("%d%d%d", &N, &M, &Q);
	for (int i = 1; i <= N; ++i)
		for (int j = 1; j <= M; ++j)
			scanf("%1d", &A[i][j]),
			B[i][j] = A[i][j] && A[i - 1][j],
			C[i][j] = A[i][j] && A[i][j - 1];
	for (int i = 1; i <= N; ++i)
		for (int j = 1; j <= M; ++j)
			A[i][j] += A[i - 1][j] + A[i][j - 1] - A[i - 1][j - 1],
			B[i][j] += B[i - 1][j] + B[i][j - 1] - B[i - 1][j - 1],
			C[i][j] += C[i - 1][j] + C[i][j - 1] - C[i - 1][j - 1];
	while (Q--) {
		int sx, sy, tx, ty;
		scanf("%d%d%d%d", &sx, &sy, &tx, &ty);
		printf("%d\n", A[tx][ty] - A[sx - 1][ty] - A[tx][sy - 1] + A[sx - 1][sy - 1] - B[tx][ty] + B[sx][ty] + B[tx][sy - 1] - B[sx][sy - 1] - C[tx][ty] + C[sx - 1][ty] + C[tx][sy] - C[sx - 1][sy]);
	}
	return 0;
}

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

using i64 = long long int;

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

    a *= 100; b *= 100;
    int ans_total = a, ans_sugar = 0;
    for(int i=0;i<=30;++i){
        if(i*a > f)break;
        for(int j=0;j<=30;++j){
            if(i*a + j*b > f)break;
            for(int k=0;k*c+i*a+j*b<f;++k){
                int water = i*a + j*b;
                if(water <= 0)break;
                int l = min((f - (k*c+water)) / d, (water*e/100 - k*c) / d);
                int sugar = k*c + l*d;
                if(l < 0 || water + sugar > f)continue;
                if(sugar * (100+e) > e * (water + sugar))continue;
                if(sugar * ans_total > ans_sugar * (water + sugar)){
                    ans_total = water + sugar;
                    ans_sugar = sugar;
                }
            }
        }
    }

    cout << ans_total << " " << ans_sugar << endl;

    return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair

//comb(a, b) = a! / b! / (a-b)!
int main(){
	int N;
	cin >> N;
	int a[100000];
	for(int i=0; i<N; i++) cin >> a[i];
	sort(a, a+N);
	cout << a[N-1] << " ";
	double d = INT_MAX;
	int idx = -1;
	for(int i=0; i<N-1; i++){
		if(d > abs(a[i] - (double)a[N-1]/2.0)){
			d = abs(a[i] - (double)a[N-1]/2.0);
			idx = i;
		}
	}
	cout << a[idx] << endl;
}

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


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

    string ans;
    if(x==3 || x==5 || x==7) ans = "YES";
    else ans = "NO";

    cout<<ans<<endl;
        
    return 0;
}


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

int main(void) {
	char all[26][13];
	memset(all, 0, sizeof(all));
	int i, n;
	char c;
	scanf("%d", &n);
	while(~scanf("%c %d", &c, &n)) {
		all[c - 'A'][n - 1] = 1;
	}
	for(i = 0; i < 4; i++) {
		for (n = 0; n < 13; n++) {
			all["SHCD"[i] - 'A'][n] || printf("%c %d\n", "SHCD"[i], n + 1);
		}
	}
	return 0;
}

Measured memory_bytes: 596
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N = int(input())
A = list(map(int, input().split()))


def makeDivisors(n):
	divisors = []
	
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			
			if n // i != i:
				divisors.append(n // i)
			
	return divisors

counter = [0] * N
ballNum = 0
boxWithBall = []

for i in range(N - 1, -1, -1):
	if counter[i] != A[i]:
		ballNum += 1
		boxWithBall.append(i + 1)
		
		for j in makeDivisors(i + 1):
			counter[j - 1] ^= 1
			
print(ballNum)

for i in boxWithBall:
	print(i, end=' ')


Measured memory_bytes: 68200
S = input()

S = list(set(S))
S.sort()

T = [0 for _ in range(26)]

for s in S:
    T[ord(s)-97] = 1

for n in range(26):
    if T[n] == 0:
        print(chr(n+97))
        break
else:
    print('None')

Measured memory_bytes: 3188
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

const double PI = acos(-1);
typedef long long ll;
#define int ll
#define fori(n) for(int i=0; i<int(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a, n) vd a(n); fori(n) { cin>>a[i]; }


typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;

/* increment lunlun number */
void inc(vi &a) {
    bool all9=true;
    for(int i=0; i<a.size(); i++) {
        if(a[i]!=9)
            all9=false;
    }
    if(all9) {
        for(int i=0; i<a.size(); i++)
            a[i]=0;
        a.push_back(1);
        return;
    }

    for(int i=0; i+1<a.size(); i++) {
        if(a[i]<a[i+1]+1 && a[i]<9) {
            a[i]++;
            for(int j=i-1; j>=0; j--)
                a[j]=max(0LL, a[j+1]-1);
            return;
        }
    }
    a.back()++;
    for(int i=0; i+1<a.size(); i++) {
        a[a.size()-2-i]=max(0LL, a[a.size()-1-i]-1);
    }
}
    

/* every digit can have at most 3 values */
void solve() {
    cini(n);
    vi a;
    a.push_back(1);
    for(int i=1; i<n; i++)  {
        inc(a);
/*
for(int i=0; i<a.size(); i++)
    cout<<a[a.size()-1-i];
cout<<endl;
*/
    }

    while(a.size()) {
        cout<<a.back();
        a.pop_back();
    }
    cout<<endl;
}

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

// auto mod int
const int mod = 1000000007;

signed main() {
    int n;
    cin >> n;
    int a[n];
    rep(i, 0, n) cin >> a[i];
    int s[n + 1];
    s[0] = 0;
    rep(i, 0, n) s[i + 1] = (s[i] + a[i]) % mod;
    int ans = 0;
    rep(i, 0, n) ans = (ans + a[i] * (s[n] - s[i + 1] + mod) % mod) % mod;
    cout << ans << "\n";
}

Measured memory_bytes: 6680
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 K;
  std::cin >> K;

  i64 found = 0;
  std::vector<i64> digits;
  i64 max_depth;
  std::function<void(void)> dfs;
  dfs = [&]() {
    if (static_cast<i64>(digits.size()) == max_depth) {
      ++found;

      if (found == K) {
        i64 answer = 0;
        for (const i64& digit : digits) {
          answer *= 10;
          answer += digit;
        }

        std::cout << answer << std::endl;
        std::exit(0);
      }
    } else {
      for (i64 i = digits.empty() ? 1 : std::max<i64>(0, digits.back() - 1); i <= (digits.empty() ? 9 : std::min<i64>(digits.back() + 1, 9)); ++i) {
        digits.push_back(i);
        dfs();
        digits.pop_back();
      }
    }
  };

  for (max_depth = 1; ; ++max_depth) {
    dfs();
  }

  return EXIT_FAILURE;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define LL_MAX LLONG_MAX
#define ULL_MAX ULLONG_MAX
#define ull unsigned long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define mk make_pair
#define endl '\n'

int main()
{
    IOS;
        int n;
        cin>>n;
        vector<int> a(n,0);
        map<int,int> mp;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
            
        }
        vector<int> pre(n,0);
        for (int i = n - 1; i >= 0; i--)
        {
            pre[i]=mp[a[i]+i];
            mp[i-a[i]]++;
        }
        ll ans=0;
        for (int i = 0; i < n; i++)
        {
            ans+=pre[i];
        }
        cout<<ans;
}

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

int main(){
    int64_t S;
    cin >> S;
    const int X = 1e9;
    int64_t Q = S/X;
    int64_t R = S%X;
    int64_t x1, x2, y1, y2;
    if(R == 0){
        x1 = X;
        y2 = Q;
        x2 = 1;
        y1 = 0;
    }else{
        x1 = X;
        y2 = Q+1;
        x2 = 1;
        y1 = X - R;
    }
    assert(abs(x1*y2 - x2*y1) == S);
    printf("%lld %lld %lld %lld %lld %lld\n", 0, 0, x1, y1, x2, y2);
    return 0;
}


Measured memory_bytes: 256
import sys
from math import log2,floor,ceil,sqrt
# import bisect
# from collections import deque

# from types import GeneratorType
# def bootstrap(func, stack=[]):
#     def wrapped_function(*args, **kwargs):
#         if stack:
#             return func(*args, **kwargs)
#         else:
#             call = func(*args, **kwargs)
#             while True:
#                 if type(call) is GeneratorType:
#                     stack.append(call)
#                     call = next(call)
#                 else:
#                     stack.pop()
#                     if not stack:
#                         break
#                     call = stack[-1].send(call)
#             return call
#     return wrapped_function

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
 
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

n = int(ri())
a = Ri()
a.sort()

if a[0] == 0:
    print(0)
else:
    ans = 1
    for i in range(n):
        ans = ans*a[i]
        flag  = True
        if ans > INF : 
            print(-1)
            flag = False
            break
    if flag : 
        print(ans)



Measured memory_bytes: 83292
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <algorithm>

using namespace std; 

int n, dx[4] = {-1, 0, 0, 1}, dy[4] = {0, 1, -1, 0}; 
int dis[505][505], vis[505][505]; 

void dfs(int x, int y) {
    for (int i = 0; i < 4; i++) {
        int nx = x + dx[i], ny = y + dy[i]; 
        if (dis[nx][ny] > dis[x][y] + 1 - vis[nx][ny]) {
            dis[nx][ny] = dis[x][y] + 1 - vis[nx][ny];
            dfs(nx, ny);
        }
    }
}

int main() {
    scanf("%d", &n); 
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            dis[i][j] = min(min(i, j), min(n - i + 1, n - j + 1)); 
        }
    }
    int ans = 0; 
    for (int i = 1; i <= n * n; i++) {
        int p;
        scanf("%d", &p); 
         
        int x = (p - 1) / n + 1, y = p - (x - 1) * n;
        vis[x][y] = 1;
        ans += dis[x][y] - 1; 
        for (int j = 0; j < 4; j++) {
            int nx = x + dx[j], ny = y + dy[j]; 
            dis[x][y] = min(dis[x][y], dis[nx][ny]); 
        }
        dfs(x, y); 
    }
    printf("%d\n", ans); 
    return 0; 
}

Measured memory_bytes: 12564
// 2012/11/07 Tazoe

#include <iostream>
using namespace std;

int main()
{
	bool is_prime[1000000];

	is_prime[0] = is_prime[1] = false;
	for(int i=2; i<1000000; i++){
		is_prime[i] = true;
	}

	for(int i=2; i*i<1000000; i++){
		if(is_prime[i]){
			for(int j=i*i; j<1000000; j+=i){
				is_prime[j] = false;
			}
		}
	}

	int n_prime[1000000];

	int cnt = 0;
	for(int i=0; i<1000000; i++){
		if(is_prime[i]){
			cnt++;
		}

		n_prime[i] = cnt;
	}

	while(true){
		int n;
		cin >> n;

		if(cin.eof())
			break;

		cout << n_prime[n] << endl;
	}

	return 0;
}

Measured memory_bytes: 6040
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

void solve(int n,int m){
	int t,s,d;
	vb b(n,false);
	b[0]=true;
	vector<tlll> v(m);
	rep(i,m){
		cin>>t>>s>>d;
		t--;s--;d--;
		v[i]=tlll(t,s,d);
	}
	sort(all(v));
	rep(i,m){
		b[get<2>(v[i])]=b[get<2>(v[i])]|b[get<1>(v[i])];
	}
	int cnt=0;
	rep(i,n)if(b[i])cnt++;
	cout<<cnt<<endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;
	while(cin>>n>>m,n)solve(n,m);
}


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=100005;
int n,ql,qr,len;
vector<int>edge[maxn];
int dist[maxn],que[maxn],par[maxn],path[maxn];
int ans1[maxn],ans2[maxn];

void bfs(int s){
	REP(i,n)dist[i]=n;
	dist[s]=0;
	ql=1;qr=0;
	que[++qr]=s;
	while(ql<=qr){
		int x=que[ql++];
		rep(i,int(edge[x].size())){
			int y=edge[x][i];
			if(dist[y]==n){
				par[y]=x;
				dist[y]=dist[x]+1;
				que[++qr]=y;
			}
		}
	}
}

int main(){
	scanf("%d",&n);
	REP(i,n-1){
		int u,v;
		scanf("%d%d",&u,&v);
		edge[u].pb(v);
		edge[v].pb(u);
	}
	bfs(1);
	int s=1,t=1;
	REP(i,n)if(dist[i]>dist[s])s=i;
	bfs(s);
	REP(i,n)if(dist[i]>dist[t])t=i;
	while(t!=s)path[++len]=t,t=par[t];
	path[++len]=s;
	int now=0;
	REP(i,len){
		int cur=int(edge[path[i]].size());
		if(i>1)cur--;
		if(i<len)cur--;
		REP(j,cur)ans1[now+j]=now+1+j;
		ans1[now+1+cur]=now+1;
		now+=cur+1;
	}
	if(now!=n){
		puts("-1");
		return 0;
	}
	now=0;
	for(int i=len;i>=1;i--){
		int cur=int(edge[path[i]].size());
		if(i>1)cur--;
		if(i<len)cur--;
		REP(j,cur)ans2[now+j]=now+1+j;
		ans2[now+1+cur]=now+1;
		now+=cur+1;
	}
	bool ok=false;
	REP(i,n)if(ans1[i]!=ans2[i]){
		ok=(ans2[i]<ans1[i]);
		break;
	}
	if(ok)REP(i,n)ans1[i]=ans2[i];
	REP(i,n)printf("%d%c",ans1[i],i==n?'\n':' ');
	return 0;
}

Measured memory_bytes: 8576
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		double x1 = sc.nextDouble();
		double y1 = sc.nextDouble();
		double x2 = sc.nextDouble();
		double y2 = sc.nextDouble();
		sc.close();

		System.out.println(Math.pow((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1), 0.5));
	}
}

Measured memory_bytes: 27920
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,ans=0;
  int a[109];
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i!=j){
	ans=max(ans,abs(a[i]-a[j]));
      }
    }
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 256
import java.util.*;
import java.util.Scanner;
class Main{
    public static void main(String[] args)
    {
        int a[][] = new int[3][3];
        int flag[][] = new int[3][3];
        int n;
        int b[] = new int[10];
        int flag1, flag2, flag3;
        String result = "No";
        int cal1;
        Scanner scanner = new Scanner(System.in);
        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 3; j++){
                a[i][j] = scanner.nextInt();
            }
        }
        n = scanner.nextInt();
        for(int i = 0; i < n; i++){
            b[i] = scanner.nextInt();
            for(int j = 0; j < 3; j++){
                for(int k = 0; k < 3; k++){
                    if(b[i] == a[j][k]){
                        flag[j][k] = 1;
                    }
                }
            }
        }
        if(flag[0][0] == 1 && flag[0][1] == 1 && flag[0][2] == 1){
            result = "Yes";
        }else if(flag[0][0] == 1 && flag[1][1] == 1 && flag[2][2] == 1){
            result = "Yes";
        }else if(flag[0][0] == 1 && flag[1][0] == 1 && flag[2][0] == 1){
            result = "Yes";
        }else if(flag[0][1] == 1 && flag[1][1] == 1 && flag[2][1] == 1){
            result = "Yes";
        }else if(flag[0][1] == 1 && flag[1][1] == 1 && flag[2][1] == 1){
            result = "Yes";
        }else if(flag[1][0] == 1 && flag[1][1] == 1 && flag[1][2] == 1){
            result = "Yes";
        }else if(flag[2][0] == 1 && flag[1][1] == 1 && flag[0][2] == 1){
            result = "Yes";
        }else if(flag[2][0] == 1 && flag[2][1] == 1 && flag[2][2] == 1){
            result = "Yes";
        }else if(flag[0][2] == 1 && flag[1][2] == 1 && flag[2][2] == 1){
            result = "Yes";
        }

        System.out.println(result);
    }
}

Measured memory_bytes: 23764