akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

template<class T, class U> bool chmax(T &a, U b) { if (a < b) a = b; return true; }
template<class T, class U> bool chmin(T &a, U b) { if (a > b) a = b; return true; }

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

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

  ll n, c; cin >> n >> c;
  vll x(n), v(n);

  rep(i, n) cin >> x[i] >> v[i];

  vll ldp(n+1, 0), rdp(n+1, 0), v_sum(n+1, 0);
  rep(i, n) v_sum[i+1] += v_sum[i] + v[i];

  rep2(i, 1, n) rdp[i] = max(rdp[i-1], v_sum[i] - x[i-1]);
  rep2(i, 1, n) ldp[i] = max(ldp[i-1], (v_sum[n] - v_sum[n-i]) - (c - x[n-i]));

  /* rep(i, n+1) cout << ldp[i] << " "; cout << endl; */
  /* rep(i, n+1) cout << rdp[i] << " "; cout << endl; */

  ll ans = 0;
  rep2(i, 1, n) {
    ll score = v_sum[i] - x[i-1];
    chmax(ans, score);
    if (i >= n) continue;

    chmax(ans, (score + ldp[n-i]) - x[i-1]);
  }

  rep2(i, 1, n) {
    ll score = (v_sum[n] - v_sum[n-i]) - (c - x[n-i]);
    chmax(ans, score);
    if (i >= n) continue;

    chmax(ans, (score + rdp[n-i]) - (c - x[n-i]));
  }

  cout << ans << endl;

  return (0);
}


Measured memory_bytes: 7148
while true
    a,op,b = gets.split.map(&:to_s)
 
    case op
    when "?" then
        break
    when "+" then
        puts a.to_i + b.to_i
    when "-" then
        puts a.to_i - b.to_i
    when "*" then
        puts a.to_i * b.to_i
    when "/" then
        puts a.to_i / b.to_i
    else
        break
    end
end

Measured memory_bytes: 6096
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    int A = scn.nextInt();
    int B = scn.nextInt();
    int C = scn.nextInt();

    int ans = C - (A - B);
    if (ans < 0) {
      ans = 0;
    }
    System.out.println(ans);

  }
}

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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
typedef long long  ll;
typedef vector<ll> VL;
typedef pair<ll,ll> PLL;
#define pb push_back
#define F first
#define S second
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(ll i=x;i<y;i++)
#define frr(i,x,y) for(ll i=x-1;i>=y;i--)
#define inf 10000000000000000
const ll mod=998244353;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

void solve()
{
	string a,b;
	cin>>a>>b;
	map<char,char> mp,mp2;
	fr(i,0,a.size())
	{
		if(!mp.count(a[i]))
		{
			mp[a[i]]=b[i];
		}
		else
		{
			if(mp[a[i]]!=b[i])
			{
				cout<<"No\n";
				return;
			}
		}
		if(!mp2.count(b[i]))
		{
			mp2[b[i]]=a[i];
		}
		else
		{
			if(mp2[b[i]]!=a[i])
			{
				cout<<"No\n";
				return;
			}
		}
	}
	cout<<"Yes\n";
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
	solve();
	return 0;
}

Measured memory_bytes: 916
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let s = scan!();

    let mut num = 0;
    for c in s.chars() {
        if c == 'g' {
            num += 1;
        }
    }

    println!("{}", (2 * num - s.chars().count()) / 2);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

typedef signed long long ll;
typedef long double ld;

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

#define DEBUG

int main()
{
	vector<int> a, b;
	vector<char> c;

	int A, B;
	char C;

	for(int i = 0; C != '?'; i++)
	{
		cin >> A >> C >> B;
		a.push_back(A);
		b.push_back(B);
		c.push_back(C);
	}

	for(int i = 0; c[i] != '?'; i++)
	{
		switch (c[i])
		{
		case '+':
			cout << a[i]+b[i] << endl;
			break;

		case '-':
			cout << a[i]-b[i] << endl;
			break;

		case '*':
			cout << a[i]*b[i] << endl;
			break;

		case '/':
			cout << (a[i]-(a[i]%b[i])) / b[i] << endl;
			break;

		default:
			break;
		}
	}
	return 0;
}



Measured memory_bytes: 3112
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <limits>
#include <numeric>
#include <type_traits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <complex>
#include <climits>

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

ll gcd(ll a, ll b) { //gcdを返す
	if(a == 0){
		return b;
	} else if (b == 0){
		return a;
	} else {
	  if(a < b) return gcd(b, a);
	  ll r;
	  while ((r=a%b)) {
	    a = b;
	    b = r;
	  }
	  return b;
	}
}
ll ketasum(ll n) { //桁の数字全ての和を返す 例: 112 -> 4
	ll sum=0;
	if (n<0) return 0;
	while (n>0) {
		sum += n%10;
		n /= 10;
	}
	return sum;
}

typedef pair<ll, ll> pair_t;

bool comp(const pair_t &a, const pair_t &b) {
        return a.first < b.first;
}

void sort2vectors(vector<ll> &av, vector<ll> &bv)
{ // ふたつの配列をまとめてそーと A[2,1] B[3,4] -> 1,4 2,3
        ll n = av.size();
        vector<pair_t> p(n);
        vector<ll> av2(n), bv2(n);
        for (ll i = 0; i < n; i++)
                p[i] = make_pair(av[i], bv[i]);
        sort(p.begin(), p.end(), comp);
        for (ll i = 0; i < n; i++) {
                av2[i] = p[i].first;
                bv2[i] = p[i].second;
        }
        av = av2;
        bv = bv2;
}

int main(){
	ll N;
	cin >> N;
	vl L(2*N);
	REP(i, 2*N){
		cin >> L[i];
	}
	sort(L.begin(), L.end());
	ll ans = 0;
	REP(i, 2*N){
		if(i % 2 == 0){
			ans += L[i];
		}
	}
	cout << ans << endl;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a, Ts... ts) {return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }

template<typename T,typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v){ t = v; }

template<typename T,typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v){ for(auto &e : t) fill_v(e, v); }

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<int> t(n), a(n);
    REP(i, n) cin >> t[i];
    REP(i, n) cin >> a[i];

    vector<bool> c(n), d(n);
    c[0] = true;
    d[n-1] = true;
    REP(i, n-1) if(t[i] != t[i+1]) c[i+1] = true;
    REP(i, n-1) if(a[n-i-1] != a[n-i-2]) d[n-i-2] = true;

    LL ans = 1;
    REP(i, n) if(c[i] && d[i]) if(t[i] != a[i]) ans = 0;
    REP(i, n) if(c[i]) if(t[i] > a[i]) ans = 0;
    REP(i, n) if(d[i]) if(t[i] < a[i]) ans = 0;

    REP(i, n)
    {
        if(!c[i] && !d[i])
        {
            ans = ans * min(t[i], a[i]) % MOD;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
N=int(input())
A=list(map(int,input().split()))
ans=1000
for i in range(1,N):
  if A[i]>A[i-1]:
    Key=ans//A[i-1]
    key=ans%A[i-1]
    Ans=Key*A[i]+key
    ans=Ans
print(ans)

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

struct mint {
  ll v;
  mint() : v(0) {}
  mint(ll v) : v((v % MOD + MOD) % MOD) {}
  mint pow(ll t) const;
  mint inv() const;
};
mint& operator+=(mint& a, mint b) { return a = a.v + b.v; }
mint& operator-=(mint& a, mint b) { return a = a.v - b.v; }
mint& operator*=(mint& a, mint b) { return a = a.v * b.v; }
mint operator+(mint a, mint b) { return a += b; }
mint operator-(mint a, mint b) { return a -= b; }
mint operator*(mint a, mint b) { return a *= b; }
mint operator-(mint a) { return 0 - a; }
mint& operator/=(mint& a, mint b) { return a *= b.inv(); }
mint operator/(mint a, mint b) { return a /= b; }
mint mint::pow(ll t) const {
  if (!t) return 1;
  mint a = pow(t >> 1);
  a *= a;
  if (t & 1) a *= *this;
  return a;
}
mint mint::inv() const { return pow(MOD - 2); }
bool operator==(mint a, mint b) { return a.v == b.v; }
bool operator!=(mint a, mint b) { return a.v != b.v; }
istream& operator>>(istream& os, mint& a) { return (os >> a.v); }
ostream& operator<<(ostream& os, const mint& a) { return (os << a.v); }

struct mcount {
  vector<mint> fact;  // n! (mod MOD)
  vector<mint> ifact; // k!^{M-2} (mod MOD)
  mcount(int n) : fact(n + 1), ifact(n + 1) {
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint perm(int n, int k) { // nPk (mod MOD)
    if (k < 0 || n < k) return 0;
    return fact[n] * ifact[n - k];
  }
  mint comb(int n, int k) { // nCk (mod MOD)
    dump(n, k);
    if (k < 0 || n < k) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

void solve() {
  int n, m;
  cin >> n >> m;
  mint ans = 1;
  map<ll, int> prime;
  mcount mc(100050);
  for (ll i = 2; i * i <= m; i++) {
    while (m % i == 0) {
      prime[i]++;
      m /= i;
    }
  }
  if (m != 1) prime[m] = 1;
  for (auto p : prime) {
    ans *= mc.comb(n + p.second - 1, n - 1);
  }
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

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

bool isPrime(int n){
	if(n%2 == 0){
		return false;
	}
	for(int i=3; i*i<=n; i+=2){
		if(n%i == 0){
			return false;
		}
	}
	return true;
}

main(){
	while(true){
		int n;
		cin >> n;
		
		if(n == 0){
			break;
		}
		
		// 偶数だったらnを1へらす
		if(n%2 == 0){
			n--;
		}
		
		for(int i=n; i>=4; i-=2){
			if( isPrime(i) && isPrime(i-2) ){
				printf("%d %d\n",i-2,i);
				break;
			}
		}
	}
}


Measured memory_bytes: 3228
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
    vector<int> points(2, 0);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string a, b;
        cin >> a >> b;
        if (a > b) {
            points[0] += 3;
        } else if (a < b) {
            points[1] += 3;
        } else {
            points[0]++;
            points[1]++;
        }
    }
    cout << points[0] << " " << points[1] << endl;
}

Measured memory_bytes: 1212
def q2():
    import math
    N, D = (int(i) for i in input().split())
    X = []
    for n in range(N):
        X.append([int(i) for i in input().split()])

    ans = 0
    for i in range(N):
        for j in range(N):
            if i >= j:
                continue  # 既に評価した座標はスキップ

            s = 0  # 距離の合計
            for d in range(D):
                s += (X[i][d] - X[j][d])**2

            if math.sqrt(s).is_integer():
                ans += 1

    print(ans)


if __name__ == '__main__':
    q2()


Measured memory_bytes: 38256
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define V vector<int>
#define S set<int>
#define pb(v) push_back(v)
int main(){
    CIN(N);
    long long ans = 1;
    FOR(a,1,N+1){
        ans*=a;
        ans%=MOD;
    }
    COUT(ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[105][105];
int a,b;
int main()
{
    scanf("%d%d",&a,&b);
    printf("100 100\n");
    a--;b--;
    for(int i=0;i<50;i++)
    {
        for(int j=0;j<100;j++)
        {
            if(i%2&&j%2&&a)
            {
                a--;
                printf(".");
            }
            else
                printf("#");
        }
        printf("\n");
    }
    for(int i=50;i<100;i++)
    {
        for(int j=0;j<100;j++)
        {
            if(i%2&&j%2&&b)
            {
                b--;
                printf("#");
            }
            else
                printf(".");
        }
        printf("\n");
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;



int main() {
	string s;
	int k;
	cin >> s >> k;
	int n = s.length();
	
	set<string> dic;

	for (int i = 0; i < n; i++) {
		for (int j = 1; j+i <= n && j <=k; j++) {
			
			string sb = s.substr(i, j );
			
			//cout << sb << endl;
			dic.insert(sb);
		}
	}

	auto p = dic.begin();
	for (int i = 1; i < k; i++) {
		p++;
	}

	cout << *p << endl;
	
}

Measured memory_bytes: 1664
#include <iostream>

using namespace std;

int main() {
  // input
  int R;
  cin >> R;

  string ans;
  if (R<1200){
    ans = "ABC";
  }else if(1200<=R && R<2800){
    ans = "ARC";
  }else{
    ans = "AGC";
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace Program
{
    static class Console_
    {
        private static Queue<string> param = new Queue<string>();
        public static int NextInt() => int.Parse(NextString());
        public static string NextString()
        {
            if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item);
            return param.Dequeue();
        }
    }

    public class ABC125A
    {
        static public void Main(string[] args)
        {
            var A = Console_.NextInt();
            var B = Console_.NextInt();
            var T = Console_.NextInt();

            var bis = Math.Floor((T + 0.5) / A) * B;

            Console.WriteLine(bis);
        }
    }
}


Measured memory_bytes: 13268
// https://atcoder.jp/contests/dp/tasks/dp_j
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pr pair<ll, ll>
#define infinity (ll)4e18
#define tp tuple<ll, ll, ll>
using namespace std;
long long int mod = 1e9 + 7;

ld dp[301][301][301];

ld solve(ll n, ll one, ll two, ll three)
{
    if (one < 0 || two < 0 || three < 0)
        return 0;
    if (dp[one][two][three] != -1)
        return dp[one][two][three];
    if (one == 0 && two == 0 && three == 0)
        dp[one][two][three] = 0;
    else
    {
        ld f = one + two + three;
        dp[one][two][three] = n / f + one * solve(n, one - 1, two, three) / f + two * solve(n, one + 1, two - 1, three) / f + three * solve(n, one, two + 1, three - 1) / f;
    }
    return dp[one][two][three];
}

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

    ll n, x;
    cin >> n;
    ll count[4] = {0};
    for (ll i = 0; i < 301; i++)
        for (ll j = 0; j < 301; j++)
            for (ll k = 0; k < 301; k++)
                dp[i][j][k] = -1;
    for (ll i = 0; i < n; i++)
    {
        cin >> x;
        count[x]++;
    }
    printf("%0.14Lf\n", solve(n, count[1], count[2], count[3]));
    return 0;
}

Measured memory_bytes: 426496
#include<iostream>
#include<string>
int main()
{
    std::string s;
    while (std::getline(std::cin, s)) {
        while (s.find("the") == s.npos && s.find("this") == s.npos && s.find("that") == s.npos) {
            for (size_t i = 0; i < s.size(); i ++) {
                if (s[i] >= 'a' && s[i] <= 'y')
                    s[i] ++;
                else if (s[i] == 'z')
                    s[i] = 'a';
            }
        }
        std::cout << s << std::endl;
    }
    return 0;
}

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

using namespace std;

int main()
{
	int a, b;

	cin >> a >> b;
	
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
		cout << "Possible " << endl;
	}
	else {
		cout << "Impossible " << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fore(b,c) for(int val0=b;val0<c;val0++)
#define forr(k,c,s) for(int k=c;k<s;k++)
#define pb push_back
#define mmp make_pair
#define oset(T) tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int> ii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long double ld;
typedef vector<vii> al;
typedef vector<ll> vl;
const int INF = 1e9;
const ll INFL = 1LL<<61;
const ll M = 998244353;
const int MN = 200200;
ll fr[MN];
ll mul(ll a, ll b) {return (a*b)%M;}
ll bp(ll b, ll p) {
	ll ac = 1;
	while(p) {
		if(p&1) {
			ac = mul(ac,b);
		}
		b = mul(b,b);
		p >>= 1;
	}
	return ac;
}
ll w[MN];
int main() {
	ios::sync_with_stdio(0);cout.precision(20);cout.tie(0);cin.tie(0);
	int n;
	cin >> n;
	for(int i=0;i<n;i++) {
		cin >> w[i];
		fr[w[i]]++;
	}
	ll tot = 1;
	if(fr[0] != 1) {
		tot = 0;
	}
	if(w[0] != 0) {
		tot = 0;
	}
	for(int i=1;i<n;i++) {
		tot = mul(tot,bp(fr[i-1],fr[i]));
	}
	cout << tot << '\n';
}


Measured memory_bytes: 1792
/****************************************

			LostMartian

****************************************/
#pragma GCC optimize("Ofast")  
#pragma GCC target("avx,avx2,fma") 
#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 <unordered_set>
#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;

template <typename Arg1>
void pn(Arg1&& arg1) {
	cout << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void pn(Arg1&& arg1, Args&&... args) { 
	cout << arg1 << " "; 
	pn(args...); 
}
template <typename Arg1>
void ps(Arg1&& arg1) { 
	cout << arg1 << " ";
}
template <typename Arg1, typename... Args>
void ps(Arg1&& arg1, Args&&... args) { 
	cout << arg1 << " "; 
	ps(args...); 
}
template <typename Arg1>
void read(Arg1&& arg1) {
	cin >> arg1; 
}
template <typename Arg1, typename... Args>
void read(Arg1&& arg1, Args&&... args) { 
	cin >> arg1; 
	read(args...); 
}

#define rep(i,m,n) for(ll i=m; i<n; i++)
#define repr(i,m,n) for(ll i=m; i>=n; i--)
#define vll vector<ll >
#define vvl vector<vector<ll > >
#define pi pair<ll, ll >
#define vpi vector<pi >
#define umap unordered_map<ll, ll >
#define pb push_back
#define mk make_pair
#define sz size()
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define test ll t; cin>>t; while(t--)
#define ini(a, x) memset(a, x, sizeof(a))
#define d(x) cout<<"Value of "#x" = "<<x<<"\n";
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define iAmSpeed ios_base::sync_with_stdio(false); cin.tie(NULL);
void LOCAL();
int main()
{
	clock_t z = clock();
	//LOCAL();
	iAmSpeed
	ll n;
	cin>>n;
	ll a[n];
	rep(i,0,n) {
		cin>>a[i];
	}	
	if(n<3) {
		pn(0);
		return 0;
	}
	sort(a,a+n);
	ll c=0;
	rep(i,0,n) {
		rep(j,i+1,n) {
			rep(k,j+1,n) {
				if(a[i]!=a[j] && a[j]!=a[k] && a[k]!=a[i]) {
					if(a[i]+a[j]>a[k]) {
						c++;
					}
				}
			}
		}
	}
	pn(c);















	debug("Total Time: %.7f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
	return 0;
}
void LOCAL() {
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
}


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

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i=0;i<n;++i) cin >> p[i];
  
  int ans = 0;
  int curMin = 1e9;
  for (int i=0;i<n;++i){
    curMin=min(curMin,p[i]);
    if (curMin==p[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1152
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353
class RollingHash:
    # Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_14_B
    def __init__(self, seq, base=10 ** 9 + 7, mod=2 ** 89 - 1):
        """
        :param str|typing.Sequence[int] seq:
        :param int base:
        :param int mod:
        """
        if isinstance(seq, str):
            self._seq = seq = list(map(ord, seq))
        else:
            self._seq = seq
        self._base = base
        self._mod = mod

        hashes = [0] * (len(seq) + 1)
        power = [1] * (len(seq) + 1)
        for i, c in enumerate(seq):
            hashes[i + 1] = (hashes[i] * base + c) % mod
            power[i + 1] = power[i] * base % mod
        self._hashes = hashes
        self._power = power


    # @debug
    def get(self, L, r):
        """
        [L, r) のハッシュ値を取得します
        :param int L:
        :param int r:
        """
        if L >= r:
            return 0
        return (self._hashes[r] - self._hashes[L] * self._power[r - L]) % self._mod


N = int(sys.stdin.buffer.readline())
S = sys.stdin.buffer.readline().decode().rstrip()
rh = RollingHash(S)


# @debug
def test(size):
    l = 0
    r = size
    hist = {}
    while r <= N:
        h = rh.get(l, r)
        if h in hist:
            pl, pr = hist[h]
            if pr <= l:
                return True
        else:
            hist[h] = l, r
        l += 1
        r += 1
    return False


ok = 0
ng = N
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if test(mid):
        ok = mid
    else:
        ng = mid
print(ok)


Measured memory_bytes: 4732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int n, s, si;
ll ans;
int x[maxn];
ll p[maxn];
int main()
{
	scanf("%d%d", &n, &s);
	for(int i = 1; i <= n; ++i) scanf("%d%lld", &x[i], &p[i]);
	si = lower_bound(x + 1, x + n + 1, s) - x;
	int dir = -1;
	int l = 1, r = n;
	while(l < si && si <= r)
	{
		if(p[l] >= p[r])
		{
			if(dir != 1) ans += x[r] - x[l];
			p[l] += p[r];
			dir = 1;
			--r;
		}
		else
		{
			if(dir != 0) ans += x[r] - x[l];
			p[r] += p[l];
			dir = 0;
			++l;
		}
	}
	if(l >= si) ans += x[r] - s;
	else ans += s - x[l];
	printf("%lld\n", ans);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

ll DP[1010][1<<13];

int main(){
    ll N, M;
    cin >> N >> M;
    vector<ll> A(M);
    vector<ll> C(M);
    REP(i,M){
        ll a, b;
        cin >> a >> b;
        A[i] = a;
        ll bit = 0;
        REP(j,b){
            ll c;
            cin >> c;
            c--;
            bit |= (1 << c);
        }
        C[i] = bit;
    }

    const ll INF = 1e15;
    REP(i,M+1) REP(j,1<<N) DP[i][j] = INF;
    DP[0][0] = 0;
    REP(i,M){
        ll a = A[i];
        ll c = C[i];
        REP(b, 1<<N){
            chmin(DP[i+1][b | c], DP[i][b] + a);
            chmin(DP[i+1][b], DP[i][b]);
        }
    }

    ll ans = -1;
    ans = DP[M][(1 << N) - 1];

    if(ans == INF)
        ans = -1;
    cout << ans << endl;
    return 0;
}


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

int main() {
 
  //この中に何種類の異なる値があるでしょう。確かに
  int N;
  cin >> N;
  int d[110];
  for (int i = 0; i < N; ++i) cin >> d[i];

  //これバケツ
  int num[110] = {0};
  
  //d[i]の一つ一つについて、バケツをインクリメントする
  for (int i = 0; i < N; i++) {
    num[d[i]]++;
  }

  //1以上のバケツがいくつあるか

  int counter = 0;

  for (int i = 0; i <= 100; i++) {
    if (num[i] > 0) counter++;
  }

  cout << counter << endl;
  


}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define rep(i,j,k) for (i=j;i<=k;i++)
using namespace std;
const int N=1e5+5;
int n,L,T,i,rk,x[N],d[N];
int main()
{
//	freopen("ants.in","r",stdin);
//	freopen("ants.out","w",stdout);
	scanf("%d%d%d",&n,&L,&T);
	rep(i,0,n-1) scanf("%d%d",&x[i],&d[i]);
	rep(i,0,n-1)
	{
		if (d[i]==1)
		{
			rk+=(x[i]+T)/L;
			x[i]=(x[i]+T)%L;
		}
		else {
			rk+=(x[i]-T)/L;
			x[i]=(x[i]-T)%L;
			if (x[i]<0) {
				x[i]+=L;
				rk--;
			}
		}
	}
	rk=(rk%n+n)%n;
	sort(x,x+n);
	rep(i,rk,n-1) printf("%d\n",x[i]);
	rep(i,0,rk-1) printf("%d\n",x[i]);
	return 0;
}

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

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

#define endl '\n'
#define MAX

typedef long long ll;
typedef pair<int,int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const int maxn = 3000 + 5;
double p[maxn], dp[maxn][maxn];
bool ok[maxn][maxn];
int n;

double solve(int pos, int tails){
	if(pos == n)
		return (pos > 2 * tails ? 1.0 : 0.0);
	if(ok[pos][tails])
		return dp[pos][tails];
	ok[pos][tails] = true;
	double ans = 0.0;
	ans += solve(pos + 1, tails + 1) * (1.0 - p[pos]);
	ans += solve(pos + 1, tails) * p[pos];
	return dp[pos][tails] = ans;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cout << setprecision(10) << fixed;
	
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> p[i];
	
	cout << solve(0, 0) << endl;
	
	return 0;
}

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

int main(){

    int a, b;

    cin >> a >> b;

    if(a == 1 && b != 1){
        cout << "Alice" << endl;
    }
    else if(b == 1 && a != 1){
        cout << "Bob" << endl;
    }
    else if(a == 1 && b == 1){
        cout << "Draw" << endl;
    }
    else{
        if(a > b){
            cout << "Alice" << endl;
        }
        else if(b > a){
            cout << "Bob" << endl;
        }
        else{
            cout << "Draw" << endl;
        }
    }

    return 0;

}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n);
#define vsort(v) sort(v.begin(),v.end());
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
typedef pair<int,int> p;
typedef pair<ll,ll> lp;
bool is_uruu(int y) {
        return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
}
const ll MOD=1e9+7;
//---------------------------------------------------------------------------//

int main(){
        int n;
        string s;
        cin>>n;
        cin>>s;
        int x=0,a=0;
        rep(i,0,n){
                if(s[i]=='I') {
                        a++;
                        x=max(x,a);
                }else{
                        a--;
                }
        }
        cout<<x<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
        int a,b,c,k;
        cin>>a>>b>>c>>k;
        if(k<=a) { cout<<k<<endl; return 0;}
        if(k<=b){ cout<<a<<endl; return 0;}
        cout<<a-(k-(a+b))<<endl;
        return 0;
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll a(n); rep(i,n) cin>>a[i];
  
  ll ans=0, r=0, sum=0;
  rep(l,n){
    while(r<n&&sum+a[r]==(sum^a[r])){
      sum+=a[r];
      r++;
    }
    ans+=r-l;
    if(r==l) r++;
    else sum-=a[l];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h> 
 
 
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define repv(arr)  for(auto it=arr[i].begin();it!=arr[i].end();it++)  
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vl vector<long long int>
#define sortA(arr)   sort(arr.begin(),arr.end())
#define search(arr,c)  binary_search(arr.begin(),arr.end(),c)
#define pb   push_back
#define ll long long
#define LCM(a,b) boost::math::lcm(a,b)
#define cl_bf cin.ignore(numeric_limits<streamsize>::max(), '\n');
 
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  int x,y;
  cin>>x>>y;
  int flag=0;
  rep(i,0,x+1){
    if(i*2+(x-i)*4==y)
    {cout<<"Yes"<<endl;
    	flag=1;
     break;
    }
  }
  if(flag==0){
    cout<<"No"<<endl;
  }
  
}

Measured memory_bytes: 3652
from itertools import accumulate

n, q = map(int, input().split())

s = input()

problems = [list(map(int, input().split())) for _ in range(q)]


def count(total, i):
    return total + 1 if s[i-1:i+1] == 'AC' else total


cumsum = list(accumulate(range(n), count))

for l, r in problems:
    print(cumsum[r-1] - cumsum[l-1])


Measured memory_bytes: 30744
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
using vpii = vector<pair<int, int>>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep1(i, n) for (int i = 1; i < (int)n; i++)
const ll mod = 1e9+7;
const ll inf = 1e10;
const double pi = 3.141592;

ll gcd(ll a, ll b){
  return (b != 0) ? gcd(b, a%b) : a;
}

ll lcm(ll a, ll b){
  return (a/gcd(a,b))*b;
}

template<class T>
bool contain(const string& s, const T& v){
  return s.find(v) != std::string::npos;
}

ll f(int a, int b){
  if(a == b || a == 0 || b == 0) return 1;
  else return f(a-1, b-1)%mod+f(a-1, b)%mod;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> h(n+1);
  rep(i, n) cin >> h[i];
  h[n] = 0;
  int ans = 0;
  bool ok = false;
  while(!ok){
    ok = true;
    int cnt = 0;
    rep(i, n+1){
      if(h[i] == 0){
        if(cnt){ ++ans; cnt = 0; }
        continue;
      }
      ++cnt;
      --h[i];
      ok = false;
    }
  }
  cout << ans << "\n";
  return 0;
} 

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

using namespace std;

using Int = long long;
using P = pair<int, int>;

const long long MOD = 1e9 + 7;
const int INF = 1e9;
const double EPS = 1e-9;

int main() {
  int ans = 0;
  string S, T;
  cin >> S >> T;
  for (int i = 0; i < 3; ++i) if (S[i] == T[i]) ans++;
  cout << ans << endl;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

const int INF = 1001001001;


int main() {

    string s;
    cin >> s;

    if (s == "Sunny") {
        cout << "Cloudy" << endl;
    } else if (s == "Cloudy") {
        cout << "Rainy" << endl;
    } else {
        cout << "Sunny" << endl;
    }

}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()

int main(void){
    int a, b;

    std::cin >> a >> b;

    if(a <= b) std::cout << a << std::endl;
    else if(a > b) std::cout << a-1 << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
ll a[200010], b[200010];
ll k, n;
bool chck(ll x){
    ll tmp=0;
    for(ll i=0; i<n; ++i){
        tmp+=max(0ll, a[i]-x/b[i]);
    }
    return tmp<=k;
}
int main(){
    while(cin>>n>>k){
        ll ans=0;
        for(int i=0; i<n; ++i){
            scanf("%lld",a+i);
        }
        for(int i=0; i<n; ++i){
            scanf("%lld",b+i);
        }
        sort(a, a+n);
        sort(b, b+n);
        reverse(b, b+n);
        ll st=0, nd=0, md;
        for(int i=0; i<n; ++i){
            nd=max(nd, a[i]*b[i]);
        }
        while(st<nd){
            md=(st+nd)/2;
            if(chck(md)){
                nd=md;
            }
            else{
                st=md+1;
            }
        }
        cout<<nd<<endl;
    }
  return 0;
}




Measured memory_bytes: 3328
#include <bits/stdc++.h>
const int INF=1e9;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
bool prime(int a){
  for(int i=2;i*i<=a;i++)if(a%i==0)return false;
  return true;
}
//main
signed main(){
  int N;cin>>N;
  int cnt=0,a=11;
  while(cnt<N){
    if(prime(a)){
      cout<<a<<" ";
      cnt++;
    }
    a+=10;
  }
  cout<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

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

   int n;
   cin >> n;
   vector<ll> a(n);
   rep(i, 0, n) cin >> a[i];

   ll ans = 0;
   rep(i, 0, 60) {
      ll x = 0;
      rep(j, 0, n) {
         if (a[j] >> i & 1) x++;
      }
      ll now = x * (n - x) % MOD;
      rep(j, 0, i)(now *= 2) %= MOD;
      (ans += now) %= MOD;
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 5516
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a[100],i,c=0,ans=1,j;
    cin>>n;
    for(i=0;i<n;i++)
        cin>>a[i];
    for(i=n-1;i>=0;i--)
    {
        for(j=i-1;j>=0;j--)
        {
            if(a[i]<a[j])
            {
                ans=0;
                break;
            }
        }
        if(ans)
            c++;
        ans=1;
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3548
n,q=map(int,input().split())
s=input()
num=[0]
be=""

for i in range(n):
  if be=="A" and s[i]=="C":
    num.append(num[-1]+1)
    
  else:
    num.append(num[-1])
    
  be=s[i]
    
for i in range(q):
  l,r=map(int,input().split())
  
  print(abs(num[l]-num[r]))

Measured memory_bytes: 11424
#include <bits/stdc++.h>
#define rep(i, l, r) for (__typeof(l) i = (l); i <= (r); ++i)
#define per(i, r, l) for (__typeof(r) i = (r); i >= (l); --i)
using namespace std;
typedef long long ll;
const int mod = 998244353;
int read() {
	int f = 1, x = 0; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return f * x;
}
int qpow(int a, int b) { int res = 1; while (b) { if (b & 1) res = (ll)res * a % mod; a = (ll)a * a % mod; b >>= 1; } return res; }

const int N = 100010;
int x, y, p[N], q[N], r[N], A, B, C;
long long ft[N], bk[N], sum;
multiset <int> now;
void ins(int x, int sz) {
	now.insert(x);
	sum += x;
	if (now.size() > sz) sum -= *(now.begin()), now.erase(now.begin());
}
int main() {
	scanf ("%d%d%d%d%d", &x, &y, &A, &B, &C);
	for (int i = 1; i <= A; ++i) scanf ("%d", &p[i]);
	for (int i = 1; i <= B; ++i) scanf ("%d", &q[i]);
	for (int i = 1; i <= C; ++i) scanf ("%d", &r[i]);
	sort (r + 1, r + C + 1, greater <int>());
	for (int i = 1; i <= A; ++i) ins(p[i], x);
	ft[0] = sum;
	for (int i = 1; i <= C; ++i) {
		ins(r[i], x);
		ft[i] = sum;
	}
	sum = 0;
	while (now.size()) now.erase(now.begin());
	for (int i = 1; i <= B; ++i) ins(q[i], y);
	bk[C + 1] = sum;
	for (int i = C; i >= 1; --i) {
		ins(r[i], y);
		bk[i] = sum;
	}
	long long ans = 0;
	for (int i = 0; i <= C; ++i) ans = max(ans, ft[i] + bk[i + 1]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7168
#ifndef VS
#include<bits/stdc++.h>
#endif

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};
typedef vector<int > V;
typedef vector<V> VV;

template <typename ITR>
bool next_value(int base, ITR bg, ITR ed) {
	int c = 1;
	for (; bg != ed && c == 1; ++bg) {
		(*bg) += c;
		if ((c = ((*bg) == base)))(*bg) = 0;
	}
	return !c;
}

int main() {
	int N;
	cin >> N;
	map<V, int> f;
	VV ei(6);
	{
		V latte = { 0,1,2 };
		int id = 0;
		do {
			f[latte] = id;
			ei[id] = latte;
			id++;
		} while (next_permutation(ALL(latte)));
	}
	V g(6);
	for (int i : range(N)) {
		int w;
		cin >> w;
		V x = { 0,1,2 };
		for (int j : range(w)) {
			int a;
			cin >> a;
			if (a == 0) {
				swap(x[0], x[1]);
			}
			else {
				swap(x[1], x[2]);
			}
		}
		g[f[x]]++;
	}
	V o(6, 0);
	do {
		V  malta = g;
		V beet = { 0,1,2 };
		for (int i : range(6)) {
			if (malta[o[i]] == 0)break;
			malta[o[i]]--;
			V nxt(3);
			for (int j : range(3)) {
				nxt[ei[o[i]][j]] = beet[j];
			}
			swap(beet, nxt);
			if (beet == V{0, 1, 2}) {
				cout << "yes" << endl;
				return 0;
			}
		}
	} while (next_value(6,ALL(o)));
	cout << "no" << endl;
	return 0;
}



Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define OUT(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
constexpr int MOD = 1000000007;

int mod(const ll &x){
    return x > 0 ? x % MOD : (x+MOD) % MOD;
}

int modm(const ll &x,const ll &m){
    return x * m % MOD;
}

int modpow(ll x, ll p) {
    int ret = 1;
    while(p > 0) {
        if (p & 1) ret = modm(ret,x);
        x = modm(x,x);
        p >>= 1;
    }
    return ret;
}

// x * modinv(d)
int modd(ll x,ll d) {
    return modm(x,modpow(d,MOD-2));
}

int main(void)
{
    IOS
    constexpr int N = 62;
    int n; cin >> n;
    vector<bitset<N>> v;
    vector<int> c1(N) , c0(N);
    REP(i,n) {
        ll x;
        cin >> x;
        v.push_back(bitset<N>(x));
        REP(j,N) {
            if(v[i][j]) c1[j]++;
            else c0[j]++;
        }
    }

    int ans = 0;
    REP(i,n-1) {
        REP(j,N) {
            if(v[i][j]) c1[j]--;
            else c0[j]--;
        }
        ll tmp = 0;
        REP(j,N) {
            if (v[i][j]) tmp = mod(tmp + modm(mod(1LL << j),c0[j]));
            else tmp = mod(tmp + modm(mod(1LL << j),c1[j]));
        }
        ans = mod(ans + tmp);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int N = 1e6;

int main() {
    ios_base::sync_with_stdio(0);
    int a,b,n,T,cas=0;
    string s;
    cin>>s;
    map<int, int> mp;
    mp[0]=1;
    int r=0, pow10=1;
    ll res=0;
    for(int i=s.size()-1;~i;--i) {
        r = (r + (s[i]-'0')*pow10)%2019;
        res += mp[r];
        mp[r]++;
        pow10 = (pow10*10)%2019;
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 3652
n = int(input())
s = int(input())

def f(b,n):
    if n < b:
        return n
    elif n >= b:
        return f(b,n//b) + n % b

res = -1

import sys
import math

#sys.setrecursionlimit(10000000)

if s == n:
    print(n+1)
    sys.exit()

bound = int(math.sqrt(n))

for b in range(2,bound+1):
    if f(b,n) == s:
        print(b)
        sys.exit()

for p in range(bound,0,-1):
    b = (n-s)//p + 1
    if b <= 1:
        continue
    if f(b,n) == s:
        res = b
        break

print(res)


Measured memory_bytes: 3064
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	B
# CreatedDate:  2020-08-15 20:38:49 +0900
# LastModified: 2020-08-15 21:11:14 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    N = int(input())
    L = sorted(list(map(int, input().split())))
    cnt = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            for k in range(j+1, N):
                if L[k] < L[i] + L[j] and L[k] != L[i] and L[k] != L[j] and L[i] != L[j]:
                    cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9192
const lines=readlines(open("/dev/fd/0"))
let
    state=0
    global input
    input()=lines[state+=1]
end
int(s::String)=parse(Int32,s)
intSub(s::SubString{String})=parse(Int32,s)
intLine()=map(intSub,split(input()))
function main()
    n=int(input())
    m=c=0
    for h in intLine()
        if h>=m
            c+=1
            m=h
        end
    end
    print(c)
end
main()

Measured memory_bytes: 118784
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,x,sum=0,ans=0;scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&x),sum+=x,ans+=x*x;
	int a=sum/n,b=a+1;
	printf("%d",ans+min(n*a*a-2*sum*a,n*b*b-2*sum*b));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<ll,ll>
#define mod 1000000007
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=((a%mod)*(a%mod))%mod;
		b>>=1;
	}
	return ans;
}

void sieve(ll n){
	bool prime[n+1];
	memset(prime,true,sizeof(prime));
	for(ll p=2;p*p<=n;p++){
		if(prime[p]){
			for(ll i=p*p;i<=n;i+=p)
				prime[i]=false;
		}
	}
	for(ll p=2;p<=n;p++){
		if(prime[p])
			cout<<p<<" ";
	}
}

void dfs(ll i,bool vis[],vector<ll> adj[],ll a[],ll last){
	vis[i]=true;
	a[i]+=last;
	last=a[i];
	for(auto j:adj[i]){
		if(vis[j])
			continue;
		dfs(j,vis,adj,a,last);
	}
}

int main() {
	IOS;
	ll t=1;
	//cin>>t;
	while(t--){
		ll n,q;
		cin>>n>>q;
		vector<ll> adj[n+1];
		for(ll i=0;i<n-1;i++){
			ll p,qa;
			cin>>p>>qa;
			adj[p].push_back(qa);
			adj[qa].push_back(p);
		}
		ll a[n+1];
		memset(a,0,sizeof(a));
		for(ll i=0;i<q;i++){
			ll p,x;
			cin>>p>>x;
			a[p]+=x;
		}
		bool vis[n+1];
		memset(vis,false,sizeof(vis));
		ll val=0;
		dfs(val+1,vis,adj,a,val);
		for(ll i=1;i<=n;i++)
			cout<<a[i]<<" ";
	}
	return 0;
}

Measured memory_bytes: 27648
#include<iostream>
#define abs(a) (a)<0?-(a):(a)
using namespace std;
int M=1e5,s[1<<17],ans,n,m,a;
main()
{
	cin>>n>>m;
	for(int i=0;i<n-1;i++)
	{
		cin>>s[i+1];
		s[i+1]+=s[i];
	}
	for(int i=0;i<m;i++)
	{
		cin>>n;
		(ans+=abs(s[a]-s[a+n]))%=M;
		a+=n;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3468
#include<stdio.h>
int main(){
    int d[3];
    int di[3]={};
    int max=-100;
    for(int i=0;i<3;i++){
        scanf("%d",&d[i]);
        if(max<d[i]){
            max=d[i];
        }
    }

    int tmp;
    for(int i=0;i<2;i++){
        for(int j=i+1;j<3;j++){
            if(d[i]>d[j]){
                tmp=d[i];
                d[i]=d[j];
                d[j]=tmp;
            }
        }
    }

    int ans=0;
    ans=d[2]-d[1];
    d[0]+=d[2]-d[1];
    d[1]=d[2];
    ans+=(d[2]-d[0])/2;
    d[0]+=2*((d[2]-d[0])/2);
    //printf("%d %d %d\n",d[0],d[1],d[2]);
    printf("%d\n",(d[2]-d[0])%2==0?ans:ans+2);
    return 0;
}

Measured memory_bytes: 128