akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
const ll INF = 1e17;

using Cost = ll;
struct Edge{
    Cost cost;
    int to;
    bool operator>(const Edge &right)const{
        return cost > right.cost;
    }
};

const int MAX_V = 100010;

void dijkstra(vector<vector<Edge>> &g,
              vector<Cost> &dp,Edge start){
    priority_queue<Edge,vector<Edge>,greater<Edge>> qu;
    dp[start.to] = start.cost;
    qu.push(start);
    while(qu.size()){
        Edge cur = qu.top(); qu.pop();
        int v = cur.to;
        if(dp[v] < cur.cost) continue;
        for(Edge e : g[v]){
            if( dp[e.to] > cur.cost + e.cost){
                dp[e.to] = cur.cost + e.cost;
                qu.push({dp[e.to], e.to});
            }
        }
    }
}


int main(void){
    int n,m,s,t;
    cin>>n>>m>>s>>t;
    s--,t--;
    vector<vector<Edge>> ga(n),gb(n);
    vector<Cost> dpa(n,INF),dpb(n,INF);
    rep(i,m){
        int u,v,a,b;
        cin>>u>>v>>a>>b;
        u--,v--;
        ga[u].push_back({a,v});
        ga[v].push_back({a,u});
        gb[u].push_back({b,v});
        gb[v].push_back({b,u});
    }
    dijkstra(ga,dpa,{0,s});
    dijkstra(gb,dpb,{0,t});

    vector<Cost> vc(n);
    rep(i,n){
        vc[i] = dpa[i]+dpb[i];
    }
    reverse(all(vc));
    rep1(i,n-1){
        vc[i] = min(vc[i],vc[i-1]);
    }
    reverse(all(vc));
    const Cost kenko = 1e15;
    rep(i,n){
        cout<<kenko-vc[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 19012
/*************************************************************************
    > File Name: E.cpp
    > Author: Roundgod
    > Mail: wcysai@foxmail.com 
    > Created Time: 2018-09-02 13:17:01
 ************************************************************************/

#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 6005
#define INF 1000000000
#define MOD 998244353
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll N,K;
ll fact[MAXN],invf[MAXN];
ll pow_mod(ll a,ll i)
{
    ll s=1;
    while(i)
    {
        if(i&1) s=1LL*s*a%MOD;
        a=1LL*a*a%MOD;
        i>>=1;
    }
    return s;
}
ll comb(ll n,ll k)
{
    if(n<k) return 0;
    return 1LL*fact[n]*invf[k]%MOD*invf[n-k]%MOD;
}
ll calc(ll v,ll n,ll k)
{
    ll ans=0;
    ll lim=max(0LL,v/2-max(0LL,v-1-k));
    for(ll i=0;i<=lim;i++)
        ans=(1LL*pow_mod(2,i)*comb(lim,i)%MOD*comb(k-lim*2+n-1,k-lim*2+i-1)+ans)%MOD;
    return ans;
}
int main()
{
    fact[0]=invf[0]=1;
    for(ll i=1;i<=6000;i++) fact[i]=1LL*fact[i-1]*i%MOD;
    invf[6000]=pow_mod(fact[6000],MOD-2);
    for(ll i=5999;i>=1;i--) invf[i]=1LL*invf[i+1]*(i+1)%MOD;
    scanf("%lld%lld",&K,&N);
    for(ll i=2;i<=2*K;i++)
    {
        if(i&1) printf("%lld\n",calc(i,N,K));
        else printf("%lld\n",(calc(i-1,N,K-1)+calc(i-1,N-1,K-1))%MOD);
    }
    return 0;
}



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

int main()
{
  string c,ans;
  cin>>c;
  string vowel = "aeiou";
  for(int i=0;i<vowel.size();i++)
  {
	if (vowel.at(i)==c.at(0))
    {
      ans="vowel";
      break;
    }
    else ans="consonant";
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int A[3001];
int MOD = 998244353;
long long dp[3010][6010][3] = {0};

int main() {
    int N, S;
    dp[0][0][0] = 1;

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

    for(int i=0;i<N;i++) {
        for(int j=0;j<=S;j++) {
            dp[i+1][j][0] += dp[i][j][0];
            dp[i+1][j+A[i]][1] += dp[i][j][0] * (i+1);
            dp[i+1][j+A[i]][2] += dp[i][j][0] * (i+1) * (N-i);

            dp[i+1][j][1] += dp[i][j][1];
            dp[i+1][j+A[i]][1] += dp[i][j][1];
            dp[i+1][j+A[i]][2] += dp[i][j][1] * (N-i);

            dp[i+1][j][2] += dp[i][j][2];

            dp[i+1][j][0] %= MOD;
            dp[i+1][j][1] %= MOD;
            dp[i+1][j][2] %= MOD;
        }
    }

    printf("%lld\n", dp[N][S][2]);
    return 0;
}

Measured memory_bytes: 262080
#include<iostream>
#include<vector>
#include<climits>
#include<queue>
#include<utility>
#include<string>

typedef std::pair<int, int> coord;
coord start = std::make_pair(INT_MAX, INT_MAX);
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
int H, W;

int bfs(std::vector<std::vector<int>> &world, coord start){
    std::vector<std::vector<int>> d(H, std::vector<int>(W, INT_MAX));
    std::queue<coord> Q;
    Q.push(start);
    d[start.first][start.second] = 0;
    coord now_coord;
    int max_d = 0;

    while(!Q.empty()){
        now_coord = Q.front();
        Q.pop();

        for(int i = 0; i < 4; i++){
            // 左→上→右→下
            int next_x = now_coord.first + dx[i];
            int next_y = now_coord.second + dy[i];
            if(next_x < 0 || next_x >= H || next_y < 0 || next_y >= W) continue;
            if(world[next_x][next_y] != INT_MAX){
                // 進むことができる
                if(d[next_x][next_y] > d[now_coord.first][now_coord.second] + 1){
                    // 未探索か短くいける場合
                    d[next_x][next_y] = d[now_coord.first][now_coord.second] + 1;
                    Q.push(std::make_pair(next_x, next_y));
                    if(d[next_x][next_y] > max_d) max_d = d[next_x][next_y];
                }
            }
        }
    }

    return max_d;
}

void solve(std::vector<std::vector<int>> &world){
    int max_d = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(world[i][j] == INT_MAX) continue;
            int temp_d = bfs(world, std::make_pair(i, j));
            if(temp_d > max_d) max_d = temp_d;
        }
    }

    // output
    printf("%d\n", max_d);
}

int main(){
    scanf("%d %d%*c", &H, &W);

    std::vector<std::vector<int>> world(H, std::vector<int>(W, INT_MAX));
    for(int i = 0; i < H; i++){
        std::string temp;
        std::cin >> temp;
        for(int j = 0; j < W; j++){
            if(temp[j] == '.'){
                world[i][j] = 0;
                start.first = i;
                start.second = j;
            }
        }
    }

    solve(world);

    return 0;
}

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

int f(int x){
    int cnt = 0;
    for(; x % 2 == 0; x /= 2) cnt++;
    return cnt;
}

int main(){
    int cnt = 0, in;
    int n; cin >> n;
    rep(i,n){
        cin >> in;
        cnt += f(in);
    }

    cout << cnt << endl;
}

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

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  string str;
  cin >> str;
  int ac = 0;
  int foreignRanking = 0;
  rep(i, str.length()){
    if(str[i] == 'a'){
      if(ac < A+B){
        cout << "Yes" << endl;
        ac++;
      }else{
        cout << "No" << endl;
      }
    }else if(str[i] == 'b'){
      if(ac < A+B && foreignRanking < B){
        cout << "Yes" << endl;
        ac++;
        foreignRanking++;
      }else{
        cout << "No" << endl;
      }
    }else{
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std; 
const int dx[]={1,0,-1,0,1,-1,-1,1}; 
const int dy[]={0,1,0,-1,1,1,-1,-1}; 
const int INF = 1e9; 
const long long LINF = 1e18; 
const double EPS = 1e-8; 
#define pb push_back
#define mk make_pair 
#define fr first 
#define sc second 
#define ll long long 
#define reps(i,j,k) for(int i = (j); i < (k); ++i) 
#define rep(i,j) reps(i,0,j) 
#define all(a) (a).begin(),(a).end() 
#define MOD 1000000007 
typedef pair<int,int> Pii;
typedef pair<Pii,int> P;
typedef vector<int> vi;
int main(){
	int N;
	cin >> N;
	string str;
	vector < string > vs;
	int memo[64][64];
	rep(i,N){
		cin >> str;
		vs.pb(str);
		rep(j,str.size()){
			memo[i][str[j]-'a']++;
		}
	}
	string ans = "";
	rep(i,'z'-'a' + 1){
		int a = INF;
		rep(j,N){
			a  = min(a,memo[j][i]);
		}
		rep(j,a){
			ans += i+'a';
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
program main
    implicit none
    integer, parameter:: inf = 10000
    integer, allocatable:: dist(:,:), a(:), b(:), c(:) 
    integer:: n, m, i, j, k
    integer:: ans
    logical:: shortest

    read*, n, m
    allocate(dist(n,n), a(m),b(m),c(m))

    do i = 1, m
        read*, a(i), b(i), c(i)
    end do

    dist(:,:) = inf
    
    do i = 1, n
        dist(i,i) = 0
    end do

    do i = 1, m
        dist(a(i),b(i)) = min(dist(a(i),b(i)),c(i))
        dist(b(i),a(i)) = min(dist(b(i),a(i)),c(i))
    end do


    do k = 1, n
        do i =1, n
            do j = 1, n
                dist(i, j) = min(dist(i,j), dist(i,k) + dist(k,j))
            end do
        end do
    end do

    ans = m

    do i = 1, m
        shortest = .false.
        do j = 1, n
            if (dist(j,b(i)) == dist(j,a(i)) + c(i)) then
                shortest = .true.
            end if
        end do
        if (shortest) ans = ans - 1
    end do

    print'(i0)', ans

end program

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef int Int;
typedef pair<Int,Int> pii;
typedef pair<Int,double> pid;
typedef pair<double,double> pdd;
typedef pair<Int,pii> pip;
typedef pair<double,Int> pdp;
#define A first
#define B second
#define pb(x) push_back(x)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (x).size()
#define CLR(x) memset(x,0,sizeof x)
#define pdebug() printf("%d\n",__LINE__)
#define Itype(a) typeof(a.begin()) 
#define REP(i,a,b) for(int i = (a);i <= (b);i++)
#define FORO(i,n) REP(i,0,(int)n-1)
#define FORI(i,n) REP(i,1,(int)n)
#define FORIT(i,t) for(Itype(t) i = t.begin();i != t.end();i++)
#define eps 1e-6
#define sqr(x) ((x)*(x))
#define dist(_a,_b) sqrt(sqr(_a.A-_b.A)+sqr(_a.B-_b.B))
#define norm(_a) sqrt(sqr(_a.A)+sqr(_a.B))
template<typename T>void getMin(T &a,T b) { if(a > b) a = b; }
template<typename T>void getMax(T &a,T b) { if(a < b) a = b; }
template<typename T> vector<T> getVector(const int n) { return vector<T>(n); }
template<typename T> vector<T> getVector(const int n, const T a) { return vector<T>(n, a); }
template<typename T> vector<T> getEmptyVector() { return vector<T>(); }
// #define X first
// #define Y second
const ll MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int L, R, d;
    cin >> L >> R >> d;
    cout << R / d - (L - 1) / d << endl;
    return 0;
}

Measured memory_bytes: 3636
# coding: utf-8
 
 
def main():
 
    in_data = input()
 
    if (in_data == 'AAA' or
        in_data == 'BBB'):
        print('No')
    else:
        print('Yes')
 
    return 0
 
 
if __name__ == '__main__':
    main()

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

int main() {
    ll n;
    cin >> n;
    string s="";
    while(n){
        n--;
        s += char('a' + n%26);
        n/=26;
    }
    reverse(all(s));
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3616
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt(),d=sc.nextInt();
		if(a*b>c*d){
			System.out.println(a*b);
		}
		else{
			System.out.println(c*d);
		}
	}
}

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

#define ll long long int
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define repm(i, a, n) for (ll i = a; i >= n; i--)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define mod (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vb vector<bool>
#define vs vector<string>
#define vii vector<vector<int>>
#define vllll vector<vector<ll>>
#define ALL(a) (a).begin(), (a).end()

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

void print(bool f)
{
    cout << (f ? "Yes" : "No") << endl;
}

void Print(bool f)
{
    cout << (f ? "YES" : "NO") << endl;
}

int main(void)
{
    string s;
    int k;
    cin >>k >> s;
    cout << (s.size() <= k ? s : s.substr(0, k) + "...") << endl;
}

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

using namespace std;

const long long MOD = 1e9 + 7;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,pii> iii;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef priority_queue<pii, vector<pii>, greater<pii>> fila_prioridade;
typedef priority_queue<iii, vector<iii>, greater<iii>> fila_prioridade_grids;

#define nl '\n'
#define INF 1000000000
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define NeedForSpeed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

string a,b,numerotexto;
float numero;

int main() {
        NeedForSpeed

	cin >> a >> b;

	numerotexto = a + b;

	numero = stoi(numerotexto);

	if ( pow(sqrt(numero),2) == numero) {
		cout << "Yes" << nl;
	} else {
		cout << "No" << nl;
	}


        return 0;
}



Measured memory_bytes: 3596
import java.util.*;
import java.awt.*;
import static java.lang.System.*;
import static java.lang.Math.*;
//Loopで使う文字列の長さは固定！
//intで大丈夫？オーバーフローしない？
//Loop回数は本当に10⁹以内になってる？Loopは回る？？
public class Main {
    public static void main(String[]$){
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        double t=sc.nextDouble();
        double a=sc.nextDouble();
        double[] h=new double[n];
        double[] ave=new double[n];
        int ans=0;
        double temp=114514;
        for (int i = 0; i < n; i++) {
            h[i]=sc.nextDouble();
            ave[i]=t-h[i]*0.006;
            if(temp>abs(a-ave[i])){
                temp=abs(a-ave[i]);
                ans=i+1;
            }
        }
        out.println(ans);
    }
}

Measured memory_bytes: 26952
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vv = vector<vector<ll>>;
using vvv = vector<vector<vector<ll>>>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define BIT(n, num) std::bitset<(n)>((num)).to_string()
#define REV(T) greater<T>()
#define PQ priority_queue<ll, vector<ll>, greater<ll>>
#define VVI(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVI(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))

typedef pair<ll, ll> Pair;
bool pairCompare(const Pair &a, const Pair &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp) % MOD;
  } else {
    return (n * POW(n, m - 1)) % MOD;
  }
}
ll factorial(ll n) {
  ll ans = 1;
  for (ll i = 2; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll P(ll n, ll m) {
  ll ans = 1;
  for (ll i = m + 1; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}

ll C(ll n, ll m) { return (P(n, n - m) * POW(factorial(m), MOD - 2)) % MOD; }

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

int main() {
  ll N;
  cin >> N;
  map<ll, ll> M;
  vector<ll> A(N, 0);
  ll S = 0;
  REP(i, N) cin >> A[i];
  REP(i, N) {
    S = S + A[i];
    if (M.find(S) != M.end())
      M[S] = M[S] + 1;
    else
      M[S] = 1;
  }
  ll ans = 0;
  AUTO(m, M) {
    if (m.first == 0) {
      ans += (m.second + 1) * m.second / 2;
    } else if (m.second >= 2) {
      ans += m.second * (m.second - 1) / 2;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 14336
import sys
from operator import itemgetter
import math

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    XY = [[int(x) for x in input().split()] for _ in range(N)]

    ans = 0

    for i, (x, y) in enumerate(XY):
        if x == 0:
            katamuki =  1 / (10 ** 7)
            katamuki2 =  - 1 / (10 ** 7)
        else:
            katamuki = y / x + 1 / (10 ** 7)
            katamuki2 = y / x - 1 / (10 ** 7)
        plus = [0, 0]
        minus = [0, 0]
        plus2 = [0, 0]
        minus2 = [0, 0]
        for j, (xx, yy) in enumerate(XY):
            if yy > katamuki * xx:
                plus[0] += xx
                plus[1] += yy
            else:
                minus[0] += xx
                minus[1] += yy

            if yy > katamuki2 * xx:
                plus2[0] += xx
                plus2[1] += yy
            else:
                minus2[0] += xx
                minus2[1] += yy

        ans = max(ans, math.sqrt(plus[0] ** 2 + plus[1] ** 2))
        ans = max(ans, math.sqrt(minus[0] ** 2 + minus[1] ** 2))
        ans = max(ans, math.sqrt(plus2[0] ** 2 + plus2[1] ** 2))
        ans = max(ans, math.sqrt(minus2[0] ** 2 + minus2[1] ** 2))

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9300
N, M = map(int, input().split())
answer = set([])
for i in range(N):
  K_A = [int(x) for x in input().split()]
  K = K_A[0]
  A = K_A[1:]
  if i==0:
    answer = answer.union(set(A))
  else:
    answer = answer.intersection(set(A))

print(len(answer))


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

int main(){

  char c;
  
  cin >> c;
  
  if( c == 'a' || c == 'i' || c == 'e' || c == 'u' || c == 'o' ){
    cout << "vowel";
  }else{
    cout << "consonant";
  }
    
    return 0;
}


Measured memory_bytes: 256
# include <iostream>
# define MAX 202

using namespace std;

int N, A, B;
int ans = 0;

int sum ( int  num ) {
    int ret = 0;
    while ( num >= 10 ) {
        int mod = num % 10;
        ret += mod;
        num = ( num - mod ) / 10;
    }
    ret += num;
    return ret;
}

int main() {
    cin >> N >> A >> B;
    for ( int i = 1; i <= N; i++ ){
        if ( A <= sum(i) && sum(i) <= B) { ans += i; }
    }
    cout << ans;

    return 0;
}

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;
using P =pair<int,int>;

//最大公約数を求める関数
ll lcm(ll a,ll b){
    ll c,d,e;
    c=max(a,b);
    d=min(a,b);
    while(1){
        c=c%d;
        if(c==0){
            break;
        }
        e=d;
        d=c;
        c=e;
    }
    return a*b/d;
}
int main(){
    ll n,m;
    cin >> n >> m;
    vector <ll> a(n);
    rep(i,n) cin >> a[i];

    ll sk;
    sk=1;
    int n2;
    n2=0;
    ll n3;
    n3=a[0];


    while(n3%2==0){
        n3/=2;
        ++n2;
        if(n3==0) break;
    }

    ll w;
    w=ll(pow(2,n2));

    rep(i,n){
        sk=lcm(sk,a[i]/2);
        if(a[i]%w!=0){
           sk=-1;
           break; 
        }
        if(sk>m){
            sk=-1;
            break;
        }
    }
    //cout << sk << endl;
    int n4;
    n4=0;
    ll sk2;
    sk2=sk;
    while(sk2%2==0){
        sk2/=2;
        ++n4;
        if(sk2==0) break;
    }
    if(n2!=n4+1){
        sk=-1;
    }
    ll ans;
    if(sk==-1){
        cout << 0 << endl;
    }
    else{
        ans=(m-sk)/(2*sk)+1;
        cout << ans << endl;
    }

    

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<int >    vecint;
typedef vector<ll >    vecll;
typedef vector<string > vecstr;
////////////////////////////////////////////////
int main()
{
  int n;
  cin >> n;
  map<char, int> a;
  string s, s0;
  cin >> s;
  REP(i, s.size()){
    a[s[i]] ++;
  }
  s0 = s;
  REP(i,n - 1){
    cin >> s;
    map<char, int> b;
    REP(i,s.size()){
      b[s[i]] ++;
    }
    REP(i,s.size()){
      a[s[i]] = min(a[s[i]], b[s[i]]);
    }
    REP(i,s0.size()){
      a[s0[i]] = min(b[s0[i]], a[s0[i]]);
    }

  }
  string ans;
  REPvec(itr,a){
    // cout << itr->first << " " << itr->second << endl;
    if(itr->second > 0){
      REP(i,itr->second){
	cout << itr->first ;
      }
    }
  }
  cout << endl;
}

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

const int N = 1e6 + 100;

int main() {
    // freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int mod = 1e9 + 7;
    int n, K;
    cin >> n >> K;
    vector<int> v(n);
    int ans = 0;
    for(int i = 0; i < n; i++) {
        cin >> v[i];
        for(int j = 0; j < i; j++) {
            if(v[j] > v[i]) ans++;
        }
    }
    ans = 1ll*ans*K%mod;
    long long t = 1ll*K*(K-1)/2;
    int mul = t%mod;
    for(int i = 0; i < n; i++) {
        int big = 0;
        for(int j = 0; j < n; j++) {
            if(v[j] > v[i]) big++;
        }
        ans += 1ll*mul*big%mod;
        ans %= mod;
    }
    cout << ans << endl;

    return 0;
}



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

cnt = [0] * n
for i in a:
    cnt[i-1] += 1
t=0
for i in cnt:
    t += i * (i-1)
t/=2
for i in a:
    print(int(t-(cnt[i-1]-1)))

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  ll a, b, c;
  cin >> a >> b >> c;

  ll a2 = a, b2 = b, c2 = c;
  if (a > b && a > c) {
    a2 /= 2;
    a -= a2;
  }
  else if (b > a && b > c) { 
    b2 /= 2;
    b -= b2;
  }
  else if (c > a && c > b) {
    c2 /= 2;
    c -= c2;
  }
  else {
    a2 /= 2;
    a -= a2;
  }

  cout << (a*b*c)-(a2*b2*c2) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> input(H);
  
  for(int i = 0; i < H; i++){
    cin >> input.at(i);
  }
  
  for(int i = 0 ; i < W + 2 ; i++){
    cout << "#";
  }
  cout << endl;
  
  for(int i = 0; i < H; i++){
    cout << "#";
    cout << input.at(i);
    cout << "#";
    cout << endl;
  }
  
  for(int i = 0 ; i < W + 2 ; i++){
    cout << "#";
  }
  cout << endl;
  
  return 0;
}

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

int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  ll n,p,q;
  cin >> n >> p >> q;
  priority_queue<ll> pq;
  vector<ll> c(n);
  rep(i,n){
    cin >> c[i];
    pq.push(c[i] - (q+i)*p - (n-1-i)*2*p);
  }

  ll res = p*(n*q + n*(n-1)/2), sum = res, k = 0;
  while(pq.size()){
    ll x = pq.top(); pq.pop(); k++;
    //cout << x << endl;
    sum += x;
    res = max(res, sum + k*(k-1)*p);
  }
    
  cout << res << endl;
}

Measured memory_bytes: 11172
#include "bits/stdc++.h"
using namespace std;

long long maximumBlackSum(const vector<int> &a, const int k){
    const int n = a.size();
    long long lef = 0LL;
    long long mid = 0LL;
    for(int i=0; i<k; i++){
        mid += a[i]*1LL;
    }
    long long rig = 0LL;
    for(int i=n-1; i>=k; i--){
        rig += max(a[i], 0)*1LL;
    }
    long long foo = 0LL;
    for(int i=0; i<=n-k; i++){
        foo = max(foo, lef+rig+max(mid, 0LL));
        if(i!=n-k){
            lef += max(a[i], 0)*1LL;
            mid += (a[i+k]-a[i])*1LL;
            rig -= max(a[i+k], 0)*1LL;
        }
    }
    return foo;
}

int main(){
    int n, k;
    while(scanf("%d%d", &n, &k)!=EOF){
        vector<int> a(n, 0);
        for(int i=0; i<n; i++){
            scanf("%d", &a[i]);
        }
        printf("%lld\n", maximumBlackSum(a, k));
    }
    return 0;
}

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


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

current_height = h[0]
current_count = 0
max_count = current_count
for i in range(1, n):
    if current_height >= h[i]:
        current_count += 1
    else:
        max_count = max(current_count, max_count)
        current_count = 0
    current_height = h[i]

max_count = max(current_count, max_count)
print(max_count)


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

int main(){
  int n, l, i;
  cin>>n>>l;
  string arr[n];
  for(i=0; i<n; i++)
    cin>>arr[i];
  sort(arr, arr+n);
  for(i=0; i<n; i++)
    cout<<arr[i];
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define Max 1000001
using namespace std;

int n;
long long euler[Max],ans[Max];

int main(){
  for(int i=0;i<Max;i++)euler[i] = i;
  for(int i=2;i<Max;i++){
    if(euler[i] == i){
      for(int j=i;j<Max;j+=i)euler[j] = euler[j] / i *(i-1);
    }
  }

  ans[1] = 0;
  for(int i=2;i<Max;i++)ans[i] = ans[i-1] + euler[i];

  int t;
  cin >> t;
  for(int i=0;i<t;i++){
    cin >> n;
    cout << ans[n] + 2 << endl;
  }
}

Measured memory_bytes: 16000
#include <cstdio>
#include <map>

using namespace std;

#define R register

const int MAXN=2e5+10;

int n;
int a[MAXN];

map<int,int> mp;

inline bool chk(int k)
{
	mp.clear();
	k--;
	for(R int i=2;i<=n;i++)
	{
		if(a[i-1]<a[i]) continue;
		if(k==0) return 0;
		while(!mp.empty()&&mp.rbegin()->first>a[i]) mp.erase(mp.rbegin()->first);
		int j=a[i];
		while(j&&mp[j]==k) mp.erase(j--);
		if(j) mp[j]++;
		else return 0;
	}
	return 1;
}

int main()
{
	scanf("%d",&n);
	for(R int i=1;i<=n;i++) scanf("%d",&a[i]);
	int l=1,r=n,mid,res=n;
	while(l<=r)
	{
		int mid=l+r;mid>>=1;
		if(chk(mid)) r=mid-1,res=mid;
		else l=mid+1;
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 1024
from itertools import accumulate

N, M = map(int, input().split())
A = list(map(int, input().split()))

A.sort(reverse=True)
d = [0] * (A[0] * 2 + 1)
for i in range(N):
    d[A[i]] += 1
d = list(accumulate(d[::-1]))[::-1]
S = list(accumulate([0] + A))

left = 0
right = A[0] * 2 + 1
while right - left > 1:
    mid = (left + right) // 2
    m = 0
    for i in range(N):
        m += d[max(0, mid - A[i])]
    if m >= M:
        left = mid
    else:
        right = mid

ans = 0
m = 0
for i in range(N):
    t = min(d[max(0, right - A[i])], M - m)
    ans += S[t] + A[i] * t
    m += t
ans += left * (M - m)
print(ans)


Measured memory_bytes: 18732
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();

    // input
    let n: usize = read(&mut stdin_lock, &mut buf, b' ');
    let k: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let mut hv = vec![0usize; n];
    for i in 0..n - 1 {
        hv[i] = read(&mut stdin_lock, &mut buf, b' ');
    }
    hv[n - 1] = read(&mut stdin_lock, &mut buf, b'\n');

    hv.sort();
    let ans = hv.iter().take(n.saturating_sub(k)).sum::<usize>();
    println!("{}", ans);
}


Measured memory_bytes: 6396
#include <iostream>
    using namespace std;
    int main(){
    	char a,b;
        cin >> a;
        for(int i = 0; i<3; i++){
        	cin >> b;
            if(b == a){
        		cout << "Bad" << endl;
       			return 0;
      		}
          	a = b;
    	}
      	
    	cout << "Good" << endl;
    }

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        Integer n = Integer.parseInt(sc.next());
        Integer[] x = new Integer[n];
        for (int i = 0; i < n; i++) {
            x[i] = Integer.parseInt(sc.next());
        }

        // 主処理
        int sum = 0;
        for (int num : x) {
            sum += num;
        }
        int ave = (int)Math.round((double)sum / n);

        int result = 0;
        for (int num : x) {
            result += Math.pow(num - ave, 2);
        }

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
#include <cstring>
#include <numeric>
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<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define repll(i,n) for(long long int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
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;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
template <typename T_char>
char ToUpper (char cX) { return toupper(cX); }
//g++ -std=c++1z temp.cpp
//./a.exe
ll digit(ll a){
    ll count = 0;
    for (ll i = 0; i < a; i++)
    {   if (a == 0)
        {
            break;
        }else
        {
            a = a/10;
            count++;
        }
    }
    return count;
}

uintmax_t comb(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}
//桁数のカウント
//pow(x,n) == x^n
//sum = accumulate(v.begin(),v.end(),0);
using Graph = vector<vector<int>>;




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

ll n,k;
cin >> n >> k;
if(n%k == 0){
  cout << 0 << endl;
  return 0;
}else{
  n = n % k;
  while(1){
    if(n < abs(n-k)){
      cout << n << endl;
      return 0;
    }else n = abs(n-k);
  }
}


//////////////////////////////////////////////////////
return 0;}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
#define pii pair<int, int>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1e8;

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

    vector<int> a(m), b(m), c(m);
    rep(i, m) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;  b[i]--;
    }

    vector<vector<int>> dist(n, vector<int>(n, INF));
    rep(i, n) {
        rep(j, n) {
            if(i == j) {
                dist[i][j] = 0;
            }
        }
    }

    rep(i, m) {
        dist[a[i]][b[i]] = min(dist[a[i]][b[i]], c[i]);
        dist[b[i]][a[i]] = min(dist[b[i]][a[i]], c[i]);
    }

    rep(k, n) {
        rep(i, n) {
            rep(j, n) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    int ans = m;
    rep(i, m) {

        int shortestflag = 0;
        rep(j, n) {
            if(dist[j][a[i]] + c[i] == dist[j][b[i]]) {
                shortestflag = 1;
            }
        }

        if(shortestflag) {
            ans--;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc119d
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = ReadIntList();
            var N = NM[0];
            var M = NM[1];
            var A = ReadLongList();
            var B = new long[M+N];
            var C = new long[M+N];

            for (int i = 0; i < M; i++)
            {
                var s = ReadLongList();
                B[i] = s[0];
                C[i] = s[1];
            }

            for (int i = 0; i < N; i++)
            {
                B[M + i] = 1;
                C[M + i] = A[i];
            }

            var ns = Enumerable.Range(0, N + M).OrderByDescending(n => C[n]).ToList();

            var ans = 0L;
            var j = 0L;

            for (int i = 0; i < N + M; i++)
            {
                if (N - j > B[ns[i]])
                {
                    ans += C[ns[i]] * B[ns[i]];
                    //Console.WriteLine($"{C[ns[i]]} * {B[ns[i]]} {ans}");
                    j += B[ns[i]];
                }
                else
                {
                    ans += C[ns[i]] * (N - j);
                    //Console.WriteLine($"{C[ns[i]]} * {N-j} {ans}");
                    break;
                }
            }

            Console.WriteLine(ans);

            


#if DEBUG
            Console.ReadKey();
#endif
        }

        private static bool IsRange(int a, int from, int to) => (from <= a && a <= to);
        private static int ReadInt() => int.Parse(Console.ReadLine());
        private static List<int> ReadIntList() => Console.ReadLine().Split().Select(int.Parse).ToList();
        private static double ReadDouble() => double.Parse(Console.ReadLine());
        private static List<double> ReadDoubleList() => Console.ReadLine().Split().Select(double.Parse).ToList();
        private static long ReadLong() => long.Parse(Console.ReadLine());
        private static List<long> ReadLongList() => Console.ReadLine().Split().Select(long.Parse).ToList();
        private static List<int> Int2Digits(int a) => a.ToString().ToCharArray().Select(_ => int.Parse(_.ToString())).ToList();
        private static int BinarySearch<Type>(IReadOnlyList<Type> s, Type target) // target 以下の最大要素のインデックスを返す
            where Type : IComparable
        {
            var lower = 0;
            var upper = s.Count - 1;
            while (upper - lower > 1)
            {
                var mid = lower + (upper - lower) / 2;
                if (s[mid].CompareTo(target) <= 0)
                {
                    lower = mid;
                }
                else
                {
                    upper = mid;
                }

            }
            return lower;
        }
    }
}


Measured memory_bytes: 33532
if __name__ == '__main__':
    n = int(input())
    s = list(input())
    all_b = s.count("#")
    all_w = s.count(".")

    b = [0 for i in range(n)]
    w = [0 for i in range(n)]

    if s[0] == "#":
        b[0] = 1
    else:
        w[0] = 1
    for i in range(1, n):
        if s[i] == "#":
            b[i] = b[i - 1] + 1
            w[i] = w[i - 1]
        else:
            b[i] = b[i - 1]
            w[i] = w[i - 1] + 1

    ans = min(all_w, all_b)
    for i in range(n):
        ans = min(ans, b[i] + (all_w - w[i]))
    print(ans)


Measured memory_bytes: 14452
#include<bits/stdc++.h>
using namespace std;
int n,k,a[1003];
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		a[i]+=a[i-1];
		if(a[i]>k){
			cout<<i;
			return 0;
		}
	}
	cout<<n+1;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader

fun main(args: Array<String>) {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val n = br.readLine().toInt()
    val a1 = br.readLine().split(' ').map { it.toInt() }
    val a2 = br.readLine().split(' ').map { it.toInt() }
    val candy = (1..n)
            .map { a1.subList(0, it).sum() + a2.subList(it - 1, n).sum() }
            .max()
            ?: 0
    println(candy)
}

fun err(print: Any) {
    System.err.println(print)
}

Measured memory_bytes: 33960
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);++i)
#define rep1(i, n) for(int i=1;i<=(int)(n);++i)
#define irep(i, a, n) for(int i=a;i<(int)(n);++i)
#define rrep(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define rrep1(i, n) for(int i=(int)(n);i>=1;--i)
#define allrep(V, v) for(auto&& V:v)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const int INF=1<<29;
const double EPS=1e-9;
using namespace std;


int main (void)
{
  int n,h,w; cin>>n>>h>>w;
  vector<pair<int,int>> v(n);
  rep(i,n) cin>>v[i].first>>v[i].second;
  cout << count_if(all(v),[&](pair<int,int> p){return p.first >= h && p.second >= w;}) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 N, M;
  std::cin >> N >> M;

  std::vector<i64> passed(N, false);
  std::vector<i64> penalties(N, 0);
  for (i64 i = 0; i < M; ++i) {
    i64 p;
    std::string S;
    std::cin >> p >> S;
    --p;

    if (!passed[p]) {
      if (S == "AC") {
        passed[p] = true;
      } else {
        ++penalties[p];
      }
    }
  }
  for (i64 i = 0; i < N; ++i) {
    if (!passed[i]) {
      penalties[i] = 0;
    }
  }

  std::cout << std::count(passed.begin(), passed.end(), true) << ' ' << std::accumulate(penalties.begin(), penalties.end(), static_cast<i64>(0)) << std::endl;
  return 0;
}

Measured memory_bytes: 1792
def solution(h):
    n = len(h)
    INF = float('inf')
    dp = [INF]*n
    dp[0] = 0
    for i in range(n):
        for j in range(i+1,i+3):
            if j < n:
                dp[j] = min(dp[j] , dp[i]+abs(h[i]-h[j]) )
    
    return dp[n-1]

N = int(input())
h = list(map(int,input().split()))
res = solution(h)
print(res)


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

typedef long long ll;

const int MAXN = 2.1e5;
int N;
int A[MAXN];

const int MAXB = 4.2e5;
int bit[MAXB];

void reset() {
	memset(bit, 0, sizeof(bit));
}

void add(int a) {
	for (a += MAXN; a < MAXB; a += (a & -a)) {
		assert(a > 0);
		bit[a]++;
	}
}

int sum(int a) {
	int r = 0;
	for (a += MAXN; a; a -= (a & -a)) {
		assert(a > 0);
		r += bit[a];
	}
	return r;
}

ll S;

bool is_good(ll v) {
	reset();
	add(0);
	ll cnt = 0;
	int pref = 0;
	for (int i = 1; i <= N; i++) {
		if (A[i-1] <= v) pref++;
		ll val = 2 * pref - i;
		cnt += sum(val-1);
		add(val);
	}
	return cnt >= S;
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N;
	vector<int> sorted;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		sorted.push_back(A[i]);
	}

	sort(sorted.begin(), sorted.end());
	sorted.erase(unique(sorted.begin(), sorted.end()), sorted.end());
	S = ll(N) * (N+1) / 4 + 1;
	int mi = -1, ma = int(sorted.size()) - 1;
	while (ma - mi > 1) {
		int md = (mi + ma) / 2;
		if (is_good(sorted[md])) {
			ma = md;
		} else {
			mi = md;
		}
	}
	cout << sorted[ma] << endl;

	return 0;
}


Measured memory_bytes: 2808
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain, product
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    N = ii()
    A = lmis()
    dp = [1000] * N
    for i in range(1, N):
        for j in range(i):
            m = dp[j]
            s = m//A[j]
            m %= A[j]
            m += s*A[i]
            dp[i] = max(dp[i], m, dp[j])
    print(dp[-1])







main()



Measured memory_bytes: 10008
from heapq import *
h,w=map(int,input().split())
g=[[] for i in range(10)]
for i in range(10):
    l=list(map(int,input().split()))
    for j in range(10):
         g[i].append([l[j],j])
d={}
for i in range(10):
    q=[[0,i]]
    heapify(q)
    l=[-1 for i in range(10)]
    while l[1]==-1:
        c,t=heappop(q)
        if(l[t]==-1):
            l[t]=c
            for j in g[t]:
                C,T=j
                if(l[T]==-1):
                    heappush(q,[c+C,T])
    d[i]=l[1]           
ans=0
for i in range(h):
    l=list(map(int,input().split()))
    for j in l:
        ans+=d.get(j,0)
print(ans)

Measured memory_bytes: 3188
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll ans;
ll n,k,q;vector<ll>ar(ms);
void solve()
{
    cin>>n>>k>>q;
    for(int i=0;i<q;i++)
    {
        ll a;cin>>a;
        ar[a]++;
    }
    for(int i=1;i<=n;i++)
    {
        if(q-ar[i]<k)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
}

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

Measured memory_bytes: 2176
#include <iostream>
using namespace std;
int main(void){
    int a,b,c;
    cin >> a >> b >> c;
    if(a == 1 && b == 0 && c == 0)
    cout << "Close" << endl;
    if(a == 0 && b == 1 && c == 0)
    cout << "Close" << endl;
    if(a == 1 && b == 1 && c == 0)
    cout << "Open" << endl;
    if(a == 0 && b == 0 && c == 1)
    cout << "Open" << endl;
    if(a == 0 && b == 0 && c == 0)
    cout << "Close" << endl;
}


Measured memory_bytes: 3092
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}

ll N, K;
vector<ll> a;
vector<ll> x;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    a.pb(0);
    rep(i, N){
        ll inp;
        cin >> inp;
        inp += a[a.size() - 1];
        a.pb(inp);
    }
    for(ll i =0  ; i < a.size(); i++){
        for(ll j = i+1; j < a.size(); j++){
            x.pb(a[j] - a[i]);
        }
    }

    ll ans = 0 ;
    for(ll i = 40; i >= 0; i--){
        vector<ll> candi;
        rep(j, x.size()){
            if((x[j] >> i) & 1) candi.pb(x[j]);
        }
        if(candi.size() >= K){
            ans += (ll)((ll)1 << i);
            x.clear();
            rep(j, candi.size()){
                x.pb(candi[j]);
            }
        }
    }
    
    cout << ans << endl;
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 6512
N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

answer = 0
for i in range(N):
    x -= a[i]
    if x < 0:
        break
    answer += 1
    if i == N-1 and x != 0:
        answer -= 1
        break
    if x < a[i]:
        break
print(answer)

Measured memory_bytes: 3060