akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
const int MO=1e9+7;
int N,M,NN,MM,n,m,a[1111111],b[1111111],ts,tmp[1111111];
LL f[1111111],fac[1111111],inv[1111111];
LL pw(LL x,LL y){
	LL t=1;
	for (;y;y>>=1){
		if (y&1) t=t*x%MO;
		x=x*x%MO;
	}
	return t;
}
LL C(int x,int y){
	if (x<y) return 0;
	return fac[x]*inv[y]%MO*inv[x-y]%MO;
}
int main(){
	fac[0]=1;
	FOR(i,1,1000000) fac[i]=fac[i-1]*i%MO;
	inv[1000000]=pw(fac[1000000],MO-2);
	FORD(i,999999,0) inv[i]=inv[i+1]*(i+1)%MO;
	cin>>n>>m;
	FOR(i,1,n) getint(a[i]),tmp[++ts]=a[i];
	FOR(i,1,m) getint(b[i]),tmp[++ts]=b[i];
	sort(a+1,a+n+1);
	FOR(i,1,n) if (a[i]==a[i-1]) return puts("0"),0;
	sort(b+1,b+m+1);
	FOR(i,1,m) if (b[i]==b[i-1]) return puts("0"),0;
	sort(tmp+1,tmp+ts+1);
	ts=unique(tmp+1,tmp+ts+1)-tmp-1;
	f[ts]=1;
	N=n,M=m;
	FORD(rp,ts,1){ //f[rp]->f[rp-1]
		NN=N;
		MM=M;
		while (a[NN]>tmp[rp-1]) --NN;
		while (b[MM]>tmp[rp-1]) --MM;
		int r=tmp[rp]-tmp[rp-1];
	//	原来填了>tmp[rp] n*m-tmp[rp]
	//	原来有格子(n-N)*(m-M)
	//	现在有格子(n-NN)*(m-MM)
		if (NN==N){
			(f[rp-1]+=f[rp]*(n-N)%MO*C((n-NN)*(m-MM)-(n*m-tmp[rp])-1,r-1)%MO*fac[r-1])%=MO;
		}
		else if (MM==M){
			(f[rp-1]+=f[rp]*(m-M)%MO*C((n-NN)*(m-MM)-(n*m-tmp[rp])-1,r-1)%MO*fac[r-1])%=MO;
		}
		else{
			(f[rp-1]+=f[rp]*C((n-NN)*(m-MM)-(n*m-tmp[rp])-1,r-1)%MO*fac[r-1])%=MO;
		}
		N=NN;
		M=MM;
	}
	cout<<(f[0]%MO+MO)%MO<<endl;
	return 0;
}

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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    ll a, b, x;
    cin >> a >> b >> x;

    --a;
    ll pls = (a < 0 ? 0 : 1);
    if(a < 0) a = 0;
    cout << (b / x + 1) - (a / x + pls) << endl;
}

Measured memory_bytes: 256
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int main(){
  int a,b;
  cin>>a>>b;
  if(a<=0 && 0<=b) puts("Zero");
  else{
    bool sign=false;
    int cnt=min(b,0)-a+1;
    if(cnt>0 && cnt&1) sign=true;
    puts(sign?"Negative":"Positive");
  }
  return 0;
}



Measured memory_bytes: 764
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const int maxm = 1e6 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
int n;
set<int> s;
int main(){
 	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	int x;
	for(int i = 0;i < n;i++){
		cin >> x;
		s.insert(x);
	}
	if(s.size() == n) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 9728
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}


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

    ll a[n];
    ll sum[n];
    rep(i,n){
        cin >> a[i];
        if(i==0){
            sum[i] = a[i];
        }else{
            sum[i] = a[i] + sum[i-1];
        }
        //cout << sum[i] << ' ';
    }

    ll ans = 100000000000000;

    srep(i,1,n-2){
        int l1 = 0;
        int r1 = i;
        int l2 = i+1;
        int r2 = n-1;
        ll ma1,mi1,ma2,mi2;

        while(true){
            //cout << i;
            if(l1==r1)break;
            if(r1-l1==1){
                if(abs(sum[i]-sum[l1]-sum[l1])<=abs(sum[i]-sum[r1]-sum[r1])){
                    r1 = l1;
                }else{
                    l1 = r1;
                }
            }
            int half = (l1+r1)/2;
            if(sum[i]-sum[half]==sum[half]){
                l1 = half; r1 = half;
            }else if(sum[half]<sum[i]-sum[half]){
                l1 = half;
            }else{
                r1 = half;
            }
        }
        ma1 = max(sum[l1],sum[i]-sum[l1]);
        mi1 = min(sum[l1],sum[i]-sum[l1]);

        while(true){
            //cout << i;
            //cout << l2 << r2;
            if(l2==r2)break;
            if(r2-l2==1){
                if(abs(sum[n-1]-sum[l2]-(sum[l2]-sum[i]))<=abs(sum[n-1]-sum[r2]-(sum[r2]-sum[i]))){
                    r2 = l2;
                }else{
                    l2 = r2;
                }
            }
            int half = (l2+r2)/2;
            if(sum[n-1]-sum[half]==sum[half]-sum[i]){
                l2 = half; r2 = half;
            }else if(sum[half]-sum[i]<sum[n-1]-sum[half]){
                //cout << "rrr";
                l2 = half;
            }else{
                //cout << "lll";
                r2 = half;
            }
            //cout << l2 << endl;
        }
        ma2 = max(sum[l2]-sum[i],sum[n-1]-sum[l2]);
        mi2 = min(sum[l2]-sum[i],sum[n-1]-sum[l2]);

        //cout << l2 << ' ' << ma1 << ' ' << mi1 << ' ' << ma2 << ' ' << mi2 << endl;

        ans = min(ans,max(ma1,ma2)-min(mi1,mi2));
    }

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

Measured memory_bytes: 3328
// abc115_d
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;



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

    ll N, X;
    cin >> N >> X;

    vector<ll> B(N+1), P(N+1);

    B[0] = 1;
    P[0] = 1;
    REP(i, N) {
        B[i + 1] = 2 * B[i] + 3;
        P[i + 1] = 2 * P[i] + 1;
    }

    int i = N;
    ll ans = 0;
    while (true){
        if (X == 1){
            if (i == 0) ans++;
            ans += 0;
            break;
        } else if (X <= B[i-1] + 1){
            X -= 1;
            ans += 0;
        } else if (X == B[i-1] + 2){
            ans += P[i-1] + 1;
            break;
        } else if (X <= 2 * B[i-1] + 2){
            X -= B[i-1] + 2;
            ans += P[i-1] + 1;
        } else {
            ans += 2 * P[i-1] + 1;
            break;
        }
        i--;
    }

    print(ans);


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ld a,b;cin>>a>>b;
    cout<<(ll)(a*b)<<"\n";
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            if (s[i] == 'p') ans--;
        } else {
            if (s[i] == 'g') ans++;
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 512
import math
def is_ok(mid,k):
  cnt=0
  for i in a:
    cnt+=max(int((i-0.1)/mid),0)
  if cnt<=k:return 1
  else:return 0
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
ng=0
ok=a[-1]
while abs(ng-ok)>0.0001:
  mid=(ng+ok)/2
  if is_ok(mid,k):ok=mid
  else:ng=mid
print(math.ceil(ok))

Measured memory_bytes: 94016
#include "bits/stdc++.h"
using namespace std;

int main(){
	int N , a , b;
	scanf( "%d" , &N );

	if( N == 1 ){
		puts( "Hello World" );
		return 0;
	}

	scanf( "%d%d" , &a , &b );
	printf( "%d\n" , a + b );
	return 0;
}

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

int main(){
    int n; cin >> n;
    map<ll, ll> m;
    for(int i = 0; i < n; i++){
        ll a; cin >> a;
        m[a]++;
    }
    int ans = 0;
    for(auto &x: m){
        ans += (x.second % 2);
    }
    cout << ans << endl;
}

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

int main()
{
    vector<string> ans;
    int N, L;
    cin >> N >> L;
    for (int i = 0; i < N; i++)
    {
        string temp;
        cin >> temp;
        ans.push_back(temp);
    }
    sort(ans.begin(), ans.end());
    for (int i = 0; i < N; i++)
    {
        cout << ans[i];
    }
}

Measured memory_bytes: 256
w=[]
k=[]

for i in range(0,10):
    w.append(int(input()))
    w.sort(reverse=True)
    sum_w=sum(w[0:3])
for i in range(10,20):
    k.append(int(input()))
    k.sort(reverse=True)
    sum_k=sum(k[0:3])
print(sum_w,sum_k)


Measured memory_bytes: 5600
import sys
N = int(sys.stdin.readline())
S = list(map(str,sys.stdin.read().rstrip().split("\n")))

ans = 0
A = 0
B = 0
BA = 0
for s in S:
	ans += s.count('AB')
	if  s[0] == 'B' and s[-1] == 'A':
		BA += 1
		continue
	elif s[0] == 'B':
		B += 1
	elif s[-1] == 'A':
		A += 1

if BA == 0:
	ans += min(A,B)
else:
	if A+B > 0:
		ans += BA + min(A,B)
	else:
		ans += BA-1

print(ans)

Measured memory_bytes: 3828
#include <stdio.h>
int main(void) {
	int n, k, r, s, p, sum_score = 0;
	char t[100000];
	scanf("%d%d%d%d%d", &n, &k, &r, &s, &p);
	scanf("%s", t);

	for (int i = k; i < n; i++)
		if (t[i] == t[i - k])
			t[i] = 'd';

	for (int i = 0; i < n; i++) {
		if (t[i] == 'r')
			sum_score += p;
		else if (t[i] == 's')
			sum_score += r;
		else if(t[i] == 'p')
			sum_score += s;
	}

	printf("%d\n", sum_score);
	return 0;
}

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

namespace _169A
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine()?.Split(' ').Select(tmp => long.Parse(tmp)).ToArray();
            long answer = 1;
            foreach (var a in input)
            {
                answer = answer * a;
            }
            Console.WriteLine(answer);
        }
    }
}


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

int main(){

  int t,n,k;
  int a[100001];
  int b[100001];
  int ans;

  cin >> t;

  for(int l=0;l<t;l++){
    memset(a,-1,sizeof(a));
    memset(b,-1,sizeof(b));
    ans = 0;

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

    sort(a,a+n);

    for(int i=0;i<n-1;i++) b[i] = a[i+1] - a[i];

    sort(b,b+n);
    reverse(b,b+n);

    for(int i=0;i<k-1;i++) b[i] = 0;

    for(int i=0;i<n-1;i++) ans += b[i];

    cout << ans << endl;
  }
}

Measured memory_bytes: 1964
//#define DEB1 //input from input.txt
//#define NDEBUG
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <thread>
#include <mutex>
#include <iomanip>
#include <cassert>

#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define ALL(t) (t).begin(),(t).end()
#define FILL(a,c) fill(a, a+ sizeof(a)/sizeof(*a),c)
#define FILL2D(A,c) fill(A[0], A[0] +sizeof(A)/sizeof(**A),c)
#define FILL3D(A,c) fill(A[0][0], A[0][0] +sizeof(A)/sizeof(***A),c)
#define REP(i,m) for(int i=0;i<(m);++i)
// closed interval, inverse repeat
#define CIREP(i,start,fin) for(int i=(start);i>=(fin);i--)
#define CREP(i,start,fin) for(int i=(start);i<=(fin);i++)
#define RNG(i,start,fin) for(int i=(start);i<(fin);i++)
#define IN(a, x, b) (a<=x && x<b)
#define PB push_back
#define SZ(x) (int)(x).size()

using namespace std;

using LL = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<LL,LL>;
using VI = vector<int>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VVI = vector<VI>;
const LL LINF = 1001002003004005006ll;
//const int MX = 31001;
//const ll INF= 1LL<<60 ;//INF = 1001001001001; //1e9


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; }


/*
constant values
*/

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


// Main program
void solve(){
    int N;
    cin >> N;
    string S = "abcdefghij";
    //cerr << S[1] << endl;
    vector<pair<string, int>> V[11]; 
    //pair<string, int> P;
    //vector<string> T;

    V[0].PB( make_pair("a",0) );
    //V.PB(P);

    //string tmp = S.substr(1,1);
    //T.PB(tmp);
    //V.PB(T);


    CREP(n,1,N-1){
        cerr << "step=" << n << endl;
        REP(i, V[n-1].size()){
            string old = V[n-1][i].first;
            int jmax = V[n-1][i].second;
            REP(j,jmax+2){
                string tmp;
                tmp = old + S.substr(j,1);
                V[n].PB( make_pair(tmp,max(V[n-1][i].second,j)) );
                cerr << tmp << endl;
            }
        }
    }
    cerr << "answer" << endl;
    REP(i,V[N-1].size()){
        cout << V[N-1][i].first << endl;
    }
    return;
}

// ----------------------------------------------
int main(){

#ifdef DEB1
    cout << "DEBUG MODE"  << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf()); //for debug
#endif

    int T=1; 

    for (int i = 0; i < T; ++i) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 10352
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int be = max(a, c);
	int en = min(b, d);

	cout << max(en - be, 0) << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#define INF 10000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;
using namespace std;

int main(){
	int n;
	cin >> n;
	map<int, int> x;
	REP(i, n){
		int a;
		cin >> a;
		if(x[a]) x[a] = 0;
		else x[a] = 1;
	}
	int ans = 0;
	for(map<int, int>::iterator it = x.begin(); it != x.end(); ++it) if(it->second) ans++;
	cout << ans << endl;
	return 0;
}


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

int prime[4000],size;
bool flg[30100];

bool isPrime(int x){
	double to = sqrt(x);
	for(int i=0;i<size && prime[i]<=to;i++)
		if(x % prime[i] == 0)
			return false;
	return true;
}

void mkPrime(void){
	prime[0] = 2;
	size = 1;
	for(int i=3;i<30100;i+=2){
		if(isPrime(i)){
			prime[size++] = i;
			flg[i] = true;
		}
		else{
			flg[i] = false;
		}
		flg[i-1] = false;
	}
	flg[0] = flg[1] = false;
	flg[2] = true;
}

int main(void){
	int t;
	mkPrime();
	while(cin>>t && t){
		int ans = 0;
		for(int i=0;prime[i]<t;i++){
			for(int j=i;prime[j]<t;j++){
				int rem = t - (prime[i] + prime[j]);
				if(rem>=prime[j] && flg[rem] && prime[i]+prime[j]>rem && prime[i]+rem>prime[j] && prime[j]+rem>prime[i])
					ans++;
			}
		}
		cout<<ans<<endl;
	}

	return 0;
}

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

void solve(long long N, std::string S)
{
    long long nr = 0, ng = 0, nb = 0;
    for (size_t i = 0; i < S.length(); i++)
    {
        if (S[i] == 'R')
        {
            nr++;
        }
        else if (S[i] == 'G')
        {
            ng++;
        }
        else
        {
            nb++;
        }
    }

    long long res = nr * ng * nb;

    for (size_t h = 1; h < S.length() / 2 + 1; h++)
    {
        for (size_t i = 0; i + 2 * h < S.length(); i++)
        {
            int j = i + h;
            int k = i + 2 * h;

            if (S[i] == 'R' && S[j] == 'G' && S[k] == 'B')
            {
                res--;
            }

            if (S[i] == 'R' && S[j] == 'B' && S[k] == 'G')
            {
                res--;
            }

            if (S[i] == 'G' && S[j] == 'R' && S[k] == 'B')
            {
                res--;
            }

            if (S[i] == 'G' && S[j] == 'B' && S[k] == 'R')
            {
                res--;
            }

            if (S[i] == 'B' && S[j] == 'R' && S[k] == 'G')
            {
                res--;
            }

            if (S[i] == 'B' && S[j] == 'G' && S[k] == 'R')
            {
                res--;
            }
        }
    }

    cout << res << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 3712
import sys
def read(): return sys.stdin.readline() # 標準入力
def fbit(i, j=-1): return format(i, 'b').zfill(j) # bit 表示
def popcount(x): # ビットカウント
    x=x-((x>>1)&0x5555555555555555)
    x=(x&0x3333333333333333)+((x>>2)&0x3333333333333333)
    x=(x+(x>>4))&0x0f0f0f0f0f0f0f0f;x=x+(x>>8);x=x+(x>>16);x=x+(x>>32)
    return x&0x0000007f


def solv(N:int, M: int, k:list, s: list, p: list):
    ans = 0
    for bits in range(1<<N):
        flag = True
        for i in range(M):
            mask = 0
            for j in s[i]:
                mask = mask|1<<(j-1)
            if not popcount(bits&mask)%2==p[i]: flag = False
        if flag: ans += 1
    print(ans)

def main():
    [N, M] = list(map(int, read().rsplit()))
    k = []; s = []
    for i in range(M):
        _tmp = list(map(int, read().rsplit()))
        k.append(_tmp.pop(0))
        s.append(_tmp)

    p = list(map(int, read().rsplit()))
    solv(N, M, k, s, p)


if __name__ == '__main__':
    main()

Measured memory_bytes: 68444
#include <iostream>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <cstdio>

using namespace std;

int main() {
	double pai = 3.141592653589793;

	int64_t r;
	cin >> r;

	cout << r * 2 * pai << endl;
}

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

long long int h[100005];
long long int memo[100005];
long long int call(long long int i)
{
	if(i<0)
		return 0;
	if(i==0)
		return 0;
  	if(i==1)
      return abs(h[1]-h[0]);
	if(memo[i]!=-1)
		return memo[i];
	
	long long int ans=0;
	
	ans=min(call(i-1)+abs(h[i]-h[i-1]),call(i-2)+abs(h[i]-h[i-2]));
	memo[i]=ans;
	return memo[i];	
}
int main()
{
	long long int n,i;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>h[i];
	}
	memset(memo,-1,sizeof(memo));
	cout<<call(n-1);
	return 0;
}


Measured memory_bytes: 3328
use std::io::prelude::*;
use std::str::FromStr;

fn main() {
    let stdin_ = std::io::stdin();
    let stdout_ = std::io::stdout();
    let mut stdin = stdin_.lock();
    let mut stdout = stdout_.lock();

    let mut buffer = String::new();
    stdin.read_line(&mut buffer).unwrap();
    let mut v = buffer.split_whitespace().map(|s| u64::from_str(s).unwrap());
    let a = v.next().unwrap();
    let b = v.next().unwrap();

    let s = if a > b {
        if a - 1 > b {
            a + a - 1
        } else {
            a + b
        }
    } else {
        if b - 1 > a {
            b + b - 1
        } else {
            a + b
        }
    };

    write!(stdout, "{}\n", s).unwrap();
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n, x;
    cin >> n >> x;
    if (x == 1 || x == 2 * n - 1) {
        cout << "No" << endl;
        return 0;
    } else cout << "Yes" << endl;

    if (n == 2){
        for(int i = 1; i < 4; ++i) cout << i << "\n";
        return 0;
    }

    vector<int> a;
    for (int i = 1; i < 2 * n; ++i) {
        if (i == x - 1) i += 2;
        else a.emplace_back(i);
    }

    for (int i = 0; i < (int) a.size(); ++i) {
        if (i == n - 2) {
            cout << x - 1 << "\n" << x << "\n" << x + 1 << endl;
        }
        cout << a[i] << endl;
    }

    return 0;

}

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

int main(){
    int k,a,b;
    cin>>k>>a>>b;
    if(a/k==b/k && a%k && b%k) cout << "NG" << endl;
    else cout << "OK" << endl;
}


Measured memory_bytes: 3640
n, m = map(int, input().split())
count = 0

def comb(n, r):
    if r == 0 or r == n:
        return 1
    elif r == 1:
        return n
    else:
        return (comb(n - 1, r - 1) + comb(n - 1, r))

if n >= 2:
    count += comb(n, 2)

if m >= 2:
    count += comb(m, 2)

print(count)


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

#define sswap(x, y) { x+=y; y=x-y; x-=y; }
#define LSOne(S) ((S) & (-S))

#define EPS 1e-6
#define MOD 1000000007

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
	ll l, r;
	cin >> l >> r;
	ll mn = 2019;
	for (ll i = l; i < r; i++)
		for (ll j = i+1; j <= r; j++) {
			mn = min(mn, (i*j)%2019);
			if (!mn)
				j = i = r+1;
		}
	cout << mn << ende;
  return 0;
}


Measured memory_bytes: 256
def s()
  gets().chomp
end
def i()
  gets.to_i
end
def li()
  gets.split.map(&:to_i)
end
def ili()
  n = gets.to_i
  as = gets.split.map(&:to_i)
  [n, as]
end

t = i()
qs = []
t.times{
  qs << li()
}

qs.each{|q|
  a, b, c, d = q
  diff = a%b
  if a-b < 0 || (diff < b && diff > c) || (b>d)
    puts "No"
    next
  end
  rui = d-d/b*b
  if (rui==0 && diff <= c) || b <= c+1
    puts "Yes"
    next
  elsif  rui==0 && diff > c
    puts "No"
    next
  end
  gcd = d.gcd(b)

  max = b - gcd + (a%gcd)
  
  if max > c
    puts "No"
  else
    puts "Yes"
  end

}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N; cin >> N;
  vector<int> cnt(9);
  VI xs = {400,800,1200,1600,2000,2400,2800,3200,5000};
  REP(i,N){
	int x;
	cin >> x;
	REP(j,SZ(xs))
	  if(x < xs[j]){
		cnt[j]++;
		break;
	  }
  }

  int c = 0;
  REP(i,8) c += (cnt[i]?1:0);
  cout << max(1, c) << " " << c+cnt[8] << endl;

  return 0;
}


Measured memory_bytes: 256
abc = input()
indiv = abc.split(" ")

#Swap A and B
temp = indiv[0]
indiv[0] = indiv[1]
indiv[1] = temp

#Swap A and C
temp = indiv[2]
indiv[2] = indiv[0]
indiv[0] = temp

print(indiv[0] + " " + indiv[1] + " " + indiv[2])


Measured memory_bytes: 9100
#include<bits/stdc++.h>
using namespace std;
const int N=500005;
int n,q,a[N],l[N],r[N],b[N],c[N],ans[N];
vector<int>v;
vector<pair<int,int>>x[N];
void add(int x,int v)
{
	for(int i=x;i<=n;i+=i&(-i))
		b[i]+=v;
}
int sum(int x)
{
	int v=0;
	for(int i=x;i;i-=i&(-i))
		v+=b[i];
	return v;
}
int main()
{
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		v.push_back(a[i]);
	}
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	for(int i=1;i<=n;i++)
		a[i]=lower_bound(v.begin(),v.end(),a[i])-v.begin()+1;
	for(int i=1;i<=q;i++)
	{
		scanf("%d%d",&l[i],&r[i]);
		x[r[i]].emplace_back(l[i],i);
	}
	for(int i=1;i<=n;i++)
	{
		if(c[a[i]])
			add(c[a[i]],-1);
		c[a[i]]=i;
		add(i,1);
		for(auto zh:x[i])
			ans[zh.second]=sum(i)-sum(zh.first-1);
	}
	for(int i=1;i<=q;i++)
		printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 39040
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int h = Integer.parseInt(sc.next());
        int w = Integer.parseInt(sc.next());
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(sc.next());
        }

        // 主処理
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < a[i]; j++) {
                list.add(i + 1);
            }
        }
        List<String> line = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            line.add(Integer.toString(list.get(i)));
            if ((i + 1) % w == 0) {
                if ((i + 1) / w % 2 == 0) {
                    Collections.reverse(line);
                }
                System.out.println(String.join(" ", line));
                line.clear();
            }
        }

        // 出力
        sc.close();
    }
}


Measured memory_bytes: 27012
#define _USE_MATH_DEFINES

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

double absolute(double x) {
	return x < 0.0 ? -1.0 * x : x;
}

double get_angle(int hour, int minute) {
	double angle = absolute((double)minute*6.0 - (double)hour*30.0 - (double)minute*0.5);
	return angle < 180.0 ? angle : (360.0 - angle); 
}
 
int main() {
	int a,b,h,m;
	cin >> a>>b>>h>>m;
	double radian = get_angle(h,m)*M_PI/180.0;
	double ans = sqrt(pow(b*cos(radian) - a, 2.0) + pow(b*sin(radian), 2.0));
	cout << setprecision(15) << ans << endl;
	return 0;
}


Measured memory_bytes: 4020
#include<cstdio>

using namespace std;

int x, n;
bool wtf[400];

int abs(int x) {
  return x > 0 ? x : -x;
}

int main() {
  scanf("%d %d", &x, &n);
  for (int i = 0; i < n; i++) {
    int p;
    scanf("%d", &p);
    wtf[p] = true;
  }
  int ans = 0;
  for (int i = 0; i < 400; i++) {
    if (!wtf[i]) {
      if (abs(x - i) < abs(ans - x)) {
        ans = i;
      }
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define pb push_back
#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007
#define INF 93193111451418101
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

vector<ll> G[123456];
ll n, m, fir = 0;
list<ll> ans;
bool vis[123456];

void DFS(ll now, bool v) {
  vis[now] = 1;
  if (v)
    ans.push_back(now + 1);
  else if (now != fir)
    ans.push_front(now + 1);
  for (auto &a : G[now]) {
    if (!vis[a]) {
      DFS(a, v);
      return;
    }
  }
}

int main() {
  cin >> n >> m;
  REP(i, m) {
    ll a, b;
    cin >> a >> b;
    a--, b--;
    G[a].pb(b);
    G[b].pb(a);
  }
  REP(i, n) {
    if (G[i].size() == 1)
      fir = i;
  }
  DFS(fir, 1);
  DFS(fir, 0);
  cout << ans.size() << endl;
  bool f = 0;
  for (auto &a : ans) {
    if (f)
      cout << " ";
    cout << a;
    f = 1;
  }
  cout << endl;
}


Measured memory_bytes: 10112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int M = 13;
ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

int mod = 1e9+7;
int main(){
    string S;
    cin >> S;
    int N = S.size();
    ll dp[N][13] = {};
    for (int i=0;i<N;i++){
        if (i == 0){
            if (S[N-1-i] == '?') for(int j=0;j<10;j++) dp[0][j] += 1;
            else {
                int d = S[N-1-i] - '0';
                dp[0][d] += 1;
            }
        }else{
            ll tmp = mpow(10, i);
            if(S[N-1-i] == '?'){
                for(int j=0;j<10;j++){
                    for(int k=0;k<13;k++){
                        dp[i][(j*tmp+k)%13] += dp[i-1][k];
                        dp[i][(j*tmp+k)%13] %= mod;
                    }
                }
            }else{
                int d = S[N-1-i] - '0';
                for(int k=0;k<13;k++){
                    dp[i][(d*tmp+k)%13] += dp[i-1][k];
                    dp[i][(d*tmp+k)%13] %= mod;
                }
            }
        }
    }
    /*
    for(int i=0;i<N;i++){
        for(int j=0;j<13;j++){
            cout << dp[i][j]<< " ";
        }
        cout << endl;
    }
    */
   
    cout << dp[N-1][5] << endl;
}

Measured memory_bytes: 10624
#include<iostream>
#include<vector>
#include<cmath>

using namespace std;

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

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


  vector<int> dp(n);
  for (int i=0; i<n; ++i) {
    if (i==0) dp[0] = 0;
    else if (i==1) {
      dp[1] = abs(costs[0] - costs[1]);
    } else {
      int min = -1;
      for (int j = 1; j<=k; ++j) {
        if (i-j >= 0) {
          int num = dp[i-j] + abs(costs[i-j] - costs[i]);
          if (min == -1 || min > num) min = num;
        } else break;
      } 
      dp[i] = min;
    }
    // cout << dp[i] << endl;
  }
  cout << dp.back() << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(void)
{
  int N,i,j,x,y,MOD,A[200000]={0},check[200000]={},move[200000]={0};
  long long K;
  x=scanf("%d %lld",&N,&K);
  for(i=0;i<N;i++)x=scanf("%d",&A[i]),check[i]=-1;
  for(i=0,j=0;;i=A[i]-1,j++)if(check[i]<0)check[i]=j,move[j]=i;else{x=j-1,y=check[i],MOD=x-y+1;break;}
  if(K>x)K=(K-y)%MOD+y;
  return printf("%d\n",move[K]+1),0;
}

Measured memory_bytes: 4076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 100000;
vector<ll> a(MAX_N);

int main(void) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) { 
        cin >> a[i];
    }
    sort(a.begin(), a.end(), greater<int>());

    ll s = -1, t = -1, ans = 0LL; 
    for (int i = 0; i < n-1; i++) {
        if (s > 0 && a[i] == a[i+1]) {
            t = a[i];
            ans = s * t;
            break;
        }
        if (s < 0 && a[i] == a[i+1]) {
            s = a[i];
            i++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N,M;
	cin >> N >> M;
	vector<ll> X(M);
	if(N>=M){
		cout << 0 << endl;
		return 0;
	}
	FOR(i,0,M)cin>>X[i];
	SORT(X);
	priority_queue<ll> Q;
	FOR(i,0,M-1){
		Q.push(X[i]-X[i+1]);
	}
	ll ans = 0;
	while(Q.size() != N-1){
		ans -= Q.top();
		Q.pop();
	}
	cout << ans << endl;
}


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

string a;

bool f() {
	int i;
	bool v[150] = {};
	for (i = 0; a[i]; i++) {
		if (v[a[i]]) return 0;
		v[a[i]] = 1;
	}
	return 1;
}

int main()
{
	int i, j, k;
	cin >> a;
	a += 'a' - 1;
	for (i = a.size() - 1; i >= 0; i--) {
		for (j = a[i] + 1; j <= 'z'; j++) {
			a[i] = j;
			if (f()) {
				for (k = 0; a[k]; k++) cout << a[k];
				return 0;
			}
		}
		a[i] = '\0';
	}
    cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n,a[10000000],sum=0;
  map<int,int> date;
  vector<int> b;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
    date[a[i]]++;
    if(date[a[i]]==1) b.push_back(a[i]);
  }
  for(int i=0;i<b.size();i++){
    sum+=(((date[b[i]]-1)*(date[b[i]])/2));
  }
  int save;
  for(int i=0;i<n;i++){
    save=sum;
    save-=(((date[a[i]]-1)*(date[a[i]])/2));
    save+=(((date[a[i]]-2)*(date[a[i]]-1)/2));
    cout<<save<<"\n";
  }
}
       

Measured memory_bytes: 13812
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
LL fac[SIZE];
void ADD(LL& x,LL v){
    x=(x+v)%MOD;
    if(x<0)x+=MOD;
}
LL mypow(LL x,LL y){
    x%=MOD;
    LL res=1%MOD;
    while(y){
        if(y&1)res=res*x%MOD;
        y>>=1;
        x=x*x%MOD;
    }
    return res;
}
int p[SIZE];
int BIT[SIZE];
void ins(int x){
    for(;x<SIZE;x+=x&-x)BIT[x]++;
}
int qq(int x){
    int res=0;
    for(;x;x-=x&-x)res+=BIT[x];
    return res;
}
int BIT2[SIZE];
void ins2(int x){
    for(;x<SIZE;x+=x&-x)BIT2[x]++;
}
int qq2(int x){
    int res=0;
    for(;x;x-=x&-x)res+=BIT2[x];
    return res;
}
bool use[SIZE];
int main(){
    fac[0]=1;
    REPP(i,1,SIZE)fac[i]=fac[i-1]*i%MOD;
    DRI(n);
    LL zero=0;
    REP(i,n){
        RI(p[i+1]);
        if(!p[i+1])zero++;
        else use[p[i+1]]=1;
    }
    LL sum=0;
    int it=0;
    REPP(i,1,n+1)
        if(!use[i]){
            ins(i);
            sum+=i-1-it;
            it++;
        }
    sum%=MOD;
    LL an=fac[zero];
    LL emp=0;
    LL inv_two=mypow(2,MOD-2);
    REPP(i,1,n+1){
        if(!p[i]){
            ADD(an,sum*fac[zero-1]%MOD*fac[n-i]);
            if(zero>1)ADD(an,fac[zero]*(zero-emp-1)%MOD*inv_two%MOD*fac[n-i]);
            emp++;
        }
        else{
            LL ll=qq(p[i]);
            LL ll2=qq2(p[i]);
            ADD(an,(p[i]-1-ll-ll2)*fac[zero]%MOD*fac[n-i]);
            if(zero)ADD(an,ll*(zero-emp)%MOD*fac[zero-1]%MOD*fac[n-i]);
            ADD(sum,-(zero-ll));
            ins2(p[i]);
        }
        //printf("%d:%lld\n",i,an);
    }
    cout<<an<<endl;
    return 0;
}


Measured memory_bytes: 14464
// Author: drunken_legend
 
#include <bits/stdc++.h>
using namespace std;
#define lli long long int

int main()
{
    int n;
    cin >>n;
    int a,b,c;
    int dp[n][3];
    for (int i = 0; i < n; ++i)
    {
    	/* code */cin>>a>>b>>c;
    	if(i==0){
    		dp[0][0]=a;
    		dp[0][1]=b;
    		dp[0][2]=c;
    	}
    	else{
    		dp[i][0]=a+max(dp[i-1][1],dp[i-1][2]);
    		dp[i][1]=b+max(dp[i-1][2],dp[i-1][0]);
    		dp[i][2]=c+max(dp[i-1][1],dp[i-1][0]);

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

Measured memory_bytes: 4764
n = gets.chomp.to_i
a = gets.split.map(&:to_i)
mean = a.reduce(:+) / n
cost1 = a.reduce(0) { |sum, e| sum += (e-mean)**2 }
cost2 = a.reduce(0) { |sum, e| sum += (e-mean-1)**2 }
puts [cost1,cost2].min


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

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

    int A, B, K;
    cin >> A >> B >> K;
    for (int i = 0; i < K; ++i) {
        if (A + i > B) break;
        cout << A + i << endl;
    }
    for (int i = K - 1; i >= 0; --i) {
        if (B - i <= A + K - 1) continue;
        cout << B - i << endl;
    }

    return 0;
}

Measured memory_bytes: 256
let s = read_line () in
let n = String.length s in
let rec fill i k acc =
    if i = n then acc else
        fill (i + 1) (1 - k) (acc + if s.[i] = '0' && k = 0 || s.[i] = '1' && k = 1 then 0 else 1)
in
min (fill 0 0 0) (fill 0 1 0) |> Printf.printf "%d\n"

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

using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void debugF(ostream &os) {os << endl;}
template <typename Head, typename... Tail>
void debugF(ostream &os, Head H, Tail... T) { os << " " << H; debugF(os, T...); }
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debugF(cout, __VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); os << (i>0 ? " ":"") << v[i++]); return os;}

class UnionFind{
  public:
  vector<int> par;
  UnionFind(int n) : par(n,-1) {}

  int root(int v){
    if(v == -1) return v;
    return par[v] < 0 ? v : (par[v] = root(par[v]));
  }

  void merge(int u, int v){
    u = root(u); v = root(v);
    if(u == -1 || v == -1 || (u == v)) return;
    if(par[u] >= par[v]) swap(u,v);
    //link v -> u
    par[u] += par[v];
    par[v] = u;
  }

  int size(int u){
    return u == -1 ? 0 : -par[root(u)];
  }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, i, u, v;
    cin >> n >> m;
    auto U = UnionFind(n);
    for(i=0;i<m;i++){
        cin >> v >> u;
        v--;u--;
        U.merge(v,u);
    }
    int ans = 1;
    for(i=0;i<n;i++){
        ans = max(ans, U.size(i));
    }
    cout << ans << "\n";
    return 0;
}

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

int main(){
  int Math,Greedy,Geometry,DP,Graph,Other;

  while(cin >> Math >> Greedy >> Geometry >> 
	DP >> Graph >> Other){

    if(!Math && !Greedy && !Geometry && !DP &&
       !Graph && !Other) break;

    int MD = Math + DP , GG = Greedy + Graph;
    int GO = Geometry + Other;

    int ans = 0;
    if(MD >= 0 && GG >= 0 && GO >= 0)
      ans = max(ans, MD/3 + GG/3 + GO/3);

    if(MD >= 1 && GG >= 1 && GO >= 1)
      ans = max(ans, ((MD-1)/3 + (GG-1)/3 + (GO-1)/3) + 1);

    if(MD >= 2 && GG >= 2 && GO >= 2)
      ans = max(ans, ((MD-2)/3 + (GG-2)/3 + (GO-2)/3) + 2);

    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#import sys 
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n,k=map(int,input().split())
p=list(map(int,input().split()))
p.sort()
print(sum(p[:k]))

Measured memory_bytes: 67232
from collections import deque

V, E = map(int, input().split())
Edge = [[] for _ in range(V)]

for _ in range(E): #??£????????????
    u, v = map(int, input().split())
    Edge[u].append(v)
    Edge[v].append(u)
    
Group = [-1] * V #Group???????????????????????°?????????????±????????????????????????°?????????????????°??????????????????????????????
Cnt = 0 # Group???????????????????±????????????????

for i in range(V):
    if Group[i] == -1:
        Group[i] = Cnt
        Stack = deque([i])
        while Stack:
            v = Stack.pop()
            for c in Edge[v]:
                if Group[c] == -1:
                    Group[c] = Cnt
                    Stack.append(c)
        Cnt += 1

q = int(input())
for _ in range(q):
    s, t = map(int, input().split())
    print('yes' if Group[s] == Group[t] else 'no')

Measured memory_bytes: 26908
import numpy as np
from numba import njit

N,K=map(int,input().split())
a=np.array([int(i) for i in input().split()],dtype=np.int64)

dp=np.full((N+1,K+1),0,dtype=np.int64)
c=np.full(K+2,0,dtype=np.int64)
MOD=10**9+7

@njit('i8(i8,i8,i8,i8[:,:],i8[:])', cache=True)
def main(N,K,MOD,dp,c):

    dp[0][0]=1
    for i in range(1,N+1):
        c[0]=0
        for j in range(1,K+2):
            c[j]=(c[j-1]+dp[i-1][j-1])%MOD
        for j in range(K+1):
            dp[i][j]=(c[j+1]-c[max(0,j-a[i-1])])%MOD

    return dp[N][K]

print(main(N,K,MOD,dp,c))


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

int ans[52][52];
char str[52][52], a[52][52];
int dy[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dx[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int main(){
	int h, w;
	scanf("%d%d", &h, &w);
	fill((char*)a, (char*)(a+52), '.');
	rep(i,h)scanf("%s", str[i]);
	rep(i,h)rep(j,w)a[i+1][j+1] = str[i][j];
	
	rrep(y,h)rrep(x,w){
		if(a[y][x] == '#'){
			rep(i,8)ans[y+dy[i]][x+dx[i]]++;
		}
	}
	
	rrep(i,h){
		rrep(j,w){
			if(a[i][j] == '#')printf("#");
			else printf("%d", ans[i][j]);
		}
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define pb push_back
#define fi first
#define se second
const int N=1e6+10;
const int mod7=1e9+7;
const int mod=998244353;
const double pi=3.14;
void read(int &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
void read(ll &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
int vis[105];
int main()
{
    int x,n;
    read(x),read(n);
    for(re int i=1,y;i<=n;i++)
    {
        read(y);
        vis[y]=1;
    }
    int minx=1000,ans;
    for(re int i=0;i<=101;i++)
    {
        if(vis[i]) continue;
        if(minx>abs(i-x)) ans=i,minx=abs(i-x);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3632