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

#define fi first
#define se second
#define int long long

int n,k;
int pd[102][100002];
bool seen[102][100002];
vector<pair<int,int>> A;
inline void mmax(int &a,int b){
    a = max(a,b);
}
int dp(int id,int peso){
    if(id==n) return 0;
    if(seen[id][peso]) return pd[id][peso];
    int n_esc = dp(id+1,peso);
    if(peso-A[id].fi>=0){
        seen[id][peso] = true;
        return pd[id][peso] = max(n_esc,dp(id+1,peso-A[id].fi)+A[id].se);
    }
    seen[id][peso] = true;
    return pd[id][peso] = n_esc;
}
int32_t main(){
    cin >> n >> k;
    A = vector<pair<int,int>> (n);
    for(auto &a:A)
        cin >> a.fi >> a.se;
    
    cout << dp(0,k) << '\n';
}


Measured memory_bytes: 87936
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb push_back
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<ii> vii;

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

	int n, res = 1;
	string s;

	cin >> n >> s;
	for (int i = 0; i + 1 < n; i++)
		if (s[i] != s[i+1])
			res++;
	cout << res << endl;

	return 0;
} 

Measured memory_bytes: 512
Scanf.scanf "%d %d %d %d %d %d" (fun h w ch cw dh dw ->
    let ch, cw, dh, dw = ch - 1, cw - 1, dh - 1, dw - 1 in
    let s = Array.init h (fun _ -> Scanf.scanf " %s" (fun s -> s)) in
    let cost = Array.make_matrix h w max_int in
    cost.(ch).(cw) <- 0;
    let magic_cost = 1000000000 in
    let module S = Set.Make (struct type t = int * int * int let compare = compare end) in

    let rec loop rest set =
        if rest = 0 then (if cost.(dh).(dw) <> max_int then cost.(dh).(dw) / magic_cost else -1) else
            let ((cc, cy, cx) as c) = S.min_elt set in
            let set = S.remove c set in
            let rest = rest - 1 in
            let rec loop_vy vy rest set =
                let rec loop_vx vx rest set =
                    if vx = 3 || cx + vx >= w then loop_vy (vy + 1) rest set else
                        if s.(cy + vy).[cx + vx] = '#' then loop_vx (vx + 1) rest set else
                            let co = if vy = 0 && abs vx = 1 || vx = 0 && abs vy = 1 then 1 else magic_cost in
                            if cc + co < cost.(cy + vy).(cx + vx) then (
                                cost.(cy + vy).(cx + vx) <- cc + co;
                                let set = S.add (cc + co, cy + vy, cx + vx) set in
                                let rest = rest + 1 in
                                loop_vx (vx + 1) rest set
                            ) else loop_vx (vx + 1) rest set
                in
                if vy = 3 || cy + vy >= h then loop rest set else
                    loop_vx (-min 2 cx) rest set
            in
            loop_vy (-min 2 cy) rest set
    in
    loop 1 (S.singleton (0, ch, cw)) |> Printf.printf "%d\n"
)

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

using _i64 = int64_t;
using _u64 = uint64_t;
using _f64 = double;

#define _for(i, start, end) for(_i64 i = (_i64)start; i < (_i64)end; ++i)
#define _rep(i, number) _for(i, 0, number)
#define _foreach(e, data) for(auto& e : data)
#define _all(data) data.begin(), data.end()

template<typename type>
_i64 _size(const type& data) { return static_cast<_i64>(data.size()); }
template<typename type, size_t size>
_i64 _size(const type (&)[size]) { return static_cast<_i64>(size); }

enum _flag : bool { able = true, disable = false };

struct _time {
    _time(_flag flag) { check = flag; if(!check) { return; } gettime(start); }
    ~_time() {
        if(!check) { return; }; gettime(end);
        _i64 elapse = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cout << endl << "Time: " << elapse << " ms" << endl;
    }
    private:
    using _timer = chrono::time_point<chrono::system_clock>;
    _timer start, end; bool check;
    void gettime(_timer& time) { time = chrono::system_clock::now(); }
};

struct _ini { _ini() { ios::sync_with_stdio(false); cin.tie(nullptr); } } _ini;

int main() {
    {
        _time time(disable);
        string str, func, p; _i64 q, a, b; cin >> str >> q;
        _rep(i, q) {
            cin >> func >> a >> b;
            if(func == "print") {
                _for(j, a, b + 1) { cout << str[j]; } cout << endl;
            }
            else if(func == "reverse") {
                reverse(str.begin() + a, str.begin() + b + 1);
            }
            else if(func == "replace") {
                cin >> p; str.replace(a, b - a + 1, p);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3216
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
 
using namespace std;
 
int main()
{
	int n;
	cin>>n;
	long long cnt=0;
	for(int i=1;i<=n;i++){
		if(i%3!=0&&i%5!=0)cnt+=i;
	}
	cout<<cnt<<endl;     
	return 0; 
}
 

Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

int main(){
  ll n, k;
  cin >> n >> k;
  if(n < k){
  	ll ans = min(n, abs(n - k));
  	cout << ans << endl;
  	return 0;
  }
  else if(n == k){
  	cout << 0 << endl;
  	return 0;
  }
  else{
  	ll nn = n % k;
  	ll ans = min(nn, abs(nn - k));
  	cout << ans << endl;
  	return 0;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define p pair<int,int>
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
using namespace std;
int POW(int x,int y){return int(pow(double(x),double(y)));}


int main(){
	int n;
	cin>>n;
	vector<int> a(101);
	rep(i,n){
		int d;
		cin>>d;
		a[d]=1;
	}
	int ans=0;
	FOR(i,1,101){
		if(a[i]==1) ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <iomanip>
#include <map>
#include <bits/stl_numeric.h>

#define DEBUG 0
#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

ll d[200][200] = {};


void warshallFloyd(int n) {
  for (int k = 0; k < n; ++k){       // 経由する頂点
    for (int i = 0; i < n; ++i) {    // 始点
      for (int j = 0; j < n; ++j) {  // 終点
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
 
      }
    }
  }
}

int main(){

    int N,M,R;
    cin >> N >> M >> R;
    //訪れる街のリスト(最大8))
    vector <int> r;
    r.resize(R);

    REP(i,R)
    {
        cin >> r[i];
        --r[i];
    }



    REP(i,N)
    {
        REP(j,N)
        {
            if(i == j) d[i][j] = 0;
            else    d[i][j] = INF;
        }
    }

    REP(i,M)
    {
        int a,b,c;
        cin >> a >> b >> c;
        --a;--b;

        d[a][b] = c;
        d[b][a] = c;
    }

    //各橋を結んで、最小を更新する(ワーシャルフロイド)
    warshallFloyd(N);
    

    ll res = INF;
    sort(r.begin(),r.end()); //permutationを使う前はソートする。
    do {
        ll tmp = 0;
        bool flg = true;
        for(int i = 0; i < R-1; ++i)
        {
            int from = r[i];
            int to = r[i+1];
            if(d[from][to] == -1)
            {
                flg = false;
                break;
            }
            //町から町へのコストを足す
            tmp += d[from][to];
        }
        if(flg)
        {
            res = min(res,tmp);
        }

    } while( next_permutation(r.begin(), r.end()) );     // 次の順列を生成

    cout << res << endl;

    return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
typedef long long LL;
vector<int> v, x;
LL dp[105][100005];
int main(){
    v.push_back(0);
    x.push_back(0);
    int n, k;
    scanf("%d%d", &n, &k);
    for(int i=1;i*i<=n;i++){
        v.push_back(i);
        if(n/i != i) v.push_back(n/i);
    }
    sort(v.begin(), v.end());
    for(int i=1;i<v.size();i++){
        int lo = 1, hi = v.size()-1;
        x.push_back(1);
        while(lo <= hi){
            int mid = (lo+hi)/2;
            if(v[i]*1ll*v[mid] <= n) x.back() = mid, lo = mid+1;
            else hi = mid-1;
        }
    }
    for(int i=1;i<=k;i++){
        if(i == 1){
            for(int j=v.size()-1;j>=1;j--){
                dp[i][j] = (v[j]-v[j-1])%mod;
                dp[i+1][x[j]] = (dp[i+1][x[j]] + dp[i][j])%mod;
            }
        }
        else{
            LL sum = 0;
            for(int j=v.size()-1;j>=1;j--){
                sum = (sum + dp[i][j])%mod;
                dp[i][j] = sum*(v[j]-v[j-1])%mod;
                dp[i+1][x[j]] = (dp[i+1][x[j]] + dp[i][j])%mod;
            }
        }

    }
    LL ans = 0;
    for(int j=1;j<v.size();j++){
        ans = (ans + dp[k][j])%mod;
    }
    printf("%lld\n", ans);
}

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

int main() {
  int A, B; cin >> A >> B;
  
  int ans = 0;
  for (int i=A; i<= B; i++) {
    string s = to_string(i);
    string t = to_string(i);
    reverse(s.begin(), s.end());
    
    if (s == t) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
private fun readInts() = readLine()!!.split(" ").map { it.toInt() }.toList()

fun main(args: Array<String>) {
    val (N, M) = readInts()
    println(if (M % N == 0) M / N else (1 until M / N).asSequence().filter { M % it == 0 }.max() ?: 1)
}

Measured memory_bytes: 114224
N, K = map(int, input().split())
lst = [int(x) for x in input().split()]
ret = 100 ** 100
for i in range(N - K + 1):
    if lst[i] >= 0 and lst[i + K - 1] >= 0:
        t = lst[i + K - 1]
    elif lst[i] < 0 and lst[i + K - 1] < 0:
        t = abs(lst[i])
    else:
        t = lst[i + K - 1] - lst[i] + min(abs(lst[i]), abs(lst[i + K - 1]))
    ret = min(ret, t)
print(ret)


Measured memory_bytes: 14224
s = input()
t = input()

num = 0;
cnt = 0
min = len(t)
for i in range(len(s)-len(t)+1):
    ss = s[num:num+len(t)]
    for x,y in zip(ss,t):
        if x != y:
            cnt += 1
    if cnt < min:
        min = cnt
    cnt = 0
    num = num +1

print(min)

Measured memory_bytes: 9088
#include<bits/stdc++.h>
#define hell  1000000007
using namespace std;
vector<int> v[500];
int main(){
	int n,m; cin >> n >>m;
	while(m--){
		int a,b; cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	
	for(int i=1;i<=n;i++){
		  cout << v[i].size() << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>

int main() {
	long long int n;
	std::cin >> n;
	std::string s = std::to_string(n);
	int ans = s.size();
	for (int i = 2;i <= 100000;i++) {
		if (n%i == 0) {
			if (i < n / i) {
				std::string t = std::to_string(n / i);
				if (ans > t.size()) {
					ans = t.size();
				}
			}
			else {
				std::string t = std::to_string(i);
				if (ans > t.size()) {
					ans = t.size();
				}
			}
		}
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << #x << ':' << (x) << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


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

	int n;
	cin >> n;
	vector<int> a(n), b(n);
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	vector<vector<int>> cost(51, vector<int>(51, inf));
	rep(i, 51) cost[i][i] = 0;
	rep(i, 51) {
		rep(j, i) {
			int c = inf;
			for (int k = 1; k < 51; k++) {
				chmin(c, max(k, cost[i % k][j]));
			}
			cost[i][j] = c;
		}
	}
	vector<vector<bool>> ok(n, vector<bool>(51));
	rep(i, n) ok[i][a[i]] = true;
	ll ans = 0;
	while (true) {
		int ma = 0;
		rep(i, n) {
			int mi = inf;
			rep(j, 51) {
				if (ok[i][j]) chmin(mi, cost[j][b[i]]);
			}
			chmax(ma, mi);
		}
		debug(ma);
		if (ma == inf) {
			cout << "-1\n";
			return 0;
		}
		if (ma == 0) break;
		rep(i, n) {
			rep(j, 51) {
				if (ok[i][j]) ok[i][j % ma] = true;
			}
		}
		ans += 1ll << ma;
	}
	cout << ans << '\n';
}

Measured memory_bytes: 3608
n ,k = map(int,input().split())
s = input()
ans = ''
for i in range(n):
    if i == k-1:
        if s[i] == 'A':
            ans += 'a'
        elif s[i] == 'B':
            ans += 'b'
        else:
            ans += 'c'
    else:
        ans += s[i]

print(ans)

Measured memory_bytes: 38256
#include <atcoder/scc>
#include <iostream>

int main()
{
    int N, M;
    std::cin >> N >> M;

    atcoder::scc_graph G(N);
    for (int i = 0; i < M; i++) {
        int A, B;
        std::cin >> A >> B;

        G.add_edge(A, B);
    }

    auto ans = G.scc();
    std::cout << ans.size() << '\n';
    for (const auto& a : ans) {
        std::cout << a.size() << ' ';
        for (const auto ai : a) {
            std::cout << ai << ' ';
        }
        std::cout << '\n';
    }
}

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

int h,w,x;
char s[1000][1000];
bool visited [1000][1000];
pair<int,int> start,goal;
queue<pair<int,pair<int,int>>> q;
vector<pair<int,int>> ino;

int main(){
  int a,b,c,d;cin>>a>>b>>c>>d;
  /*if(a<1200){
    cout << "ABC";
    return 0;
  }else{
    result = "ARC";
  }*/
  cout << max(a*b,c*d);
}


Measured memory_bytes: 256
// And in the end, the love you take is equal to the love you make.
//                      Paul McCartney (the Beatles). The End. Abbey Road.

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

using LL = long long;

namespace _buff {

const size_t BUFF = 1 << 19;
char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
char getc() {
  if (ib == ie) {
    ib = ibuf;
    ie = ibuf + fread(ibuf, 1, BUFF, stdin);
  }
  return ib == ie ? -1 : *ib++;
}

}

LL read() {
  using namespace _buff;
  LL ret = 0;
  bool pos = true;
  char c = getc();
  for (; (c < '0' || c > '9') && c != '-'; c = getc()) {
    assert(~c);
  }
  if (c == '-') {
    pos = false;
    c = getc();
  }
  for (; c >= '0' && c <= '9'; c = getc()) {
    ret = (ret << 3) + (ret << 1) + (c ^ 48);
  }
  return pos ? ret : -ret;
}

const size_t N = 1e5 + 5;
const size_t M = 16;

int val[N], cnt[M];
int dp[1 << M];

int solve(int msk) {
  if (!msk) return 0;
  if (~dp[msk]) return dp[msk];
  int &ret = dp[msk] = 1e9;
  for (int i = 0; i < M; ++i) {
    if (msk >> i & 1) {
      for (int j = 0; j < i; ++j) {
        if (msk >> j & 1) {
          int nmsk = msk;
          nmsk ^= 1 << i;
          nmsk ^= 1 << j;
          int tmp = 1 << (i ^ j);
          nmsk ^= tmp;
          ret = min(ret, solve(nmsk) + 1 + (!(nmsk & tmp)));
        }
      }
      ret = min(ret, solve(msk ^ (1 << i)) + 1);
    }
  }
  return ret;
}

int main() {
  int n = read();
  int ans = 0;

  for (int i = 1; i < n; ++i) {
    int x = read();
    int y = read();
    int a = read();
    val[x] ^= a;
    val[y] ^= a;
  }

  for (int i = 1; i <= n; ++i) {
    ++cnt[val[i]];
  }

  int msk = 0;
  for (int i = 1; i < M; ++i) {
    ans += cnt[i] >> 1;
    msk |= (cnt[i] & 1) << i;
  }

  memset(dp, -1, sizeof dp);
  cout << ans + solve(msk) << '\n';
  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug: "<<x<<" "<<y<<endl;
using namespace std;
typedef long long ll;
const int maxn = 1005;



int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
#endif
  int a,p;
  cin>>a>>p;
  cout<<(a*3+p)/2<<endl;
  return 0;
}

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

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

    bool ok = false;
    for (int i = B*10; i <= B*10+10; i++) {
        if (int((i)*0.1) == B && int((i)*0.08) == A) {
            cout << (i) << "\n";
            ok = true;
            break;
        }
    }

    if (!ok) {
        cout << "-1\n";
    }
}


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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#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--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB emplace_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

int main(){
    ll n, m;
    cin >> n >> m;
    vector<ll> k(m), p(m);
    vector<vector<bool>> s(m, vector<bool>(10, 0));
    REP(i, m){
        cin >> k[i];
        REP(j, k[i]){
            ll tmp;
            cin >> tmp;
            s[i][tmp-1] = true;
        }
    }
    REP(i, m) cin >> p[i];
    ll ans = 0;
    // {0, 1, ..., n-1} の部分集合の全探索
    for (int bit = 0; bit < (1<<n); ++bit) {
        /* bit で表される集合の処理を書く */
        bool ok = true;
        vector<ll> tmp(m, 0);
        for(int i = 0; i < n; i++){
            if(bit & (1<<i)){
                // 立っているbit
                REP(j, m) if(s[j][i] == true) tmp[j]++;
            }
        }
        REP(i, m) if(tmp[i] % 2 != p[i]) ok = false;
        if(ok) ans++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, M, K;
vi A, B;
string S, T;

void input() {
  int x, y, z;
  cin >> N;
  A.resize(N);
  rep(i, 0, N - 1) { cin >> A[i]; };
}
void solve() {
  sort(all(A));

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

  // ====================
  if (N % 2 == 1) {
    N--;
  }
  int ans = 1;
  rep(i, 1, N / 2) {
    ans *= 2;
    ans %= MOD;
  }
  cout << ans << endl;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 1024
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------

int n, a;
int b;

struct SegmentTree {
private:
    int n;
    vpi node;

public:
    SegmentTree(vpi v) {
        int sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, {0,0});
        REP(i,sz) node[i+n-1] = v[i];
        REPN(i,n-2) node[i] = max(node[2*i+1], node[2*i+2]);
    }
    void update(int k, pi x){
        k += n-1;
        node[k] = x;
        while(k){
            k = (k-1)/2;
            node[k] = max(node[2*k+1],node[2*k+2]);
        }
    }
    pi getmax(int a, int b, int k=0, int l=0, int r=-1){
        if(r<0) r=n;
        if(r<=a || b<=l) return {0,0};
        if(a<=l && r<=b) return node[k];
        return max( getmax(a,b,2*k+1,l,(l+r)/2),getmax(a,b,2*k+2,(l+r)/2,r) );
    }
};

SegmentTree st = SegmentTree(vpi(100010));

signed main(){
    I(n);

    REP(i,n){
        I(a);
        pi pre = st.getmax(0, a);
        st.update(a, mp(pre.first+1, pre.second+a));    
    }

    auto ans = st.getmax(0,100001);
    cout << ans.second << endl;
}


Measured memory_bytes: 8228
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INT()
    A = LIST()

    C = Counter(A)

    X = 0
    for v in C.values():
        X += v * (v - 1) // 2

    for i in range(N):
        print(X - C[A[i]] + 1)


if __name__ == '__main__':
    main()


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

void DFS(vector<int> &allNums, int num, set<int> nums) {
    if (nums.size() == 0)allNums.push_back(num);
    for (auto itr = nums.begin(); itr != nums.end(); ++itr) {
        set<int> s = nums;
        s.erase(*itr);        
        DFS(allNums, num * 10 + *itr, s);
    }
}
 
int main() {
    int N;
    cin >> N;
    int P, Q;
    P = Q = 0;
    for (int i = 0; i < N; i++) {
        int num;
        cin >> num;
        P = P * 10 + num;
    }
    for (int i = 0; i < N; i++) {
        int num;
        cin >> num;
        Q = Q * 10 + num;
    }
    vector<int> allNums;
    set<int> nums;
    for (int i = 0; i < N; i++) {
        nums.insert(i + 1);
    }
    DFS(allNums, 0, nums);
    sort(allNums.begin(), allNums.end());
    
 
    int a = 0;
    int b = 0;
    for (int i = 0; i < allNums.size(); i++) {
        //cout << allNums[i] << endl;
        if (P == allNums[i])a = i;
        if (Q == allNums[i])b = i;
    }
    cout << abs(a - b) << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>

int main(int argc, char *argv[])
{
    int n, m;

    std::cin >> n >> m;

    const int ans = n * (n - 1) / 2 + m * (m - 1) / 2;

    std::cout << ans << std::endl;

    return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;

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

const double DINF = 5e14, eps = 1e-10;
const long long MOD = 1e9 + 7, INF = 5e18;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()

ll n, t, a, b;
ll ans = INF;

int main() {
	cin >> n >> t;
	for (int i = 0;i < n;i++) {
		cin >> a >> b;
		if (b <= t)ans = min(ans, a);
	}
	if (ans == INF)cout << "TLE" << endl;
	else cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  string s;
  map<string, int>m;
  int64_t result = 0;
  
  cin >> n;
  
  for(int i = 0; i < n; i++){
    cin >> s;
    sort(s.begin(), s.end());
    
    if(m.count(s)){
      result += m.at(s);
      m.at(s)++;
    }else{
      m[s] = 1;
    }
  }
  
  cout << result << endl;
}

Measured memory_bytes: 11136
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<stdbool.h>
#include<vector>
#include<algorithm>
#include<string>
typedef long long ll;
using namespace std;

int main(void) {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	if (a[0] == a[1])cout << a[2] << endl;
	if (a[1] == a[2])cout << a[0] << endl;
	return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(5e2 + 5);

int n;
ll k;
ll a[MAX_N];

ll whole = 0LL;

ll ans;

bool check(ll cand) {
  vector<ll> tmp;

  for (int i = 0; i < n; ++i) {
    tmp.push_back(a[i] % cand);
  }

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

  vector<ll> plus;
  vector<ll> minus;

  for (auto &e : tmp) {
    if (e == 0) continue;
    plus.push_back(cand - e);
    minus.push_back(e);
  }

  int size = plus.size();

  for (int i = 1; i < size; ++i) {
    plus[i] += plus[i - 1];
    minus[i] += minus[i - 1];
  }

  for (int i = 0; i < size; ++i) {
    if (minus[i] == (plus[size - 1] - plus[i])) {
      if (minus[i] <= k) {
        return true;
      }
    }
  }

  return false;
}

int main(void) {
  // Here your code !
  scanf("%d %lld", &n, &k);

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

  ans = 1LL;

  for (ll i = 1LL; i * i <= whole; ++i) {
    if (whole % i != 0) continue;  // not candidate

    ll other = whole / i;

    if (check(i)) {
      ans = max(ans, i);
    }

    if (check(other)) {
      ans = max(ans, other);
    }
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 256
s = input()
k = int(input())
se = set()
for i in s:
    se.add(i)
if len(s) > 1:
    for i in range(len(s)-1):
        se.add(s[i]+s[i+1])
if len(s) > 2:
    for i in range(len(s)-2):
        se.add(s[i]+s[i+1]+s[i+2])
if len(s) > 3:
    for i in range(len(s)-3):
        se.add(s[i]+s[i+1]+s[i+2]+s[i+3])
if len(s) > 4:
    for i in range(len(s)-4):
        se.add(s[i]+s[i+1]+s[i+2]+s[i+3]+s[i+4])
se = sorted(se)
print(se[k-1])

Measured memory_bytes: 4464
import java.util.*;
public class Main  {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      int a1 = sc.nextInt();
      int a2 = sc.nextInt();
      int a3 = sc.nextInt();
      int a4 = sc.nextInt();
      int a5 = sc.nextInt();
      
      if (a1 == 0) {
         System.out.println("1");
      }
      if (a2 == 0) {
         System.out.println("2");
      }
      if (a3 == 0) {
         System.out.println("3");
      }
      if (a4 == 0) {
         System.out.println("4");
      }
      if (a5 == 0) {
         System.out.println("5");
      }
   }
}

Measured memory_bytes: 35792
# Sの入力受付
S = input()
# Sを順に読み込みBがあったとき直前の文字と一緒に消去
STR = ""
for i in S:
    STR = STR + i
    if i == "B" and STR == "":
        STR = ""
    elif i == "B":
        STR = STR[:len(STR) - 2]
print(STR)


Measured memory_bytes: 9064
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,x,t;
	scanf("%d%d%d",&n,&x,&t);
	if(n%x==0)
		printf("%d",n/x*t);
	else
		printf("%d",n/x*t+t);
	return 0;
}

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

using namespace std;

int main()
{
    int n,a,b,t,tt=0;
    vector<int> l;
    cin >> a >> n;
    for(int i=0;i<a;i++)
    {
        cin >> t;
        l.push_back(t);
    }
    int i=0;
    while(i <a)
    {
        tt++;
        i+=n;
        i--;
        if(i==a-1)
            break;
    }
    cout << tt << endl;
    return 0;
}


Measured memory_bytes: 892
def f(a):
    for x in ['b','w']:
        if a[0::4].count(x)==3 or a[2:7:2].count(x)==3:return x
        for i in range(3):
            if a[i*3:i*3+3].count(x)==3 or a[i::3].count(x)==3:return x
    return 'NA'

while 1:
    a=list(input())
    if len(a)==1:break
    a+=list(input())+list(input())
    print(f(a))

Measured memory_bytes: 7420
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

constexpr double pi = acos(-1.0);

double solve(int a, int b, int h, int m)
{
  double h_theta = 2 * pi * (h * 60.0 + m) / 720.0;
  double m_theta = 2 * pi * m / 60.0;

  const auto x1 = a * std::sin(h_theta);
  const auto y1 = a * std::cos(h_theta);
  const auto x2 = b * std::sin(m_theta);
  const auto y2 = b * std::cos(m_theta);
  return std::sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

int main()
{
  int a, b, h, m;
  std::cin >> a >> b >> h >> m;

  std::cout << std::setprecision(20);
  std::cout << solve(a, b, h, m) << std::endl;
}


Measured memory_bytes: 4164
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
int main(){
	int a,b,c,tmp;
	cin>>a>>b>>c;
	if(a>b){
		tmp=a;
		a=b;
		b=tmp;
	}
	if(b>c){
		tmp=b;
		b=c;
		c=tmp;
	}
	if(a>b){
		tmp=a;
		a=b;
		b=tmp;
	}
	cout<<a<<" "<<b<<" "<<c<<endl;
	}


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

int main()
{
    int w,a,b;
    cin>>w>>a>>b;
    int ar=w+a;
    int br=w+b;
    if(b>ar)
    {
        cout<<b-ar<<endl;
    }
    else if(a>br)
    {
        cout<<a-br<<endl;
    }
    else
        cout<<"0"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int CASES = 3;

void solve() {
    int n; cin >> n;
    vector<vector<int>> a(n, vector<int>(n));
    for(int i = 0; i < n; ++i){
        int m; cin >> m;
        for(int j = 0; j < m; ++j){
            int k, v; cin >> k>>v;
            --k; ++v;
            a[i][k] = v;
        }
    }

    int ans = 0;
    for(int bit = 0; bit < (1 << n); ++bit){
        vector<int> vec(n);
        int tmp = 0;
        for (int i = 0; i < n; ++i) {
            if ( bit & (1<<i) ) {
                vec[i] = 2;
                ++tmp;
            }
            else{
                vec[i] = 1;
            }
        }
        bool flag = true;
        // i人目が嘘つきか判断
        for (int i = 0; i < n; ++i){
            bool honest = true;
            if(vec[i] == 1) honest = false;
            for (int j = 0; j < n; ++j) {
                //矛盾check
                if(a[i][j]==0) continue;
                if(honest){
                    if(a[i][j] != vec[j]){
                        flag = false;
                        break;
                    }
                }
            }
        }
        if(flag){
            ans = max(ans, tmp);
        }
    }
    cout << ans << endl;
}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
#else

    solve();

#endif
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long double LD;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#ifdef LOCAL
#define DEBUG(x) { cerr << "# " << #x << ": " << x << endl;}
#else
#define DEBUG(x)
#endif
mt19937_64 mt(time(0));
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/






int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cout.precision(10); cout << fixed;
#ifdef LOCAL
  freopen("../test.txt", "r", stdin);
    // freopen("../output.txt", "w", stdout);
#endif
  string s; cin >> s;
  int zero = 0, dual = 0, n = s.size(), cur = 0;
  int tot_zero = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '0') tot_zero++;
  }
  LL ret = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '0') {
      zero++;
      cur = 0;
      continue;
    }
    cur++;
    if (i+1 == n || s[i+1] == '0') {
      dual += cur/2;
      if (cur % 2 == 0) continue;
      int tot = zero + 1;
      if (i % 2 == 0) tot++;
      ret += tot / 2;
      ret += tot_zero - zero;
    }
  }
  ret += (LL)dual * (tot_zero+1);
  cur = n - tot_zero - 1;
  while (cur > 0) {
    ret += (cur+1)/2;
    cur--;
  }
  cout << ret << '\n';







/*---------------------------------------Coding Space End------------------------------------------*/
#ifdef LOCAL
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
#endif
  return 0;
}
/* author:  txingml */
/* picture is from hamayanhamayan(CF handle) */


Measured memory_bytes: 3476
def main():
    import sys
    input = sys.stdin.readline

    A = (1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51)
    print(A[int(input()) - 1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<cmath>
#include<bitset>
#include<cstdio>
#include<iomanip>

#define pii pair<int,int>
#define ll long long
#define IMAX 1000000007
#define in2d(i,j,H,W)(0<=i&&i<H&&0<=j&&j<W)

using namespace std;

int main(){
	int N;cin>>N;
	vector<double>p(N);for(int i=0;i<N;i++)cin>>p[i];
	vector<vector<double> >dp(N,vector<double>(N+1,0));
	dp[0][0]=1-p[0];
	dp[0][1]=p[0];
	for(int i=1;i<N;i++)for(int j=0;j<=i+1;j++){
		if(j==0)
			dp[i][0]=dp[i-1][0]*(1-p[i]);
		else
			dp[i][j]=dp[i-1][j]*(1-p[i])+dp[i-1][j-1]*p[i];
	}
	double ans=0;
	for(int i=N/2+1;i<=N;i++)ans+=dp[N-1][i];
	cout<<fixed<<setprecision(11)<<ans<<endl;

	return 0;
}



Measured memory_bytes: 70656
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
char A;
  char B;
  cin >>A>>B;
  if(A=='H') {
    if(B=='H') {
      cout << 'H' << endl;
    }
    else {
     cout << 'D' << endl;
    }
  }
else {
  if (B=='H') {
cout << 'D' << endl;
  }
else {
  cout << 'H' << endl;
}
}
}
    

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(int argc, char const *argv[])
{
   int d, n;
   cin >> n >> d;

   vector<vector<int>> x(n, vector<int>(d));

   for (int i = 0; i < n; i++)
   {
      for(int j = 0; j < d; j++)
      {
         cin >> x[i][j];
      }
   }
   int ans = 0;
   for (int i = 0; i < n; i++)
   {

      for (int j = 0; j < i; j++)
      {
         int norm = 0;
         for(int k = 0; k < d; k++)
         {
            int diff = x[i][k] - x[j][k];
            norm += diff*diff;
         }
         for(int k = 1; k <= sqrt(norm); k++)
         {
            if(k*k == norm)
               ans++;
         }
      }

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


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

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

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

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

int a[N];
int main()
{
   int n;
   Int(n);

   for(int i=1;i<=n;++i){
    Int(a[i]);
   }
   sort(a+1,a+n+1);

   int res=0;
   for(int i=1;i<=n;++i){
    for(int j=i+1;j<=n;++j){
      for(int k=j+1;k<=n;++k){
        if(a[i]==a[j] or a[j]==a[k] or a[i]==a[k])continue;
        if(a[i]+a[j]>a[k]){
          ++res;
        }
      }
    }
   }
   printf("%d\n", res);

   
    return 0;
}






Measured memory_bytes: 3760
H,W = map(int,input().split())
N = int(input())
a = list(map(int,input().split()))
now = 0
grid = [0]*(H*W)

for i in range(N):
  for j in range(now,now+a[i]):
    grid[j] = i+1
  now += a[i]

reverse = 0

for k in range(0,H*W,W):
  if reverse:
    print(*grid[k+W-1:k-1:-1])
    reverse = 0
  else:
    print(*grid[k:k+W])
    reverse = 1

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

int main() {
  long long a;
  double b;
  cin >> a >> b;

  int b_int = b;
  int b_dem100 = (b-b_int)*100.001;
  //cout << a << b_int << b_dem100 << endl;
  
  long long ans_int = a * b_int;
  long long ans_dem100 = a * b_dem100;
  long long ans_dem = ans_dem100/100;
  long long ans = ans_int + ans_dem;
  cout << ans << endl;
}

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

int main()
{
	int n;
	cin>>n;
	int a[n][3];

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


	int dp[n][3];
	for(int i=0;i<n;i++)
	{
		dp[i][0]=0;
		dp[i][1]=0;
		dp[i][2]=0;
	}

	dp[0][0]=a[0][0];

	dp[0][1]=a[0][1];

	dp[0][2]=a[0][2];

	for(int i=1;i<n;i++)
	{
		dp[i][0]=max(a[i][0]+dp[i-1][1],a[i][0]+dp[i-1][2]);
		dp[i][1]=max(a[i][1]+dp[i-1][0],a[i][1]+dp[i-1][2]);
		dp[i][2]=max(a[i][2]+dp[i-1][0],a[i][2]+dp[i-1][1]);
	}

	// for(int i=0;i<n;i++)
	// {
	// 	cout<<dp[i][0]<<" ";
	// 	cout<<dp[i][1]<<" ";
	// 	cout<<dp[i][2]<<" ";
	// 	cout<<endl;
	// }

	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
	return 0;
}

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

int main(){
    string s;
    getline(cin,s);
    int n=s.size();
    for(int i=0; i<n; ++i){
        if(s[i]>='a'&&s[i]<='z')cout<<char(s[i]-32);
        else if(s[i]>='A'&&s[i]<='Z')cout<<char(s[i]+32);
        else cout<<s[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3188
from operator import itemgetter
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########
def main(n,task):
    t = 0
    task = sorted(task, key=itemgetter(1))
    for item in task:
        t += item[0]
        if item[1] < t:
            return "No"
    return "Yes"

n = ii()
task = mix(n)
print(main(n,task))

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

int main(){
  string S;
  cin >> S;
  vector<int> A(26);
  for(int i=0;i<S.size();i++){
    for(char C='a';C<='z';C++){
      if(S.at(i)==C){
        int B=C-'a';
        A.at(B)++;
        break;
      }
    }
  }
  bool a=false;
  for(int i=0;i<26;i++){
    if(A.at(i)==0){
      char D='a'+i;
      a=true;
      cout << D << endl;
      break;
    }
  }
  if(!a){
    cout << "None" << endl;
  }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int H,A;
    cin >> H >> A;
    cout << (H+A-1)/A << endl;



}


Measured memory_bytes: 256
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;


int h, w; ll ans = 0;
int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
vector<string> s(400);
vector<vector<bool>> ok(400, vector<bool>(400, false));

void bfs(int sx, int sy){
    ll cnt_b = 0, cnt_w = 0;
    queue<P> que;
    que.push({sx, sy});
    while(!que.empty()){
        P p = que.front(); que.pop();
        int x = p.first, y = p.second;
        rep(i, 4){
            int nx = x + dx[i], ny = y + dy[i];
            if(nx < 0 || nx >= h || ny < 0 || ny >= w)continue;
            if(!ok[nx][ny] && s[x][y] != s[nx][ny]){
                if(s[nx][ny] == '#')cnt_b++;
                if(s[nx][ny] == '.')cnt_w++;
                ok[nx][ny] = true;
                que.push({nx, ny});
            }
        }
    }
    ans += cnt_b * cnt_w;
}

int main() {
    cin >> h >> w;
    rep(i, h)cin >> s[i];
    rep(i, h)rep(j, w){
        if(!ok[i][j])bfs(i, j);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3844
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define ll_MAX LONG_LONG_MAX
#define ll_MIN LONG_LONG_MIN
#define pi pair<int,int>
#define endl "\n"
#define MAXN 100005
using namespace std;

int l,r,d;

void solve()
{
	cin>>l>>r>>d;
    int a=(l-1)/d, b=r/d;
    cout<<b-a<<endl;
}

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

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

int main(){
	char a;
	while(scanf("%c",&a) != EOF){
		if(a=='@'){
			int s;
			cin>>a;
			s = a-'0';
			cin>>a;
			for(int i=0; i<s; i++){
				cout<<a;
			}
		}
		else if(a=='\n')cout<<endl;
		else cout<<a;
	}
}

Measured memory_bytes: 1168
#include<cstdio>
#include<iostream>
using namespace std;
int n,a[3][110],f[3][110];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=2;i++)
		for(int j=1;j<=n;j++)
			scanf("%d",&a[i][j]);
	for(int i=1;i<=2;i++)
		for(int j=1;j<=n;j++)
			f[i][j]=max(f[i][j-1],f[i-1][j])+a[i][j];
	printf("%d\n",f[2][n]);
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
#define int ll
const int maxn = 1e5 + 10;
//char table[maxn][maxn];
vector<int> g[2][maxn];
int seq[2][maxn];
int vis[2][maxn];
int pt[2];
int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string str;
    cin >> str;
    string str1 = "a",str2;
    for (char ch : str){
        if (ch != 'x'){
            str1 += ch;
        }
    }
    str1 +='a';
    str2 = str1;
    reverse(str2.begin(),str2.end());
    if (str1 != str2){
        cout << -1 << endl;
        return 0;
    }
    vector<int> v;
    int l = 0;
    for (int i = 0;i < str.length();i++){
        if (str[i] != 'x') v.pb(l),l = 0;
        else l++;
    }
    v.pb(l);
    int ans = 0;
    for (int i= 0;i < v.size() / 2;i++){
        ans += abs(v[i] - v[v.size() - 1-i]);
    }
    if (v.size() == 0){
        cout << 0 << endl;
        return 0;
    }
    cout <<ans << endl;
    return 0;
}


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

int main() {
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  int left = max({a, b, c, d, e});
  int right = min({a, b, c, d, e});

  if (left - right <= k)
    cout << "Yay!" << endl;
  else
    cout << ":(" << endl;
}

Measured memory_bytes: 256