akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>

int main() {
	{
		int N;
		std::string S, T;
		std::cin >> N;
		std::cin >> S >> T;
        for(int i = 0;i < N;i++){
            std::cout << S[i] << T[i];
        }
        std::cout << std::endl;
    }
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)
ll N,X;
ll dp[202][101010];
ll S[222];
ll i,j,k;
int main(){
    scanf("%lld%lld", &N ,& X);
    fornum(i,0,N){
        scanf("%lld", &S[i]);
    }
    sort(S, S + N, greater<ll>());
    dp[0][X] = 1;
    fornum(i,0,N){
        fornum(j,0,X+1){
            dp[i+1][j % S[i]] =(dp[i+1][j % S[i]] + dp[i][j])%MOD;
        }
        fornum(j,0,X+1){
            dp[i + 1][j] = (dp[i+1][j]+dp[i][j] * (N-1-i)) % MOD;
        }
    }
    ll ans = 0;
    fornum(i,0,S[N-1]){
        ans = (ans+dp[N][i] * i)%MOD;
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 158080
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;

struct LazySegmentTree {
private:
    int n;
    vector<ll> node, lazy;

public:
    LazySegmentTree(vector<ll> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
    }

    void eval(int k, int l, int r) {
        if(lazy[k] != 0) {
            node[k] += lazy[k];
            if(r - l > 1) {
                lazy[2*k+1] += lazy[k] / 2;
                lazy[2*k+2] += lazy[k] / 2;
            }
            lazy[k] = 0;
        }
    }

    void add(int a, int b, ll x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] += (r - l) * x;
            eval(k, l, r);
        }
        else {
            add(a, b, x, 2*k+1, l, (l+r)/2);
            add(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = node[2*k+1] + node[2*k+2];
        }
    }

    ll getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[k];
        ll vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }
};
main(){
    ll N,D,A;
    cin >> N >> D >> A;
    vector<ll> X(N),H(N);
    rep(i,0,N)cin >> X[i] >> H[i];
    vector<P> V(N);
    rep(i,0,N)V[i] = P(X[i], H[i]);
    sort(V.begin(), V.end());
    
    //rep(i,0,N)cout << V[i].first << " " << V[i].second << endl;
    ll ans = 0;
    LazySegmentTree seg(vector<ll>(N,0));
    rep(i,0,N){
        ll num = seg.getsum(i,i+1);
        ll rem = V[i].second - num;
        if(rem <= 0)continue;
        ll l = i, r;
        ll xl = V[i].first, xr = V[i].first + D * 2;
        auto itr = upper_bound(V.begin(), V.end(), P(xr, INF));
        itr--;
        r = distance(V.begin(), itr);
        //cout << l << "," << r << endl;
        ll cnt = (rem + A - 1) / A;
        //cout << i << "^" << rem << "^" << cnt << endl;
        ans += cnt;
        seg.add(l, r+1, A * cnt);
    }
    rep(i,0,N){
        //cout << i << ":" << seg.getsum(i,i+1) << endl;
    }
    cout << ans << endl;

}

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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define outl(x) cout<< (x) << '\n'
#define pb(a) push_back(a)
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
  return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
  return a / gcd(a, b) * b;
}

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

int main()
{
  int a[3];

  ci >> a[0] >> a[1] >> a[2];

  sort(a, a + 3);
  
  co << a[0] + a[1] + a[2] * 10 << en;
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
int a,b;
char op;
while(1){
scanf("%d %c %d",&a,&op,&b);
if(op=='?')break;
else switch(op){
case '+':
printf("%d\n",a+b);
break;

case '-':
printf("%d\n",a-b);
break;

case '*':
printf("%d\n",a*b);
break;

case '/':
printf("%d\n",a/b);
break;
}
}
return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;


const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}


int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    REP(i,n){
        cin >> a[i];;
    }
    REP(i,k){
        vector<int> b(n, 0);
        REP(i, n)
        {
            int l = max(0LL, i - a[i]);
            int r = min(n - 1, int(i + a[i]));
            b[l]++;
            if (r + 1 < n)
            {
                b[r + 1]--;
            }
        }
        a[0]=b[0];
        int ndesu=0;
        if(a[0]==n){
            ndesu++;
        }
        REP(j, n)
        {
            if (j == 0)
                continue;
            b[j] += b[j - 1];
            a[j]=b[j];
            if(a[j]==n){
                ndesu++;
            }
        }
        if(ndesu==n){
            REP(j,n){
                cout << n << " ";
            }
            cout << endl;
            return 0;
        }
    }
    REP(i,n){
        cout << a[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 4812
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
using namespace std;

typedef long long ll;

int H,W;
string s[100];
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

void dfs(int x,int y) {
  s[x][y] = '.';
  // cout << "x " << x <<" " << "y " << y << endl;
  for ( int i = 0; i < 4; i++ ) {
    int nx = x+dx[i],ny = y+dy[i];
    if( 0 <= nx && nx < H && 0 <= ny && ny < W &&
	s[nx][ny] == '#' ) {
      //cout << "nx " << nx << " " << "ny " << ny << endl;
      dfs(nx,ny);
    }
  }
  
}

int main() {
  cin >> H >> W;
  for ( int i = 0; i < H; i++ ) cin >> s[i];

  for ( int i = 0; i < H; i++ ) {
    for ( int j = 0; j < W; j++ ) {
      if( (s[i][j] == '#' &&  i-1 >= 0 && s[i-1][j] == '#' ) ||
	  (s[i][j] == '#' &&  i+1 < H  && s[i+1][j] == '#' )  ||
	  (s[i][j] == '#' &&  j-1 >= 0 && s[i][j-1] == '#' ) ||
	  (s[i][j] == '#' &&  j+1 < W && s[i][j+1] == '#' ) )  {
	
	dfs(i,j);
      }
    }
  }
  /*
  for ( int i = 0; i < H; i++ ) {
    for ( int j = 0; j < W; j++ ) {
      cout << s[i][j];
    }
    cout << endl;
  }
  */
  
  bool f = true;
  for ( int i = 0; i < H; i++ ) {
    for ( int j = 0; j < W; j++ ) {
      if ( s[i][j] == '#') {
	f = false;
	break;
      }
    }
  }

  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define rep(i,l,r)for(ll i=l;i<r;i++)

typedef long long ll;

int main(){
    ll n, m1, m2, ans = 2;

    scanf("%lld", &n);
    if (n == 2){
        printf("1");
        return 0;
    }

    rep (k,2,sqrt(n) + 1){
        m1 = n;
        m2 = n;
        if (k * k == n - 1) ans++;
        else if ((n - 1) % k == 0) ans += 2;
        if (k * k == n) ans++;
        else if (n % k == 0){
            while (m1 % k == 0) m1 /= k;
            while (m2 % (n / k) == 0) m2 /= n / k;
            if (m1 % k == 1) ans++;
            if (m2 % k == 1) ans++;
        }
    }
    printf("%lld", ans);

    return 0;
}


Measured memory_bytes: 2112
s = input()
ans = "YES"

while (len(s) - 5) > 2:
    c = s[-5:]
    if (c == "dream"):
        s = s[ : -5]
    else:
        if (c == "erase"):
            s = s[: -5]
        else:
            c = s[-6:]
            if (c == "eraser"):
                s = s[: -6]
            else:
                c = s[-7:]
                if (c == "dreamer"):
                    s = s[: -7]
                else:
                    ans = "NO"
                    break

                    
if s != "dream":
    if s != "erase":
        if s != "dreamer":
            if s != "eraser":
                ans = "NO"

print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h> 
#define ll long long
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define F first
#define S second
#define mp make_pair
#define PII pair<int,int>
#define PLL pair<long long,long long>
#define pq priority_queue
#define M map
#define UM unordered_map
#define graph unordered_map<int,vector<int>>
#define graphw unordered_map<int,vector<pair<int,int>>>
#define V vector
#define mod 1000000007
#define inf 3000000000000000007ll
#define P pair
#define Fast ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) signed(a.size())
#define FIXED cout << fixed << setprecision(12)
#define L list
#define D deque
#define ld long double
using namespace std;
// pair operation
template<class T, class U>istream& operator>>(istream& in, pair<T,U> &rhs){in >> rhs.first;in >> rhs.second;return in;}
template<class T, class U>ostream& operator<<(ostream& out,const pair<T,U> &rhs){out << rhs.first;out << " ";out << rhs.second;return out;}
template<class T, class U>pair<T,U> operator+(pair<T,U> &a, pair<T,U> &b){return pair<T,U>(a.first+b.first,a.second+b.second);}
template<class T, class U>pair<T,U> operator-(pair<T,U> &a, pair<T,U> &b){return pair<T,U>(a.first-b.first,a.second-b.second);}
// Linear STL
// VECTOR
template<class T>istream& operator>>(istream& in, vector<T> &a){for(auto &i: a)cin >> i;return in;}
template<class T>ostream& operator<<(ostream& out, const vector<T> &a){for(auto &i: a)cout << i << " ";return out;}
// SET
template<class T>ostream& operator<<(ostream& out, const set<T> &a){for(auto &i: a)cout << i << " ";return out;}
template<class T>ostream& operator<<(ostream& out, const unordered_set<T> &a){for(auto &i: a)cout << i << " ";return out;}
template<class T>ostream& operator<<(ostream& out, const multiset<T> &a){for(auto &i: a)cout << i << " ";return out;}
// MAP
template<class T,class U>ostream& operator<<(ostream& out, const map<T,U> &a){for(auto &i: a)cout << "(" << i.first << ", " << i.second << "(\n";return out;}
template<class T,class U>ostream& operator<<(ostream& out, const unordered_map<T,U> &a){for(auto &i: a)cout << "(" << i.first << ", " << i.second << "(\n";return out;}

int main() {
    Fast;
    int t=1;
    // cin>>t;
    while(t--){
        int n,q;
        cin>>n>>q;
        int a[q+1];
        for(int i=0;i<q;i++)cin>>a[i];
        sort(a,a+q);
        a[q]=a[0]+n;
        int ans=0;
        for(int i=1;i<=q;i++)
        ans=max(ans,a[i]-a[i-1]);
        cout<<n-ans<<endl;
    }
}


Measured memory_bytes: 1024
import Data.List (foldl')
import Data.Vector.Unboxed (Vector, fromList, (!), null)
import qualified Data.Vector.Unboxed as V
import Debug.Trace (trace)

main :: IO ()
main = do
    getLine
    ns <- fmap (fromList . (map read) . words) getLine :: IO (Vector Int)
    getLine
    ms <- fmap ((map read) . words) getLine :: IO [Int]
    print $ solve ns ms

solve :: Vector Int -> [Int] -> Int
solve ns ms = snd $ foldl' bSearch (ns, 0) ms
  where
    bSearch :: (Vector Int, Int) -> Int -> (Vector Int, Int)
    bSearch (ns', c) m
        | V.null ns'     = (ns, c)
        | m == ns' ! mid = (ns, c + 1)
        | m <  ns' ! mid = bSearch ((V.take mid ns'), c) m
        | otherwise      = bSearch ((V.drop (mid + 1) ns'), c) m
      where
        mid = V.length ns' `div` 2



Measured memory_bytes: 81660
#include <bits/stdc++.h>
#define MOD 998244353
#define pb push_back
#define ll long long int
#define con 1000000007

using namespace std;
int main()
{    
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     ll i,j,k,n,m;
     ll t;
     ll a,b;
     cin>>n>>m;
     if(m%2==0)
     {   j=1;
         k=m+1;
         for(i=0;i<m/2;i++)
         {
             cout<<j<<" "<<k<<"\n";
             j++;
             k--;
         }
         j=m+2;
         k=2*m+1;
         for(i=0;i<m/2;i++)
         {
             cout<<j<<" "<<k<<"\n";
             j++;
             k--;
         }
     }
     else
     {
         j=1;
         k=m;
         for(i=0;i<m/2;i++)
         {
             cout<<j<<" "<<k<<"\n";
             j++;
             k--;
         }
         j=m+1;
         k=2*m+1;
         for(i=0;i<=m/2;i++)
         {
             cout<<j<<" "<<k<<"\n";
             j++;
             k--;
         }
     }
}  


Measured memory_bytes: 3692
#include <cstring>
#include <cctype>
#include <cstdio>
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e2+5;
int max(int a, int b) { return a>b?a:b; }
int min(int a, int b) { return a<b?a:b; }
short f[N][N][N][N], g[N][N], h[N][N];
char s[N][N];
int n, m, ans, px, py;
int main()
{
    n = read(), m = read(); memset(f, -1, sizeof(f));
    for(int i = 1; i <= n; ++i) scanf("%s", s[i]+1);
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= m; ++j)
        {
            if(s[i][j] == 'E') px = i, py = j;
            g[i][j] = g[i][j-1]+(s[i][j] == 'o');
            h[i][j] = h[i-1][j]+(s[i][j] == 'o'); 
        }    
    f[0][0][0][0] = 0;    
    int pl = py-1, pr = m-py, pd = px-1, pu = n-px, p;
    for(int l = 0; l <= pl; ++l)
        for(int r = 0; r <= pr; ++r)
            for(int d = 0; d <= pd; ++d)
                for(int u = 0; u <= pu; ++u)
                {
                    if(!(~f[l][r][d][u])) continue;
                    int cl = max(r+1, py-l), cr = min(m-l, py+r);
                    int cd = max(u+1, px-d), cu = min(n-d, px+u);
                    if((p = py+r+1) <= m-l) f[l][r+1][d][u] = max(f[l][r+1][d][u], f[l][r][d][u]+h[cu][p]-h[cd-1][p]);
                    if((p = py-l-1) >= r+1) f[l+1][r][d][u] = max(f[l+1][r][d][u], f[l][r][d][u]+h[cu][p]-h[cd-1][p]);
                    if((p = px+u+1) <= n-d) f[l][r][d][u+1] = max(f[l][r][d][u+1], f[l][r][d][u]+g[p][cr]-g[p][cl-1]);
                    if((p = px-d-1) >= u+1) f[l][r][d+1][u] = max(f[l][r][d+1][u], f[l][r][d][u]+g[p][cr]-g[p][cl-1]);                 
                    ans = max(ans, f[l][r][d][u]);
                }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 237696
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		String s=sc.next();
		int dpw[]=new int[n];
		int dp[]=new int[n];

		if(s.charAt(0)=="W".charAt(0)) {
			dpw[0]=1;
		}
		else {
			dpw[0]=0;
		}

		dp[0]=0;

		for(int i=1;i<n;i++) {
			if(s.charAt(i)=="W".charAt(0)) {
				dpw[i]=dpw[i-1]+1;
				dp[i]=dp[i-1];
			}
			else {
				dpw[i]=dpw[i-1];
				dp[i]=dp[i-1]+1;
			}

			if(dpw[i-1]<dp[i]) {
				dp[i]=dpw[i-1];
			}

		}

		System.out.print(dp[n-1]);


	}

}


Measured memory_bytes: 30468
from collections import Counter

N = int(input())
A = [int(zz) for zz in input().split()]
b = Counter(A)
p = list(set(A))
ans = 0
for i in range(len(p)-2):
    q = b[p[i]]+b[p[i+1]]+b[p[i+2]]
    if ans < q:
        ans = q

if N == 2:
    if A[0]-1 <= A[1] <= A[0]+1:
        ans = 2
    else:
        ans = 1
elif N == 1:
        ans = 1

if len(p) == 2:
    if p[0]-1 <= p[1] <= p[0]+1:
        ans = N
    else:
        ans = max(b[p[0]],b[p[1]])
elif len(p) == 1:
    ans = N
    
print(ans)


Measured memory_bytes: 58860
// Confessions of a Dangerous Mind

/*
	"We know what we are, but know not what we may be."
*/

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 2e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 5;
const int logN = 20, BL = 400;
const double EPS = 3e-16;

/*
	"You never know how strong you are until being strong is the only choice you have."
*/

int main(){
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

/*
	"With self-discipline most anything is possible."
*/	

	long long n; cin >> n;
	
	double ans = 0, x = n / 3.0;
	
	ans = x * x * x;
	cout << fixed << setprecision(10) << ans;
	return 0;
}

/*
	"Reach for it. Push yourself as far as you can."
*/

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(){
  long n;  scanf("%ld", &n);

  int table[300][2] = {0}, len = 0;
  long ncopy = n;
  long sqrtn = sqrt(n);
  long sqrtnc = sqrt(ncopy);
  //    for(long i = 2; i<=sqrt(n); i++){
  for(long i=2; ncopy!=1; i++){
    if(len == 0  &&  i > sqrtn)  break;
    if(i > sqrtnc){
      table[len][0] = ncopy;
      table[len][1]++;
      len++;
      break;
    }
    if(ncopy % i == 0){
      table[len][0] = i;
      while(ncopy % i == 0){
	ncopy /= i;
	table[len][1]++;
      }
      len++;
      sqrtnc = sqrt(ncopy);
    }
  }

  long ans = 0;

  for(int i=0; i<len; i++){
    //    printf("table[%d] %d\n", table[i][0], table[i][1]);
    long count, j;
    for(j=1; ; j++){
      if(j*(j+1)/2 > table[i][1]){
	break;
      }
    }
    ans = ans + (j-1);
  }
      
  if(len == 0)  ans = 1;
  if(n == 1)  ans = 0;

  printf("%ld\n", ans);
  return 0;
}
  

  


Measured memory_bytes: 2160
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = 0;
		ArrayList array = new ArrayList();
		for(int i = 0;i<a;i++){
			array.add(sc.nextInt());
		}
		Collections.sort(array);
		Collections.reverse(array);
		for(int j=0;j<b;j++){
			c += (int)array.get(j);
		}
		System.out.println(c);

	}
}

Measured memory_bytes: 21716
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int N = scan.nextInt();
        String S = scan.next();
        if (S.length() % 2 == 1) {
            os.println("No");
            return;
        }

        int secondStart = S.length()/2;
        String first = S.substring(0, secondStart);
        String second = S.substring(secondStart, S.length());

        if(first.equals(second)) {
            os.println("Yes");
        } else {
            os.println("No");
        }
    }
}

Measured memory_bytes: 23636
#include <iostream>
#define ll long long
#define ld long double
#define pi 3.14159
using namespace std;

int main(){
    ll n, m, s = 0;
    cin >> n >> m;
    ll ar[m];
    for(ll i = 0;i<m;i++){
        cin >> ar[i];
        s += ar[i];
    }
    if(s > n)
        cout << "-1";
    else
        cout << n-s;
}


Measured memory_bytes: 3652
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=2050;
//ここまでテンプレ
int main(){
	int N;
	cin>>N;
	vll A;
	for(int i=0;i<N;i++){
		ll a;
		cin>>a;
		a-=i+1;
		A.pb(a);
	}
	sort(A.begin(),A.end());
	ll ans=0;
	for(int i=0;i<N;i++)
		ans+=llabs(A[i]-A[N/2]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main() {
    
    ld n,m,d;
    cin>>n>>m>>d;
    ld ans;
    if(d==0){
        ans=(m-1)/n;
    } else {
        ans=(m-1)*2*(n-d)/(n*n);
    }
    printf("%.7Lf\n",ans);
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <iostream>
#include <cassert>
#include <algorithm>
#include <set>
#include <cmath>
#include <tuple>
#include <vector>
#include <array>
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
	std::string s;
	std::cin >> s;
	int n = 3;
	// {0, 1, ..., n-1} の部分集合の全探索
	for (int bit = 0; bit < (1<<n); ++bit)
	{
		std::bitset<3> b = std::bitset<3>(bit);
		int ans = s[0] - '0';
		for ( int i = 0 ; i < 3 ; i++ ) {
			if(b[i]){
				ans = ans - (s[i+1] - '0');
			}else{
				ans = ans + (s[i+1] - '0');
			}
		}
		if(ans==7){
			char a[10];
			a[0] = s[0];
			for ( int i = 0 ; i < 3 ; i++ ) {
				if(b[i]){
					a[i*2+1] = '-';
					a[i*2+2] = s[i+1];
				}else{
					a[i*2+1] = '+';
					a[i*2+2] = s[i+1];
				}
			}
			a[7] = '=';
			a[8] = '7';
			a[9] = '\0';
			std::cout << a << std::endl;
			break;
		}
	}
	return 0;
}



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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug if(true)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i] == '7'){printf("Yes\n"); return 0;}
	}
	printf("No\n");
	return 0;
};

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#include<string>
#define int long long
using namespace std;
main()
{
	//freopen("input.txt","rt",stdin);
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	int c =0;
	sort(arr,arr+n);
	for(int i=0;i<n-2;i++)
	{
		for(int j=i+1;j<n-1;j++)
		{
			for(int k=j+1;k<n;k++)
			{
//				cout<<arr[i]<<" "<<arr[j]<<" "<<k<<" "<<arr[k]<<endl;
//				cout<<arr[i]<<" "<<arr[j]+arr[k]<<endl;
//				cout<<arr[j]<<" "<<arr[i]+arr[k]<<endl;
//				cout<<arr[k]<<" "<<arr[i]+arr[j]<<endl;
				if(arr[i]< arr[j]+arr[k] && arr[j]<arr[i]+arr[k] && arr[k] < arr[i]+arr[j])
				{
					c++;
				}
			}
		}
	}
	cout<<c<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
int main()
{
    int n,m;
    char a[100][100];
    char c;
    cin >> n >> m;
    memset(a,0,sizeof(a));
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
        {
            scanf("%c",&c);
            if(c==' '||c=='\n') j--;
            else  a[i][j]=c;
        }
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            if(a[i][j]=='.')
            {
                int sum=0;
                if(a[i-1][j]=='#') sum++;
                if(a[i-1][j-1]=='#') sum++;
                if(a[i-1][j+1]=='#') sum++;
                if(a[i][j+1]=='#') sum++;
                if(a[i][j-1]=='#') sum++;
                if(a[i+1][j]=='#') sum++;
                if(a[i+1][j-1]=='#') sum++;
                if(a[i+1][j+1]=='#') sum++;
                printf("%d",sum);
            }
            else printf("#");
        }
        printf("\n");
    }
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
const int INF = 1<<28;
const ll MOD = 1000000007;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

void add_Node(int a, int b, vector<vi> &node, vi &edge) {
	node[a].pb(b);
	node[b].pb(a);
	edge[a]--;
	edge[b]--;
	return;
}

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

	int n; cin >> n;
	while(n--) {
		vi edge, cur;
		vector<vi> node(100);
		int in, cnt = -1, times = -1, pre;
		while(cin >> in, in) {
			if(in > 0) {
				cnt++; times++;
				edge.pb(in);
				if(times)
					add_Node(times, pre, node, edge);
				cur.pb(cnt);
				pre = times;
			}
			else if(in < 0) {
				for(int i = pre; i >= 0; i--) {
					if(cur[i] - cnt == in && edge[i] > 0) {
						add_Node(pre, i, node, edge);
						break;
					}
				}
			}
			while(!edge[pre]) pre--;
			cnt = cur[pre];
		}
		REP(i, node.size()) {
			if(node[i].empty())
				continue;
			cout << i + 1;
			sort(node[i].begin(), node[i].end());
			REP(j, node[i].size())
				cout << ' ' << node[i][j] + 1;
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0; return gcd(a, b, x, y);}
ll modpow(lll a,lll n,ll m){if(a==0)return a;lll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
const int N = 200000;
int n, a[N], b[N], c[N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n){
    int p;
    cin >> p;
    a[p-1] = i;
  }
  FOR(i, 1, n) b[i] = (a[i] < a[i-1]) ? i : b[i-1];
  FORR(i, n-2, 0) c[i] = (a[i] > a[i+1]) ? n-i-1 : c[i+1];
  int ans = iinf;
  FOR(i, 0, n) mins(ans, b[i] + c[i]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2560
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    N = 10**6+1
    bit = [0]*(N+1)
    def add(i):
        while i <= N:
            bit[i] += 1
            i += i&-i
    def sum(i):
        res = 0
        while i:
            res += bit[i]
            i -= i&-i
        return res

    n = I()
    l = LI()
    l.sort()
    ans = 0
    s = []
    k = 0
    for i in range(n):
        li = l[i]
        ans += k-sum(li)
        for j in range(i):
            add(li+l[j])
            k += 1
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 49132
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

bool isParindrome(string s) {
    int head_idx = 0;
    int tail_idx = s.size() - 1;

    while(head_idx <= tail_idx) {
        if (s[head_idx] != s[tail_idx]) {
            return false;
        }
        head_idx++;
        tail_idx--;
    }
    return true;
}

int main() {
    // assert(isParindrome("lel"));
    // assert(!isParindrome("le"));
    // assert(isParindrome("e"));

    string S;
    cin >> S;
    int len = S.size();

    string head_str = S.substr(0, (len - 1) / 2);
    string tail_str = S.substr((len + 1) / 2, (len-1)/ 2);

    if (isParindrome(S) && isParindrome(head_str) && isParindrome(tail_str)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 100005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

string op[N];

ll dp[N][5][5][5];
ll nxt[N][5][5][5];
ll val[3];
ll offset = 2;

ll n;

ll recur(ll pos, ll val1, ll val2, ll val3) {

  if (abs(val1) > 2)
    return 0;
  if (abs(val2) > 2)
    return 0;
  if (abs(val3) > 2)
    return 0;

  if ((val1 + val[0]) < 0)
    return 0;
  if ((val2 + val[1]) < 0)
    return 0;
  if ((val3 + val[2]) < 0)
    return 0;

  if (pos == n)
    return 1;

  ll &ans = dp[pos][val1 + offset][val2 + offset][val3 + offset];

  ll &nxt1 = nxt[pos][val1 + offset][val2 + offset][val3 + offset];
  if (ans != -1)
    return ans;

  ll a = op[pos][0] - 'A';
  ll b = op[pos][1] - 'A';

  ll nwVal[3] = {val1, val2, val3};
  nwVal[a]++;
  nwVal[b]--;
  ans = recur(pos + 1, nwVal[0], nwVal[1], nwVal[2]);
  nwVal[a] -= 2;
  nwVal[b] += 2;
  if (ans) {
    nxt1 = 0;
  } else {
    ans = recur(pos + 1, nwVal[0], nwVal[1], nwVal[2]);
    if (ans)
      nxt1 = 1;
  }
  return ans;
}

vector<char> res;

void solve(ll pos, ll val1, ll val2, ll val3) {
  if (pos == n)
    return;
  ll &nxt1 = nxt[pos][val1 + offset][val2 + offset][val3 + offset];
  res.emplace_back(op[pos][nxt1]);
  ll a = op[pos][0] - 'A';
  ll b = op[pos][1] - 'A';

  if (nxt1)
    swap(a, b);
  ll nwVal[3] = {val1, val2, val3};
  nwVal[a]++;
  nwVal[b]--;
  solve(pos + 1, nwVal[0], nwVal[1], nwVal[2]);
}

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

  cin >> n;

  for (ll i = 0; i < 3; i++) {
    cin >> val[i];
  }

  for (ll i = 0; i < n; i++) {
    cin >> op[i];
  }

  memset(dp, -1, sizeof(dp));
  ll ans = recur(0, 0, 0, 0);
  if (ans == 0) {
    cout << "No" << en;
    return 0;
  }
  cout << "Yes" << en;
  solve(0, 0, 0, 0);

  for (char c : res)
    cout << c << en;

  return 0;
}


Measured memory_bytes: 213176
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        m: usize,
        mut v: [i64; m]
    }
    if n >= m {
        println!("0");
        return;
    }
    v.sort();
    let mut d: Vec<i64> = vec![0; m - 1];
    for i in 0..m - 1 {
        d[i] = v[i + 1] - v[i];
    }
    d.sort();
    println!("{}", d.iter().take(m - n).map(|x| *x).sum::<i64>());
}


Measured memory_bytes: 6396
n,x,y=map(int, input().split())
es=[[] for _ in range(n)]
for i in range(n):
    if i<n-1:
        es[i].append([1,i+1])
    if i>0:
        es[i].append([1,i-1])
    es[x-1].append([1,y-1])
    es[y-1].append([1,x-1])

import heapq

def dijkstra_heap(s):
    d = [float("inf")] * n
    used = [True] * n
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in es[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in es[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    return d

from collections import defaultdict, Counter
from copy import deepcopy
dist=dijkstra_heap(0)
distx=dijkstra_heap(x-1)
disty=dijkstra_heap(y-1)
counts=[]
for i in range(n-1):
    if i<x-1:
        tmp=[d-i for d in dist[i:]]
        counts.append(Counter(tmp))
    elif x-1<=i<y-1:
        tmp=[min(distx[i]+distx[d], disty[i]+disty[d], abs(d-i)) for d in range(i,n)]
        counts.append(Counter(tmp))
    else:
        tmp=[disty[d]-disty[i] for d in range(i,n)]
        counts.append(Counter(tmp))
ans=defaultdict(int)

for i in range(n-1):
    keys=counts[i].keys()
    for kk in keys:
        ans[kk]+=counts[i][kk]

for i in range(1,n):
    print(ans[i])

Measured memory_bytes: 158568
#include <iostream>
#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define endl "\n"
using namespace std;
using ll = long long;
const ll mod = 1e9+7;

ll fac[1000001];

void pre(){
    fac[0]=fac[1]=1;
    for(int i=2;i<=1000001;i++)
{

    fac[i]=(fac[i-1]*1LL*i)%mod;
}
}

ll binpower(ll a,ll n){
    ll res=1;
    while(n){

    if(n%2)
        res = (res*1LL*a)%mod;

        n/=2;
        a=(a*1LL*a)%mod;

    }
    return res;

}

ll nCrmod(ll n,ll r){


ll res= fac[n];
res = (res*1LL*binpower(fac[r],mod-2))%mod;
res= (res*1LL*binpower(fac[n-r],mod-2))%mod;
return res;

}

long long ncr(int n, int r) {
    if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
    long long ans = 1;
    int i;

    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
ll modexp(ll a,ll b,ll m){
    if(b==0)return 1;
    if(b%2==0){
        ll y =  modexp(a,b/2,m);
        return (y*y)%m;
    }
    else{
        return ((a%m)*modexp(a,b-1,m))%m;
    }
}

ll modinv(ll a,ll m){
return modexp(a,m-2,m);
//works only for prime m.
//else calculate phi(m)-1.
}

void SieveOfEratosthenes(ll n)
{
    // Create a boolean array "prime[0..n]" and initialize
    // all entries it as true. A value in prime[i] will
    // finally be false if i is Not a prime, else true.
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (ll p=2; p*p<=n; p++)
    {
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == true)
        {
            // Update all multiples of p greater than or
            // equal to the square of it
            // numbers which are multiple of p and are
            // less than p^2 are already been marked.
            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

    // Print all prime numbers
    for (ll p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}

vector<int> Centroid(vector<int>g[],int n) {

        vector<int> centroid;
        vector<int> sz(n+1);
        function<void (int, int)> dfs = [&](int u, int prev) {
                sz[u] = 1;
                bool is_centroid = true;
                for (auto v : g[u]) if (v != prev) {
                        dfs(v, u);
                        sz[u] += sz[v];
                        if (sz[v] > n / 2) is_centroid = false;
                }
                if (n - sz[u] > n / 2) is_centroid = false;
                if (is_centroid) centroid.push_back(u);
        };
        dfs(1, 0);
        return centroid;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    vector<pair<int,int>>v(n);
    for(int i=0;i<n;i++){
        cin>>v[i].first>>v[i].second;
    }
    bool ok =false;
    for(int i=0;i<n-2;i++){
        if(v[i].first==v[i].second&&
           v[i+1].first==v[i+1].second&&
           v[i+2].first==v[i+2].second
           )ok=true;
    }
if(ok)cout<<"Yes";
else cout<<"No";

    return 0;
}


Measured memory_bytes: 3664
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int[] team=new int[100];
		int[] data=new int[100];
		int ptr=0;
		while(true){
			String str=sc.next();
			if(str.equals("0,0")){
				break;
			}
			team[ptr]=Integer.parseInt(str.split(",")[0]);
			data[ptr]=Integer.parseInt(str.split(",")[1]);
			ptr++;
		}
		for(int i=0;i<ptr;i++){
			for(int j=ptr-1;j>=i+1;j--){
				if(data[j]>data[j-1]){
					int box=data[j];
					data[j]=data[j-1];
					data[j-1]=box;
					box=team[j];
					team[j]=team[j-1];
					team[j-1]=box;
				}
			}
		}
		int[] ranking=new int[ptr];
		int checkRank=data[0];
		int rank=1;
		for(int i=0;i<ptr;i++){
			if(data[i]!=checkRank){
				checkRank=data[i];
				rank++;
			}
			ranking[i]=rank;
		}
		while(sc.hasNext()){
			int searchTeam=sc.nextInt();
			for(int i=0;i<ptr;i++){
				if(team[i]==searchTeam){
					System.out.println(ranking[i]);
					break;
				}
			}
		}
	}
}

Measured memory_bytes: 17220
#include <bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define SZ(x) ((int)(x.size()))
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))

const double pi = 4 * atan(1);
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;
const int MAXN = 200005;

ll a[1005];
ll b[1005];
ll c[1005];
ll sums[1000005];
ll final[10000005];
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int x, y, z;
	cin >> x >> y >> z;
	int k;
	cin >> k;
	FOR(i,0,x)
	{
		cin >> a[i];
	}
	FOR(i,0,y)
	{
		cin >> b[i];
	}
	FOR(i,0,z)
	{
		cin >> c[i];
	}
	
	int si = 0;
	for (int i = 0; i < x; i++) {
		for (int j = 0; j < y; j++) {
			sums[si++]=a[i]+b[j];
		}
	}
	sort(sums,sums+si, greater<ll>());
	sort(c,c+z,greater<ll>());
	
	int ck = k;
	int fi = 0;
	
	for (int i = 0; i < min(k,si) && ck; i++) {
		for (int j = 0; j < min(k,z) && ck; j++) {
			final[fi++]=sums[i]+c[j];
		}
	}
	
	sort(final,final+fi,greater<ll>());
	FOR(i,0,k) {
		cout << final[i] << "\n";
	}
	
}


Measured memory_bytes: 34948
#include <iostream>
#include <vector>
#include <map>
using namespace std ;
 
int n, m ;
 
int a[100010] ;
 
vector < int > g[100010] ;
 
bool vis[100010] ;
 
int group[100010], nGroup ;
 
void dfs(int u){
	vis[u] = true ; 
	group[u] = nGroup ;
	//printf("group[%d]=%d\n",u,nGroup);
	for (int i = 0; i < (int)g[u].size(); ++ i)
	{
		int v = g[u][i] ;
		//printf("v=%d\n",v);
		if(!vis[v]) 
			dfs(v) ;
		
	}
}
 
int main(){

	ios_base :: sync_with_stdio(false) ;
 
	cin >> n >> m ;
 
	for (int i = 1; i <= n; ++ i) cin >> a[i] ; 
 
	for (int i = 1; i <= m; ++ i){
		int x, y ; cin >> x >> y ;
		g[x].push_back(y) ; g[y].push_back(x) ;
	}
 
	for (int i = 1; i <= n; ++ i){
		if(!vis[i]) nGroup ++, dfs(i) ;
	}
 
	int ans = 0 ;
 
	for (int i = 1; i <= n; ++ i) 
	{
		
		if(group[i] == group[a[i]]) 
		{
			//printf("group[%d]==group[%d]==%d,a[%d]=%d\n",i,a[i],group[i],i,a[i]);
			ans ++ ;
		}
			
	}
		
 
	cout << ans << endl ;
 
	return 0 ;
}

Measured memory_bytes: 9728
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
c = Counter(a)
m = c.most_common()

if (len(m)==1) and (m[0][0]==0):
  print('Yes')
elif (m[0][1]==2*N//3) and (m[1][0]==0) and (len(m)==2):
  print('Yes')
elif (m[0][1]==N//3) and (m[1][1]==N//3) and (m[2][1]==N//3) and (m[0][0]^m[1][0]^m[2][0]==0):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 20792
import fractions
N = int(input())
A = list(map(int,input().split()))
hard = fractions.gcd(A[0],A[1])
easy = [A[0],A[1]]
del A[0]
del A[0]
while len(A) != 0:
  easyt1 = fractions.gcd(easy[0],A[0])
  easyt2 = fractions.gcd(easy[1],A[0])
  easyt3 = hard
  easy = sorted([easyt1,easyt2,easyt3])[1:3]
  hard = fractions.gcd(hard,A[0])
  del A[0]
print(max(easy))

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

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    vector<int> b(n);
    rep(i,n) cin>>a[i];
    b=a;
    sort(b.begin(),b.end());

    rep(i,n){
        if(a[i]!=b[n-1]) cout<<b[n-1]<<"\n";
        else cout<<b[n-2]<<"\n";
    }
    return 0;
}

Measured memory_bytes: 4804
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;

public class Main {

	/* several useful subroutines */
	private static BufferedReader brStdin = new BufferedReader(new InputStreamReader(System.in));
	private static String[] readBuf = null;
	private static int readPtr = 0;
	private static String getString() throws IOException {
		while ( readBuf == null || readPtr >= readBuf.length ) {
			readBuf = brStdin.readLine().split(" ");
			readPtr = 0;
		}
		return readBuf[readPtr++];
	}
	private static int getInt() throws IOException {
		return Integer.parseInt(getString());
	}
	private static long getLong() throws IOException {
		return Long.parseLong(getString());
	}
	private static BigDecimal getBD() throws IOException {
		return new BigDecimal(getString());
	}
	@SuppressWarnings("unused")
	private static String[] getStringArray(int size) throws IOException {
		String stringArray[] = new String[size];
		for (int i = 0; i < stringArray.length; i++) {
			stringArray[i] = getString();
		}
		return stringArray;
	}
	@SuppressWarnings("unused")
	private static int[] getIntArray(int size) throws IOException {
		int intArray[] = new int[size];
		for (int i = 0; i < intArray.length; i++) {
			intArray[i] = getInt();
		}
		return intArray;
	}
	@SuppressWarnings("unused")
	private static long[] getLongArray(int size) throws IOException {
		long longArray[] = new long[size];
		for (int i = 0; i < longArray.length; i++) {
			longArray[i] = getLong();
		}
		return longArray;
	}
	@SuppressWarnings("unused")
	private static BigDecimal[] getBDArray(int size) throws IOException {
		BigDecimal bdArray[] = new BigDecimal[size];
		for (int i = 0; i < bdArray.length; i++) {
			bdArray[i] = getBD();
		}
		return bdArray;
	}
	@SuppressWarnings("unused")
	private static long calculateLCM(long a, long b) throws IOException {
		if ( a  < b ) {
			long t = a;
			a = b;
			b = t;
		}
		while ( b > 0 ) {
			long t = b;
			b = a % b;
			a = t;
		}
		return a;
	}

	
	/* main routine */
	
	public static void main(String args[]) throws IOException {
		int n = getInt();
		long d[] = getLongArray(n);

		long ans = 0;
		for (int i = 0 ; i < n-1; i++ ) {
			for ( int j = i+1 ; j < n ; j++ ) {
				ans += d[i] * d[j];
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 22228