akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define foru(i, a, b) for(int i = a; i <= b; i++) 
#define ford(i, a, b) for(int i = a; i >= b; i--) 
#define endl "\n"
#define scv(a, b, c) #a#b#c
#define com(a,b) a ## b

using namespace std;

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vii;
typedef vector<pll> v2l;
typedef pair<char, int> pci;

typedef vector<pci> vci;

const int N = 1e6 + 1;
const int NN = 1e3 + 1;
const ll MOD = 1e9 + 7;
const ll oo = 1e18 + 7;
const int BASE = 10000;

void solve() {
	int n, k;
	cin >> n >> k;
	vi a(n + 1);
	int sum = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	vi div;
	for (int i = 1; i <= sqrt(sum); i++) {
		if (sum % i) {
			continue;
		}
		int t = sum / i;
		div.pb(i);
		div.pb(t);
	}
	sort(all(div), greater<int>());
	for (int x : div) {
		vi c(n + 1);
		int s = 0;
		for (int i = 1; i <= n; i++) {
			c[i] = a[i] % x;
			s += c[i];
		}
		int step = 0;
		sort(c.begin() + 1, c.end());
		for (int i = 1; i <= n - s / x; i++) {
			step += c[i];
		}
		if (step <= k) {
			cout << x;
			return;
		}
	}
}

int main() {
    #ifdef DEBUG
        com(fre, open) (scv(solve, ., inp), "r", stdin);
        com(fre, open) (scv(solve, ., out), "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.precision(10);
    solve();
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

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

  stable_sort(a.begin(), a.end());

  ll i = lower_bound(a.begin(), a.end(), a[n - 1] / 2) - a.begin();

  if(i == 0){
    cout << a[n - 1] << ' ' << a[i] << endl;
    return 0;
  }
  if(i == n - 1){
    cout << a[n - 1] << ' ' << a[n - 2] << endl;
    return 0;
  }

  if((a[n - 1] / 2 - a[i - 1]) >= (a[i] - a[n - 1] / 2))
    cout << a[n - 1] << ' ' << a[i] << endl;
  else
    cout << a[n - 1] << ' ' << a[i - 1] << endl;
  
  return 0;
}


Measured memory_bytes: 1408
use std::io::*;
use std::str::FromStr;

fn main() {
    let L: i64 = read();
    let n: usize = read();
    let mut x: Vec<i64> = (0..n).map(|_| read()).collect();

    let mut ans = 0;
    for _ in 0..2 {
        let mut rx: Vec<i64> = vec![0; n];
        for i in 0..n {
            rx[i] = L - x[n - 1 - i];
        }

        let mut rui: Vec<i64> = vec![0; n + 1];
        let mut gyaku: Vec<i64> = vec![0; n + 1];
        for i in 0..n {
            rui[i + 1] = rui[i] + x[i];
            gyaku[i + 1] = gyaku[i] + rx[i];
        }

        for i in 0..n {
            let r = (n - i + 1) / 2;
            let l = n - i - r;

            let mut d = 2 * (rui[i + r] - rui[i]);
            d += 2 * gyaku[l];

            d -= if l != r { x[i + r - 1] } else { rx[l - 1] };
            ans = std::cmp::max(ans, d);
        }
        std::mem::swap(&mut x, &mut rx);
    }
    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 12540
#include<iostream>
#include<vector> 
#include<math.h>

bool is_prime(int num);

int main(){
    int n,x;
    int cnt=0;
    std::cin>>n;
    for(int i=0;i<n;i++){
        std::cin>>x;
        if(is_prime(x))cnt++;
    }
    std::cout<<cnt<<"\n";
}
bool is_prime(int num){
    
    for(int i=2;i<=sqrt(num);i++){
        if(num%i==0){
            // std::cout<<"num:"<<num<<"\n";
            return false;
        }
    }
    return  true;
}


Measured memory_bytes: 3104
// C - Otoshidama
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N,Y; cin>>N>>Y;
	Y /= 1000;
	rpz(x, min(N+1, (Y+10-1)/10+1)){
		int y = max(0, (Y-N-x*9)/4);
		int z = max(0, N - x - y);
		if(x + y + z != N) continue;
		if(x*10 + y*5 + z != Y) continue;
		printf("%d %d %d\n", x, y, z);
		return 0;
	}
	puts("-1 -1 -1");
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
typedef long long ll;
using namespace std;
const int MOD = 1000000007;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

int main()
{
    int N;
    cin >> N;
    char color[N];
    for(int i = 0; i < N; i++) cin >> color[i];
    int count = 1;
    for(int i = 0; i < N - 1; i++)
    {
        if(color[i] != color[i+1]) count++;
    }
    cout << count << endl;
}     

Measured memory_bytes: 384
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    String out = "";
    while (scanner.hasNext()) {
      double v = scanner.nextDouble();
      for (int n = 1; ; n++) {
        double vv = 9.8 * Math.sqrt((5 * n - 5) / 4.9);
        if (vv >= v) {
          out += n + "\n";
          break;
        }
      }
    }
  System.out.print(out);
  }
}

Measured memory_bytes: 18556
#include<iostream>
#include<sstream>
#include<iomanip>
#include<bitset>
#include<map>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define lli long long int
#define uli unsigned long long int
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
using namespace std;
int main(){
  int r,d,x;
  cin>>r>>d>>x;
  rep(i,0,10){
    ou(r*x-d);
    x=r*x-d;
  }
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  set<int> s;
  rep(i,n) s.insert(a[i]);
  if (n == s.size()) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> t(n+ 1,0),x(n + 1,0),y(n + 1,0);
    for(int i = 1; i < n + 1; i++){
        cin >> t[i] >> x[i] >> y[i];
    }
    bool ans = true;
    for(int i = 1; i < n + 1; i++){
        if((t[i] - t[i - 1]) % 2 == 0){
        int a = (abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]));
        if(a % 2 == 1 || t[i] - t[i - 1] < a)
        ans = false;
        }

        if((t[i] - t[i - 1]) % 2 != 0)
        {
             int b = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
             if(t[i] - t[i -1] < b || b % 2 == 0)
             ans = false;
        }
    }
    ans == true ? cout << "Yes" : cout << "No";
    cout << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
 
 
int main (){
    int i=0;
    int n = 0;
    int c[1000] = {0};
    int s[11] = {0};
    int count = 0;
    int b=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&c[i]);
 
        if(c[i]<=399){
            s[0]++;
        }else if(c[i] <= 799){
            s[1]++;
        }else if(c[i] <= 1199){
            s[2]++;
        }else if(c[i] <= 1599){
            s[3]++;
        }else if(c[i] <= 1999){
            s[4]++;
        }else if(c[i] <= 2399){
            s[5]++;
        }else if(c[i] <= 2799){
            s[6]++;
        }else if(c[i] <= 3199){
            s[7]++;
        }else{
            s[8]++;
        }
    }
 
    for(i=0;i<9;i++){
        if(s[i] > 0 && i != 8){
            count++;
        }
    }
 
    /*for(i=0;i<9;i++){
        printf("s[%d] = %d\n",i,s[i]);
    }*/
    if(count == 0 && s[8] <= 8){
        printf("1 %d\n",s[8]);
    }else if(count == 0 && s[8] > 8){
        printf("1 %d\n",s[8]);
    }else if(count+s[8] <= 8 && count > 0){
        printf("%d %d\n",count,count+s[8]);
    }else if(count+s[8] > 8 && count > 0){
        printf("%d %d\n",count,count+s[8]);
    }
    
 
    
    return 0;
}

Measured memory_bytes: 256
/*
    @uthor: Amit Kumar
    user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#define ln mp::cpp_int;
#define ll    long long
#define ld    long double
#define ull   unsigned long long
#define endl "\n"
ll google_itr = 1;
#define google(x) cout<<"Case #"<<x<<":"
#define pi 3.14159265358979323846264338327950L

const ll mod = 1e9+7;
const ll inf = 1e18;

ll popcount(ll num){
    num = num - ((num >> 1) & 0x55555555);
    num = (num & 0x33333333) + ((num >> 2) & 0x33333333);
    return ((num + (num >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}

vector<pair<ll,ll>> factor_arr;

void myfactor(ll num){ 
    ll count = 0;   
    while (!(num % 2)) { 
        num >>= 1; count++; 
    }  
    if (count) factor_arr.push_back({2,count}); 
    for (auto i = 3; i <= sqrt(num); i += 2) { 
        count = 0; 
        while (num % i == 0) { 
            count++; 
            num /= i; 
        } 
        if (count) factor_arr.push_back({i,count}); 
    } 
    if (num > 2) factor_arr.push_back({num,1});
}

void virus(){
          ll len;
          cin>>len;
          vector<vector<ll>> arr;
          for(auto i=0; i<len; i++){
              vector<ll> temp(3);
              for(auto &j:temp) cin>>j;
              arr.push_back(temp);
          }
          for(auto i=1; i<len; i++){
              arr[i][0] = max(arr[i][0] + arr[i-1][1], arr[i][0] + arr[i-1][2]);
              arr[i][1] = max(arr[i][1] + arr[i-1][0], arr[i][1] + arr[i-1][2]);
              arr[i][2] = max(arr[i][2] + arr[i-1][1], arr[i][2] + arr[i-1][0]);
          }
          cout<<*max_element(arr[len-1].begin(),arr[len-1].end())<<endl;
}


int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
  /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/

    ll t = 1;
    //cin>>t;
    while(t--){
           auto start = high_resolution_clock::now();
           virus();
           auto stop = high_resolution_clock::now();
           auto duration = duration_cast<seconds>(stop - start);
         //cout << "Time: "<<duration.count()<<endl;
        //your code goes here
    }
    return 0;
}

Measured memory_bytes: 8808
# 2019-11-13 01:43:55(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    a, b, t = [int(x) for x in sys.stdin.readline().split()]
    ans = int((t + 0.5) // a) * b
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
#define N 50
int n,k;
int field[2*N][2*N][2*N];
vector<int> compress(int *x1,int *x2){
    vector<int>xs;
    for(int i=0;i<n;i++){
        xs.push_back(x1[i]);
        xs.push_back(x2[i]);
    }
    sort(xs.begin(),xs.end());
    xs.erase(unique(xs.begin(),xs.end()),xs.end());

    for(int i=0;i<n;i++){
        x1[i]=find(xs.begin(),xs.end(),x1[i])-xs.begin();
        x2[i]=find(xs.begin(),xs.end(),x2[i])-xs.begin();
    }
    vector<int>len;
    for(int i=0;i<xs.size()-1;i++){
        len.push_back(xs[i+1]-xs[i]);
    }
    return len;
}
int main(){
    scanf("%d%d",&n,&k);
    int x1[N],x2[N],y1[N],y2[N],z1[N],z2[N];
    for(int i=0;i<n;i++){
        scanf("%d%d%d",&x1[i],&y1[i],&z1[i]);
        scanf("%d%d%d",&x2[i],&y2[i],&z2[i]);
    }
    vector<int>X,Y,Z;
    X=compress(x1,x2);
    Y=compress(y1,y2);
    Z=compress(z1,z2);
    fill(field[0][0],field[0][0]+8*N*N*N,0);
    for(int i=0;i<n;i++){
        for(int z=z1[i];z<z2[i];z++){
            for(int y=y1[i];y<y2[i];y++){
                for(int x=x1[i];x<x2[i];x++){
                    field[z][y][x]++;
                }
            }
        }
    }
    ll sum=0;
    for(int z=0;z<Z.size();z++){
        for(int y=0;y<Y.size();y++){
            for(int x=0;x<X.size();x++){
                if(field[z][y][x]>=k)sum+=(ll)X[x]*Y[y]*Z[z];
            }
        }
    }
    printf("%lld\n",sum);
    return 0;
}

Measured memory_bytes: 4964
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

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

using ll = long long;

ll N;
ll cnt[110];
ll mi = 1ll<<60, ma = 0;
bool fl = true;

int main()
{
  std::cin >> N;

  rep( i, N )
  {
    ll a;
    std::cin >> a;

    ++cnt[a];
    chmax( ma, a );
    chmin( mi, a );
  }

  if( ma % 2 == 0 )
  {
    if( mi != ma/2 )
      fl = false;

    if( cnt[mi] != 1 )
      fl = false;

    repi( i, mi+1, ma+1 )
    {
      if( cnt[i] < 2 )
      {
        fl = false;
        break;
      }
    }
  }
  else
  {
    if( mi != (ma+1)/2 )
      fl = false;

    if( cnt[mi] != 2 )
      fl = false;
    
    repi( i, mi+1, ma+1 )
    {
      if( cnt[i] < 2 )
      {
        fl = false;
        break;
      }
    }
  }

  puts( fl ? "Possible" : "Impossible" );

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"]  " << (x) << "\n";
#define errp(x) cerr << "["#x"]  {" << ((x).first) << ", " << ((x).second) << "}\n";
#define errv(x) {cerr << "["#x"]  [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"]  [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";

//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer","inline")
//#pragma GCC option("arch=native","tune=native","no-zero-upper")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2")

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getrnd(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

ll getrndll(ll l, ll r) {
    return uniform_int_distribution<ll>(l, r)(rng);
}

template <typename T1, typename T2>
inline bool relax(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T1, typename T2>
inline bool strain(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

// :::::::::::::::::::::::::::::::

void solve() {
    int n;
    cin >> n;
    
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    
    ll ans = 0;
    map<int, int> cnt;
    for (int i = 0; i < n; ++i) {
        ans += cnt[i + 1 - a[i]];
        ++cnt[a[i] + i + 1];
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    srand(time(0));
    
    int t = 1;
//    cin >> t;
    while (t--)
        solve();
    
    return 0;
}



Measured memory_bytes: 21044
#include <stdio.h>
int main(void){
	int n,k,z,f,i;
	while(1){
		scanf("%d",&n);
		if(!n)break;
		z=f=0;
		for(i=0;i<n;i++){
			scanf("%d",&k);
			if(k==0)z++;
			if(k>1)f=1;
		}
		if(f){
			printf("%d\n",n-z+1);
		}
		else{
			puts("NA");
		}
	}
	return 0;
}

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

using namespace std;

void addSubStr(vector<string> *v, set<string> *st, string *S, int loc)
{
    string sbs;
    for (int i = 1; i <= 5 && i <= (*S).length() - loc; i++)
    {
        sbs = (*S).substr(loc, i);
        if ((*st).find(sbs) == (*st).end())
        {
            (*v).push_back(sbs);
            (*st).insert(sbs);
        }
    }
}

int main()
{
    int K;
    string S;

    cin >> S;
    scanf("%d", &K);

    vector<string> v;
    set<string> st;
    int size = 0;
    string sbs;
    for (char c = 'a'; c <= 'z'; c++)
    {
        for (int i = 0; i < S.length(); i++)
        {
            if (S[i] == c)
            {
                addSubStr(&v, &st, &S, i);
            }
        }

        if (st.size() > 5)
        {
            break;
        }
    }

    sort(v.begin(), v.end());

    cout << v[K - 1] << "\n";

    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    int n, k; cin >> n >> k;
    VL a(n); cin >> a;
    FOR(i, 1, n)a[i] += a[i - 1];

    VL r;
    FOR(i, 0, n)FOR(j, i, n) {
        ll num = a[j];
        if (i)num -= a[i - 1];
        r.push_back(num);
    }

    ll ans = 0;
    rFOR(i, 0, 40) {
        ll now = ans + (1LL << i);
        int cnt = 0;
        FOR(j, 0, n * (n + 1) / 2) {
            if ((now & r[j]) == now)++cnt;
        }
        if (cnt >= k)ans += (1LL << i);
    }

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


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> vec(H + 2);
  string padding = "##";
  for (int j = 0; j < W; j++) {
    padding += "#";
  }
  vec.at(0) = padding;
  for (int i = 0; i < H; i++) {
    cin >> vec.at(i + 1);
    vec.at(i + 1) = "#" + vec.at(i + 1) + "#";
  }
  vec.at(H + 1) = padding;
  for (int i = 0; i < H + 2; i++) {
    cout << vec.at(i) << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n, p[100], a, b, i, cnta=0, cntb=0, acntb=0, min;

    scanf("%d", &n);
    scanf("%d %d", &a, &b);

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

    for(i=0;i<n;i++){
        if(p[i]<=a)
            cnta++;
        else if(a < p[i] && p[i] <= b)
            acntb++;
        else if(p[i] > b)
            cntb++;
    }

    min=cnta;
    if(min>acntb)
        min=acntb;
    if(min>cntb)
        min=cntb;

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


Measured memory_bytes: 128
INF = 2 ** 31 - 1
class SegmentTree:
	def __init__(self, n):
		self.N = 1
		while self.N < n:
			self.N *= 2
		self.tree = [INF] * (self.N * 2 - 1)

	# O(ln(n))
	def update(self, i, x):
		i += self.N - 1
		self.tree[i] = x
		while i > 0:
			i = (i-1) // 2
			self.tree[i] = min(self.tree[i*2+1], self.tree[i*2+2])

	def find(self, a, b, k, l, r):
		"""[a, b), ノードkが[l, r)を担当する"""
		if r <= a or b <= l:
			return INF
		if a <= l and r <= b:
			return self.tree[k]
		else:
			c1 = self.find(a, b, 2*k+1, l, (r+l)//2)
			c2 = self.find(a, b, 2*k+2, (l+r)//2, r)
			return min(c1, c2)

import sys
input = sys.stdin.readline
from operator import itemgetter

def main():
	n, q = map(int, input().strip().split())
	st = SegmentTree(n)
	for _ in range(q):
		com, x, y = map(int, input().strip().split())
		if com:
			print(st.find(x, y+1, 0, 0, st.N))
		else:
			st.update(x, y)

if __name__ == '__main__':
	main()



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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;
const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;

const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};
inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  return is;
}

template<typename T>
string join(vector<T>& vec, string sep = " "){
  stringstream ss;
  for(int i=0; i<vec.size(); i++){
    ss << vec[i] << ( i+1 == vec.size() ? "" : sep );
  }
  return ss.str();
}
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : " " );
  }
  return os;
}

vector<ll> memo(101);
ll calc(ll n){
  ll count = 0;
  repa(k, memo){
    if(k >= n - 1) ++count;
  }
  return count;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  REP(i , 2, n+1){
    ll a = i;
    REP(j, 2, i+1){
      while(a % j == 0){
        memo[j]++;
        a /= j;
      }
    }
  }
  cout << calc(75) + calc(25) * (calc(3) - 1) + calc(15) * (calc(5) - 1) + calc(5) * (calc(5) - 1) * (calc(3) - 2) / 2 << endl;
  return 0;
}

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

int main(){
    long long H,W; cin >> H >> W;
    int N; cin >> N;
    map<pair<int,int>,int> MAP;

    for(int i=0;i<N;i++){
        int a,b; cin >> a >> b;
        a--;b--;
        for(int j=a-1;j<=a+1;j++){
            for(int k=b-1;k<=b+1;k++){
                if(j<=0||j>=H-1) continue;
                if(k<=0||k>=W-1) continue;
                //cout << j << k << endl;
                MAP[{j,k}]++;
            }
        }
    }

    long long ans[10]={0};
    int sum=0;
    for(auto it=MAP.begin();it!=MAP.end();it++){
        ans[it->second]++;
        sum++;
    }
    ans[0]=(H-2)*(W-2)-sum;
    for(int i=0;i<10;i++){
        cout << ans[i] << endl;
    }
}

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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) (a).begin(),(a).end()

template<typename T1, typename T2> inline void chkmin(T1 & x, const T2 & y) {if (y < x) x = y;}
template<typename T1, typename T2> inline void chkmax(T1 & x, const T2 & y) {if (x < y) x = y;}

void read() {
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		if (i % 2 == 1 && x % 2 == 1) {
			ans++;
		}
	}
	cout << ans << endl;
}

void run() {

}

void write() {

}

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(20), cout.setf(ios::fixed);
	read();
	run();
	write();
	return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
//#define int long long  
int main(){
    int A,B,C;
    cin >> A >> B >> C;
    if(B==C){cout <<A;}else if(A==C){cout <<B;}else{cout << C;}
    cout <<endl;
	return 0;
}

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

using namespace std;

const int nax = 100005;
vector<int> graph[nax];
bool visited[nax];
int in_degree[nax];
int dist[nax];



void dfs(int a){
assert(!visited[a]);
visited[a]=true;
for(int b:graph[a]){
    dist[b]=max(dist[b],dist[a]+1);
    --in_degree[b];
    if(in_degree[b]==0){
        dfs(b);
    }
}



}



int main()
{
    /*for(int i=0;i<nax;i++){

    visited[i]=false;
    in_degree[i]=0;
    dist[i]=0;
}*/
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        graph[a].push_back(b);
        ++in_degree[b];

    }

    for(int i=1;i<=n;i++){
        if(!visited[i]&&in_degree[i]==0){
            dfs(i);
        }

    }
    int answer  = 0;
    for(int i=1;i<=n;i++){
        answer = max(answer, dist[i]);
    }
    cout<<answer;
    return 0;
}


Measured memory_bytes: 9728
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    A, B, C = inl()
    if A % 2 == 0 or B % 2 == 0 or C % 2 == 0:
        return 0
    x = sorted([A, B, C])

    return x[0] * x[1]


print(solve())


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

int n,a[101],b[101],dp[111][111];

int dfs(int l,int r){
    if(dp[l][r]!=-1)return dp[l][r];
    int res=1e17;
    for(int i=l;i<r;i++){
        res=min(res,dfs(l,i)+dfs(i+1,r)+a[l]*b[i]*a[i+1]*b[r]);
    }
    return dp[l][r]=res;
}

main(){
    memset(dp,-1,sizeof(dp));
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        dp[i][i]=0;
    }
    cout<<dfs(0,n-1)<<endl;
}


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

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

using namespace std;

template<class G>
class Fenwick_tree{
	vector<G> a;
public:
	Fenwick_tree(int n):a(n){}
	void add(int i,G val){
		for(i++;i<=a.size();i+=i&-i) a[i-1]+=val;
	}
	G sum(int l,int r)const{
		if(l==0){
			G res{};
			for(;r>0;r-=r&-r) res+=a[r-1];
			return res;
		}
		return sum(0,r)-sum(0,l);
	}
	int lower_bound(G val)const{
		if(val<=G{}) return 0;
		int x=0,k;
		for(k=1;k<=a.size();k<<=1);
		for(k>>=1;k>0;k>>=1) if(x+k<=a.size() && a[x+k-1]<val) val-=a[x+k-1], x+=k;
		return x;
	}
	int upper_bound(G val)const{
		if(val<G{}) return 0;
		int x=0,k;
		for(k=1;k<=a.size();k<<=1);
		for(k>>=1;k>0;k>>=1) if(x+k<=a.size() && a[x+k-1]<=val) val-=a[x+k-1], x+=k;
		return x;
	}
};

template<class T>
class sparse_table{
	vector<vector<T>> st;
	vector<int> h;
public:
	sparse_table(const vector<T>& a){
		int n=a.size();
		h.assign(n+1,0);
		for(int i=2;i<=n;i++) h[i]=h[i>>1]+1;
		st.resize(h[n]+1);
		st[0]=a;
		for(int i=1;i<h[n]+1;i++){
			st[i].resize(n-(1<<i)+1);
			rep(j,n-(1<<i)+1) st[i][j]=min(st[i-1][j],st[i-1][j+(1<<(i-1))]);
		}
	}
	T query(int l,int r)const{
		int i=h[r-l];
		return min(st[i][l],st[i][r-(1<<i)]);
	}
};

const int INF=1<<29;

int main(){
	int n; scanf("%d",&n);
	vector<int> p(n),pos(n);
	rep(i,n){
		scanf("%d",&p[i]); p[i]--;
		pos[p[i]]=i;
	}

	vector<int> even(n,INF),odd(n,INF);
	rep(i,n) (i%2==0?even:odd)[i]=p[i];
	sparse_table<int> RMQ[2]={even,odd};

	vector<bool> used(n);
	Fenwick_tree<int> F(n); // F[i] = 1 if p[i] is used, = 0 otherwise

	priority_queue<int,vector<int>,greater<int>> Q;
	Q.emplace(RMQ[0].query(0,n));

	vector<int> ans;
	while(ans.size()<n){
		int x,i,l;
		while(1){
			x=Q.top(); Q.pop();
			i=pos[x];
			if(used[i]) continue;

			l=F.lower_bound(F.sum(0,i+1));
			if(used[l]) l++;
			if((i-l)%2==1) continue; // i の左にできる区間が奇数長

			break;
		}

		int r=F.upper_bound(F.sum(0,i+1));
		int y=RMQ[(i+1)%2].query(i+1,r);
		int j=pos[y];

		used[i]=used[j]=true;
		F.add(i,1);
		F.add(j,1);
		ans.emplace_back(x);
		ans.emplace_back(y);

		// Q に区間 (i, j) での次の候補を追加
		if(i+1<j){
			Q.emplace(RMQ[(i+1)%2].query(i+1,j));
		}
		// Q に区間 [l, i) での次の候補を追加
		if(l<i){
			Q.emplace(RMQ[l%2].query(l,i));
		}
		// Q に区間 (j, r) での次の候補を追加
		if(j+1<r){
			Q.emplace(RMQ[(j+1)%2].query(j+1,r));
		}
	}

	rep(i,n) printf("%d%c",ans[i]+1,i<n-1?' ':'\n');

	return 0;
}


Measured memory_bytes: 34292
def prity(mat, line):
    print(line, 100)
    for i in range(line):
        for j in range(100):
            print(mat[i][j], end='')
        print()

A, B = map(int, input().split())

if A*B == 1:
    print(1, 2)
    print(".#")
else:

    mat = [['' for i in range(100)] for j in range(100)]

    # start with white
    line=0
    if A > 1: 
        B -= 1
        while A > 1:
            for j in range(50):
                if A > 1:
                    mat[line][2*j] = "."
                    A -= 1
                else:
                    mat[line][2*j] = "#"
                mat[line][2*j+1] = "#"
            for j in range(100):
                mat[line+1][j] = "#"
            line += 2

    # one line of white
    for j in range(100):
        mat[line][j] = "."
    A -= 1
    line += 1
    assert A == 0
    
    # finish black
    if B > 0:
        while B > 0:
            for j in range(50):
                if B > 0:
                    mat[line][2*j] = "#"
                    B -= 1
                else:
                    mat[line][2*j] = "."
                mat[line][2*j+1] = "."
            for j in range(100):
                mat[line+1][j] = "."
            line += 2

    prity(mat, line)

Measured memory_bytes: 3828
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int n,a,b,cou;
  vector<int> v;
  scanf("%d %d",&n,&a);
  b = a;
  cou = 1;
  for(int i=1;i<n;i++){
    scanf("%d",&a);
    cou += (b!=a);
    if(b == a){
      v.push_back(cou);
      cou = 1;
    }
    b = a;
  }
  v.push_back(cou);
  if(v.size() == 1) printf("%d\n",v[0]);
  else if(v.size() == 2) printf("%d\n",v[0]+v[1]);
  else {
    int ans = 0;
    for(int i=0;i<v.size()-2;i++){
      ans = max(ans,v[i]+v[i+1]+v[i+2]);
    }
    printf("%d\n",ans);
  }
  return (0);
}

Measured memory_bytes: 2860
n,a,b,c,d = gets.split.map &:to_i
xcnt = n / a
xcnt += 1 if (n % a) != 0
x = xcnt * b
ycnt = n / c
ycnt += 1 if (n % c) != 0
y = ycnt * d
# puts x,y
if x < y then
  puts x
else
  puts y
end



Measured memory_bytes: 8864
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define fastcin() ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef pair<int, int> ii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 2e5 + 100; 
int n, p[maxn], dp[maxn], pos[maxn], mx; 

signed main()
{
	cin >> n; 
	for(int i = 1; i <= n; i++) cin >> p[i], pos[p[i]] = i; 
	for(int i = 1; i <= n; i++) {
		if(pos[i - 1] < pos[i]) dp[i] = dp[i-1] + 1; 
		else dp[i] = 1; 
		mx = max(mx, dp[i]); 
	}
	cout << n - mx; 
}


Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include<algorithm>
#include <map>
#include <vector>
#include <set>
#define mp make_pair
#define pb push_back
using namespace std;
const int maxn = 10000 + 10;
bool mark[maxn];
vector<int> v[maxn], u[maxn];
int par[maxn];
vector<pair<int, pair<int,int> > > q;
int find(int x)
{
    int k = par[x] == -1 ? x : find(par[x]);
    return k;
}
void unio(int x, int y)
{
     int a = find(x), b = find(y);
     if(a < b)
          par[find(y)] = find(x);
     else
         par[find(x)] = find(y);
}
int main()
{
    int n,m;
    cin >> n >> m;
    for(int i=0;i<n;i++)
            par[i] = -1;
    for(int i=0;i<m;i++)
    {
            int a, b, c;
            cin >> a >> b >> c;
            //a--; b--;
            v[a].pb(b);
            v[b].pb(a);
            q.pb(mp(c,mp(a,b)));
    }
    //cerr << 1 << endl;
    sort(q.begin(), q.end());
    //cerr << 2 << endl;
    int edges = 0;
    int i = 0;
    long long sum = 0;
    while(edges < n-1)
    {
                int x = q[i].first;
                int a = q[i].second.first, b = q[i].second.second;
                //cerr << 3 << endl;
                if(find(a) != find(b))
                {
                           //cerr << 4 << endl;
                           unio(a,b);
                           //cerr << 5 << endl;
                           sum += x;
                           u[a].pb(b);
                           u[b].pb(a);
                           edges++;
                }
                i++;
                           
    }
    cout << sum << endl;
    return 0;
    //cin >> n;
}

Measured memory_bytes: 4504
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <unordered_set>
#include <cmath>
#include <queue>
#include <stdio.h>

using namespace std;
using ll = long long;
using ld = long double;
template <class T> using vec = std::vector<T>;
template <class T> using vvec = std::vector<std::vector<T>>;

#define REP(i, s, e) for (ll i = s; i < e; ++i)

void rec(int i, int p, int x, const vvec<int>& od, const vec<int>& c, vec<int>& result)
{
    result[i] += x;
    for (auto& o : od[i])
    {
        if (o != p) rec(o, i, x + c[o], od, c, result);
    }
    return;
}

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

    int A, B; cin >> A >> B;
    int r = -(1 << 14);
    r = max(r, A + B);
    r = max(r, A - B);
    r = max(r, A * B);
    cout << r << endl;

    return 0;
}


Measured memory_bytes: 256
//
///
//
//
///
//

#include <bits/stdc++.h>
using namespace std;
#define ri(a,b,c) for(int a=(b);a<(c);++a)
typedef long long ll;
#define fcout cout << fixed << setprecision(10)
int main(){
    //cin.tie(0);
    //ios::sync_with_stdio(false);

    int b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;
    cin>>n;
    int a[n];
    ri(i,0,n){
        cin>>a[i];
    }
    m=a[0];
    p=a[0];
    ri(j,1,n){
        m=m>a[j]?m:a[j];
        p=p<a[j]?p:a[j];
    }


    cout<<(m-p)<<"\n";

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int s;
    cin >> s;
    set<int> used;
    while (used.count(s) == 0) {
        used.insert(s);
        if (s % 2 == 0) s /= 2;
        else s = s * 3 + 1;
    }
    cout << used.size() + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(register int i=(a);i<(b);++i)
#define ROF(i,a,b) for(register int i=(a);i>=(b);--i)
#define pi pair<int,int>
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 100005;
const int maxm = 100;
const int inf = 2147483647;
typedef long long ll;
const double eps = 1e-9;
const long long INF = 9223372036854775807ll;
ll qpow(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c;b>>=1;}return ans;}
ll a[maxn];

int main(){
	int n;
	scanf("%d",&n);
	ll sm=0;
	FOR(i,0,n){
		scanf("%d",&a[i]);
		if(i%2==0)sm+=a[i];else sm-=a[i];
	}
	printf("%lld ",sm);
	FOR(i,0,n-1){
		sm=a[i]*2-sm;
		printf("%lld ",sm);
	}
	printf("\n");
}


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

using namespace std;
typedef long long ll;

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

    int cnt = 0;

    for(int i=1; i <= n; i++) {
        if(data[i-1] != i) cnt++;
    }

    if(cnt <= 2) cout << "YES";
    else cout << "NO";

    return 0;
}

Measured memory_bytes: 256
//
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
//
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 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")
    };
}

//
// solution 
//
#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input! {
        N: i64
    }
    if N == 0 {
        println!("0");
        return
    }

    let mut digits = Vec::new();
    let mut q = N;
    while q != 0 {
        match q % -2 {
            0 => {
                digits.push('0');
                q /= -2;
            },
            1 => {
                digits.push('1');
                q /= -2;
            },
            -1 => {
                digits.push('1');
                q = (q-2) / -2;
            },
            _ => panic!(),
        }
    }

    let s: String = digits.into_iter().rev().collect();
    println!("{}", s);
}


Measured memory_bytes: 4352
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] X = new int[N];
        int Xmax = 0;
        int Xmin = 1000;
        int Xsum = 0;
        for (int i = 0; i < N; i ++) {
            X[i] = sc.nextInt();
            Xsum += X[i];
            if (Xmax < X[i]) {
                Xmax = X[i];
            }
            if (X[i] < Xmin) {
                Xmin = X[i];
            }
        }
        sc.close();

        // int P = (Xmin + Xmax) / 2;
        int P = Xsum / N;
        int Power1 = 0;
        int Power2 = 0;
        for (int i = 0; i < N; i++) {
            Power1 += (X[i] - P) * (X[i] - P);
            Power2 += (X[i] - P - 1) * (X[i] - P - 1);
        }

        System.out.println(Math.min(Power1, Power2));
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


int n, m, ans=0, k; char a[6][6];


void solve()
{
    cin >> n >> m >> k;
    for (int i=0; i<n; i++) for (int j=0; j<m; j++) cin >> a[i][j];

    for (int mi=0; mi<(1<<n); mi++) {
        for (int mj=0; mj<(1<<m); mj++) {
            int b=0;
            for (int i=0; i<n; i++) {
                for (int j=0; j<m; j++) {
                    if ((mi&(1<<i)) || (mj&(1<<j))) continue;
                    if (a[i][j]=='#') b++;
                }
            }
            if (b==k) ans++;
        }
    }

    nout(ans);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}   

Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
//23:45:00
typedef long long ll;
ll n,a[200007],h[200007],st[800007];
ll dp[200007];
void update(ll l,ll r,ll in,ll pos,ll val)
{
	if(l==r)
	{
		st[in]=val;
		return;
	}
	ll mid=(l+r)/2;
	if(pos<=mid)
		update(l,mid,2*in+1,pos,val);
	else
		update(mid+1,r,2*in+2,pos,val);
	
	st[in]=max(st[2*in+1],st[2*in+2]);
}
ll query(ll l,ll r,ll in,ll x,ll y)
{
	if(x>r||l>y)return 0;
	if(x<=l&&y>=r)return st[in];
	ll mid=(l+r)/2;
	return max(query(l,mid,2*in+1,x,y),query(mid+1,r,2*in+2,x,y));
}
int main()
{
	cin>>n;
	ll i,j;
	for(i=0;i<n;i++)
		cin>>h[i];
	for(i=0;i<n;i++)
		cin>>a[i];
	for(i=0;i<n;i++)
	{
		ll q=query(0,2e5L,0,0,h[i]);
		dp[i]=q+a[i];
		update(0,2e5L,0,h[i],dp[i]);
	}
	ll ans=0;
	for(i=0;i<n;i++)
		ans=max(dp[i],ans);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 11264
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

#N = int(input())
#s = [input() for i in range(N)]
#M = int(input())
#t = [input() for i in range(M)]
# print(s)
# print(t)

n, a, b = map(int, input().split())
print(min(a*n, b))


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

using namespace std;
 
#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  f              first                 
#define  s              second
#define  endl           "\n"
#define  pb             push_back  
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";cout<<endl;
#define  deb1(a)        cout<<a<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<endl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<endl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;            
          
 
typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  unordered_map<ll,ll>  um;
typedef  vector<pll>           vpll;

const ll   N     =  2e5+5;
const ll   mod   =  998244353;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;

ll test=1, n, a[N], b[N], s = 0, k, m;

void solve(){
	vll v;
	v.pb(0);
	cin>>n>>m>>k;
	for(int i = 1; i <= n; i++) cin>>a[i], s += a[i], v.pb(s);
	s = 0;
	ll ans = (upper_bound(v.begin(), v.end(), k) - v.begin()) - 1;
	for(int i = 1; i <= m; i++){
		cin>>b[i];
		s += b[i];
		if(s > k) break;
		ans = max(ans,i + (upper_bound(v.begin(), v.end(), k-s) - v.begin()) - 1ll);
	}
	deb1(ans)
}

int main(){
    fastio;
    //cin>>test;
    for(int i = 1; i <= test; i++){
        solve();
    }
}

Measured memory_bytes: 7924
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#pragma GCC diagnostic ignored "-Wunused-result"

#include <cstdio>
#include <chrono>
#include <random>
using namespace std;
using namespace chrono;

constexpr int c_max = 26;
constexpr int D = 365;
constexpr int INF = 1e9;
constexpr int time_limit = 1980;

int c[c_max];
int s[D][c_max];
int best_score[D];
int last[c_max];
int schedule[D];

inline int calc_score(const int &day, const int &examining) {
  int ret;
  if (day == 0) ret = s[day][examining];
  else ret = best_score[day - 1] + s[day][examining];
  
  for (int i = 0; i < c_max; i++) {
    if (i == examining) continue;
    ret -= (day - last[i]) * c[i];
  }

  return ret;
}

inline int calc_score_diff(const int &day1, const int &day2) {
  int prev_interval_1 = 0;
  for (int i = day1 - 1; i >= 0; i--) {
    prev_interval_1++;
    if (schedule[i] == schedule[day1]) break;
  }

  int prev_interval_2 = 0;
  for (int i = day2 - 1; i >= 0; i--) {
    prev_interval_2++;
    if (schedule[i] == schedule[day2]) break;
  }

  int new_interval_1 = 0;
  for (int i = day2 - 1; i >= 0; i--) {
    new_interval_1++;
    if (schedule[i] == schedule[day1]) break;
  }

  int new_interval_2 = 0;
  for (int i = day1 - 1; i >= 0; i--) {
    new_interval_2++;
    if (schedule[i] == schedule[day2]) break;
  }

  int ret = s[day1][schedule[day2]]
          + s[day2][schedule[day1]]
          - s[day1][schedule[day1]]
          - s[day2][schedule[day2]];
  
  ret += c[schedule[day1]] * ((prev_interval_1 + 1) * prev_interval_1 - (new_interval_1 + 1) * new_interval_1) / 2;
  ret += c[schedule[day2]] * ((prev_interval_2 + 1) * prev_interval_2 - (new_interval_2 + 1) * new_interval_2) / 2;

  return ret;
}

int main() {
  system_clock::time_point start = system_clock::now(), now;

  random_device seed;
  mt19937 rnd(seed());

  /* input */
  scanf("%*d");

  for (int i = 0; i < c_max; i++) {
    scanf("%d", &c[i]);
  }

  for (int i = 0; i < D; i++) {
    for (int j = 0; j < c_max; j++) {
      scanf("%d", &s[i][j]);
    }
  }

  /* calc initial solution */
  for (int d = 0; d < D; d++) {
    int best = -INF;
    int contest_to_hold = 0;
    for (int type = 0; type < c_max; type++) {
      int score = calc_score(d, type);
      if (best < score) {
        best = score;
        contest_to_hold = type;
      }
    }
    last[contest_to_hold] = d;
    schedule[d] = contest_to_hold;
  }

  /* try and error */
  int day1, day2, score_diff;
  while (1) {
    now = system_clock::now();
    if (duration_cast<milliseconds>(now - start).count() > time_limit) break;
    day1 = rnd() % D;
    day2 = rnd() % D;
    score_diff = calc_score_diff(day1, day2);
    if (score_diff > 0) {
      swap(schedule[day1], schedule[day2]);
    }
  }

  /* output */
  for (const int &x : schedule) {
    printf("%d\n", x+1);
  }

  return 0;
}

Measured memory_bytes: 3424