akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

/* Dinic */

// (行き先,容量,逆辺)
struct edge{
    int to;
    ll cap;
    int rev;
};

const int MAX_V = 111; // TODO:initialize
const ll F_INF = LLONG_MAX/3; // TODO:initialize
vector<edge> G[MAX_V];
ll level[MAX_V]; // sからの距離
int iter[MAX_V]; // どこまで調べ終わったか

void add_edge(int from, int to, ll cap){
    G[from].pb({to,cap,(int)G[to].size()});
    G[to].pb({from,0,(int)G[from].size()-1});
}

void dinic_bfs(int s){
    memset(level,-1,sizeof(level));
    queue<int> que;
    level[s]=0;
    que.push(s);
    while(!que.empty()){
        int v = que.front();
        que.pop();
        rep(i,G[v].size()){
            edge &e = G[v][i];
            if(e.cap>0 && level[e.to]<0){
                level[e.to] = level[v]+1;
                que.push(e.to);
            }
        }
    }
}

// 増加パスをdfsで探す
ll dinic_dfs(int v, int t, ll f){
    if(v==t) return f;
    for(int &i=iter[v]; i<(int)G[v].size(); ++i){
        edge &e=G[v][i];
        if(e.cap>0 && level[v]<level[e.to]){
            ll d = dinic_dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

// sからtへの最大流
ll max_flow(int s, int t){
    ll flow = 0;
    while(1){
        dinic_bfs(s);
        if(level[t]<0) return flow;
        memset(iter,0,sizeof(iter));
        ll f;
        while( (f=dinic_dfs(s,t,F_INF)) > 0 ) flow+=f;
    }
}

/*
「Xが赤でYが青だとZ円罰金」
X->Yに容量Zの辺を貼る

「Xが赤 or 青だとZ円罰金」
赤だと罰金:X->Tに容量Zの辺
青だと罰金:S->Xに容量Zの辺
*/

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

    // S:割らない, T:割る
    int S = n, T = n+1;

    ll ss = 0;
    rep(i,n){
        if(a[i]>0){
            ss += a[i];
            add_edge(S,i,a[i]);
        }
        else{
            add_edge(i,T,-a[i]);
        }

        int I=i+1;
        rep(j,i){
            int J=j+1;
            if(I%J == 0) add_edge(i,j,F_INF);
        }
    }

    cout << ss - max_flow(S,T) << endl;
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map(String::toInt)
    var aMatrix = Array(n) {Array(m) {0}}
    var bVector = Array(m) {0}

    // Read matrix elements.
    repeat(n) {
        val values = readLine()!!.split(" ").map(String::toInt).toTypedArray()
        aMatrix[it] = values
    }

    // Read vector elements.
    repeat(m) { bVector[it] = readLine()!!.toInt() }

    // Compute A[i][j] * B[j] for each i.
    aMatrix.forEach {
        val sum = it.zip(bVector) { a, b -> a * b } .sum()
        println("$sum")
    }
}



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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

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

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

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

	cout << min(A*N, B) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    string s;
    cin >> s;

    VI a(4);
    REP(i,4) a[i] = (s[i] - '0');

    string t;
    if (a[0] + a[1] + a[2] + a[3] == 7){
        t = "+++";
    }
    if (a[0] + a[1] + a[2] - a[3] == 7){
        t = "++-";
    }
    if (a[0] + a[1] - a[2] + a[3] == 7){
        t = "+-+";
    }
    if (a[0] + a[1] - a[2] - a[3] == 7){
        t = "+--";
    }
    if (a[0] - a[1] + a[2] + a[3] == 7){
        t = "-++";
    }
    if (a[0] - a[1] + a[2] - a[3] == 7){
        t = "-+-";
    }
    if (a[0] - a[1] - a[2] + a[3] == 7){
        t = "--+";
    }
    if (a[0] - a[1] - a[2] - a[3] == 7){
        t = "---";
    }

    REP(i,3) cout << s[i] << t[i];
    cout << s[3] << "=7" << endl;

    return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
v = list(map(int,input().split()))

m=[]
for i in range(k+1):
 for j in range(min(k,n)-i+1):
  # print(i,j)
  t=sorted(v[:i]+v[:~j:-1])
  while t and(k-i-j)*t[0]<0:t.pop(0);j+=1
  m+=sum(t),
print(max(m))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    cout<<max((ll)0,c-(a-b))<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int N,K;
    cin>>N;
    double* v=new double[N]();
    double sum;
    int cnt;
    for(int i=0;i<N;i++){
        cin>>v[i];
    }
    cnt=0;
    while(1){
        if(v[cnt]>v[cnt+1]){
            K=v[cnt+1];
            v[cnt+1]=v[cnt];
            v[cnt]=K;
            cnt=0;
        }else{
            cnt++;
        }

        if(cnt==N-1){
            break;
        }
    }

    for(int i=0;i<N-1;i++){
        sum=(v[i]+v[i+1])/2;
        v[i+1]=sum;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	int n;
	cin>>n;
	vector<int> e(n+1);
	FOR(i,0,n+1){
		cin>>e[i];
	}
	LL ans=0;
	FOR(i,0,n){
		int t;
		cin>>t;
		if(e[i]>t){
			ans+=t;
			e[i]-=t;
			t=0;
		}else{
			ans+=e[i];
			t-=e[i];
		}
		int ii=i+1;
		if(e[ii]>t){
			ans+=t;
			e[ii]-=t;
			t=0;
		}else{
			ans+=e[ii];
			e[ii]=0;
			t-=e[ii];
		}
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 640
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;

 main()

{
    fast
    int x,y;
    cin>>x>>y;
    int a=(4*x-y);
    if(a%2==1)
    {
        cout<<"No"<<endl;
        return 0;
    }
    a=a/2;
    int b=x-a;
    if(b>=0 && a>=0 && (a+b)==x)
    {
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
    return 0;

}





































Measured memory_bytes: 3652
// g++ -std=gnu++1y -O2 xxx.cpp

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    ll H,W; cin>>H>>W;

    if (H==1 || W==1) {
        cout << 1 << endl;
    } else {
        cout << (H * W + 1) / 2 << endl;
    }

    return 0;
}

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

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

int main() {
    int A, B;
    cin >> A >> B;
    int x = A - 2 * B;
    if(x < 0) x = 0;
    cout << x << endl;
}
 

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

using namespace std;
using ll = long long;
using vi = vector<int>;

#define in(v) v; cin >> v;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rrep(i,n) for(long long i=(n);i>=0;--i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

// ========== debug ==========
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(size_t i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
ostream& operator<<(ostream& os,const vector<char>&v){for(size_t i=0;i<v.size();++i)os<<v[i];return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
void debug2() {cerr << "\n";}
template<class First> void debug2(const First& first) {cerr<<first<<" ";}
template<class First, class... Rest> void debug2(const First& first, const Rest&... rest) {cerr<<first<<" ";debug2(rest...);}
#else
#define debug(...) 42
#define debug2(...) 42
#endif
// ===========================

int main() {
  int L, R, d;
  ins(L, R, d);

  int ans = 0;
  rep(i, R-L+1) {
    if ((L + i) % d == 0)
      ++ans;
  }
  cout << ans << endl;

  return 0;
}


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

int main(){

    string s;

    cin >>s;

    int y,m,d;

    y=stoi(s.substr(0,4));
    m=stoi(s.substr(5,2));
    d=stoi(s.substr(8,2));

    if(y>=2019){
        if(m>=5){
            cout << "TBD" << endl;
            return 0;
        }
    }

    cout << "Heisei" << endl;

    return 0;
}

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

void solve(int n,int W,const int w[],const int v[]){
	long long dp[n+1][W+1];
	int i,j;
	for(i=0;i<=W;i++){
		dp[0][i]=0;
	}
	for(i=0;i<=n;i++){
		dp[i][0]=0;
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=W;j++){
			if(j<w[i]){
				dp[i][j] = dp[i-1][j];
			}else{
				dp[i][j] = max(dp[i-1][j],v[i]+dp[i-1][j-w[i]]);
			}
		}
	}
	// for(i=0;i<=n;i++){
	// 	for(j=0;j<=W;j++){
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	cout<<dp[n][W]<<endl;
}

int main(){
	int test;
  	test=1;
	while(test--) {
	int n,W,i,j;
	int w[101],v[101];
	cin>>n>>W;

	for(i = 1;i <= n; i++){
		cin>>w[i];
		cin>>v[i];
}
	solve(n,W,w,v);

}	

	return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;




int main() {
//    cout << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    string s;
    cin >> s;
    for (int i = 0; i < s.size() - 1; i++) {
        if (s[i] == s[i + 1]) {
            cout << "Bad";
            return 0;
        }
    }

    cout << "Good";







}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//3*3の2次元配列A
//vector<vector<int>> A(3, vector<int>(3));

void solve(){
    string S;
    cin >> S;
    if(S[0] == 'A' && S[1] == 'A' && S[2] == 'A' || S[0] == 'B' && S[1] == 'B' && S[2] == 'B'){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int n; cin>>n;
    string ans="Christmas";
    if(n<25) ans+=" Eve";
    if(n<24) ans+=" Eve";
    if(n<23) ans+=" Eve";
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> p2;
ll p[200005],inv[200005],hell=pow(10,9)+7;
ll exp(ll x,ll y){
    ll res=1;
    while(y>0){
        if(y&1)
        res=(res*x)%hell;
        y>>=1;
        x=(x*x)%hell;
    }
    return res;
}
ll bin(ll n,ll r){
    ll res=p[n];
    res*=inv[n-r];
    res%=hell;
    res*=inv[r];
    res%=hell;
    return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k,res=0;
    cin>>n>>k;
    p[0]=1;
    inv[0]=1;
    for(ll i=1;i<200005;i++){
        p[i]=(i*p[i-1])%hell;
        inv[i]=exp(p[i],hell-2);
    }
    for(ll i=0;i<min(k+1,n);i++){
        res+=(bin(n,i)*bin(n-1,i))%hell;
        res%=hell;
    }
    cout<<res;
}


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

ll n, p, a[60], ans, dp[60][2];
// dp[i][j] iは何袋までか jは2で割ったあまり
int main() {
    cin >> n >> p;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 2; j++) {
            dp[i + 1][(j + a[i]) % 2] += dp[i][j];
            dp[i + 1][j] += dp[i][j];
        }
    }
    cout << dp[n][p] << endl;
}

Measured memory_bytes: 3604
var
  a:array[0..100000]of longint;
  n,x,i,ans:longint;
Function g(x,y:longint):longint;
begin
  if x mod y=0 then exit(y) else
  exit(g(y,x mod y));
end;
begin
  readln(n,x);
  a[0]:=x;
  for i:=1 to n do
    begin
      read(a[i]);
    end;
  ans:=abs(a[0]-a[1]);
  for i:=0 to n-1 do
    begin
      if a[i]<>a[i+1] then ans:=g(ans,abs(a[i]-a[i+1]));
    end;
  write(ans);
end.


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

int main() {
    int a,b;
    cin >> a >> b;
    string out = "";
    if (a > b) out = "a > b";
    else if (a < b) out = "a < b";
    else out = "a == b";
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 3184
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    i32 a, b, c, d;
    std::cin >> a >> b >> c >> d;
    std::cout << std::max(i32{0}, std::min(b, d) - std::max(a, c)) << '\n';
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (a,b) = readLine()!!.split(" ").map { it.toInt() }

    if ( b == 1) {
        println(0)
        return
    }

    var cnt = 1
    var now = a
    while(now < b) {
        now += a-1
        cnt += 1
    }

    println(cnt)
}

Measured memory_bytes: 36088
N = int(input())
a = list(map(int,input().split()))
table = [0 for _ in range(100001)]
for i in a:
    table[i] += 1
ans = [0 for _ in range(100001)]
for j in range(1,100000):
    ans[j] = table[j-1]+table[j] + table[j+1]
print(max(ans))

Measured memory_bytes: 85972
fun main(args: Array<String>) {
    val s = readLine() ?: return
    val h = s.length / 2
    val fh = s.take(h)
    val sh = s.takeLast(h)
    if (fh == sh.reversed()) {
        println("0")
        return
    }
    val hag = 0.until(h).sumBy {
        if (fh[it] != sh[h - it - 1]) {
            1
        } else {
            0
        }
    }
    println(hag.toString())
}

Measured memory_bytes: 33800
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
 
P = (A1 - B1) * T1
Q = (A2 - B2) * T2
if P > 0:
	P *= -1
	Q *= -1
 
if P + Q < 0:
	print(0)
elif P + Q == 0:
	print("infinity")
else:
	S = (-P) // (P + Q)
	T = (-P) % (P + Q)
	if T != 0:
		print(S * 2 + 1)
	else:
		print(S * 2)

Measured memory_bytes: 38480
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define emp emplace

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int MOD = 1000 * 1000 * 1000 + 7;
const int H = 100010, N = 3010;

int fat[2*H], ifat[2*H];
int pd[N];

int mul(ll a, ll b)
{
	return (a*b)%MOD;
}

int inv(int x)
{
	const int y = (MOD-2);
	int ret = 1, base = x;
	for (int i = 0; y >> i; i++)
	{
		if ((y >> i)&1)
			ret = mul(ret, base);
		base = mul(base, base);
	}
	return ret;
}

int ways(int dx, int dy)
{
	if (dx < 0) dx *= -1;
	if (dy < 0) dy *= -1;
	return mul(fat[dx + dy], mul(ifat[dx], ifat[dy]));
}

int main()
{
	fat[0] = 1;
	ifat[0] = 1;
	for (int i = 1; i < 2*H; i++)
	{
		fat[i] = mul(i, fat[i-1]);
		ifat[i] = inv(fat[i]);
	}
	int h, w, n;
	scanf("%d %d %d", &h, &w, &n);
	vector<ii> v;
	for (int i = 0; i < n; i++)
	{
		int x, y;
		scanf("%d %d", &x, &y);
		v.eb(x, y);
	}
	v.eb(h, w);
	sort(v.begin(), v.end());
	
	for (int i = 0; i < v.size(); i++)
	{
		int x = v[i].fi, y = v[i].se;
		pd[i] = ways(x-1, y-1);
		for (int j = i-1; j >= 0; j--)
		{
			int xx = v[j].fi, yy = v[j].se;
			if (xx <= x and yy <= y)
			{
				int m = mul(pd[j], ways(x-xx, y-yy));
				pd[i] = (MOD + pd[i] - m)%MOD;
			}
		}
	}
	printf("%d\n", pd[(int)v.size()-1]);
	return 0;
}

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

#define int long long

#define MOD 1000000007
#define maxlen 9223372036854775807
#define minlen -9223372036854775807


int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
vector<int> primeFact(int n){vector<int> ans;for(int t=2;t<=sqrt(n);t++){if(n%t==0){ans.push_back(t);while(n%t==0){n=n/t;}}}if(n>2)ans.push_back(n);return ans;}
vector<int> fact(int n){vector<int> ans;for(int i=1;i<=sqrt(n);i++){if(n%i==0){if( i*i == n ){ans.push_back(i);}else{ans.push_back(i);ans.push_back(n/i);}}}return ans;}
int powerr(int base,int exp,int mod) { if(exp==0)return 1;int t = powerr(base,exp/2,mod)%mod;if(exp%2==0){return (t%mod*t%mod)%mod;}else{return (t%mod*t%mod*base%mod)%mod;}} 
void fastio(){ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}

vector<int> dp(9,1);

void dpsolve(){
	for(int i=2;i<9;i++ ){
		dp[i] = dp[i-1]*i;
	}
}


int solve( vector<int> &a , int n ){
	int ans = 1;


	for(int i=n-1;i>=0;i--){
		int t=0;
		for(int j=i+1;j<n;j++){
			if( a[i] > a[j] ){
				t++;
			}
		}

		ans += t*( dp[n-1-i] ); 


	}




	return ans;
}


int32_t main(){
	fastio();
	int n;
	cin >> n;
	dpsolve();
	vector<int> a(n),b(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}

	for(int j=0;j<n;j++){
		cin >> b[j];
	}

	int l = solve( a , n );
	int r = solve(b,n);

	//cout << l << "  " << r << "\n";
	cout << abs( l-r ) << "\n";	



	return 0;
}






Measured memory_bytes: 256
def main():
    n = int(input())
    b = [int(x) for x in input().split()]
    ans = 0
    for i in range(n-2):
        ans += min(b[i],b[i+1])
    ans += b[0]
    ans += b[-1]
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

signed main(){
	string s;cin>>s;
	bool flag=true;
	rep(i,s.size()/2){
		if(s[i]!=s[s.size()-i-1])flag=false;
	}
	puts(flag?"Yes":"No");
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int a[55];
long long dp[55][2655];
int main(){
	int n,p;
	while(cin>>n>>p){
		memset(dp,0,sizeof(dp));
		for(int i=0;i<n;i++){
			cin>>a[i];
			
			for(int j=i+1;j>0;j--){
				for(int k=0;k<=2500;k++){
					dp[j][k+a[i]]+=dp[j-1][k];
				}
			}
			dp[1][a[i]]++;
		}
		/*for(int i=1;i<=5;i++){
			for(int j=0;j<=30;j++)
				printf("%d ",dp[i][j]);
			cout<<endl;
		}*/
		long long ans=0;
		for(int i=1;i<=n;i++){
			ans+=dp[i][i*p];
		}
		cout<<ans<<endl;
	
		
	}
	
	return 0 ;
}
/*
8 5
3 6 2 8 7 6 5 9
33 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3

19
*/

Measured memory_bytes: 1408
float a,b,c,d,e,f,y;main(){for(;~scanf("%f%f%f%f%f%f",&a,&b,&c,&d,&e,&f);printf("%.3f %.3f\n",(c-b*y)/a,y))y=(a*f-c*d)/(a*e-b*d);}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main(void)
{
    int a,b,k;
    cin >> a >> b >> k;
    if(b-a<=2*k-2){
        for(int i=a;i<b+1;i++) cout << i << "\n";
    }
    else{
        for(int i=0;i<k;i++) cout << a+i << "\n";
        for(int i=k-1;i>=0;i--) cout << b-i << "\n";
        
    }
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define REL

#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <string>
#include <set>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <cassert>
#include <complex>
#include <stack> 
#include <random>

using namespace std;

typedef int64_t i64;
typedef long long LL;
typedef long long ll;
typedef long double LD;
typedef complex <LD> cld;
typedef unsigned int uint;
typedef complex <double> cd;
typedef unsigned long long ULL;

#define endl "\n"
#define dendl "\n\n"
#define mp make_pair
#define mt make_tuple
#define size(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

/////////////////////////////////////////////////////////////////////

template <typename T>
T sqr(T a) {
	return a * a;
}

template <typename T>
int sign(T a) {
	if (a == 0)
		return 0;
	return (a > 0 ? 1 : -1);
}

template <typename T>
bool uax(T& a, const T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T>
bool uin(T& a, const T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T1, typename T2>
istream& operator >> (istream& in, pair<T1, T2>& p) {
	in >> p.first >> p.second;
	return in;
}

template <typename T1, typename T2>
ostream& operator << (ostream& out, pair<T1, T2>& p) {
	out << p.first << ' ' << p.second;
	return out;
}

mt19937_64 rnd(0);

const int LOG = 64;
const int N = (int)2e5 + 7;
const int MAXN = (int)3e3 + 7;
const int MOD = (int)998244353;
const int INF = (int)1e9 + 7;
const int CONST = 450;
const LL LINF = (i64)1e17;
const LD PI = 3.1415926535897932384626433832795;
const LD EPS = 1;

/////////////////////////////////////////////////////////////////////

int gcd(int a, int b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

void solve() {
	LL ans = 0;
	int n; cin >> n;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			for (int k = 1; k <= n; k++) {
				int d = gcd(gcd(i, j), k);
				ans += d;
			}
		}
	}
	cout << ans;
}

int main() {
	double start = clock();
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	cout << fixed << setprecision(20);
	cerr << fixed << setprecision(20);
#else
	cout << fixed << setprecision(20);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	rnd.seed(time(0));
#endif

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

#ifdef _DEBUG
	cout << endl << "Time is " << (clock() - start) / 1000.0;
#endif
}

Measured memory_bytes: 3656
#include<iostream>
using namespace std;
#include<string>
#include<strstream>
#include<sstream>
#include<algorithm>
#include<math.h>
#include<iomanip>
int main()
{
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end(), greater<int>());
	if (t > s)
		cout << "Yes";
	else
		cout << "No";
}

Measured memory_bytes: 3580
def modfac(n, MOD):
 
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
    return factorials, invs


def modnCr(n,r,mod,fac,inv): #上で求めたfacとinvsを引数に入れるべし(上の関数で与えたnが計算できる最大のnになる)

    return fac[n] * inv[n-r] * inv[r] % mod


N,M,K = map(int,input().split())

mod = 998244353
fac,inv = modfac(3*(10**5),mod)

ans = 0

for i in range(K+1):

    now = modnCr(N-1,i,mod,fac,inv)
    ans += M * now * pow(M-1,N-i-1,mod)
    ans %= mod

print (ans)


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

#define PI 3.14159265358979323846
#define int long long int
#define ff first
#define ss second
#define pb push_back

#define N 1010

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    double a, b, x;
    cin >> a >> b >> x;
    double k = a * a * b / 2;

    double ans;
    if(x >= k)
    	ans = atan(2 * (-x + a * a * b) / (a * a * a)) * 180 / PI;
    else
    	ans = atan(a * b * b / (2 * x)) * 180 / PI;
    cout << fixed << ans << "\n";
	return 0;	
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
H,W = map(int,input().split())
meiro = []
for h in range(H):
    meiro.append(input())
from collections import deque
Q = deque([[0,0]])
ansmap = [[-1 for _ in range(W)] for __ in range(H)]
ansmap[0][0] = 0
step = 0
while Q:
    cue = Q.popleft()
    step = ansmap[cue[0]][cue[1]]
    for i in range(4):
        # 上
        if cue[0]-1 >= 0:
            if meiro[cue[0]-1][cue[1]] == "." and (ansmap[cue[0]-1][cue[1]] > step+1 or ansmap[cue[0]-1][cue[1]] == -1):
                ansmap[cue[0]-1][cue[1]] = step+1
                Q.append([cue[0]-1,cue[1]])
        # 右
        if cue[1]+1 < W:
            if meiro[cue[0]][cue[1]+1] == "." and (ansmap[cue[0]][cue[1]+1] > step+1 or ansmap[cue[0]][cue[1]+1] == -1):
                ansmap[cue[0]][cue[1]+1] = step+1
                Q.append([cue[0],cue[1]+1])
        # 下
        if cue[0]+1 < H:
            if meiro[cue[0]+1][cue[1]] == "." and (ansmap[cue[0]+1][cue[1]] > step+1 or ansmap[cue[0]+1][cue[1]] == -1):
                ansmap[cue[0]+1][cue[1]] = step+1
                Q.append([cue[0]+1,cue[1]])
        # 左
        if cue[1]-1 >= 0:
            if meiro[cue[0]][cue[1]-1] == "." and (ansmap[cue[0]][cue[1]-1] > step+1 or ansmap[cue[0]][cue[1]-1] == -1):
                ansmap[cue[0]][cue[1]-1] = step+1
                Q.append([cue[0],cue[1]-1])
cnt=0
for m in meiro:
    cnt += m.count('#')
if ansmap[H-1][W-1] == -1:
    print(-1)
else:
    print(H*W - ansmap[H-1][W-1]-1 - cnt)


Measured memory_bytes: 3444
/////////////////////////////////////////////////
//                                             //
//                 _ooOoo_                     //
//                o8888888o                    //
//                88" . "88                    //
//                (| -_- |)                    //
//             ____/`---'\\____                //
//           .'  \|     |//  `.                //
//           /  \|||  :  |||// \               //
//          /  _||||| -:- |||||- \             //
//          |   | \\  -  /// |   |             //
//          | \_|  ''\---/''  |  |             //
//          \  .-\__  `-`  ___/-. /            //
//         ___`. .'  /--.--\  `. . __          //
//      ."" '<  `.___\_<|>_/___.'  >'"".       //
//     | | :  `- \`.;`\ _ /`;.`/ - ` : | |     //
//     \  \ `-.   \_ __\ /__ _/   .-` /  /     //
//=====`-.____`-.___\_____/___.-`____.-'=======//
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^//
//.............................................//
/////////////////////////////////////////////////

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll modn=1000000007;
const ll INF = 0x3f3f3f3f;
int n,kk;
ll dp[500][500];
int h[500];
int main(){
    memset(dp,0x3f,sizeof(dp));
    scanf("%d%d",&n,&kk);
    for(int i=0;i<n;i++){
        scanf("%d",&h[i+1]);
    }
    dp[0][0]=0;
    for(int i=1;i<=n;i++){
        dp[i][i-1]=h[i];
        for(int j=0;j<i-1;j++){
            for(int k=0;k<n;k++){
                if(i-k-1>=0 &&j-k>=0)
                    dp[i][j]=min(dp[i][j],dp[i-k-1][j-k]+max(h[i]-h[i-k-1],0));
            }
        }
        //for(int j=0;j<=n;j++)cout<<dp[i][j]<<" ";
        //cout<<endl;
    }
    ll ans = 0x3f3f3f3f3f3f3f3fLL;
    //cout<<kk<<endl;
    for(int i=0;i<=n;i++){
        for(int j=0;kk-n+i>=j;j++){
            //cout<<i<< " "<<j<<endl;
            ans = min(ans,dp[i][j]);
        }
    }
    cout<<ans<<endl;
    return 0;
}
/*
5
1 2 3 4 5
5 3 2 1 4
*/


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 222;
const LL mod = 1e9 + 7;
int N;
LL K;
LL A[MC];
LL B[MC];
int s[MC];
map<vector<LL>,int> key;
vector<vector<pair<LL,LL> > > ans;

int main(){
	cin >> N >> K;
	repp(i,0,N){
		cin >> A[i];
		s[i] = i;
	}
	sort(A,A+N);
	repp(i,0,61){
		if(i > K) break;
		vector<LL> v;
		repp(j,1,N) v.PB((A[j]>>i)-(A[j-1]>>i));
		repp(j,0,N) B[j] = A[j]%((LL)1<<i);
		sort(s,s+N,[&](const int &x , const int &y){return B[x] < B[y];});
		auto it = key.find(v);
		if(it != key.end()) ans[(*it).second].PB(MP(A[0]>>i,K-i));
		else {
			key[v] = ans.size();
			ans.push_back(vector<pair<LL,LL> >(1,MP(A[0]>>i,K-i)));
		}
		repp(j,0,N-1){
			if(s[j]) --v[s[j]-1];
			if(s[j]<N-1) ++v[s[j]];
			if(B[s[j]] == B[s[j+1]]) continue;
			int z = 1;
			LL x = B[s[j]] ^ B[s[j+1]];
			while(x != (x&-x)) x -= x&-x;
			LL p = x;
			for(LL y = B[s[j]] ; y ; y -= y&-y){
				if((y&-y) > x){
					p += y&-y;
					++z;
				}
			}
			if(p<=A[0] && i+z<=K){
				auto it = key.find(v);
				if(it != key.end()) ans[(*it).second].PB(MP((A[0]-p)>>i,K-i-z));
				else {
					key[v] = ans.size();
					ans.push_back(vector<pair<LL,LL> >(1,MP((A[0]-p)>>i,K-i-z)));
				}
			}
		}
	}
	LL r = 0;
	for(auto v : ans){
		LL z = -1;
		sort(v.begin(),v.end());
		for(auto u : v){
			(r += min(u.second+1,u.first-z)) %= mod;
			z = u.first;
		}
	}
	cout << r << endl;
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  int64_t sum = 0;
  for(int i=1; i<N+1; i++){
    if((i % 3 != 0) && (i % 5 != 0))
      sum += i;
  }
  cout << sum << endl;
}

Measured memory_bytes: 3636
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

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

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
//// mod power
ll mod_pow(ll x,ll n,ll mod){
  ll res=1;
  while(n>0){
    if(n&1)res=res*x%mod;
    x=x*x%mod;
    n>>=1;
  }
  return res;
}


int n;
int a[111111];
int cnt[111111];

int main(){
  cin.sync_with_stdio(false);
  cin>>n;
  rep(i,n)cin>>a[i];
  rep(i,n){
    cnt[a[i]]++;
  }
  if(n%2==1&&cnt[0]!=1){
    cout<<0<<endl;
    return 0;
  }
  repl(i,1,n){
    if(cnt[i]!=0&&cnt[i]!=2){
      cout<<0<<endl;
      return 0;
    }
  }
  cout<<mod_pow(2,n/2,1e9+7)<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

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

    LL n;
    cin >> n;

    vector<bool> dp(n+1,false);

    dp[0] = true;

    for(int i = 0; i < n+1; i++){
        if(i-4 >= 0){
            if(dp[i-4]){
                dp[i] = true;
            }
        }
    }

    for(int i = 0; i < n+1; i++){
        if(i-7 >= 0){
            if(dp[i-7]){
                dp[i] = true;
            }
        }
    }

    if(dp[n]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
	  result=(result*base)%modulus;
	  exponent=exponent>>1;
	  base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
	if(N<K)return 0;
	if(K==0)return 1;
	if(N==0)return 0;

	ll den=1;
	for(ll i=1;i<=K;i++)den*=i;
	ll num=1;
	while(K--){
		num*=N;
		if(num%den==0){
			num/=den;
			den=1;
		}
		N--;
	}

	return num;
}
*/
ll n,d;
int main(){FAST;
cin>>n>>d;
cout<<(n+2*d)/(2*d+1);
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long
#define int long long
#define ld long double
#define endl '\n'
const int mod= 1e9+7;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define trace(x) cerr << #x << " is " << x << endl;
#define all(x) x.begin(),x.end()
#define reset(x,val) memset(x,val,sizeof(x))
#define flush fflush(stdout)
#define sz(a) a.size()
#define pii pair<int,int>
using namespace std;
const int N=3003;
ld dp[N][N];int n;
ld p[N];
void smax(int &x,int y)
{
 x=max(x,y);
}
int32_t main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin>>n;
    for(int i=1;i<=n;i++)
    cin>>p[i];
    dp[0][0]=1;
    for(int i=1;i<=n;i++)
    dp[0][i]=dp[0][i-1]*(1.00-p[i]);
    
    for(int heads=1;heads<=n;heads++)
    {
     for(int j=1;j<=n;j++)
     {
      //if(heads==1 && j==1)continue;
      if(j<heads)continue;
      int i=heads;
      dp[i][j]= dp[i][j] + dp[i-1][j-1]*p[j] + dp[i][j-1]*(1-p[j]) ;
      //cout<<i<<' '<<j<<' '<<setprecision(4)<<dp[i][j]<<endl;
      //dp[heads][j]+=dp[i][j-1]*(1-p[j]);
      //dp[heads][j]+=dp[i-1][j-1]*p[j];
     }
    }
    ld ans=0;
    
    for(int i=n/2+1;i<=n;i++)
    {
     ans+=dp[i][n];
    }
    cout<<setprecision(30)<<ans<<endl;
    return 0;
}



Measured memory_bytes: 139648
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
L = []
for i in range(Q):
    in1, in2 = list(map(int,input().split()))
    L.append([in1, in2])

dic = {}
m = 10 ** 5 + 10
for i in range(1, m + 1):
    dic[i] = 0

for i in A:
    dic[i] += 1

ans = sum(A)

for i in range(Q):
    ans = ans + (-L[i][0] + L[i][1]) * dic[L[i][0]]
    dic[L[i][1]] += dic[L[i][0]]
    dic[L[i][0]] = 0
    print(ans)

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

int main(){
  int m, f, r;
  cin >> m >> f >> r;
  while ( m + f + r != -3 ) {
    if ( m == -1 || f == -1 ) cout << "F" << endl;
    else if ( m + f >= 80 ) cout << "A" << endl;
    else if ( 65 <= m + f && m + f < 80 ) cout << "B" << endl;
    else if ( 50 <= m + f && m + f < 65 ) cout << "C" << endl;
    else if ( m + f < 30 ) cout << "F" << endl;
    else if ( 30 <= m + f && m + f < 50 && r < 50 ) cout << "D" << endl;
    else cout << "C" << endl;
    cin >> m >> f >> r;
  }
  return 0;
}


Measured memory_bytes: 3096
#include <stdio.h>

int main( )
{
   int n, i, j, a, b, c;
   int M[100][100];

   scanf("%d", &n);

   for ( i = 0; i < n; i++ ) {
      for ( j = 0; j < n; j++ ) {
         M[i][j] = 0;
      }
   }

   for ( i = 0; i < n; i++ ) {
      scanf("%d%d", &a, &b);
      if ( b != 0 ) {
         for ( j = 0; j < b; j++ ) {
            scanf("%d", &c);
            M[a-1][c-1] = 1;
         }
      }
   }

   for ( i = 0; i < n; i++ ) {
      for ( j = 0; j < n; j++ ) {
         printf("%d", M[i][j]);
         if( j != n - 1 ) printf(" ");
      }
   printf("\n");
   }
   return 0;
}

Measured memory_bytes: 1808
import java.util.Scanner;

public class Main {
 static Scanner scan = new  Scanner(System.in);
    public static void main(String[] args) {
         
           
        int x = scan.nextInt();
        int [][][] arrBuilding = new int[4][3][10];
        int b,n,r,v ;
        
        for (int i = 0; i < x; i++) {
            b = scan.nextInt(); n=scan.nextInt(); r = scan.nextInt(); v = scan.nextInt();
           arrBuilding[b-1][n-1][r-1] += v;
        }
        
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 10; k++) {
                    System.out.print(" "+ arrBuilding[i][j][k]);
                }
                System.out.println();
            }
            if (i < 3) {
                System.out.println("####################");
            }

        }
     
        }
    }
    
    



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

int main(){
  int a,b;  cin >> a >> b;
  int n = b - a;
  int sum = 0;
  for(int i = 1;i <= n-1;i++)sum += i;//aの実際の高さ
  int height = sum - a;
  cout << height << endl;

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int maxn=2*100000+5;
set<int > g[maxn];
bool vis[maxn];
int n,m;
void addedge(int from,int to)
{
	g[from].insert(to);
	g[to].insert(from);
	if(from==1) vis[to]=true;
	if(to==1) vis[from]=true;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++)
	{
		int from,to;
		scanf("%d%d",&from,&to);
		addedge(from,to);
	}
	for(int i=1;i<=n;i++){
		if(vis[i]){
			if(g[i].count(n)){
				printf("POSSIBLE\n");
				exit(0);
			}
		}
	}
	printf("IMPOSSIBLE\n");
	return 0;
}



Measured memory_bytes: 28544
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)

	for i := 0.0; i <= 50000; i++ {
		if int(i*1.08) == N {
			fmt.Println(i)
			return
		}
	}
	fmt.Println(":(")
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
string k;
int d;
long long mod = 1e9 + 7;
long long count(vector<vector<vector<long long> > > &dp, int pos, int s, int t){
    if(pos==k.length()){
    //    cout<<"sss "<< s <<endl;
        if(s%d)
            return 0;
        return 1;
    }
   // s %= d;
    long long ans=0;

    if(dp[pos][s][t] != -1 )
        return dp[pos][s][t];
    int kk = k[pos]-'0';
    if(t){
        int temp = count(dp,pos+1, (s + kk)%d, t);
        ans += temp;
       // cout<<pos<<" "<<temp<<" e "<<ans<<endl;
    }
    else kk = 10;
    for(int a=0; a<kk; a++){
        long long temp = count(dp,pos+1,(s + a)%d, 0);
        ans += temp;
       // cout<<pos<<" "<<temp<<" "<<ans<<endl;
    }

        dp[pos][s][t] = ans%mod;
    return  ans%mod;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>k>>d;
    vector<vector<vector<long long> > > dp(k.length()+2,vector<vector<long long > > (d+12, vector<long long> (2, -1)));
    long long ans = 0;
    ans = count(dp,0,0,1);
    ans -= 1;
    ans = ((ans%mod) + mod)%mod;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 62848
import java.util.*;

class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        String N = sc.next();
        String judge = "No";
        for (int i = 0; i < 3; i++) {
            if (N.charAt(i) == '7') {
                judge = "Yes";
                break;
            }
        }
        System.out.println(judge);

    }
}

Measured memory_bytes: 35532
l, r = map(int, input().split())

if r - l >= 2019:
    print(0)
else:
    m = 2019
    for i in range(l, r + 1, 1):
        for j in range(i+1, r + 1, 1):
            m = min(i * j % 2019, m)
    print(m)


Measured memory_bytes: 9068
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<LL, int> P;

const int mod = 1e9 + 7;
const int maxn = 1e5 + 5;

int add(int x, int y) {
    x += y;
    if(x >= mod) x -= mod;
    return x;
}

int mul(int x, int y) {
    LL z = 1LL * x * y;
    return z - z / mod * mod;
}

int pw2(int x) {
    return mul(x,x);
}

vector<P> g[maxn];
LL ds[maxn], dt[maxn];
int fs[maxn], ft[maxn], p[maxn];
set<P> q;

bool cmp1(const int a, const int b) {
    return ds[a] < ds[b];
}
bool cmp2(const int a, const int b) {
    return dt[a] < dt[b];
}

void dij(int s, LL d[]) {
    for(int i = 0; i < maxn; i++) d[i] = 1LL * mod * mod;
    d[s] = 0;
    q.clear();
    q.insert(P(0, s));
    while(!q.empty()) {
        P e = *q.begin();
        q.erase(e);
        int u = e.se;
        LL w = e.fi;
        for(auto v : g[u]) {
            if(d[v.se] > w + v.fi) {
                q.erase(P(d[v.se], v.se));
                d[v.se] = w + v.fi;
                q.insert(P(d[v.se], v.se));
            }
        }
    }
}

int main() {
#ifdef CX_TEST
    freopen("E:\\program--GG\\test_in.txt", "r", stdin);
#endif
    int n, m, s, t, i, j, u, v, w;
    scanf("%d%d", &n, &m);
    scanf("%d%d", &s, &t);
    for(i = 0; i < m; i++) {
        scanf("%d%d%d", &u, &v, &w);
        g[u].push_back(P(w, v));
        g[v].push_back(P(w, u));
    }
    dij(s, ds);
    dij(t, dt);
    if(ds[t] > 1e18) return puts("0"), 0;
    LL dis = ds[t];
    for(i = 0; i < n; i++) p[i] = i + 1;
    sort(p, p + n, cmp1);
    fs[s] = 1;
    for(i = 0; i < n; i++) {
        for(auto e : g[p[i]]) {
            if(ds[p[i]] + dt[e.se] + e.fi == dis) fs[e.se] = add(fs[e.se], fs[p[i]]);
        }
        //cout<<p[i]<<" "<<fs[p[i]]<<endl;
    }
    //cout<<"============"<<endl;
    sort(p, p + n, cmp2);
    ft[t] = 1;
    for(i = 0; i < n; i++) {
        for(auto e : g[p[i]]) {
            if(dt[p[i]] + ds[e.se] + e.fi == dis) ft[e.se] = add(ft[e.se], ft[p[i]]);
        }
       // cout<<p[i]<<" "<<ft[p[i]]<<endl;
    }
    //cout<<fs[t]<<" "<<ft[s]<<endl;
    int ans = mul(fs[t], ft[s]);
    for(i = 1; i <= n; i++) {
        if(ds[i] + dt[i] == dis) {
            if(ds[i] == dt[i]) ans = add(ans, mod - pw2(mul(fs[i], ft[i])));
            for(auto e : g[i]) {
                if(ds[i] + dt[e.se] + e.fi == dis && abs(ds[i] - dt[e.se]) < e.fi) ans = add(ans, mod - pw2(mul(fs[i], ft[e.se])));
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 20080
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=b; }
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;
}

#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>=0;--i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;


typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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


    int N, K;
    cin >> N >> K;

    cout << N-K+1 << endl;

    return 0;
}

Measured memory_bytes: 256