akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

import static java.lang.Math.max;

public class Main {


    static class Solution {


    }

    static public boolean isValid(int total, int remain) {
        return remain * 2 - total <= 1;
    }

    static public long solve(int cur, int remain, long[][] dp, long[] arr) {
        if(!isValid(cur, remain)) {
            return Long.MIN_VALUE;
        }
        if(remain <= 0) {
            return 0L;
        }

        int state = cur / remain;
        if(dp[cur][state] != Long.MIN_VALUE) return dp[cur][state];

        long ans = Long.MIN_VALUE;
        if(isValid(cur - 1, remain)) {
            ans = max(ans, solve(cur - 1, remain, dp, arr));
        }
        ans = max(ans, solve(cur - 2, remain - 1, dp, arr) + arr[cur]);
        dp[cur][state] = ans;
        return ans;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] arr = new long[n+1];
        long[][] dp = new long[n+1][5];

        for(int i=1; i <=n; ++i) {
            arr[i] = sc.nextLong();
        }
        for(int i=1; i<=n; ++i) {
            for(int j=0; j<5; ++j){
                dp[i][j] = Long.MIN_VALUE;
            }
        }
        long ans = solve(n, n / 2, dp, arr);
        System.out.println(ans);

    }
}


Measured memory_bytes: 88048
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
using namespace std;
typedef long long ll;
int INF=1<<29;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N,K;
	long double Ans=0,Ans2=0;
	cin>>N>>K;
	long double n=N,k=K;
	if(n-k+1>0) Ans+=((n-k+1)/n);
	for(int i=1;i<=min(N,K-1);i++){
		int tmp=i;
		long double c=1;
		while(1){
			tmp*=2;
			c*=0.5;
			if(tmp>=K) break;
		}
		Ans2+=c;
		//cout<<Ans<<" ";
	}
	Ans2*=(1/n);
	Ans+=Ans2;
	cout<<fixed<<setprecision(16)<<Ans<<endl;
	return 0;
}



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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
#define mem(a,b) memset(a,b,sizeof(a))
#define shutdown ios::sync_with_stdio(false)
#define MAX 10e18+1000
#define INF 0x3f3f3f3f

int m[100];

int main() {
    shutdown;
    string a,b;
    cin>>a>>b;
    if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0])
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;

    return 0;
}



Measured memory_bytes: 764
A, B = map(int, input().split())

min_ans = int((12.5*A) // 1)
max_ans = int(-((-12.5*(A+1)) // 1))

ans = -1
for i in range(min_ans,max_ans):
  temp_A = (i*0.08)//1
  temp_B = (i*0.1)//1
  if temp_A == A and temp_B == B :
    ans = i
    break
  
print(ans)

Measured memory_bytes: 9004
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int N, sum = 0;
    cin >> N;

    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N);


    for (int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    for (int i = 0; i < N; i++){
        cin >> B.at(i);
        sum += B.at(i);
    }
    for (int i = 0; i < N; i++){
        cin >> C.at(i);
    }

    for (int i = 0; i < N-1; i++){
        if (A.at(i) + 1 == A.at(i+1)){
            sum += C.at(A.at(i)-1);
        }
    }

    cout << sum <<endl;

    return 0;
}


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

void solve(){
	ll n;
	cin>>n;
	while(n){
		if(n%10 ==  7){
			cout<<"Yes"<<endl;
			return;
		}
		n = n/10;
	}
	cout<<"No"<<endl;
}
int main()
{

  solve();

return 0;
}



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

using namespace std;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int A,B,C,D,E,F;
cin>>A>>B>>C>>D>>E>>F;
vector<int> x;
vector<int> y;
for(int i=0;i<F;i++){
for(int j=0;j<F;j++){
    int tmp_x=100*A*i+100*B*j;
    if(tmp_x<=F){
        x.push_back(tmp_x);
    }
}
}
for(int i=0;i<F;i++){
for(int j=0;j<F;j++){
    int tmp_y=C*i+D*j;
    if(tmp_y<=F){
        y.push_back(tmp_y);
    }
}
}

int max_j=-1;
int max_i=-1;
float max_val=-1;
for(int i=0;i<x.size();i++){
for(int j=0;j<y.size();j++){
    int limit=(x[i]/100)*E;
    if(y[j]<=limit){
        float tmp_w=x[i]+y[j];
        float concentration=100*(y[j]/tmp_w);
        if(tmp_w<=F&&max_val<concentration){
            max_val=concentration;
            max_i=i;
            max_j=j;
        }
    }
}
}

cout<<x[max_i]+y[max_j]<<" "<<y[max_j]<<endl;

//system("pause");
return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

map<ll, ll> prime;
void Factor(ll n){
    ll sq = sqrt(n) + 1;

    for(int i = 2; i <= sq; ++i){
        sq = sqrt(n) + 1;
        if(n%i == 0){
            if(prime.count(i) == 0)prime[i] = 0;
            while(n%i == 0){
                n /= i;
                prime[i]++;
            }
        }
    }

    if(n != 1){
        if(prime.count(n) == 0)prime[n] = 1;
        else prime[n]++;
    }
}

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

    rep(i, n)Factor(i+1);

    ll over_3, over_5, over_15, over_25, over_75;
    over_3 = over_5 = over_15 = over_25 = over_75 = 0;
    
    all_map(itr, prime)if(itr->second >= 2){
        over_3++;
        if(itr->second >= 4)over_5++;
        if(itr->second >= 14)over_15++;
        if(itr->second >= 24)over_25++;
        if(itr->second >= 74)over_75++;
    }

    ll ans = over_75 + over_25 * (over_3-1) + over_15 * (over_5 -1) + (over_5 * (over_5-1)) / 2 * (over_3-2);
    
    cout << max((ll)0, ans) << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>

using namespace std;

int n;
double p[3005];

double dp[3005][3005];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> p[i];
	}
	dp[0][0] = 1.0;
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j <= i; ++j) {
			dp[i][j] = dp[i-1][j]*(1.0-p[i]);
			if (j != 0) {
				dp[i][j] += dp[i-1][j-1]*p[i];
			}
		}
	}
	double res = 0.0;
	for (int j = n; j > n/2; --j) {
		res += dp[n][j];
	}
	cout << fixed << setprecision(15) << res << "\n";
	return 0;
}

/*
	dp[i][j] = probability of getting j heads with coins 1..i

	dp[i][j] = dp[i-1][j] * P(i_tail) + dp[i-1][j-1] * P(i_head)
*/


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

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

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

const int SIZE = 1e5+100;
ll n, d;

int main(){
    cin >> n >> d;
    ll dd = d*2+1;
    ll ans = n/dd;
    if(n%dd != 0)   ++ans;
    cout << ans << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
const int N = 2e5;
const int M = 1e9;
using namespace std;
#define INF 0x3f3f3f3f
#define e  2.718281828459045
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define memset(x,y) memset(x,y,sizeof(x))
#define ll long long
int book[N+10];
int main(){
	int n;
	cin >> n;
	for(int i=1;i<=n;i++){
		scanf("%d",&book[i]);
	}
	int fg=1,js=0;;
	for(int i=1;i<=n;i++){
		if(book[i] == fg){
			fg++;
			js++;
		}
	}
	if(js==0){
		printf("-1\n");
		return 0;
	}
	printf("%d",n-js);
	return 0;
}


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

const int MAX = 1e5;

int isp[MAX + 1];

int main()
{
fill(isp, isp + MAX + 1, 1);
isp[0] = isp[1] = 0;
for(int i = 2;i * i <= MAX;i++) {
if(isp[i]) {
for(int j = i * 2; j <= MAX;j += i) {
isp[j] = 0;
}
}
}
vector<int> sum(MAX + 1);
for(int i = 0;i <= MAX;i++) {
sum[i] = isp[i] && isp[(i + 1) / 2];
}
for(int i = 1;i <= MAX;i++) {
sum[i] += sum[i - 1];
}
int Q;
cin >> Q;
while(Q--) {
int l, r;
cin >> l >> r;
cout << sum[r] - sum[l - 1] << endl;
}
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>
#include <algorithm>

int main(){
  long long int N;
  scanf("%lld", &N);
  
  long long int ans = N-1;
  
  for(long long int i = 2; i*i <= N; i++){
    if(N%i == 0){
      ans = i + (N/i) - 2;
    }
  }
  
  std::cout << ans << std::endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/*
 template<class T> inline bool chmax(T&a,T&b){if(a<b){a=b;return true;}return false;}
 template<class T> inline bool chmin(T&a,T&b){if(a>b){a=b;return true;}return false;}
 const ll INF = 1LL<<60;
 const ll M = 1000000007;
 ll mpow(ll a,ll b) {ll res=1;while(b!=0){if(b&1)res=res*a%M;a=a*a%M;b=b>>1;}return res;}
 ll mcomb(ll n,ll k){if(k>n/2)return mcomb(n,n-k);ll res=1;for(ll i=0;i<k;i++){res=res*(n-i)%M;res=res*mpow(k-i,M-2)%M;}return res;}
 */

int main(){
    ll h,w,k;
    cin>>h>>w>>k;
    int c[h][w];
    char hoge;
    for(ll i=0;i<h;i++)for(ll j=0;j<w;j++){
        cin>>hoge;
        c[i][j]= hoge=='#';//黒が１
    }
    ll ans=0;
    ll a[h],b[w];
    for(ll i=0;i<pow(2,h);i++)for(ll j=0;j<pow(2,w);j++){
        ll i2=i;
        ll j2=j;
        for(ll i3=0;i3<h;i3++){
            a[i3]=i2%2;
            i2/=2;
        }
        for(ll i3=0;i3<w;i3++){
            b[i3]=j2%2;
            j2/=2;
        }
        ll count=0;
        for(ll i3=0;i3<h;i3++)for(ll j3=0;j3<w;j3++){
            if(a[i3] && b[j3] && c[i3][j3])count++;
        }
        if(count==k)ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4092
import java.util.Scanner;
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
 
		if(a == b + c || b == c + a || c == a + b)
		{
			System.out.println("Yes");
		}else
		{
			System.out.println("No");
		}
 
 
 
	}
 
}

Measured memory_bytes: 21844
import copy
n = int(input())
x = list(map(int,input().split()))
y = copy.copy(x)
y.sort()
left_mid = y[n//2-1]
right_mid = y[n//2]
for i in range(n):
  if x[i]<=left_mid:
    print(right_mid)
  else:
    print(left_mid)

Measured memory_bytes: 93128
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

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

int main()
{
    ll n, m;
    cin >> n >> m;

    vector<ll> X(m), Y;
    rep(i, X.size())
    {
        cin >> X[i];
    }
    sort(all(X));

    rep(i, m - 1)
    {
        Y.push_back(X[i + 1] - X[i]);
    }
    sort(all(Y));

    rep(i, n - 1)
    {
        if (Y.size() == 0)
        {
            break;
        }
        Y.pop_back();
    }

    ll ans = 0;
    if (Y.size() != 0)
    {
        ans = accumulate(all(Y), 0);
    }
    cout << ans << endl;
    return 0;
}

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

#define fio() ios_base::sync_with_stdio(false);\
cin.tie(NULL);

#define md 1000000007
#define mem(arr,x) memset(arr,x,sizeof(arr))
#define pb push_back
#define vi vector<lli>
#define vvi vi<vi>
typedef long long int lli;
typedef float fl;

bool sortinrev(const pair<lli, lli > &a,     const pair<lli , lli > &b)
{
	return (a.first > b.first);
}
int main()
{
	fio();
	lli t = 1 ;
	//cin >> t;
	while(t--)
	{
		lli n ;
		cin >> n;
		if( n)
			cout << 0 ;
		else cout << 1;
	}
}

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

int main(){
  string S;
  cin>>S;
  int ans=0,num=0;
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='A'||S.at(i)=='T'||S.at(i)=='C'||S.at(i)=='G'){
      num++;
    }else{
      ans=max(ans,num);
      num=0;
    }
  }
  ans=max(ans,num);
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
namespace ZDY{
    #pragma GCC optimize(3)
    #define il __inline__ __attribute__ ((always_inline))
    #define rg register
    #define ll long long
    #define ull unsigned long long
    #define db double
    #define sht short
    #define MB template <class T>il
    #define Fur(i,x,y) for(int i=x;i<=y;++i)
    #define Fdr(i,x,y) for(int i=x;i>=y;--i)
    #define fl(i,x) for(int i=head[x],to;to=e[i].to,i;i=e[i].nxt)
    #define clr(x,y) memset(x,y,sizeof(x))
    #define cpy(x,y) memcpy(x,y,sizeof(x))
    #define fin(s) freopen(s".in","r",stdin)
    #define fout(s) freopen(s".out","w",stdout)
    #define fcin ios::sync_with_stdio(false)
    #define l2(n) (int(log2(n)))
    #define inf 0x3f3f3f3f
    MB T ABS(T x){return x>0?x:-x;}
    MB T MAX(T x,T y){return x>y?x:y;}
    MB T MIN(T x,T y){return x<y?x:y;}
    MB T GCD(T x,T y){return y?GCD(y,x%y):x;}
    MB void SWAP(T &x,T &y){T t=x;x=y;y=t;}
}using namespace ZDY;using namespace std;
namespace IO{const char* ln="\n";const int str=1<<20;struct IN{char buf[str],*s,*t;bool _;IN():s(buf),t(buf),_(0){}il char gc(){return s==t&&((t=(s=buf)+fread(buf,1,str,stdin))==s)?EOF:(*s++);}IN&operator>>(char&ch){if(_)return *this;char c;while((c=gc())!=EOF&&isspace(c));if(c==EOF)_=1;else ch=c;return *this;}IN& operator>>(char* ch){clr(ch,0);if(_)return *this;char c;while((c=gc())!=EOF&&isspace(c));if(c==EOF)return _=1,*this;*ch=c;ch++;while((c=gc())!=EOF&&!isspace(c))*ch=c,ch++;if(c==EOF)_=1;return *this;}IN& operator>>(string& ch){if(_)return *this;char c;while((c=gc())!=EOF&&isspace(c));if(c==EOF)return _=1,*this;ch+=c;while((c=gc())!=EOF&&!isspace(c))ch+=c;if(c==EOF)_=1;return *this;}template<typename T>IN&operator>>(T&x){if(_)return *this;char c=gc();bool ff=0;while(c!=EOF&&(c<'0'||c>'9'))ff^=(c=='-'),c=gc();if(c==EOF){_=1;return *this;}x=0;while(c!=EOF&&'0'<=c&&c<='9')x=(x<<3)+(x<<1)+c-48,c=gc();if(c==EOF)_=1;if(ff)x=-x;return *this;}}in;struct OUT{char buf[str],*s,*t;OUT():s(buf),t(buf+str){}~OUT(){fwrite(buf,1,s-buf,stdout);}void pt(char c){(s==t)?(fwrite(s=buf,1,str,stdout),*s++=c):(*s++=c);}OUT&operator<<(const char*s){while(*s)pt(*s++);return *this;}OUT&operator<<(char*s){while(*s)pt(*s++);return *this;}OUT&operator<<(string s){for(int i=0;s[i];i++)pt(s[i]);return *this;}template<typename T>OUT&operator<<(T x){if(!x)return pt('0'),*this;if(x<0)pt('-'),x=-x;char a[30],t=0;while(x)a[t++]=x%10,x/=10;while(t--)pt(a[t]+'0');return *this;}}out;}using namespace IO;
#define N 100011
int n;
string a[]={"Sunny","Cloudy","Rainy"};
int main(){
	fcin;
	string s;
	cin>>s;
	if(s==a[0])cout<<a[1];
	else if(s==a[1])cout<<a[2];
	else cout<<a[0];
}

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

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.rbegin(),a.rend());
  ll ans = a[0];
  int now = 2;
  if(now == n){
    cout << ans << endl;
    return 0;
  }
  repr(i,1,n){
    ans += a[i];
    now++;
    if(now == n){
      cout << ans << endl;
      return 0;
    }
    ans += a[i];
    now++;
    if(now == n){
      cout << ans << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
 
#define    int                      long long int
#define    ld                       long double
#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int ttt; cin >> ttt; while(ttt--)
#define    ff                       first
#define    ss                       second
#define    all(container)            container.begin() , container.end()
#define    sz(container)             (int)container.size()
#define    pii                      pair <int , int>
#define    sp(x)                    setprecision(x)

int power(int x, int y, int p)  
{  
    int res = 1;     
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)  
    {  
        
        if (y & 1)  
            res = (res*x) % p;  
  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
}  
  

int32_t main()
{
    speed upp
    int n,m,ans=0;
    cin>>n;
    m=n-1;
    for(int i=1;i<=sqrt(m);i++)
    {
        if(m%i==0)
        {
            ans++;
            if(i*i!=m)
                ans++;
        }
        
    }

    for(int i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            m=n;
            while(m%i==0)
                m/=i;
            if(m%i==1)
                ans++;
            if(i*i!=n)
            {
                m=n;
                int x=n/i;
                while(m%x==0)
                    m/=x;
                if(m%x==1)
                    ans++;
            }
        }
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
#define print(x) cerr << (#x) << "is "<< x << "\n"
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e6 + 1; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int s;
   cin >> s;
   map<int,int> cnt;
   int ans = 1e9;
   f(i,1,N+1){
      if(cnt[s]){
         ans = min(ans,i);
         break;
      }
      cnt[s]++;
      if(s & 1){
         s = 3*s+1;
      }else{
         s = s/2;
      }
   }
   cout << ans << '\n';
   return 0;
} 

Measured memory_bytes: 256
import java.util.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a=sc.nextInt();
    int b = sc.nextInt();
    int ans= b*2;
    if(ans>=a) System.out.println(0);
    if(ans<a) System.out.println(a-ans);
  }
}

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

typedef long long ll;
const int maxn = 100010;
int K, a[maxn];

int main() {
    scanf("%d", &K);
    for (int i = 1; i <= K; i++) {
        scanf("%d", &a[i]);
    }
    auto chk = [&](ll x) {
        for (int i = 1; i <= K; i++) x = x / a[i] * a[i];
        return x;
    };
    ll l = 0, r = 1e18, ans = -1;
    while (l <= r) {
        ll mid = (l + r) >> 1;
        chk(mid) >= 2 ? r = (ans = mid) - 1 : l = mid + 1;
    }
    if (chk(ans) ^ 2) printf("-1\n"), exit(0);
    printf("%lld ", ans);
    l = 0, r = 1e18, ans = -1;
    while (l <= r) {
        ll mid = (l + r) >> 1;
        chk(mid) <= 2 ? l = (ans = mid) + 1 : r = mid - 1;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		D_Ears solver = new D_Ears();
		solver.solve(1, in, out);
		out.close();
	}

	static class D_Ears {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			int[] a = new int[n];
			long[] s = new long[n + 1];
			long[] sEven = new long[n + 1];
			for (int i = 0; i < n; i++) {
				a[i] = in.nextInt();
				s[i + 1] = s[i] + a[i];
				sEven[i + 1] = sEven[i] + (a[i] % 2 == 0 ? 1 : 0);
			}

			long[] pref = new long[n];
			for (int i = 1; i < n; i++) {
				pref[i] = Math.min(s[i], f(a[i - 1]) + pref[i - 1]);
			}

			long[] suff = new long[n];
			for (int i = n - 2; i >= 0; i--) {
				suff[i] = Math.min(s[n] - s[i + 1], f(a[i + 1]) + suff[i + 1]);
			}

			long ans = s[n];
			long best = Long.MAX_VALUE;
			for (int i = 0; i < n; i++) {
				best = Math.min(best, -sEven[i] + pref[i]);
				ans = Math.min(ans, sEven[i + 1] + suff[i] + best);
				if (i > 0) {
					ans = Math.min(ans, suff[i - 1] + pref[i]);
				}
			}
			ans = Math.min(ans, f(a[0]) + suff[0]);

			out.println(ans);
		}

		private long f(int x) {
			x -= 2;
			if (x < 0) {
				return Math.abs(x);
			}
			return x % 2;
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}



Measured memory_bytes: 45648
import itertools

N = int(input())
L = []
for i in range(N):
    A = int(input())
    x = [tuple(map(int,input().split())) for i in range(A)]
    L.append(x)
    
X = list(itertools.product([0,1],repeat=N))
ans = 0

for i in X:
    cnt = True
    for j,value in enumerate(i):
        if value  == 1:
            for k,m in L[j]:
                if i[k-1] != m:
                    cnt = False
    if cnt:
        ans = max(ans,sum(i))
           
print(ans)

Measured memory_bytes: 48348
#include<bits/stdc++.h>
//cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define pr pair<int,int>
#define all(x) x.begin(),x.end()
#define mod 1000000007

int main(){
  ios_base::sync_with_stdio(false);
    // #ifndef ONLINE_JUDGE
    //   freopen("input.txt", "r", stdin);
    //   freopen("output.txt", "w", stdout);
    // #endif
  ll n,k;
  cin>>n>>k;
  n=n%k;
  if(abs(n-k)<n)
    n=abs(n-k);
  cout<<n<<"\n";
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        long ans = 0;

        for(int i=1; i<=N; i++){
            if(i%3!=0 && i%5!=0){
                ans += i;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35840
use io::*;

fn main() {
    let input = read_string();
    let mut sc = Scanner::new(&input);
    let n: usize = sc.next();
    let ps: Vec<usize> = sc.next_vec(n);
    let mut c = 0;
    let mut ans = 0;
    for i in 0..n {
        if ps[i] == i + 1 {
            c += 1;
        } else {
            ans += (c + 1) / 2;
            c = 0;
        }
    }
    ans += (c + 1) / 2;
    println!("{}",ans);
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }

        pub fn next_mat<T: FromStr>(&mut self, w: usize, h: usize) -> Vec<Vec<T>> {
            (0..h).map(|_| self.next_vec(w)).collect()
        }

        pub fn next_vec_char(&mut self) -> Vec<char> {
            self.next::<String>().chars().collect()
        }

        pub fn next_mat_char(&mut self, n: usize) -> Vec<Vec<char>> {
            (0..n).map(|_| self.next_vec_char()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 6396
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;
map<ll, pair<ll,ll> > mp;
ll dp[100000];

int main(){
    ll h,w,d;
    cin>>h>>w>>d;
    for(ll i=0;i<h;i++){
        for(ll j=0;j<w;j++){
            ll a;
            cin>>a;
            mp[a]=make_pair(i,j);
        }
    }
    for(ll i=d+1;i<=h*w;i++){
        dp[i]=dp[i-d]+abs(mp[i].first-mp[i-d].first)+abs(mp[i].second-mp[i-d].second);
    }
    ll q;
    cin>>q;
    vector<ll> ans(q);
    for(ll i=0;i<q;i++){
        ll l,r;
        cin>>l>>r;
        ans[i]=dp[r]-dp[l];
    }
    for(ll i=0;i<q;i++){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(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()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>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;
#define out(a) cout<<fixed<<setprecision((a))


int main(){
	ll N;
	cin >> N;
	vector<ll> a(N);
	FOR(i,0,N)cin >> a[i];
	ll amax1=-1,i1,amax2=-1,i2;
	FOR(i,0,N){
		if(a[i]>amax1){
			amax2 = amax1;
			amax1 = a[i];
			i2=i1;
			i1=i;
		}else if(a[i]>amax2){
			amax2 = a[i];
			i2 = i;
		}
	}
	FOR(i,0,N){
		if(i!=i1){
			cout << amax1 << endl;
		}else {
			cout << amax2 << endl;
		}
	}
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 7;
const int mod = 1e9 + 7;
 
int main(){
	int n;
	scanf("%d",&n);
	if(n%2) cout << n/2+1<< endl;
	else cout << n/2<< endl; 
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

type shop struct {
	s      string
	p, idx int
}

// shops :
type shops []shop

func (p shops) Len() int {
	return len(p)
}

func (p shops) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p shops) Less(i, j int) bool {
	if p[i].s == p[j].s {
		return p[i].p > p[j].p
	}
	return p[i].s < p[j].s
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	n := make(shops, N)
	for i := 0; i < N; i++ {
		s, p := getString(), getInt()
		n[i] = shop{s, p, i}
	}

	sort.Sort(n)

	for _, v := range n {
		out(v.idx + 1)
	}
}


Measured memory_bytes: 640
N, H = map(int, input().split())

lst = []
for _ in range(N):
    a, b = map(int, input().split())
    lst.append((a, 0))
    lst.append((b, 1))
lst.sort(reverse=True)

ans = 0
ceil = lambda a, b: (a + b - 1) // b

for p, q in lst:
    if q == 1:
        H -= p
        ans += 1
        if H <= 0:
            break
    else:
        ans += ceil(H, p)
        break
print(ans)


Measured memory_bytes: 24344
I=list(map(int,input().split()))
T=list(map(int,input().split()))
N=I[0]
M=T[0]
I=[[I[i],I[i+1]] for i in range(1,2*N+1,2)]
T=[[T[i],T[i+1]] for i in range(1,2*M+1,2)]
result=list(map(list,set(map(tuple,I+T))))
result.sort()

print(str(result[0][0])+":"+'{0:02d}'.format(result[0][1]),end="")
for i in range(1,len(result)):
    print(" "+str(result[i][0])+":"+'{0:02d}'.format(result[i][1]),end="")
print()


Measured memory_bytes: 5684
<?php
fscanf(STDIN, '%d %d', $length, $key);
fscanf(STDIN, '%s', $str);
$ans = '';
for ($i=0; $i < $length; $i++) { 
    if ($i + 1 === $key) {
        $ans .= strtolower($str[$i]);
    } else {
        $ans .= $str[$i];
    }
}
echo "$ans\n";

Measured memory_bytes: 4728
#include <bits/stdc++.h>  
   
using namespace std;  
   
int main()  
{  
    long long n,k,ans=0;  
    cin >> n>> k;  
    if(k==0) ans=n*n;  
    else  
    {  
        for(int b=k+1;b<=n;b++)  
        {  
        ans+=(n/b)*(b-k);  //算分堆左边 
      //  printf ("%lld\n",ans);
        if(n%b>=k)
		{
		  ans+=n%b-k+1;  //分堆右边 
		//  printf ("%lld\n",ans);
		}
        }  
    }  
    printf("%lld\n",ans);  
    return 0;  
}

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

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rbf(i, v) for (auto& (i) : (v))
#define all(x) (x).begin(),(x).end()
#define cAll(x) (x).cbegin(),(x).cend()
#define COL(x) cout << x << endl
#define CO(x) cout << x
//#define int long long

template<typename T> constexpr auto square(T x) { return (x) * (x); }

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

const int MOD = 1000000007;
const int INF = INT_MAX;

signed main()
{
	string S;

	cin >> S;

	bool ans = false;

	rep(i, 3) {
		if (S[i] == S[i + 1]) ans = true;
	}

	if (ans) COL("Bad");
	else COL("Good");

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
    unsigned int n;
    unsigned int m;
    unsigned int a[10000];
    unsigned int i,ans;
    scanf("%d %d", &n, &m);

    for (i = 0; i < m; i++) {
        scanf("%d", &a[i]);
    }

    ans = 0;

    for (int i = 0; i < m; i++) {
        ans = ans + a[i];
    }
    
    if (n < ans) {
        printf("-1\n");
    }
    else {
        printf("%d",n-ans);
    }
    return 0;
}

Measured memory_bytes: 1716
#include "bits/stdc++.h"
using namespace std;
const int N = 105;

int t[N], v[N], z[400 * N], mv, to, s;

int main() {
    int n, i, j = 0;
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) scanf("%d", t + i), t[i] *= 2;
    for(int i = 1; i <= n; ++i) scanf("%d", v + i), v[i] *= 2;

    for(int i = 1; i <= n; ++i) {
        to += t[i];
        z[j] = min(z[j], v[i]);
        for(++j; j <= to; ++j) z[j] = min(z[j - 1] + 1, v[i]);
        j--;
    }

    for(int i = j - 1; i >= 1; i--) s += mv = (min(z[i], mv + 1));
    printf("%.9f\n", s / 4.0);
}

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

int main() {
	int N, ans = 0;
	cin >> N;
	vector<int> d(N);
	for (int& i : d) cin >> i;
	for (int i = 0; i < N - 1; ++i) {
		for (int j = 1 + i; j < N; ++j) ans += d[i] * d[j];
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define PI acos(-1)
#define sz 18500000
#define RUN_FAST ios::sync_with_stdio(false);
using namespace std;

int main()
{
    RUN_FAST; cin.tie(nullptr);
    ll a, b, c, d, ans;
    cin >> a >> b >> c >> d;
    ans=max(max(a*c, a*d), max(b*c, b*d));
    cout << ans << endl;
    return 0;
}


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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = 1e9+7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

void f(VL& idt){
	int p = sz(idt);
	rep2(i, 1, p){
		if(idt[i] !=0) idt[i] = idt[i-1]+1;
	}
	repr(i, p-1, 1){
		if(idt[i-1] !=0 && idt[i-1] < idt[i]) idt[i-1] = idt[i];
	}
}


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int h,w;
	cin >>h >>w;
	vector<string> ba(h);
	rep(i, h) cin >>ba[i];
	
	vector<VL> ysm(h, VL(w));
	rep(i, h){
		VL wdt(w);
		rep(j, w) wdt[j] = ba[i][j]=='#'? 0: 1;
		f(wdt);
		rep(j, w) ysm[i][j] += wdt[j];
	}
	rep(j, w){
		VL wdt(h);
		rep(i, h) wdt[i] = ba[i][j]=='#'? 0: 1;
		f(wdt);
		rep(i, h) ysm[i][j] += wdt[i];
	}
	//for(auto xl: ysm){for(auto x :xl) printf("%d, ",x); puts("");}



	ll ans = 0;
	rep(i,h) rep(j,w) if(ba[i][j]!='#'){
		ans = max(ans, ysm[i][j] - 1);
	}

	cout << ans <<"\n";
}


Measured memory_bytes: 35840
def main():
    t = input().split(" ")
    N, A= int(t[0]), int(t[1])

    t = input().split(" ")
    x_p = []
    x_n = []
    x_z = 0
    for i in t:
        i = int(i)
        if A < i:
            x_p.append(i - A)
        elif i < A:
            x_n.append(A - i)
        else:
            x_z += 1
    x_p.sort()
    x_n.sort()
    x_p_sum=[{0:1}]
    x_n_sum=[{0:1}]
    for i in range(len(x_p)):
        x_p_sum.append({})
        for j in sorted(x_p_sum[i]):
            if j in x_p_sum[i+1]:
                x_p_sum[i+1][j] += x_p_sum[i][j]
            else:
                x_p_sum[i+1][j] = x_p_sum[i][j]
            x_p_sum[i+1][j+x_p[i]] = x_p_sum[i][j]
    for i in range(len(x_n)):
        x_n_sum.append({})
        for j in sorted(x_n_sum[i]):
            if j in x_n_sum[i+1]:
                x_n_sum[i+1][j] += x_n_sum[i][j]
            else:
                x_n_sum[i+1][j] = x_n_sum[i][j]
            x_n_sum[i+1][j+x_n[i]] = x_n_sum[i][j]
    sum = 0
    for i in x_n_sum[-1]:
        if i in x_p_sum[-1]:
            sum += (x_n_sum[-1][i] * x_p_sum[-1][i])
    sum *= 2**x_z
    sum -= 1
    print(sum)
main()


Measured memory_bytes: 4084
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int ans = 0, now = 0;
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
            now += 1;
        }
        else{
            if(ans < now) ans = now;
            now = 0;
        }
    }
    if(ans < now) ans = now;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] numbers = new int[3];
		int task = 0;
		for(int a = 0 ; a < 3 ; a++){
			numbers[a] = sc.nextInt();
		}
		sc.close();
		Arrays.sort(numbers);
		task = Math.abs(numbers[0] - numbers[1]) + Math.abs(numbers[1] - numbers[2]);
		System.out.println(task);
	}
}

Measured memory_bytes: 23252
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int size = in.nextInt();
		int[] heap = new int[size];
		
		for (int i = 0; i < size; i++) {
			heap[i] = in.nextInt();
		}
		
		in.close();
		
		for (int i = 0; i < size; i++) {
			int parent = (i - 1) /2;
			int lchild = 2 * i + 1;
			int rchild = 2 * i + 2;
			System.out.print("node " + (i + 1) + ": key = " + heap[i] + ", ");
			if (i > parent) {
				System.out.print("parent key = " + heap[parent] + ", ");
			}
			if (lchild <= (size-1)) {
				System.out.print("left key = " + heap[lchild] + ", ");
			}
			if (rchild <= (size-1)) {
				System.out.print("right key = " + heap[rchild] + ", ");
			}
			System.out.println();
		}
	}
}



Measured memory_bytes: 27376
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int y1,m1,d1,y2,m2,d2,year[5000],month[12]={0,31,59,90,120,151,181,212,243,273,304,334};
int i,j,k;

void swap (int* x,int* y){
	int z;
	z=*x;
	*x=*y;
	*y=z;
}

int isleap(int y){
	if(y%400==0)return 1;
	if(y%100==0)return 0;
	if(y%4==0)return 1;
	return 0;
}

int serial(int y,int m,int d){
	return year[y]+month[m-1]+d+( (m>2 && isleap(y)) ? 1 : 0);
}

int main(){
	for(i=1;i<5000;i++)year[i]=year[i-1]+365+isleap(i-1);
	while(scanf("%d %d %d %d %d %d",&y1,&m1,&d1,&y2,&m2,&d2) && y1>=0){
		printf("%d\n",serial(y2,m2,d2)-serial(y1,m1,d1));
	}
	return 0;
}

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

using namespace std;

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

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

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

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int n;
ll a[312345];
ll ma[312345], mi[312345];

int main() {
	cin >> n;
	REP(i, 3 * n) scanf("%lld", a + i);
	
	priority_queue<ll> pq;
	ll sum = 0;
	
	REP(i, n) {
		sum += a[i];
		pq.push(-a[i]);
	}
	
	ma[n - 1] = sum;
	
	FOR(i, n, 2 * n) {
		if (-pq.top() < a[i]) {
			sum += a[i] - (-pq.top());
			pq.pop();
			pq.push(-a[i]);
		}
		
		ma[i] = sum;
	}
	
	while (!pq.empty()) pq.pop();
	sum = 0;
	
	for (int i = 3 * n - 1; i >= 2 * n; i--) {
		sum += a[i];
		pq.push(a[i]);
	}
	
	mi[2 * n] = sum;
	
	for (int i = 2 * n - 1; i >= n; i--) {
		if (pq.top() > a[i]) {
			sum += a[i] - pq.top();
			pq.pop();
			pq.push(a[i]);
		}
		
		mi[i] = sum;
	}
	
	
	ll ans = LLONG_MIN;
	
	FOR(i, n - 1, 2 * n) chmax(ans, ma[i] - mi[i + 1]);
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 7156
import math
import copy
import fractions
import numpy as np

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

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

data = getSomeInputListInt(m)

lower = []
upper = []

for i in range(m):
    lower.append(data[i][0])
    upper.append(data[i][1])

lowerNum = max(lower)
upperNum = min(upper)

ans = max(0, upperNum - lowerNum + 1)


print(ans)

Measured memory_bytes: 32968
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
typedef long long int ll;
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EREP(i, n) for (int i = (n - 1); i >= 0; --i)
#define D(n, retu)                                                             \
  REP(i, n) { cin >> retu[i]; }
#define mod 100000
#define INF 93193111451418101
#define MIN -933111451418101
//#define INF 931931114518101
using namespace std;
typedef pair<ll, ll> P;
template <typename T> void fill_all(T &arr, const T &v) { arr = v; }
template <typename T, typename ARR> void fill_all(ARR &arr, const T &v) {
  for (auto &i : arr) {
    fill_all(i, v);
  }
}
#define yo 100001
//------------------?????°-----------------------//
ll n, m;
bool hoge = false;
//-------------------??¢??°----------------------//
vector<ll> topological_sort(ll v, std::vector<ll> G[], ll num[]) {
  std::vector<ll> zero, tpsort; //??\?¬???°??????

  REP(i, v) {
    if (num[i] == 0) {
      zero.push_back(i);
    }
  }
  while (zero.size()) {
    ll now = zero[zero.size() - 1];
    if (zero.size() > 1) {
      hoge = 1;
    }
    tpsort.push_back(now);
    zero.pop_back();
    for (auto &j : G[now]) {
      num[j]--;
      if (num[j] == 0) {
        zero.push_back(j);
      }
    }
  }
  return tpsort;
}
int main() {
  std::vector<ll> G[5001];
  ll h[5001] = {};
  cin >> n >> m;
  REP(i, m) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    h[b]++;
  }
  std::vector<ll> v = topological_sort(n, G, h);
  REP(i, v.size()) { cout << v[i] + 1 << endl; }
  cout << hoge << endl;
  return 0;
}

Measured memory_bytes: 4380
#include <iostream>
#include <string>
using namespace std;
int main() {
  char c;
  char v[]={"aeiou"};
  cin>>c;
  bool s=true;
  for (int i=0;i<sizeof(v);i++){
    if (c==v[i]){
      cout<<"vowel";
      s=false;
      break;
    }
    }
    if(s){
      cout<<"consonant";
    }  
return 0;
}

Measured memory_bytes: 256
// Problem : D - Not Divisible
// Contest : AtCoder - AtCoder Beginner Contest 170
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db long double
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define mi map<int,int>
#define ml map<ll,ll>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define MAX 4294967295
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MAXN 15000005
#define inf 1e10
#define PI acos(-1.0)

void solve(){
    int n;
    cin>>n;
    vi a(n);
    unordered_map<int,int> m; 
    for(int i=0;i<n;i++){
        cin>>a[i];
        m[a[i]]++;
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        if(m[a[i]] > 1) continue;
        if(a[i] == 1){
            ans++;
            continue;
        }
        bool ok = true;
        for(int j=1;j*j<=a[i];j++){
            if(a[i]%j == 0){
                if(m.count(j)){
                    ok = false;
                    break;
                }
                if(j != 1 && m.count(a[i]/j)){
                    ok = false;
                    break;
                }
            }
        }
        if(ok) ans++;
    }
    cout<<ans<<endl;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int t;
    //cin>>t;
    t = 1;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 12208
#include <iostream>
using namespace std;
int main()
{
    int h, n;
    cin >> h >> n;
    
    int a[n];
    int sum = 0;
    for(int i=0; i<n; i++){
        cin >> a[i];
        sum += a[i];
    }
    

    if(h>sum) cout << "No" << endl;   
    else cout << "Yes" << endl;   
    return 0;
}

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

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

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

vector<vector<int>> memo;

int dp_cost(const string s1, const string s2, int x, int y) {
  int H = memo[0].size() - 1;
  if(memo[x][y] != -1) return memo[x][y];
  if(x == H || y == H) return memo[x][y] = 0;
  int res = dp_cost(s1, s2, x + 1, y + 1);
  if(s1[s1.length() - 1 - x] == s2[s2.length() - 1 - y]) ++res;
  return memo[x][y] = res;
}

int main(){
  int H, W;
  cin >> H >> W;
  vector<string> c(H);
  REP(i,H) cin >> c[i];

  int res = 0;
  REP(i,W - 1) {
    string s1, s2;
    REP(j,H) s1 += c[j][i];
    REP(j,H) s2 += c[j][i + 1];

    memo.resize(H + 1);
    REP(j,H + 1) memo[j].resize(H + 1, -1);

    vector<vector<int>> dp(H + 1, vector<int> (H + 1, INF));
    dp[0][0] = 0;
    REP(j,H + 1)REP(k, H + 1) {
      if(j + 1 <= H) {
        dp[j + 1][k] = min(dp[j + 1][k], dp[j][k] + dp_cost(s1, s2, j, k));
      }
      if(k + 1 <= H) {
        dp[j][k + 1] = min(dp[j][k + 1], dp[j][k] + dp_cost(s1, s2, j, k));
      }
    }
    res += dp[H][H];
    memo.clear();
  }
  cout << res << endl;
  return 0;
}



Measured memory_bytes: 1232
/*   CREATED BY
       STREAM_CIPHER
       16-02-2020
  */
  #include <bits/stdc++.h>
  using namespace std;
  typedef long long  int ll;

   int main()  
   {
        ios_base::sync_with_stdio(false); 
        cin.tie(NULL); 
        int n;
        cin>>n;
        map<string,int>m;
        vector<string>a;
        for(int i=0;i<n;i++)
        {
           string in;
           cin>>in;
           a.push_back(in);
           m[in]++;
        }
        int mx=0;
        for(int i=0;i<a.size();i++)
        {
          mx=max(mx,m[a[i]]);
        }
        vector<string>ans;
        for(int i=0;i<a.size();i++)
        {
           if(m[a[i]]==mx)
           {
             ans.push_back(a[i]);
             m[a[i]]=-1;
           }
        }
        sort(ans.begin(),ans.end());
        for(int i=0;i<ans.size();i++)
          cout<<ans[i]<<endl;
   }    

Measured memory_bytes: 28016
N=int(input())
mod=10**9+7


A=5
dp=[[[[0]*A for _ in range(A)] for _ in range(A)] for _ in range(N+1)]

def check1(a,b,c):
    t=[a,b,c]
    if t==[1,2,4] or t==[1,4,2] or t==[2,1,4]:
        return False
    return True

def check2(a,b,c,m):
    if ([b,c]==[2,4] and m==1) or ([a,c]==[2,4] and m==1):
        return False
    return check1(a,b,c)
    
    
#初期化
for n in range(min(4,N+1)):
    for i in range(A):
        for j in range(A):
            for k in range(A):
                if check1(i,j,k):
                    dp[n][i][j][k]=1
                    
for n in range(4,N+1):
    for i in range(1,A):
        for j in range(1,A):
            for k in range(1,A):
                for m in range(1,A):
                    if check2(i,j,k,m):
                        dp[n][i][j][k]+=dp[n-1][m][i][j]
                dp[n][i][j][k]%=mod
                        
ans=0
if N>=4:
    for i in range(1,A):
            for j in range(1,A):
                for k in range(1,A):
                    ans+=dp[N][i][j][k]

if N==1:
    ans=4
elif N==2:
    ans=16
elif N==3:
    ans=61

print(ans%mod)




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

int main(){
  ll N;
  cin >> N;
  vector<string> s(N);
  for(int i=0;i<N;i++){cin >> s[i]; sort(s[i].begin(),s[i].end());}
  sort(s.begin(),s.end());
  ll cnt=0;
  for(int i=0;i<N;i++){
    ll a=0;
    while(i+1<N && s[i]==s[i+1]){a++; i++;}
    cnt+=a*(a+1)/2;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 7296