Problem:
Problem B: Spellcasters
n 人の魔法使いがいる。彼らには 1 から n までの番号があり、i 番目の魔法使いは魔力 r
i
( 1 ≤ i ≤ n ) を持っている。いま彼らは強力な魔法使いと対峙しており、その敵の魔力は S である。n 人の魔法使いは協力して戦うのが得意で、特に 2 人で協力して戦うことを好む。2 人の魔法使いが協力した場合、魔力は単純にその和となり、強力な魔法などを駆使してある程度強い敵にも勝てるようになる。あなたの仕事は魔力 S を持つ敵に対して勝つことができる魔法使いのペア (i, j) ( i ≠ j かつ 1 ≤ i ≤ n かつ 1 ≤ j ≤ n ) の総数を出力することである。ただし (i, j) と (j, i) は同じ組として数える。一方の魔力が他方の魔力よりも大きいとき、大きい魔力を持っている側が勝つ。等しい場合は相打ちで勝ったことにならない。
Input
入力は複数のテストケースからなる。 各テストケースは以下の形式に従う。
n S
r
1
r
2
…
r
n
各変数の意味は問題文中の通りである。
入力の終わりは、ふたつの0が一文字の空白で区切られる一行で示される。
Constraints
入力はすべて整数
1 ≤ n ≤ 20,000
1 ≤ r
i
≤ 100 ( 1 ≤ i ≤ n )
1 ≤ S ≤ 100
テストケースの数は 100 を超えない。
Output
条件を満たす組 (i, j) (i ≠ j) の総数を各ケースに付き 1 行に出力せよ。
Sample Input
3 7
1
3
10
0 0
Sample Output
2

Submitted solutions:

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

#define BIG_NUM 2000000000

using namespace std;

void func(int N,int S){

	int table[N],index = N-1,tmp;

	priority_queue<int> Q;

	for(int i = 0; i < N; i++){
		scanf("%d",&tmp);
		Q.push(tmp);
	}

	while(!Q.empty()){
		table[index--] = Q.top();
		Q.pop();
	}

	int sum = 0,left,right,m,tmp_min;

	for(int i = 0; i < N-1; i++){
		left = i+1,right = N-1,m = (left+right)/2;

		tmp_min = N;

		while(left <= right){
			if(table[i] + table[m] > S){
				tmp_min = m;
				right = m-1;
			}else{
				left = m+1;
			}
			m = (left+right)/2;
		}
		if(tmp_min != N){
			sum += N - tmp_min;
		}
	}

	printf("%d\n",sum);
}

int main(){

	int N,S;

	while(true){
		scanf("%d %d",&N,&S);
		if(N == 0 && S == 0)break;

		func(N,S);
	}

	return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 2908
final_rank: 4

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k;
    while (cin >> n >> k, n) {
        vector<int> c(n);
        for (int i = 0; i < n; ++i) {
            cin >> c[i];
        }
        sort(c.begin(), c.end());
        ll res = 0;
        for (int i = 0; i < n; ++i) {
            res += upper_bound(c.begin(), c.end(), 2e9) - lower_bound(c.begin(), c.end(), k - c[i] + 1);
        }
        for (int i = 0; i < n; ++i) {
            if (c[i] + c[i] > k) res -= 1;
        }
        cout << res / 2 << "\n";
    }
}
accuracy: 1
time_ms: 40
memory_kb: 3356
final_rank: 13

code_snippet: // AIOJ1.0.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include<string.h>
#include<algorithm>
#include<cstring>
typedef long long ll;
using namespace std;
int main() {
	while (true) {
		int n, k;
		cin >> n >> k;
		if (n == 0) {
			break;
		}
		int c[20110];
		int nk = n;
		for (int i = 0; i < n; i++) {
			cin >> c[i];
		}
		sort(c, c + n);
		ll sum = 0;
		for (int i = 0; i < n; i++){
			if (c[i] > k) {
				nk = i;
				break;
			}
			for (int j = i+1; j < n; j++) {
				if (c[i] + c[j] > k) {
					sum += (n- j);
					break;
				}
			}
		}
		if (nk != n) {
			sum += (n - nk) * (n - nk - 1) / 2;
		}
		cout << sum << endl;
	}
	return 0;
}
// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单

// 入门使用技巧: 
//   1. 使用解决方案资源管理器窗口添加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件，或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来，若要再次打开此项目，请转到“文件”>“打开”>“项目”并选择 .sln 文件
accuracy: 1
time_ms: 250
memory_kb: 3132
final_rank: 11

code_snippet: #include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1e9
#define LINF (1LL<<40)
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define MP make_pair
#define int long long
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define umap unordered_map 
#define re0 return 0
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
 int dx[]={0,1,0,-1};
 int dy[]={1,0,-1,0};
//typedef pair<int,int> P;
const string SP = " ";
const string TAB = "\t"; 
const long long MOD=1000000007LL;
bool isupper(char c){if('A'<=c&&c<='Z')return 1;return 0;}
bool islower(char c){if('a'<=c&&c<='z')return 1;return 0;}
bool isnumber(char c){return ('0'<=c&&c<='9');}
bool isalpha(char c){return (isupper(c)||islower(c));}
bool is_kaibun(string s){string rs = s;reverse(all(rs));if(s == rs)return true;else return false;}
std::random_device rnd;
std::mt19937 mt(rnd());
const int RAND_LIMIT = 1000000;
std::uniform_int_distribution<> rand_mt(0, RAND_LIMIT); // rand_mt(mt);

inline double getTime() {
    using namespace std::chrono;
    return duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
}
template<typename T> bool chmax(T &m, const T q) {
    if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) {
    if (m > q) {m = q; return true;} else return false; }


template<typename T> 
void printv(vector<T> v, bool is_endl=true){
    for(int i=0;i<v.size();i++){
        if(i)cout<<" ";
        cout<<v[i];
    }
    if(is_endl)cout<<endl;
}
//int INF=1e18;

template<typename T>
void printendl(vector<T> v){
    for(auto date:v)cout<<date<<endl;
}

template<typename T>
void printvv(vector<vector<T>> v){
    for(int i=0;i<v.size();i++){
        for(int j=0;j<v[i].size();j++){
            if(j)cout<<" ";
            cout<<v[i][j];
        }
        cout<<endl;
    }
}
// struct Point{
//     int x,y,num;

//     double e_dis(Point other){
//         return sqrt((x-other.x)*(x-other.x)+(y-other.y)*(y-other.y));
//     }
// };

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

bool is_prime(int x){
  if(x==1)return 0;
  if(x==2)return 1;
  for(int i=2;i*i<=x;i++)if(x%i==0)return 0;
  return 1;
}

//スプリット関数
//split(文字列変数,区切りたい文字);
vector<string> split(string s, char c){
    if(s[s.size()-1]!=c)s+=c;
    vector<string> v;
    int pos=0;
    rep(i,0,s.size()){
        if(s[i]==c){
            v.push_back(s.substr(pos,i-pos));
            pos=i+1;
        }
        if(i==s.size()-1 && s.substr(pos,i-pos)!="")v.push_back(s.substr(pos,i-pos));
    }
    return v;
}

// map<int,int> prime_factor(int n){
//     map<int,int> ret;
//     if(n==1){
//         ret[1]=1;
//         return ret;
//     }
//     for(int i=2;i*i<=n;i++){
//         while(n%i==0){
//             ret[i]++;
//             n/=i; 
//         }
//     }
//     if(n!=1)ret[n]=1;
//     return ret;
// }

struct UnionFind{
    vector<int> par;
    UnionFind(int n){
        par.assign(n,-1);
    }
    int root(int x){
        if(par[x]<0)return x;
        else return par[x]=root(par[x]);
    }

    bool same(int a,int b){
        return root(a)==root(b);
    }

    bool merge(int a,int b){
        a=root(a);
        b=root(b);
        if(a==b)return false;

        if(par[a]>par[b])swap(a,b);
        par[a]+=par[b];
        par[b]=a;
        return true;
    }

    int size(int x){
        return -par[root(x)];
    }
};

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

int n_yaku(int n){
    int ct = 0;
    rep(i,1,n+1)if(n%i==0){
        ct++;
        // cout<<i<<" ";
    }
    // cout<<endl<<ct<<endl;
    return ct;
}

signed main(){
    int n, S;
    while(cin>>n>>S){
        if(n+S==0)break;
        vector<int> v(n);
        map<int,int> freq;
        rep(i,0,n){
            cin>>v[i];
            freq[v[i]]++;
        }
        sort(all(v));
        int ans = 0;
        rep(i,0,n){
            int t = S - v[i]+1;
            if(v[i]>S){
                ans += n-1;
                continue;
            }
            ans += (v.end() - lower_bound(v.begin(), v.end(), t));
            if(v[i]*2 > S)ans--;
        }
        cout<<ans/2<<endl;
    }
    
}
/*
*/
accuracy: 1
time_ms: 70
memory_kb: 3312
final_rank: 12

code_snippet: #include <bits/stdc++.h>

using namespace std;
const int inf = 1e9 + 7;

int main(void) {
    int n, S;

    while(true){
        cin >> n >> S;
        if(n + S == 0) return 0;

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

        int ans = 0;
        for(int i = 0; i < n; i++)
            for(int j = i + 1; j < n; j++) if(S < r[i] + r[j]) ans++;

        cout << ans << "\n";
    }
    return 0;
}
accuracy: 1
time_ms: 1690
memory_kb: 3040
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;

//イテレーション
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto& i : I)
// x:コンテナ
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF32 2147483647           // 2.147483647×10^{9}:32bit整数のinf
#define INF64 9223372036854775807  // 9.223372036854775807×10^{18}:64bit整数のinf
#define MOD 1000000007             //問題による
//略記
#define F first
#define S second
//出力(空白区切りで昇順に)
#define coutALL(x)                                                   \
    for (auto i = x.begin(); i != --x.end(); i++) cout << *i << " "; \
    cout << *--x.end() << endl;

// aをbで割る時の繰上げ,繰り下げ
ll myceil(ll a, ll b) { return (a + (b - 1)) / b; }
ll myfloor(ll a, ll b) { return a / b; }

int main() {
    //小数の桁数の出力指定
    // cout<<fixed<<setprecision(10);
    //入力の高速化用のコード
    // ios::sync_with_stdio(false);
    // cin.tie(nullptr);
    ll n, S;
    cin >> n >> S;
    while(n+S != 0) {
        vector<ll> rs(n, 0);
        REP(i, n) {
            cin >> rs[i];
        }
        sort(rs.begin(), rs.end());
        ll ans = 0;
        REP(i, n) {
            ll ng = i;
            ll ok = n;
            ll r = rs[i];
            while(ng + 1 != ok) {
                ll mid = (ng + ok) / 2;
                if(r + rs[mid] > S) {
                    ok = mid;
                }else {
                    ng = mid;
                }
            }
            ans += n - ok;
        }
        cout << ans << endl;
        cin >> n >> S;
    }
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3208
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
int main(){
    while(true){
        Int N,s;
        cin >> N >> s;
        if(N == s and N == 0) break;
        vector<Int>S;
        for(int i = 0; i < N; ++i){
            Int  r; cin >> r;
            S.push_back(r);
        }
        Int ans = 0;
        sort(S.begin(),S.end());
        for(auto i = S.begin(); i != S.end(); ++i){
            auto itr = upper_bound(i + 1, S.end(), s - *i);
            ans += distance(itr,S.end());
        }
        cout << ans << endl;
    }
}
accuracy: 1
time_ms: 60
memory_kb: 3472
final_rank: 15

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;
 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, int> pii;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
 
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
 
#define MOD 1000000007
 
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
const double EPS = 1e-8, PI = acos(-1);
const double pi = 3.141592653589793238462643383279;
//ここから編集    
typedef string::const_iterator State;
ll GCD(ll a, ll b){
  return (b==0)?a:GCD(b, a%b);
}
ll LCM(ll a, ll b){
  return a/GCD(a, b) * b;
}
template< int mod >
struct ModInt {
  int x;
 
  ModInt() : x(0) {}
 
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
 
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
 
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
 
  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }
 
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
 
  ModInt operator-() const { return ModInt(-x); }
 
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
 
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
 
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
 
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
 
  bool operator==(const ModInt &p) const { return x == p.x; }
 
  bool operator!=(const ModInt &p) const { return x != p.x; }
 
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
 
  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
 
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
 
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }
 
  static int get_mod() { return mod; }
};
 
using modint = ModInt< 1000000007 >;
template< typename T >
struct Combination {
  vector< T > _fact, _rfact, _inv;
 
  Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) {
    _fact[0] = _rfact[sz] = _inv[0] = 1;
    for(int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i;
    _rfact[sz] /= _fact[sz];
    for(int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
    for(int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1];
  }
 
  inline T fact(int k) const { return _fact[k]; }
 
  inline T rfact(int k) const { return _rfact[k]; }
 
  inline T inv(int k) const { return _inv[k]; }
 
  T P(int n, int r) const {
    if(r < 0 || n < r) return 0;
    return fact(n) * rfact(n - r);
  }
 
  T C(int p, int q) const {
    if(q < 0 || p < q) return 0;
    return fact(p) * rfact(q) * rfact(p - q);
  }
 
  T H(int n, int r) const {
    if(n < 0 || r < 0) return (0);
    return r == 0 ? 1 : C(n + r - 1, r);
  }
};
 
ll modpow(ll x, ll n, ll mod) {
  ll res = 1;
  while(n) {
    if(n&1) res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
} 
inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}
template<typename T> 
struct BIT{
  int N;
  std::vector<T> node;

  BIT(int n){
    N = n;
    node.resize(N+10);
  }

  /* a: 1-indexed */
  void add(int a, T x){
    for(int i=a; i<(int)node.size(); i += i & -i) node[i] += x;
  }

  /* [1, a] */
  T sum(int a){
    T res = 0;
    for(int x=a; x>0; x -= x & -x) res += node[x];
    return res;
  }

  /* [l, r] */
  T rangesum(int l, int r){
    return sum(r) - sum(l-1);
  }

  /* 
    a1+a2+...+aw >= valとなるような最小のwを返す
    @verify https://codeforces.com/contest/992/problem/E
  */
  int lower_bound(T val) {
    if(val < 0) return 0;

    int res = 0;
    int n = 1; 
    while (n < N) n *= 2;

    T tv=0;
    for (int k = n; k > 0; k /= 2) {
      if(res + k < N && node[res + k] < val){
        val -= node[res+k];
        res += k;
      }
    }
    return res+1; 
  }
};
struct UnionFind{
  std::vector<int> par;
  std::vector<int> siz;

  UnionFind(int sz_): par(sz_), siz(sz_) {
    for(int i=0; i<sz_; ++i) par[i] = i, siz[i] = 1;
  }

  void init(int sz_){
    par.resize(sz_);
    siz.resize(sz_);
    for(int i=0; i<sz_; ++i) par[i] = i, siz[i] = 1;
  }

  int root(int x){
    if(x == par[x]) return x;
    return par[x] = root(par[x]);
  }

  bool merge(int x, int y){
    x = root(x), y = root(y);
    if(x == y) return false;
    if(siz[x] < siz[y]) std::swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }

  bool issame(int x, int y){
    return root(x) == root(y);
  }

  int size(int x){
    return siz[root(x)];
  }
};
struct RollingHash {
    static const int base1 = 1007, base2 = 2009;
    static const int mod1 = 1000000007, mod2 = 1000000009;
    vector<long long> hash1, hash2, power1, power2;
    int n;
    // construct
    RollingHash(const string &S) {
        n = (int)S.size();
        hash1.assign(n+1, 0);
        hash2.assign(n+1, 0);
        power1.assign(n+1, 1);
        power2.assign(n+1, 1);
        for (int i = 0; i < n; ++i) {
            hash1[i+1] = (hash1[i] * base1 + S[i]) % mod1;
            hash2[i+1] = (hash2[i] * base2 + S[i]) % mod2;
            power1[i+1] = (power1[i] * base1) % mod1;
            power2[i+1] = (power2[i] * base2) % mod2;
        }
    }
    
    // get hash of S[left:right]
    inline pair<long long, long long> get(int l, int r) const {
        long long res1 = hash1[r] - hash1[l] * power1[r-l] % mod1;
        if (res1 < 0) res1 += mod1;
        long long res2 = hash2[r] - hash2[l] * power2[r-l] % mod2;
        if (res2 < 0) res2 += mod2;
        return {res1, res2};
    }
 
    inline pair<long long, long long> c_shift(int l) {
      auto h1 = get(0, l);
      auto h2 = get(l, n);
      return {(h1.first + h2.first * power1[l]) % mod1, (h1.second + h2.second * power2[l]) % mod2};
    }
 
    // get lcp of S[a:] and T[b:]
    inline int getLCP(int a, int b) const {
        int len = min((int)hash1.size()-a, (int)hash1.size()-b);
        int low = 0, high = len;
        while (high - low > 1) {
            int mid = (low + high) >> 1;
            if (get(a, a+mid) != get(b, b+mid)) high = mid;
            else low = mid;
        }
        return low;
    }
};

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

  int n, S;
  while(cin >> n >> S, n) {
    vector<ll> r(n);
    REP(i,n) cin >> r[i];
    BIT<int> bit(110);
    sort(all(r));
    ll ans = 0;
    for(int i=0; i<n; i++) {
      ll t = S - r[i];
      
      ans += bit.rangesum(max(0LL, t+1), 105);
      bit.add(r[i], 1);
    }
    cout << ans << '\n';
  }
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3460
final_rank: 14

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

#define BIG_NUM 2000000000
int a[20000];

void func(int N, int S) {


	int tmp = 0;
	int index = N - 1;
	std::priority_queue<int> Q;
	for (int i = 0; i < N; i++) {
		scanf("%d", &tmp);
		Q.push(tmp);
	}

	while (!Q.empty()) {
		a[index--] = Q.top();
		Q.pop();
	}


	int sum = 0, left, right, m, tmp_min;

	for (int i = 0; i < N - 1; i++) {
		left = i + 1, right = N - 1, m = (left + right) / 2;

		tmp_min = N;

		while (left <= right) {
			if (a[i] + a[m] > S) {
				tmp_min = m;
				right = m - 1;
			}
			else {
				left = m + 1;
			}
			m = (left + right) / 2;
		}
		if (tmp_min != N) {
			sum += N - tmp_min;
		}
	}

	printf("%d\n", sum);
}


int main()
{
	int n, s;

	while (1)
	{
		scanf("%d %d", &n, &s);
		if (n == 0 && s == 0)break;
		func(n, s);

	}
	return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 2864
final_rank: 2

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

#define BIG_NUM 2000000000
//int table[2000];

void func(int N, int S) {

	int index = N - 1, tmp;
	int table[N];
	std::priority_queue<int> Q;

	for (int i = 0; i < N; i++) {
		scanf("%d", &tmp);
		Q.push(tmp);
	}

	while (!Q.empty()) {
		table[index--] = Q.top();
		Q.pop();
	}

	int sum = 0, left, right, m, tmp_min;

	for (int i = 0; i < N - 1; i++) {
		left = i + 1, right = N - 1, m = (left + right) / 2;

		tmp_min = N;

		while (left <= right) {
			if (table[i] + table[m] > S) {
				tmp_min = m;
				right = m - 1;
			}
			else {
				left = m + 1;
			}
			m = (left + right) / 2;
		}
		if (tmp_min != N) {
			sum += N - tmp_min;
		}
	}

	printf("%d\n", sum);
}

int main() {

	int N, S;

	while (true) {
		scanf("%d %d", &N, &S);
		if (N == 0 && S == 0)break;

		func(N, S);
	}

	return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 2892
final_rank: 3

code_snippet: #include <iostream>
#include <vector>
#include<iomanip>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
int main(){
    int n, s;
    while (cin >> n >> s, n, s) {
        vector<int> r(n);
        rep(i, n) cin >> r[i];
        sort(ALL(r));
        int sum = 0;
        rep(i, n) {
            sum += r.end() - upper_bound(ALL(r), s - r[i]);
            if (r[i] + r[i] > s)sum--;
        }cout << sum/2 << endl;
    }
}
accuracy: 1
time_ms: 80
memory_kb: 3040
final_rank: 6

code_snippet: #include<iostream>
using namespace std;

int calc( int a )
{
    if( a == 0 )
        return 0;
    return a - 1 + calc( a - 1 );
}

int main()
{
    int n, s, r, a[101];

    while( cin >> n >> s )
    {
        if( n + s == 0 )
            break;

        for( int i = 0; i < 101; i++ )
            a[i] = 0;

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

        int cnt = 0;
        for( int i = 1; i < 100; i++ )
            for( int j = i + 1; j < 101; j++ )
                if( i + j > s )
                    cnt += a[i] * a[j];

        for( int i = 1; i < 101; i++ )
            if( i + i > s )
                cnt += calc(a[i]);

        cout << cnt << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3084
final_rank: 7

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

int main(){
    int n, s;
    while(cin >> n >> s, n+s){
        vector<int> r(n);
        for(int i = 0; i < n; i++)  cin >> r[i];
        sort(r.begin(), r.end());
        int ans = 0;
        for(int i = 0; i < n; i++){
            ans += (int)(r.end()-upper_bound(r.begin(), r.end(), s-r[i]));
            if(r[i]+r[i] > s)   ans--;
        }
        cout << ans/2 << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 3132
final_rank: 8

code_snippet: #define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e8 + 7;

int main(){
	
	while(true){
		int n, S;
		cin >> n >> S;
		if(n == 0){
			break;
		}
		long long int ans = 0;
		long long int cnt[110] = {};
		for(int i = 0; i < n; i++){
			int num;
			cin >> num;
			cnt[num] += 1;
		}
		for(int i = 1; i <= 100; i++){
			for(int j = i + 1; j <= 100; j++){
				if(i + j > S){
					ans += cnt[i] * cnt[j];
				}
			}
			if(i * 2 > S){
				ans += cnt[i] * (cnt[i] - 1) / 2;
			}
		}
		cout << ans << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 2956
final_rank: 5

code_snippet: #include<iostream>
using namespace std;
int main() {
	int n, s; 
	while (cin >> n >> s) {
		if (!n && !s)return 0;
		int a[20001]; for (int i = 0; i < n; i++)cin >> a[i];
		long long sum = 0;
		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				if (a[i] + a[j] > s)sum++;
			}
		}
		cout << sum << endl;
	}
	char c; cin >> c;
}
accuracy: 1
time_ms: 1700
memory_kb: 2992
final_rank: 18

code_snippet: //#define LOCAL

#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>

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

using namespace std;



int main()
{
#ifdef LOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    int n, S;
    int r[20010];

    while (true) {
        cin >> n >> S;
        if (n == 0 && S == 0) break;

        rep(i,n) cin >> r[i];

        sort(r, r + n);

        int ans = 0;
        rep(i,n) {
            int needle = S + 1 - r[i];
            int* pos = lower_bound(r + i + 1, r + n, needle);
            ans += (int)((r + n) - pos);
        }
        cout << ans << endl;
    }
}
accuracy: 1
time_ms: 80
memory_kb: 3168
final_rank: 9

code_snippet: #include<iostream>
using namespace std;

int main() {
	int n, s;
	while (cin >> n >> s, n, s) {
		int a[22000];
		for (int i = 0;i < n;i++)cin >> a[i];
		int ans = 0;
		for (int i = 0;i < n;i++)
		for (int j = i + 1;j < n;j++)
		if (s < a[i] + a[j])ans++;
		cout << ans << endl;
	}
}
accuracy: 1
time_ms: 1690
memory_kb: 3004
final_rank: 19

code_snippet: #include<iostream>
#include<vector>
#include<list>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<set>
using namespace std;
int main() {
	int n, s;
	while (cin >> n >> s&&n != 0 && s != 0) {
		int r[20000];
		for (int i = 0; i < n; i++) cin >> r[i];
		sort(r, r + n);
		reverse(r, r + n);
		int sum = 0;
		for (int i = 0; i < n; i++) {
			if (r[i]*2<=s) break;
			for (int j = i+1; j < n; j++) {
				if (r[i] + r[j] > s) {
					sum++;
				}
				else break;
			}
		}
		cout << sum << endl;
	}
}
accuracy: 1
time_ms: 1240
memory_kb: 3172
final_rank: 17

code_snippet: #include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
int r[20000];
int main() {
	int n, s;
	while (cin >> n >> s&&n != 0 && s != 0) {
		for (int i = 0; i < n; i++) {
			cin >> r[i];
		}
		sort(r,r+n);
		reverse(r, r + n);
		int sum = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				if (r[i] + r[j] > s) sum++;
				else break;
			}
			if (r[i] + r[i] <= s) break;
		}
		cout << sum << endl;
	}
}
accuracy: 1
time_ms: 1140
memory_kb: 3124
final_rank: 16

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

#define BIG_NUM 2000000000

using namespace std;

void func(int N,int S){

	int table[N],index = N-1,tmp;

	priority_queue<int> Q;

	for(int i = 0; i < N; i++){
		scanf("%d",&tmp);
		Q.push(tmp);
	}

	while(!Q.empty()){
		table[index--] = Q.top();
		Q.pop();
	}

	int sum = 0,left,right,m,tmp_min;

	for(int i = 0; i < N-1; i++){
		left = i+1,right = N-1,m = (left+right)/2;

		tmp_min = N;

		while(left <= right){
			if(table[i] + table[m] > S){
				tmp_min = m;
				right = m-1;
			}else{
				left = m+1;
			}
			m = (left+right)/2;
		}
		if(tmp_min != N){
			sum += N - tmp_min;
		}
	}

	printf("%d\n",sum);
}

int main(){

	int N,S;

	while(true){
		scanf("%d %d",&N,&S);
		if(N == 0 && S == 0)break;

		func(N,S);
	}

	return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 2716
final_rank: 1