akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

bool isp(string s){
  int n=s.size();
  rep(i,0,n/2){
    if(s[i]!=s[n-1-i])return false;
  }
  return true;
}

signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  string s;cin>>s;
  int n=s.size();
  string a=s.substr(0,(n-1)/2),b=s.substr(0,(n-1)/2);
  if(isp(s) && isp(a) && isp(b))cout<<"Yes"<<ENDL;
  else cout<<"No"<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

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

using namespace std;
using ll = long long int;
const long double PI = 3.1415926535;
int main () {
 ll r;
 cin >> r;
 cout << fixed << setprecision(10) << (r * 2 * PI) << endl;
}

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

int main(int argc, const char * argv[]) {
    int A, B;
    cin >> A;
    cin >> B;
    
    
    int plus = A + B;
    int minus = A - B;
    int kake = A * B;
    int ans = max(kake, max(plus, minus));
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i,n) for(ll i=0;i<(n);i++)  
#define pii pair<int,int>
#define piii pair<int,pii>
#define mp make_pair
#define pb push_back  
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-5;
const double PI = M_PI;  
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cerr<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
  
#define DIV 1000000007
typedef vector<ll> Array;
typedef vector<Array> matrix;
typedef tuple<int,int,int> tiii;
#define mt make_tuple

vector<set<int>> vs(100001);
int main(){
  int n; cin >> n;
  int ans = 0;
  rep(i,n){
    int t; cin >> t;
    vs[t].insert(i+1);
    if(vs[i+1].find(t) != vs[i+1].end()) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 9600
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

#include<iostream>

long int const MAX_N = 100000;
long int par[MAX_N]; // 親
long int depth[MAX_N]; // 木の深さ
long int num[MAX_N]; // 要素数

// n要素で初期化
void init(long int n){
    for(long int i = 0; i < n; i++){
        par[i] = i;
        depth[i] = 0;
        num[i] = 1;
    }
}

// 木の根を求める
long int find(long int x){
    if (par[x] == x) {
        return x;
    }else{
        return par[x] = find(par[x]);
    }
}

// xとyの属する集合を合併
void unite(long int x, long int y){
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (depth[x] < depth[y]) {
        par[x] = y;
        num[y] += num[x];
    }else{
        par[y] = x;
        num[x] += num[y];
        if (depth[x] == depth[y]) depth[x]++;
    }
}

// xとyが同じ集合に属するか否か
bool same(long int x, long int y){
    return find(x) == find(y);
}


int main(){
    long int n, m, k;
    cin >> n >> m >> k;
    long int a[m], b[m];
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }
    long int c[k], d[k];
    rep(i, k) {
        cin >> c[i] >> d[i];
        c[i]--; d[i]--;
    }
    init(n);
    rep(i, m) unite(a[i], b[i]);
    long int ans[n];
    fill(ans, ans + n, 0);
    rep(i, n){
        ans[i] = num[find(i)];
    }
    rep(i, m){
        ans[a[i]]--;
        ans[b[i]]--;
    }
    rep(i, k){
        if(same(c[i], d[i])){
            ans[c[i]]--;
            ans[d[i]]--;
        }
    }
    rep(i, n){
        cout << ans[i] - 1 << " ";
    }cout << endl;
}


Measured memory_bytes: 7168
# -*- coding: utf-8 -*
import sys
if False:
#if True:
    fh=open('ALDS1_1_D1.txt','r')
else:
    fh=sys.stdin
input=fh.readline

def main():
    n = int(input())
    a=[]
    for _ in range(n):
        a.append(int(input()))

    pmax=a[1]-a[0]
    pmin=a[0]
    for j in range(1, n):
        pmax = max(a[j]-pmin,pmax)
        pmin = min(pmin,a[j])

    print(pmax)
    
if __name__ == "__main__":
    main()



Measured memory_bytes: 13592
#include <iostream>
#include <string>
#include <limits.h>
#include <numeric>
#include <math.h>
#include <bits/stdc++.h>
#define rep(i,c) for (int i=0;i<c;i++)
using namespace std;
typedef long long ll;
 
 
int main(){
    int K,A,B;
    cin >> K >> A >>B;
    string ans = "NG";

    for(int i=A;i<=B;i++){
        if(i%K==0) ans="OK";
    }

    cout << ans << endl;

}

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

#define ll long long
#define ld long double
#define xx first
#define yy second
#define vi vector<int>
#define pii pair<int,int>
#define all(v) v.begin(),v.end()

#define MAX 400005

ll n, m, k;

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

    cin >> n >> m >> k;

    string mat[n];
    for(int i=0;i<n;i++)
        cin >> mat[i];

    ll ans = 0;
    for(int i=0;i< (1<<n);i++)
    {
        for(int j=0;j< (1<<m);j++)
        {
            ll cnt =0;
            for(int k=0;k<n;k++)
            {
                for(int l=0;l<m;l++)
                {
                    if((i>>k)&1 || (j>>l)&1)
                        continue;

                    if(mat[k][l] == '#')
                        cnt++;
                }
            }

            if(cnt == k) ans++;
        }        
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
    int M, N;
    cin >> M >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i], A[i]--;
    if(M == 2){
        int ans = 1e9;
        for(int k=0; k<2; k++){
            int res = 0;
            for(int i=0; i<N; i++) if((i+A[i]+k)%2) res++;
            ans = min(ans, res);
        }
        cout << ans << endl;
    }else{
        int ans = 0;
        for(int i=0; i<N-1; i++) if(A[i] == A[i+1]){
            ans++;
            A[i+1] = -i-1;
        }
        cout << ans << endl;
    }
    return 0;
}



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

using namespace std;

int main()
{
    int n;
    cin >> n ;
    int a[n], ans[n];
    rep(i, n) cin >> a[i];
    rep(i, n) ans[a[i] - 1] = i + 1;
    rep(i, n) cout << ans[i] << " ";
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    int n,W;cin >> n >> W;
    ll weight; cin >> weight;
    vector<vl> wei(4);
    rep(i,n){
        if(i==0){
            int b;cin >> b;
            wei[0].push_back(b);
            continue;
        }
        int a,b;cin >> a >> b;
        wei[a-weight].emplace_back(b);
    }
    rep(i,4){
        sort(wei[i].begin(), wei[i].end(), greater<ll>());
    }
    vector<vl> dp(n+10, vl(300,0));
    rep(w,4){
        rep(i,wei[w].size()){
            for(int j=n-1;j>=0;--j){
                rep(k,300){
                    if(k-w<0) continue;
                    dp[j+1][k] = max(dp[j+1][k], dp[j][k-w] + wei[w][i]);
                }
            }
        }
    }
    ll ans = 0;
    rep(i,n+1){
        rep(j,300){
            if(i*weight + j > W){
                break;
            }
            if(ans < dp[i][j]){
                cerr << ans << " -> " << dp[i][j] << "   ";
                cerr << "i = " << i << " j = " << j << endl;
                ans = dp[i][j];
            }
        }
    }
    cerr << "ans is ";
    cout << ans << endl;
}

Measured memory_bytes: 512
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

s = str(sum(a))

for i in range(n):
    if a[i] >= b[i]:
        a[i] -= b[i]
    elif a[i] < b[i]:
        if a[i] + a[i+1] <= b[i]:
            a[i] = 0
            a[i+1] = 0
        elif a[i] + a[i+1] > b[i]: 
            a[i+1] -= (b[i]-a[i])
            a[i] = 0

print(int(s)-sum(a))

Measured memory_bytes: 82020
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}

int main(){
  string s;
  cin >> s;
  ull len = s.size();
  ll hlen = len / 2;
  ll sum = 0;
  rep(i,hlen){
    if(s[i] != s[len-1-i]){
      sum++;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(a) begin(a), end(a)
#define csz(a) (int) a.size()
#define pb push_back
#define epb emplace_back
#define mp make_pair
#define load(a, v) fill(begin(a), end(a), v)
#define load_mem(a, v) memset(a, v, sizeof(a));
#define iostream_optimize() ios::sync_with_stdio(false); cin.tie(0);
using ll = long long;
const ll MOD = 1e9+7, LINF = 1e18 + 1e16;
const int INF = 1e9+1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const ll P1 = 31, P2 = 37, M1 = 1e9+7, M2 = 1e9+9;
 
/* <<<<<<<<<<<<<<<<<<<<<<<<<<<< END TEMPLATE >>>>>>>>>>>>>>>>>>>>>>>>>>> */

ll a, b, c, x, y, ans;
int main() {
	iostream_optimize();
	cin >> a >> b >> c >> x >> y;
	if(2*c < a+b) {
		ll mn = min(x, y);
		ans += mn * 2 * c;
		x -= mn;
		y -= mn;
	}
	ans += x * min(a, 2*c);
	ans += y * min(b, 2*c);
	cout << ans;
}


Measured memory_bytes: 256
#include <stdio.h>

int max(int a, int b){
    if(a>b){
        return a;
    }
    return b;
}

int main(){
    int n;
    int v[100100][3];
    int i,j,dp[100100][3] = {0};
    int m;

    scanf("%d",&n);
    for(i = 1; i <= n ;i++){
        for(j = 0 ; j < 3 ; j++){
            scanf("%d",&v[i][j]);
        }
    }
    dp[1][0] = v[1][0];
    dp[1][1] = v[1][1];
    dp[1][2] = v[1][2]; 
    for(i = 1; i < n ; i++){
        for(j = 0 ; j < 3 ; j++){
            if(j == 0){
                dp[i+1][1] = max(dp[i+1][1],dp[i][j]+v[i+1][1]);
                dp[i+1][2] = max(dp[i+1][2],dp[i][j]+v[i+1][2]);
            }
            if(j == 1){
                dp[i+1][0] = max(dp[i+1][0],dp[i][j]+v[i+1][0]);
                dp[i+1][2] = max(dp[i+1][2],dp[i][j]+v[i+1][2]);
            }
            if(j == 2){
                dp[i+1][1] = max(dp[i+1][1],dp[i][j]+v[i+1][1]);
                dp[i+1][0] = max(dp[i+1][0],dp[i][j]+v[i+1][0]);
            }

        }
    }
    m = 0;
    for(j = 0 ;j < 3 ; j++){
        m = max(m,dp[n][j]);
    }
    printf("%d\n",m);
    return 0;

}

Measured memory_bytes: 2560
N, M = map(int, input().split())
a_s = []
b_s = []
for i in range(M):
	a, b = map(int, input().split())
	a_s.append(a)
	b_s.append(b)

for i in range(1, N + 1):
	print(a_s.count(i) + b_s.count(i))


Measured memory_bytes: 9072
// Ryo Kamoi
//#define DEBUG

#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>

using namespace std;

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

typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;

int INF = 1000000000;

int w, h;
int cliff[70][40];
int dist[70][40][2];
pii start[2800];
pii goal[2800];

int steplx[9] = {3, 2, 2, 2, 1, 1, 1, 1, 1};
int steply[9] = {0, -1, 0, 1, -2, -1, 0, 1, 2};

int main(){
    while(1){
        cin >> w >> h;
        if (w==0 && h==0) break;

        REP(i, 70) {
            REP(j, 40) {
                cliff[i][j] = 0;
                REP(k, 2) {
                    dist[i][j][k] = INF;
                }
            }
        }

        REP(i, 2){
            start[i] = pii(-1, -1);
        }
        
        int start_num = 0;
        int goal_num = 0;
        REP(i, h) {
            REP(j, w) {
                char num;
                cin >> num;
                if (num == 'X') {
                    cliff[i][j] = -1;
                } else if (num == 'S') {
                    cliff[i][j] = 0;
                    REP(k, 2) dist[i][j][k] = 0;
                    start[start_num] = pii(i, j);
                    start_num++;
                } else if (num == 'T') {
                    cliff[i][j] = -2;
                    goal[goal_num] = pii(i, j);
                    goal_num++;
                } else {
                    cliff[i][j] = num - '0';
                }
            }
        }

        queue<pair<pii, pii>> que;
        int sign[2] = {-1, 1};
        REP(i, start_num) {
            REP(j, 2) {
                que.push(pair<pii, pii>(pii(0, sign[j]), start[i]));
            }
        }

        while(!que.empty()) {
            pair<pii, pii> p = que.front(); que.pop();
            int d = p.first.first;
            int x = p.second.second;
            int y = p.second.first;
            int lr = p.first.second;
            if (d > dist[y][x][(1+lr)/2]) continue;

#ifdef DEBUG
            cout << y << " " << x << " " << d << " " << lr << endl;
#endif

            REP(i, 9) {
                int nx = x + lr * steplx[i];
                int ny = y + steply[i];
                if (nx>=0 && ny>=0 && nx<w && ny<h) {
                    if (cliff[ny][nx] == -1) continue;
                    int next_dist = dist[y][x][(1+lr)/2] + max(0, cliff[ny][nx]);
                    if (dist[ny][nx][(1-lr)/2] > next_dist) {
                        dist[ny][nx][(1-lr)/2] = next_dist;
                        if (cliff[ny][nx] == -2) continue;
                        que.push(pair<pii, pii>(pii(next_dist, -lr), pii(ny, nx)));
                    }
                }
            }
        }

        int output = INF;
        REP(i, goal_num) {
            REP(k, 2) {
                output = min(dist[goal[i].first][goal[i].second][k], output);
            }
        }

        if (output == INF) {
            cout << -1 << endl;
        } else {
            cout << output << endl;
        }
    }
}



Measured memory_bytes: 3128
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int n,d,x,a[100];
	int ans=0;
	cin>>n>>d>>x;
	for(int i=0;i<n;i++){
		cin>>a[i];
		
	}
	
	for(int i=0;i<n;i++){
		if(a[i]+1<=d){
			ans=ans+(d-1)/a[i]+1;
		}
		
		else if(a[i]>=d){
			ans++;
		}
	}
	
	cout<<ans+x<<endl;
	
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.Math.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        int[] p = new int[n];
      
        for (int i=0; i < n; i++) {
            p[i] = sc.nextInt();
        }
      
        int cnt = 1;
        int min = p[0];
      
        for (int i = 1; i < n; i++) {
            if (min > p[i]) {
                min = p[i];
                cnt++;
            }
        }
        
        System.out.println(cnt);
        
	}
}

Measured memory_bytes: 76048
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, A, B; cin >> N >> A >> B;
	if (A + B > N + 1 || A * B < N) {
		cout << -1 << endl;
		return 0;
	}

	deque<int> ans;
	int a = A;
	int n = 1;
	vector<bool>F(N+1, false);
	while (1) {
		ans.push_front(a);
		F[a--] = 1;
		
		if (a%A == 0) {
			n++;
			a = A * n;
			B--;
			chmin(a, N);
		}
		if (B == (N - (int)ans.size()))break;
	}
	n = N;

	while (N != ans.size()) {
		if (!F[n]) {
			cout << n-- << " ";
			N--;
		}
		else n--;
	}

	REP(i, N) cout << ans[i] << " ";
	cout << endl;


	return 0;
}



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

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

int main(){
  string s;
  int cnt0=0,cnt1=0;
  cin >> s;
  rep(i,s.size()){
    if(s[i]=='0'){
      cnt0++;
    }else{
      cnt1++;
    }
  }
  cout << min(cnt0,cnt1)*2 << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define OJ \
        freopen("input.txt","r",stdin); \
        freopen("output.txt","w",stdout);

int main()
{ 
   
//  OJ;
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
  ll int n,q,b,c,sum=0;
  map<ll int,ll int> freq;
  cin>>n;
 ll int a[n];
  for(ll int i=0;i<n;i++)
  {
      cin>>a[i];
      freq[a[i]]++;
      sum+=a[i];
  }
  cin>>q;
  while(q--)
  {
    cin>>b>>c;
   // cout<<freq[b]<<" "<<freq[c]<<endl;
    
    sum+=freq[b]*c-freq[b]*b;
    
    freq[c]+=freq[b];
    freq[b]=0;
    cout<<sum<<endl;

   
  }
  
}

Measured memory_bytes: 10332
import sys
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(M)]

for i in range(10**N):
    if len(str(i)) < N:
        continue
    lst = list(str(i))
    for s, c in sc:
        if int(lst[s-1])==c:
            continue
        else:
            break
    else:
        print(i)
        exit()
print(-1)

Measured memory_bytes: 38640
/**
       **********    ************
	  Author : Avi J Patel
	  University : DAIICT
       **********    ************
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair 
#define mt make_tuple
#define ff first
#define ss second
#define si size()
#define MOD 1000000007
#define Mod 998244353
#define N 200001
#define large 10000000000000001
#define For(i,m,n) for(long long i=m;i<n;i++)
#define st(x) sort(x.begin(),x.end())
#define re(x,i) reverse(x.begin()+i,x.end())
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    if(a.second < b.second) return true; 
    else if(a.ss==b.ss) return a.ff<b.ff;
	else return false;
}
bool sortbyboth(const pair<int,int> &a, const pair<int,int> &b)
{
	if(a.first<b.first) return true;
	else if(a.first==b.first) return a.second<b.second;
	else return false;
} 
ull powr(ull x1, ull n1) {
    if(x1==0)
    {
        return 0;
    }
    ull result=1;
    while(n1>0)
    {
        if(n1&1)
        {
            result=(result*x1);
        }
        n1=n1>>1;
        x1=(x1*x1);
    }
    return result;
} 
int  days(int month, int year)
{
	if( month == 2)
	{
		if((year%400==0) || (year%4==0 && year%100!=0))	
			return 29;
		else	
			return 28;
	}
	else if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8
	||month == 10 || month==12)	
		return 31;
	else 		
		return 30;
} 
int dayofweek(int d, int m, int y)  
{  
    static int t[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };  
    y -= m < 3;  
    return ( y + y / 4 - y / 100 + y / 400 + t[m - 1] + d) % 7;  
}  
int main()
{
	FAST
	string s,t,u;
	cin>>s>>t;
	int a,b;
	cin>>a>>b;
	cin>>u;
	if(u==s){
		cout<<a-1<<" "<<b;
	}
	else 
	cout<<a<<" "<<b-1;
    return 0;
}
 
 
 
 
 
 
 
 
 
 
 


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>

using namespace std;

int main()
{
    long double aa;
    long double bb;
    long double cc;
    cin >> aa >> bb >> cc;

    long double dd = cc - bb -aa;
    if((dd > 0) && ((dd * dd) > (4 * aa * bb))){
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input()) 
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))

dp = [[0] * N for i in range(2)]
dp[0][0] = A1[0]
dp[1][0] = A1[0] + A2[0]

for i in range(1, N):
  dp[0][i] = dp[0][i - 1] + A1[i]

for i in range(1, N):
  dp[1][i] = max(dp[1][i - 1], dp[0][i]) +  A2[i] 
  
#for i in range(2):
#  print(dp[i])

print(dp[-1][-1])

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

long long A, B;
long long div(long long c) {
	long long ac, bc;
	if (A % c != 0) {
		ac = A / c + 1;
	}
	else ac = A / c;
	bc = B / c;
	return bc - ac + 1;
}

long long gcd(long long c, long long d){
	if (c == 0)return d;
	if (d < c)swap(d, c);
	return gcd(d % c, c);
}

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

	long long C, D;
	cin >> A >> B >> C >> D;
	long long z = C * D / gcd(C, D);
	
	cout << B - A + 1 - (div(C) + div(D) - div(z));
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
//cin.sync_with_stdio(false);
//streambuf
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int mincost[5001];
vector<pii> tx(5001);
vector<vector<int>> way(5001);
int main() {
    int h, w;
    while (cin >> h >> w,h) {
        int m = h*h+w*w;
        int m1, h1;
        for (m1 = m;; m1++) {
            for (h1 = (m1 == m ? h + 1 : 1); h1*h1*2<m1; h1++) {
                if ((int)sqrt(m1 - h1*h1)*(int)sqrt(m1 - h1*h1)==m1-h1*h1)goto a;
            }
        }
    a:
        cout << h1 <<" "<< (int)sqrt(m1 - h1*h1) << endl;
    }
}

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

using namespace std;
#define ll long long
#define MOD 1000000007


bool check(string s, int i, int j)
{
    if(i >= j)
        return 1;

    if(s[i] != s[j])
        return 0;

    return check(s, i+1, j-1);
}


int main()
{
    string s;
    cin >> s;
    
    check(s, 0, s.length()-1) && check(s, 0, (s.length()-1)/2-1) && check(s, (s.length()+3)/2-1, s.length()-1) ? cout << "Yes" : cout << "No";


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  char C; cin>>C;
  C++;
  cout<<C<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
int main(){
  long long A;
  cin>>A;
  double B;
  cin>>B;
  int C=B*100+0.001;
  cout<<(A*C)/100<<endl;
  /*int N;
  cin>>N;
  long long A[100000];
  long long answer=1;
  for(int i=0;i<N;i++){
    cin>>A[i];
    if(A[i]==0) answer=0;
  }
  if(answer==0) cout<<answer<<endl;
  else{
  for(int i=0;i<N;i++){
    answer=answer*A[i];
    if(answer>1000000000000000000){
      answer=-1;
      break;
    }
  }
  cout<<answer<<endl;
  }*/
  
  return 0;
}

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

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

ll mod = (ll)(1e9+7);

bool factorization_onetime(const ll &n, map<ll,ll> &mp){

    ll now = n;
    for(ll i = 2; i*i <= n; i++){
        ll times = 0;
        while(now%i==0){
            times++;
            now/=i;
        }
        if(times>=1){
            if(mp[i] > 0){
              return false;
            }
            mp[i] += times;
        }
        if(now==1){
            break;
        }
    }
    if(now > 1){
      if(mp[now] > 0){
        return false;
      }
        mp[now]++;
    }
    return true;
}

int main(){
  ll n;
  cin >> n;
  
  vector<ll> a(n);
  rep(i,n){
    cin >> a[i];
  }
  vector<ll> gcds(n);
  gcds[n-1] = a[n-1];
  bool ok = true;
  map<ll, ll> mp;
  ok = factorization_onetime(a[n-1], mp);
  for(ll i = n-1; i > 0; i--){
    gcds[i-1] = gcd(a[i-1], gcds[i]);
    if(ok){
      ok = factorization_onetime(a[i-1],mp);
    }
  }
  if(ok){
    cout << "pairwise coprime" << endl;
  }else if(gcds[0]==1){
    cout << "setwise coprime" << endl;
  }else{
    cout << "not coprime" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 18812
while True:
    n=int(input())
    if n == 0:
        break
    a=1000-n
    B=a//500
    b=a%500
    C=b//100
    c=b%100
    D=c//50
    d=c%50
    E=d//10
    e=d%10
    F=e//5
    f=e%5
    G=f//1
    print(B+C+D+E+F+G)
    


Measured memory_bytes: 5584
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = Long.parseLong(sc.next());
		long y = Long.parseLong(sc.next());
		int m = 0;
		while (x <= y) {
			m++;
			x *= 2;
		}
		System.out.println(m);
	}
}

Measured memory_bytes: 23124
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var n = nextstr();
  var sum = 0;
  for(var i = 0; i < n.length; i++){
    sum += +n[i];
  }
  return sum % 9 ? "No" : "Yes";
}

Measured memory_bytes: 32536
//Nature of Prime Numbers
#include <stdio.h>
#include <string.h>
#include <set>

int main(){
  int n;
  while(1){
    scanf("%d", &n);
    if(n == 0){
      break;
    }
    std::set<int> S;
    int A[n / 2 + 1];
    memset(A, 0, sizeof(A));
    for(int i = 1; i < n; ++i){
      S.insert(i * i % n);
    }
	for(std::set<int>::iterator a = S.begin();a != S.end(); ++a){
      for(std::set<int>::iterator b = S.begin();b != S.end(); ++b){
        if(a == b){
          continue;
        }
        int c = *a - *b;
        if(c < 0){
          c = c + n;
        }
        if(c > (n - 1) / 2){
          c = n - c;
        }
        A[c]++;
      }
    }
    for(int i = 1; i <= (n - 1) / 2; ++i){
      printf("%d\n", A[i]);
    }
  }    
  return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<float> x(n);
  float s = 0.0;
  for(int i=0;i<n;i++){
    cin >> x.at(i);
    s += x.at(i);
  }
  s /= n;
  s = round(s);
  int ans = 0;
  for(int i=0;i<n;i++){
    ans += pow(x.at(i)-s, 2);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(false);cin.tie(0);

int main() {
	optimizar_io

	int n;
	string s, ans;

	cin >> n >> s;
	for (int i = 0; i < s.size(); i++) {
		char c = s[i];
		c += n;
		if (c > 'Z')
			c -= 26;
		ans.push_back(c);
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<char,int> pci;
typedef vector<pair<int,int>> vpii;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
#define sci(a) scanf("%d",&a)
#define scii(a,b) scanf("%d %d",&a,&b)
#define sciii(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sciiii(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define scl(a) scanf("%lld",&a)
#define scll(a,b) scanf("%lld %lld",&a,&b)
#define sclll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c
#define scllll(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define print(a) printf("%d ",a)
#define println(a) printf("%d\n",a)
#define ln printf("\n")
#define pb(a) push_back(a)
#define m_p(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define rep(i,s,n) for(int i=s;i<=n;i++)
#define rrep(i,e,s) for(int i=e;i>=s;i--)
#define repv(i,m) for(auto i = m.begin();i != m.end();i++)
#define FileIO freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const long long INF = 4000000000000000000LL;
/************************************* Chocolate *************************************/
int main(){
    int n,w;
    scii(n,w);
    vi wgt(n+1),val(n+1);
    ll sum = 0;
    rep(i,1,n){
        scii(wgt[i],val[i]);
        sum += val[i];
    }
    vll dp(sum+1,INF);//dp[i]=total minimum weight for getting value exactly i.
    dp[0] = 0;
    rep(i,1,n){
        rrep(j,sum,val[i]){
            dp[j]= min(dp[j],dp[j - val[i]]+wgt[i]);
        }
    }
    int ans=0;
    rep(i,1,sum){
        if(dp[i] <= w) ans = i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4064
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const a = parseInt(args[0][0], 10)
	const b = parseInt(args[0][1], 10)
	console.log((a - 1) * (b - 1))
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


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

typedef long long ll;
using namespace std;

int main(){
  ll n, a, b, c, d, e;

  cin >> n >> a >> b >> c >> d >> e;

  ll x = min({a, b, c, d, e});

  cout << (n+x-1)/x + 4 << endl;



  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n,a[100001],h[100001];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>h[1];
    h[0]=1e10;
    for(int i=2;i<=n;i++)
    {
        cin>>h[i];
        a[i]=min(abs(h[i-1]-h[i])+a[i-1],abs(h[i-2]-h[i])+a[i-2]);
    }
    cout<<a[n];
}


Measured memory_bytes: 1792
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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


int main() {

	int k; cin >> k;
	string s; cin >> s;
	if (s.length() <= k) cout << s;
	else cout << s.substr(0, k) + "...";

	return 0;
}

Measured memory_bytes: 3624
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    X = II()
    for a in range(-1000, 1000):
        a5 = pow(a, 5)
        for b in range(-1000, 1000):
            b5 = pow(b, 5)
            if a5 - b5 == X:
                print(a, b)
                return

if __name__ == '__main__':
    solve()


Measured memory_bytes: 65012
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

const INF = 100000001000000

func main() {
	sc.Split(bufio.ScanWords)

	N := nextInt()
	H := make([]int, N)
	used := map[int]bool{}
	for i := 0; i < N; i++ {
		H[i] = nextInt()
		used[H[i]] = false
	}

	for i := 0; i < N-1; i++ {
		if H[i] == H[i+1] {
			continue
		}

		if H[i]+1 <= H[i+1] {
			if !used[H[i+1]] {
				H[i+1]--
				used[H[i+1]] = true
			}
		}

		if H[i] > H[i+1] {
			if !used[H[i]] {
				H[i]--
				used[H[i]] = true
				if H[i] > H[i+1] {
					fmt.Println("No")
					return
				}
			}

		}

	}

	flag := true
	for i := 0; i < N-1; i++ {
		if H[i] <= H[i+1] {
			continue
		}

		flag = false
	}

	// fmt.Println(H)

	if flag {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

	// dp := make([]int, N)
	// for i := 0; i < N; i++ {
	// 	dp[i] = INF
	// }

	// for i := 0; i < N; i++ {

	// 	key := UpperBound(dp, H[i])
	// 	dp[key] = H[i]

	// }

	// ans := N
	// for i := 0; i < N; i++ {
	// 	if dp[i] == INF {
	// 		ans--
	// 	}
	// }

	// fmt.Println(dp)

	// if ans >= N-1 {
	// 	fmt.Println("Yes")
	// } else {
	// 	fmt.Println("No")
	// }

}

func LowerBound(t []int, k int) int {
	lb := -1
	ub := len(t)
	for ub-lb > 1 {
		mid := (lb + ub) / 2

		if t[mid] >= k {
			ub = mid
		} else {
			lb = mid
		}
	}
	return ub
}

func UpperBound(t []int, k int) int {
	lb := -1
	ub := len(t)
	for ub-lb > 1 {
		mid := (lb + ub) / 2

		if t[mid] <= k {
			lb = mid
		} else {
			ub = mid
		}
	}
	return ub
}


Measured memory_bytes: 8704
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <cstdlib>
#include <random>
#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
//typedef vector<ll> vec;
//typedef vector<vec> mat;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;

const ll MAX_N=200010;

ll N,M;
ll a[MAX_N],b[MAX_N],a_tmp[MAX_N],b_tmp[MAX_N];

int main(){
  cin>>N;
  for(ll i=0;i<N;i++){
    cin>>a[i];
  }
  for(ll i=0;i<N;i++){
    cin>>b[i];
  }
//  sort(b,b+N);
  ll ans=0;
  for(ll k=0;k<32;k++){
    ll mod2=(1LL<<(k+1));
//    cout<<mod2<<endl;
    for(ll i=0;i<N;i++){
      a_tmp[i]=a[i]%mod2;
      b_tmp[i]=b[i]%mod2;
    }
    sort(b_tmp,b_tmp+N);
    ll bitnum=0;
    ll t=1<<k;
    for(ll i=0;i<N;i++){
      bitnum+=upper_bound(b_tmp,b_tmp+N,2*t-1LL-a_tmp[i])-lower_bound(b_tmp,b_tmp+N,t-a_tmp[i]);
      bitnum+=upper_bound(b_tmp,b_tmp+N,4*t-1LL-a_tmp[i])-lower_bound(b_tmp,b_tmp+N,3*t-a_tmp[i]);
    }
//    cout<<bitnum<<endl;
    if(bitnum%2==1)ans+=(1LL<<k);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 6528
import java.util.Scanner;

//?§????????????????S???hms?????????????????????????????°??????
public class Main{


	public static void main(String[] args){

		//?¨??????\???
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		area(a);


	}

	//????????¢?????¢???????±?????????????????????????
	private static void area(int a){

		int h, m, s;
		h=a/3600;
		m=(a%3600)/60;
		s=((a%3600)%60);
		System.out.println(h+":"+m+":"+s);
	}


}

Measured memory_bytes: 26144
import sys
input = sys.stdin.readline

# 最大値が赤であるとしてよい

import numpy as np
N = int(input())
XY = np.array([input().split() for _ in range(N)], dtype = np.int64)
X,Y = XY.T
# X \leq Y に変換
Z = X+Y
np.minimum(X,Y,out=X)
Y = Z - X

# 最大のものを赤、最小のものを青とする
# この場合、任意の箱に対して、大きい方を赤、小さい方を青
answer = (X.max() - X.min()) * (Y.max() - Y.min())

red = Y.max() - X.min()
# 青の最小値を決めると全部決まる
# 小さい側でソート -> 左からいくつかを上側、右からいくつかを下側
idx = X.argsort()
X = X[idx]
Y = Y[idx]
Y_min = np.minimum.accumulate(Y)
Y_max = np.maximum.accumulate(Y)
a = Y_max[-1] - Y_min[-1] # 全部上側からとった場合
b = (np.maximum(Y_max[:-1], X[-1]) - np.minimum(X[1:],Y_min[:-1])).min() # 途中まで上側
c = X[-1] - X[0] # 全部下側
answer = min(answer, red * min(a,b,c))

print(answer)

Measured memory_bytes: 92496
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)              (x).begin(),(x).end()
#define REP(i, n)           for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)       for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF                 (int)2e9
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846
typedef long long           ll;
typedef pair<ll, ll>	    P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	int A, B;
	cin >> A >> B;

	int ans = A * (A - 1) / 2 + B * (B - 1) / 2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/agc014/tasks/agc014_b
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define BIT(n) (1LL << (n))
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int v[100001];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    // vector<int> v(n + 1, 0);
    REP(i, m) {
        int a, b;
        cin >> a >> b;
        v[a]++;
        v[b]++;
    }
    bool ans = true;
    for (auto x : v) {
        if (x % 2 != 0) {
            ans = false;
            break;
        }
    }
    if (ans)
        cout << "YES\n";
    else
        cout << "NO\n";
    return 0;
}


Measured memory_bytes: 640
/**
 *  winners never quit
**/

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define pp pop_back
#define mp make_pair
#define IO cin.tie(0),cout.tie(0)
#define ISWS ios::sync_with_stdio(0)
typedef long long Long;
void FastIO(){ISWS;IO;}

const int N = 1e6;

int main()
{
  FastIO();
  int tc, ca = 0;
  int n;
  cin >> n;
  vector <int> a(n);
  for (int i = 0;i < n;i++){
    cin >> a[i];
  }
  string ans = "pairwise coprime";
  vector <int> cnt(N+1, 0);
  vector <int> m(N+1, 0);
  for (int i = 0;i < n;i++){
    if (m[a[i]]==0){
      m[a[i]] = 1;
      cnt[a[i]]++;
      if (cnt[a[i]] > 1 && a[i] > 1){
        ans = "setwise coprime";
        break;
      }
      for (int j = 2;j*j <= a[i];j++){
        if (a[i] % j == 0){
          int num1 = j;
          int num2 = a[i]/j;
          cnt[num1]++;
          if (num1!=num2)cnt[num2]++;
          if ((cnt[num1] > 1) || (cnt[num2] > 1)){
            ans = "setwise coprime";
            break;
          }
        }
      }
      if (ans == "setwise coprime")break;
    }
  }
  int gc = a[0];
  for (int i = 1;i < n;i++){
    gc = __gcd(gc, a[i]);
  }
  if (gc > 1){
    ans = "not coprime";
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 15040
import bisect

N = int(input())
A = list(map(int, input().split(' ')))
B= list(map(int, input().split(' ')))
C = list(map(int, input().split(' ')))

A.sort()
B.sort()
C.sort()

ans = 0
for i in B:
  a=bisect.bisect_left(A, i)
  c=bisect.bisect_right(C, i)
  ans += a*(N-c)
print(ans)

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

using namespace std;

typedef long long LL;
#define INF 0x3f3f3f3f3f3f3f3fLL

char s[2];
LL n,x,f[3],g[3];

void upd(LL x,LL &y){y=max(y,x);}

int main(){
	scanf("%lld",&n);
	scanf("%lld",&x); f[0]=x; f[1]=f[2]=-INF;
	for (LL i=1;i<n;++i){
		g[0]=f[0]; g[1]=f[1]; g[2]=f[2];
		f[0]=f[1]=f[2]=-INF;
		scanf("%s%lld",s,&x);
		if (s[0]=='-'){
			upd(g[0]-x,f[0]);
			upd(g[0]-x,f[1]);
			upd(g[1]+x,f[0]);
			upd(g[1]+x,f[1]);
			upd(g[1]+x,f[2]);
			upd(g[2]-x,f[1]);
			upd(g[2]-x,f[2]);
		}
		else{
			upd(g[0]+x,f[0]);
			upd(g[1]-x,f[0]);
			upd(g[1]-x,f[1]);
			upd(g[2]+x,f[1]);
			upd(g[2]+x,f[2]);
		}
	}
	printf("%lld\n",f[0]);
	
	return 0;
}
			

Measured memory_bytes: 256
from collections import Counter

N = int(input())
*A, = map(int, input().split())
cnt = Counter(A)
ans = []
S = sum(A)
Q = int(input())
for _ in range(Q):
    b, c = map(int, input().split())
    S += c * cnt[b] - b * cnt[b]
    cnt[c] += cnt[b]
    cnt[b] = 0
    ans.append(S)
print(*ans, sep='\n')

Measured memory_bytes: 27136
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

const int MOD = 1000000007;

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

    ll N;
    cin >> N;
    vector<ll> T(N), A(N);
    Rep (i, N) {
        cin >> T[i];
    }
    Rep (i, N) {
        cin >> A[i];
    }

    vector<ll> ttmp(N), atmp(N), mt(N);
    vector<bool> t(N, false), a(N, false), m(N, false);

    ll tmp = 0, ans = 1;
    Rep (i, N) {
        if (T[i] > tmp) {
            ttmp[i] = T[i];
            t[i] = true;
            tmp = T[i];
        } else if (T[i] == tmp) {
            ttmp[i] = T[i];
        }
    }
    tmp = 0;
    for (ll i = N - 1; i >= 0; i--) {
        if (A[i] > tmp) {
            atmp[i] = A[i];
            a[i] = true;
            tmp = A[i];
        } else if (A[i] == tmp) {
            atmp[i] = A[i];
        }
    }

    Rep (i, N) {
        if (!t[i] && !a[i]) mt[i] = min(ttmp[i], atmp[i]);
        else if (t[i] && a[i]) {
            if (ttmp[i] == atmp[i]) {
                mt[i] = 1;
            }
            else mt[i] = 0;
        }
        else if (t[i] && !a[i]) {
            if (ttmp[i] <= atmp[i]) {
                mt[i] = 1;
            } else mt[i] = 0;
        } else if (!t[i] && a[i]) {
            if (atmp[i] <= ttmp[i]) mt[i] = 1;
            else mt[i] = 0;
        }
    }

    Rep (i, N) {
        ans *= mt[i];
        ans %= MOD;
    }

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

Measured memory_bytes: 4224