akhauriyash/Code-Regression huggingface dataset:
from collections import Counter
def solve():
  N = int(input())
  A = list(map(int, input().split()))
  c = Counter(A)
  cnt = 0
  for k,v in c.items():
    cnt += v*(v-1)//2
  ans = [cnt]*N
  for i in range(N):
    ans[i] -= c[A[i]]*(c[A[i]]-1)//2
    ans[i] += (c[A[i]]-1)*(c[A[i]]-2)//2
  
  return ans
print(*solve(),sep='\n')

Measured memory_bytes: 34140
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
using namespace std;


int main(){
  int n,m;
  cin>>n;
  vector<string> user(n);
  rep(i,n)cin>>user[i];
  cin>>m;
  vector<string> t(m);
  rep(i,m)cin>>t[i];
  int key=1;
  rep(i,m){ 
    rep(j,n){
      if(t[i]==user[j]){
	cout<<(key>0?"Opened by":"Closed by")<<" "<<t[i]<<endl;
	key*=-1;
	break;
      }
      if(j==n-1){
	cout<<"Unknown"<<" "<<t[i]<<endl;
      }
    }
  }
  return 0;
}

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




int main()
{
    int n;
    cin>>n;
    vector<int> arr;
    for(int x=0;x<n;x++)
    {
        int t;
        cin>>t;
        arr.push_back(t);
    }


    vector<int> dp(n);
    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);
    if(n==2)
    {
        cout<<dp[1];
        exit(0);
    }
    for(int x=2;x<n;x++)
    {
        dp[x]=min(dp[x-1]+abs(arr[x-1]-arr[x]),dp[x-2]+abs(arr[x-2]-arr[x]));
        
    }
    // cout<<endl;
    // for(int x=0;x<n;x++)
    // {
    //     cout<<dp[x]<<" ";
    // }


    // cout<<endl;
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1144
#include<stdio.h>

void show_array(int A[], int N){
    int i;
    for(i = 0; i < N; i++){
        printf("%d", A[i]);
        if(i < N - 1){
            putchar(' ');
        }
        else{
            putchar('\n');
        }
    }
}

void insertion_sort(int A[], int N){
    int i, j;
    int val;
    for(i = 1; i < N; i++){
        val = A[i];
        j = i - 1;
        while(j >= 0 && A[j] > val){
            A[j+1] = A[j];
            j = j - 1;
        }
        A[j+1] = val;

        show_array(A, N);
    }
}

int main(void){
    int A[100];
    int N;
    int i;

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

    return 0;
}




Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define lli long long int
using namespace std;

void solve()
{
    int n;
    cin >> n;

    vector<pair<int,int>> v;
    v.push_back({0, 0});

    for(int i = 1; i <= n; i++){
        int x, y;
        cin >> x >> y;
        v.push_back({x, y});
    }

    bool flag = false;

    for(int i = 1; i <= n-2; i++){
        if((v[i].first == v[i].second) && (v[i+1].first == v[i+1].second) && (v[i+2].first == v[i+2].second)) {flag = true; break;}
    }

    if(flag) cout << "Yes" << "\n";
    else cout << "No" << "\n";
}

int main()
{
    int tc = 1;
    //cin >> tc;

    while(tc--) solve();

    return 0;
}


Measured memory_bytes: 3620
//{
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define SZ(_a) (int)_a.size()
#define ALL(_a) _a.begin(),_a.end()
#define pb push_back
#ifdef brian
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // brian
//}


const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15);

void qt()
{
  cout<<-1<<endl;
  exit(0);
}

vector<ll> v[MAXn];
ll d[MAXn];

int main()
{
    IOS();
    string s;
    cin>>s;
    ll n = SZ(s);
    REP1(i,n)d[i] = (s[i-1] == '1');
    if(!d[1] || !d[n-1] || d[n])qt();
    v[1].pb(2);
    ll now = 2;
    for(int i = 2;i<=n-1;i++)
    {
      if(d[i] != d[n-i])qt();
      v[now].pb(i+1);
      if(d[i])now = i+1;
    }
    REP1(i,n)for(ll k:v[i])cout<<i<<" "<<k<<endl;
}


Measured memory_bytes: 7760
#include<iostream>
#include<algorithm>
using namespace std;
long long a[1000000];
long long b[1000000];
signed main(){
  for(int i=0;i<7;i++){
    cin>>a[i]>>b[i];
  }
  for(int i=0;i<7;i++){
    cout<<a[i]-b[i]<<"\n";
  }
  return(0);
}


Measured memory_bytes: 3100
def main():
    s = list(input())
    t = list(input())
    n = len(s)
    memo1 = {}
    memo2 = {}

    for i in range(n):
        c1 = s[i]
        c2 = t[i]
        if (c1 in memo1 and memo1[c1] != c2) or \
                (c2 in memo2 and memo2[c2] != c1):
            print('No')
            exit()
        memo1[c1] = c2
        memo2[c2] = c1

    print('Yes')


main()


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

using namespace std;

int main() {
   string s;
   cin >> s; 
   sort(s.begin(),s.end()); 
   cout << (s=="abc" ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
//15
#include<iostream>
#include<string>

using namespace std;

int gcd(int a,int b){
  return (b==0)?a:gcd(b,a%b);
}

int main(){
  int n;
  cin>>n;
  cin.ignore();
  while(n--){
    string s;
    getline(cin,s);
    for(int a=1;;a++){
      if(gcd(26,a)!=1)continue;
      for(int b=0;b<26;b++){
	char dt[128];
	dt[' ']=' ';
	for(int c='a';c<='z';c++){
	  dt[(a*(c-'a')+b)%26+'a']=c;
	}
	string t(s);
	for(int i=0;i<t.size();i++){
	  t[i]=dt[t[i]];
	}
	if(t.find("that")!=t.find("this")){
	  cout<<t<<endl;
	  goto next;
	}
      }
    }
  next:
    ;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef unsigned long long ull;

const int N = int(5e5) + 5;
const int inf = (int)1e9 + 7;

int n, m, l[N];
vector < int > g[N], gr[N];

int main(){
  scanf("%d %d", &n, &m);
  for(int i = 1; i <= m; ++i){
    int x, y;
    scanf("%d %d", &x, &y);
    g[x].push_back(y);
    gr[y].push_back(x);
  }
  for(int i : g[1]){
    l[i] = 1;
  }
  for(int i : gr[n]){
    if(l[i]){
      printf("POSSIBLE");
      return 0;
    }
  }
  printf("IMPOSSIBLE");
  return 0;
}


Measured memory_bytes: 32000
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
const int MOD = 998244353;
using mint = modint998244353;
vector<mint> ten, one;
struct S{
    mint num;
    int r;
};
S op(S a, S b){
    return S{a.num * ten[b.r] + b.num, a.r + b.r};
}
S e(){
    return S{0, 0};
}

using F = int;
S mapping(F f, S x){
    if(f == 0) return x;
   return S{f * one[x.r - 1], x.r};
}
F composition(F f, F g){
    if(f == 0) return g;
    return f;
}
F id(){
    return 0;
}


int main(){
    int N, Q;
    cin >> N >> Q;
    ten.resize(N + 1);
    one.resize(N + 1);
    mint temp = 1;
    for(int i = 0; i < N + 1; i++){
        ten[i] = temp;
        if(i == 0) one[i] = 1;
        else one[i] = one[i - 1] + temp; 
        temp = temp * 10;
    }
    vector<S> v(N);
    for(int i = 0; i < N; i++) v[i] = S{1, 1};
    lazy_segtree<S, op, e, F, mapping, composition, id> segk(v);
    for(int i = 0; i < Q; i++){
        int l, r;
        long long d;
        cin >> l >> r >> d;
        l--;
        segk.apply(l, r, d);
        cout << segk.all_prod().num.val() << endl;
    }
}

Measured memory_bytes: 11392
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
#define myCeil(dividend, divisor) ceil((double)(dividend) / (double)(divisor))
#define myFloor(dividend, divisor) floor((double)(dividend) / (double)(divisor))
#define calcDigits(num) floor(log10(num))+1

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl;
#define dv(name, value) cerr << (name) << " is " << (value) << endl;
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl;
#define dpa(v) cerr << "[ " << endl;REPI(itr, v) { cerr << "  [" << (*itr).first << ", " << (*itr).second << ']' << (itr != --v.end() ? "," : "") << endl; } cerr << "]" << endl;


void solve(long long N, long long D){
  cout << myCeil(N, 2 * D + 1) << endl;
}

signed main(){
  long long N;
  scanf("%lld",&N);
  long long D;
  scanf("%lld",&D);
  solve(N, D);
}


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

int main(){
  int x,y;
  cin>>x>>y;

  if(x==1 && (y==3 || y==5 || y==7 || y==8 || y==10 || y==12))cout<<"Yes"<<endl;
  else if(x==3 && (y==5 || y==7 || y==8 || y==10 || y==12))cout<<"Yes"<<endl;
  else if(x==5 && (y==7 || y==8 || y==10 || y==12))cout<<"Yes"<<endl;
  else if(x==7 && (y==8 || y==10 || y==12))cout<<"Yes"<<endl;
  else if(x==8 && (y==10 || y==12))cout<<"Yes"<<endl;
  else if(x==10 && y==12)cout<<"Yes"<<endl;
  else if(x==4 && (y==6 || y==9 || y==11))cout<<"Yes"<<endl;
  else if(x==6 && (y==9 || y==11))cout<<"Yes"<<endl;
  else if(x==9 && y==11)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ

int main()
{
    int a, b;
    cin >> a >> b;
    if (a > 8 || b > 8)
    {
        cout << ":(";
    }
    else
    {
        cout << "Yay!";
    }
}


Measured memory_bytes: 256
a = [0]*26
s = str(input())
for i in range(0, len(s)):
    p = ord(s[i]) - 97
    a[p] += 1
ans = "Yes"
for i in range(0, 26):
    if a[i]%2==1:
        ans = ans.replace(ans, "No")
print(ans)

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

int move_golem(int ini, string s, string t, string d){
    int golem_temp = ini;
    for (int i = 0; i < t.size(); i++){
        if ((golem_temp == -1) || (golem_temp == s.size())){
            break;
        } 
        if (s[golem_temp] == t[i]){
            if (d[i] == 'L'){
                golem_temp = golem_temp - 1;
            }
            else if (d[i] == 'R'){
                golem_temp = golem_temp + 1;
            }
        }
    }

    

    return golem_temp;

}

int main(){
/*    int N = 8;
    int Q = 3;
    string s = "AABCBDBA";
    string t = "ABA";
    string d = "LRR";
*/
int N;
int Q;
cin >> N >> Q;
string s;
cin >> s;

string t(Q,'a');
string d(Q,'a');
for (int i = 0; i < Q; i++){
    cin >> t[i] >> d[i];
}



    /// check lower
    int lb = -1;
    int ub = s.size();
    int lower_bound = -1;
    while ((ub - lb) > 1){
        int mid = (lb + ub)/2;
        int mid_golem_temp = move_golem(mid,s,t,d);
        if (mid_golem_temp == -1 ){
            lb = mid;
        }
        else{
            ub = mid;
        }
        lower_bound = lb;
    }

        /// check upper
    lb = -1;
    ub = s.size();
    int upper_bound = Q;
    while ((ub - lb) > 1){
        int mid = (lb + ub)/2;
        int mid_golem_temp = move_golem(mid,s,t,d);
        if (mid_golem_temp == s.size() ){
            ub = mid;
        }
        else{
            lb = mid;
        }
        upper_bound = ub;
    }
    cout << upper_bound - lower_bound - 1 << endl; 

    return 0;
}

Measured memory_bytes: 1540
<?php
fscanf(STDIN, "%d %d %d", $A, $B, $K);

for ($i = 0; $i < $K; $i++) {
    if ($i % 2 === 0) {
        $A -= $A % 2 !== 0;
        $B += $A / 2;
        $A /= 2;
    } else {
        $B -= $B % 2 !== 0;
        $A += $B / 2;
        $B /= 2;
    }
}
printf("%d %d\n", $A, $B);


Measured memory_bytes: 4728
#include<bits/stdc++.h>
using namespace std;
int a[2000001],b[2000001];
int main()
{
	int n;
	cin>>n;
	int x,y;
	for(int i=1;i<=n;i++)
	{
		cin>>x>>y;
		a[i]=x+y;
		b[i]=x-y;
	}
	sort(a+1,a+1+n);
	sort(b+1,b+1+n);
	cout<<max(abs(a[1]-a[n]),abs(b[1]-b[n]))<<endl;
	return 0;
}

Measured memory_bytes: 5200
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <functional>
#include <tuple>

template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(std::min<int>(l_, r_)), r(r_) {}
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr r, l;
  constexpr revrange(int l_, int r_): r(std::max<int>(l_, r_) - 1), l(l_ - 1) {}
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

template <class T>
inline T scan() {
  T res;
  std::cin >> res;
  return res;
}

constexpr int inf = (1 << 30) - 1;

int N;
int dp[1000002][2];
std::string S;

int main() {
  std::cin >> S;
  N = S.size();
  for (int i: range(0, N + 1)) {
    dp[i][0] = dp[i][1] = inf;
  }
  dp[0][0] = 0;
  for (int i: range(0, N)) {
    int d = S[N - i - 1] - '0';
    chmin(dp[i + 1][0], dp[i][0] + d);
    chmin(dp[i + 1][0], dp[i][1] + d);
    chmin(dp[i + 1][1], dp[i][0] + 11 - d);
    chmin(dp[i + 1][1], dp[i][1] + 9 - d);
  }
  std::cout << std::min(dp[N][0], dp[N][1]) << '\n';
  return 0;
}


Measured memory_bytes: 9220
N,W = map(int,input().split())

value,weight = [],[]
for i in range(N):
    v,w = map(int,input().split())
    value.append(v)
    weight.append(w)
    
dp = [[0 for i in range(W+10)] for j in range(N+10)]    

# < DP初期配列 >
# i\w  0  1  2  3  ...  W
#  0   0  0  0  0  ...  0
#  1   0  0  0  0  ...  0
#           ...
#  N-1 0  0  0  0  ...  0
#  N   0  0  0  0  ...  0
# dp[i+1][j] = (荷物iまで選んだ場合、および重さがj-1までで荷物i+1を選んだ場合)から算出される
#               荷物0,1,...,iを重複含んで選んで重さjとなる場合の価値の最大値
#
# < DP遷移式 >
# if(w>=weght[i]):   # 荷物iを採用できるなら
#      dp[i+1][w] =  min(dp[i][w-weight[i]],    # 荷物iを採用 
#                        dp[i][w],              # 荷物iを採用しない
#                        dp[i+1][w-weight[i]],) # 荷物iを重複を許して採用 
#                                             → 1つ前のループだけでなく、同じル-プ(直前の更新情報)まで使用することで「複数回荷物を選ぶ」という操作を実現している
# elif(w<weight[i]): # 荷物iを採用できないなら
#      dp[i+1][]w = dp[i][w]  # 荷物iを採用しない


for i in range(N):
  for w in range(W+1):
    if(w>=weight[i]): # 荷物iを採用できるなら
      dp[i+1][w] = max(dp[i][w-weight[i]]+value[i], dp[i][w], dp[i+1][w-weight[i]]+value[i])
    else:
      dp[i+1][w] = dp[i][w]
    
    
print(dp[N][W])


Measured memory_bytes: 43052
// vim: shiftwidth=2 expandtab foldmethod=marker

// include {{{
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <utility>
#include <cstdlib>
// }}}

// debug(...) {{{
#ifdef LOCAL_DEBUG
#include "./debug.h"
#else
#define debug(...)
#endif
// }}}

// misc {{{
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

template<class T>
void sort(T& arr) {
  std::sort(arr.begin(), arr.end());
}
template<class T, class By>
void sort_by(T& arr, By by) {
  std::sort(arr.begin(), arr.end(), [by](auto l, auto r){return  by(l) < by(r); });
}

template<class T>
void reverse(T& arr) {
  std::reverse(arr.begin(), arr.end());
}

// }}}

// main {{{
void solve();
int main() {
  solve();
}
// }}}

bool check(int m, int d) {
  int d1 = d % 10;
  int d10 = d / 10;
  return d1 >= 2 && d10 >= 2 && d1 * d10 == m;

}
void solve() {
  int M, D;
  cin >> M >> D;
  int sum = 0;
  rep2(m, 1, M + 1) {
    rep2(d, 1, D + 1) {
      if(check(m, d)) sum++;
    }
  }
  cout << sum;
}


Measured memory_bytes: 888
import java.util.Scanner;

class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int A = sc.nextInt();
    if(X < A){
      System.out.println(0);
    }else if(A <= X){
      System.out.println(10);
    }
  }
}

Measured memory_bytes: 35684
#include <iostream>
#include <functional>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    int X, Y, Z, K;
    vector<long long> A(1001, 0);
    vector<long long> B(1001, 0);
    vector<long long> C(1001, 0);

    vector<long long> ret;
    vector<long long> ret2;

    cin >> X >> Y >> Z >> K;
    for(int i = 0; i < X; i++) cin >> A[i];
    for(int i = 0; i < Y; i++) cin >> B[i];
    for(int i = 0; i < Z; i++) cin >> C[i];

    sort(A.begin(), A.end(), greater<long long>());
    sort(B.begin(), B.end(), greater<long long>());
    sort(C.begin(), C.end(), greater<long long>());

    for(int a = 0; a < X; a++) {
        for(int b = 0; b < Y; b++) {
            ret.push_back(A[a] + B[b]);
        }
    }
    sort(ret.begin(), ret.end(), greater<long long>());


    for(int k = 0; k < min(K, X * Y); k++) {
        for(int c = 0; c < Z; c++) {
            ret2.push_back(ret[k] + C[c]);
        }
    }
    sort(ret2.begin(), ret2.end(), greater<long long>());

    for(int i = 0; i < K; i++) {
        cout << ret2[i] << endl;
    }


}

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

using namespace std;
 
typedef vector <int> vi;
typedef pair< int ,int > pii;
#define endl "\n"
#define sd(val) scanf("%d",&val)
#define ss(val) scanf("%s",&val)
#define sl(val) scanf("%lld",&val)
#define debug(val) printf("check%d\n",val)
#define all(v) v.begin(),v.end()
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define ll long long
#define MOD 1000000007
#define clr(val) memset(val,0,sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define OJ \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
 
int main()
{
 
 int n,k;cin>>n>>k;
 int a[n];
 for(int i=0;i<n;i++)
   cin>>a[i];

 sort(a,a+n);
 int ans=0;
 for(int i=0;i<k;i++)
  ans+=a[i];

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

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

int main() {
  ll x, y;
  cin>>x>>y;
  int ans=1;
  while(true){
    x*=2;
    if(x>y){
      break;
    }
    ans++;
  }
  cout<<ans<<endl;
}

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

using namespace std;

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

int a, b, c;
int solve(vector<int>& v) {
  sort(v.begin(), v.end());
  int ret = 1e9;
  for(int i = 0; i < v.size(); i++) {
    for(int j = i+1; j < v.size(); j++) {
      for(int k = j+1; k < v.size(); k++) {
        ret = min(ret, abs(a - v[i]) + abs(b - v[j]) + abs(c - v[k]));
      }
    }
  }
  for(int i = 0; i < v.size(); i++) {
    for(int j = 0; j < i; j++) {
      vector<int> nv;
      for(int k = 0; k < v.size(); k++) {
        if(k == i || k == j) continue;
        nv.push_back(v[k]);
      }
      nv.push_back(v[i] + v[j]);
      ret = min(ret, 10 + solve(nv));
    }
  }
  return ret;
}

void solve() {
  int n;
  cin >> n >> c >> b >> a;
  vector<int> v;
  v.resize(n);
  for(int i = 0; i < n; i++) cin >> v[i];
  cout << solve(v) << "\n";
}

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


Measured memory_bytes: 256
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def MI(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [LI() for _ in range(N)]
        return map(list, zip(*read_all))

#################

#0!~(n-1)!をmodしつつ求める
def fact_all(n,M=mod):
    f = [1]*n
    ans = 1
    for i in range(1,n):
        ans = (ans*i)%M
        f[i] = ans
    return f


#a!をmodしつつ求める
def fact(a,M=mod):
    ans = 1
    for i in range(2,a+1):
        ans = (ans*i)%M
    return ans


#互いに素なa,bについて、a*x+b*y=1の一つの解[x,y]を出力
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]


#aの逆元(mod M)を求める（aとMは互いに素）
def mod_inv(a,M=mod):
    x = extgcd(a,M)[0]
    return (M+x%M)%M


#nCkをmodしつつ返す
def nCk(n,k,fact_list=[],inv_list=[],M=mod):
    if fact_list and inv_list:
        return (((fact_list[n]*inv_list[k])%M)*inv_list[n-k])%M
    else:
        x = fact(n,M)
        y1 = mod_inv(fact(k,M),M)
        y2 = mod_inv(fact(n-k,M),M)
        return (x*y1*y2)%M


def g(r,c):
    retval = 0
    for i in range(r+1):
        retval += nCk(i+c+1,c,fact_list,inv_list)
        retval %= mod
    return retval

r1,c1,r2,c2 = LI()
fact_list = fact_all(r2+c2+2)
inv_list = [mod_inv(f) for f in fact_list]

print((g(r2,c2)-g(r2,c1-1)-g(r1-1,c2)+g(r1-1,c1-1))%mod)

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

int main(){
    int n;
    cin >> n;
    string Y="Yes",N="No";
    vector<pair<int,int>> p(n);
    ll s=0;
    for(int i=0;i<n;i++){
        cin >> p.at(i).second >> p.at(i).first; //firstが納期secondが時間
    }
    sort(p.begin(),p.end());
    /*
    for(auto x:p){
        cout << x.first << " " << x.second << endl;
    }
    */
    for(auto x:p){

        s += ll(x.second);
        //cout << s << endl;
        if(s>ll(x.first)){
            cout << N << endl;
            return 0;
        }

    }
    cout << Y << endl;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main() {
    int n, k; cin >> n >> k;
    if (k > (n + 1) / 2) { cout << "-1\n"; return 0; }
    for (int a = 0, b = n + (n + 1) / 2, c = 2 * n + 1; a < n; a++, b++, c += 2) {
        if (b >= 2 * n) { b = n; c = 2 * n; }
        cout << a + k << ' ' << b + k << ' ' << c + k << endl;
    }
}


Measured memory_bytes: 2304
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <stack>
using namespace std;
#define maxn 105
const int WHITE = 0;
const int GRAY  = 1;
const int BLACK = 2;
int g[maxn][maxn];
int d[maxn],f[maxn];
stack<int> s;
int color[maxn];
int t,n;
void dfs_visit(int u)
{
    color[u]=GRAY;
    d[u]=++t;
    for(int v=1;v<=n;v++)
    {
        if(g[u][v]==0) continue;
        if(color[v]==WHITE)
            dfs_visit(v);
    }
    color[u]=BLACK;
    f[u]=++t;
}
void dfs()
{
    for(int u=1;u<=n;u++)
        color[u]=WHITE;
    for(int u=1;u<=n;u++)
    {
        if(color[u]==WHITE)
            dfs_visit(u);
    }
    for(int u=1;u<=n;u++)
        printf("%d %d %d\n",u,d[u],f[u]);
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        int u,k;
        scanf("%d%d",&u,&k);
        for(int j=1;j<=k;j++)
        {
            int v;
            scanf("%d",&v);
            g[u][v]=1;
        }
    }
    dfs();
    return 0;
}

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

int main() {
    string s;
    cin >> s;

    string ans = "";
    for (int bit = 0; bit < (1<<3); bit++) {
        int sum = s[0] - '0';
        ans = s[0];
        rep(i, 3) {
            if (bit & (1<<i)) {
                sum += s[i+1] - '0';
                ans += '+';
            } else {
                sum -= s[i+1] - '0';
                ans += '-';
            }
            ans += s[i+1];
        }
        if (sum == 7) {
            cout << ans << "=7" << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	long long int n,ar[10000],i,s=0;
	scanf("%lld",&n);
	for(i=0;i<n;i++){
		scanf("%lld",&ar[i]);
		s=s+ar[i];
	}
	printf("%lld\n",s-n);
	
	
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define wi(t) int t;cin>>t;while(t--)
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
    uniform_int_distribution<int> uid(0,lim-1);
    return uid(rang);
}
int mpow(int base, int exp); 
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];
ll int gcd(ll int a, ll int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 
int tc=1;
void solve()
    { 
        ll int a;
        cin>>a;
        cout<<a*a;
    }

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

   // wi(t)
    {
      solve();
    }

    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
    int i, u, v;
    while(m--){
        cin>>u>>v;
    u--, v--;
        g[u].pb(v);
        g[v].pb(u);
    }
}

void dfs(int u, int par){
    for(int v:g[u]){
        if (v == par) continue;
        dfs(v, u);
    }
}







Measured memory_bytes: 10680
#include<iostream>
#include<algorithm>
 
using namespace std;
 
typedef long long ll;
 
int main(){
    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    for(ll i = K + 1; i <= N; i++){
        ans += (i - K) * (N / i);
        ans += max((ll)0, N % i - K + 1);
    }
    if(K == 0)cout << N * N << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;

int main(){
	vector<int> v(3);
	cin >> v[0] >> v[1] >> v[2];

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

	cout << v[0] + v[1];

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std ;
#define int                 long long
#define ull                 unsigned long long int
#define ld                  long double
#define vi                  vector<int>
#define vii                 vector<pair<int,int>>
#define vvi                 vector<vector<int>>
#define pii                 pair<int,int>
#define pb                  push_back
#define prec(x)             fixed<<setprecision(15)<<x
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define rev(x)              reverse(x.begin(),x.end())
#define mset(a,b)           memset(a,b,sizeof(a))
#define mcpy(a,b)           memcpy(a,b,sizeof(a))
#define fo0(i,n)            for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n)            for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b)           for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)            for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)            for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define mk(arr,n,type)      type *arr=new type[n];
#define dbg(x) cerr << #x << " is " << x << endl;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
clock_t beg = clock();
const int inf=1e18;const int mod=1e9+7;const int N=2e5+9;
const double pi = 3.1415926535897932384626433;
void FILE_IO(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}

void JH(){
    int d,e=0,f=0,g=0,p=0,w=0,flag=0,ans=0,res=0,cnt=0,sum=0;double f1=0.0,f2=0.0,f3=0.0;
    int n;cin>>n;cin>>d;
    fo0(i,n){
        int x,y;cin>>x>>y;
        double temp=x*x+y*y;
        temp=sqrt(temp);
        // cout<<temp<<endl;
        if(temp<=d){
            cnt++;
        }
    }
    cout<<cnt<<endl;

}

int32_t main()
{
    FILE_IO();FAST_IO;int t=1;
    // cin>>t;
    while(t--){JH();}cerr<<fixed<<setprecision(3)<<(double)(clock()-beg)/1000<<"s ";
}

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

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

using namespace std;

int main(void){

    //input
    int N, M;
    cin >> N >> M;

    vector<int> A;
    rep(i,M){
        int Ai = 0;
        cin >> Ai;
        A.push_back(Ai);
        //debug
        //cout << A[i];
    }

    int sum = 0;
    
    //cout << M;
    rep(i, M){
        sum += A[i];
    }

    if(sum <= N){
        //output
        cout<< N - sum;
    }else
    {
        cout<< -1;
    }

    
    return 0;
}


Measured memory_bytes: 3700
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::vec::Vec;

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

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

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

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

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

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

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

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

fn main() {
    input!{
        s: chars,
    }
    if s[0] != 'A' {
        println!("WA");
        return;
    }
    let mut idx = None;
    for i in 2..s.len() - 1 {
        if s[i] == 'C' {
            if idx.is_none() {
                idx = Some(i);
            } else {
                println!("WA");
                return;
            }
        }
    }
    if idx.is_none() {
        println!("WA");
        return;
    }
    for i in 1..s.len() {
        if i == idx.unwrap() {
            continue;
        }
        if !s[i].is_lowercase() {
            println!("WA");
            return;
        }
    }
    println!("AC")
}


Measured memory_bytes: 4476
import sys
import math
if __name__ == "__main__":
   s = str(input())
   K = int(input())
   uniq = sorted(list(set(list(s))))
   buf = []
   for i in range(len(uniq)):
      buf.append(uniq[i])
      for j in range(len(s)):
         if s[j] == uniq[i]:
            fin = K
            if (len(s) - j) - K < 0:
               fin = (len(s) - j)
            for k in range(1, fin):
               buf.append(s[j:j+k+1])
   ans = sorted(list(set(buf)))
#   print(ans)
   print(ans[K-1])

Measured memory_bytes: 5068
from bisect import *
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort()
b.sort()
c.sort()

ans = 0
for i in range(n):
    ans += bisect_left(a, b[i])*(n-bisect_right(c, b[i]))

print(ans)


Measured memory_bytes: 22720
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
/*
ll dx[8]={-1,-1,-1,0,0,1,1,1};
ll dy[8]={-1,0,1,-1,1,-1,0,1};

bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}
*/
int main()
{
     ll n;
     cin>>n;
     string str;
     cin>>str;
     ll mx=0;
     for(int i=0;i<n-1;i++)
     {
         ll cnt=0,arr[26],arr2[26];
         for(int k=0;k<26;k++)
             arr[k]=0,arr2[k]=0;
         for(int k=0;k<=i;k++)
             arr[str[k]-'a']++;
         for(int k=i+1;k<n;k++)
             arr2[str[k]-'a']++;
         for(int k=0;k<26;k++)
             if(arr[k]>0 && arr2[k]>0)
                cnt++;
         mx=max(mx,cnt);
     }
     cout<<mx<<endl;
}



Measured memory_bytes: 3584
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let n = read_as_vec::<usize>()[0];
    let a: Vec<usize> = read_as_vec();
    let limit = 100001;
    let mut counter: Vec<u32> = vec![0;limit];

    for &elem in &a{
        if elem > 0{
            counter[elem-1] += 1;
        }

        counter[elem] += 1;

        if elem < limit-1{
            counter[elem+1] += 1;
        }
    }

    println!("{}", counter.iter().max().unwrap());
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

vector< vector<int> > Graph;
vector< int > value;









int main(int argc, const char * argv[]) {
    
    
    
    int n; cin >> n;
    cout << n*n*n << endl;
    
    
    


    
    

    
}


Measured memory_bytes: 256
#include <stdio.h>

int	main(void)
{
  	long long int	A;
  	long long int	B;
  	long long int	K;
  	int num;
  
  	num = scanf("%lld %lld %lld", &A, &B, &K);
  	if (num != 3)
      	return (0);
  
  	if (A > K)
      	printf("%lld %lld", A-K, B);
  	else
      	if (B > K - A)
          	printf("0 %lld", B-K+A);
  		else
          	printf("0 0");
  	return (0);
}

Measured memory_bytes: 128
from collections import deque
import sys
input=sys.stdin.readline

mod=10**9+7
n,k=map(int,input().split())
A=list(map(int,input().split()))
cnt=k

B,C=[],[]
for i in range(n):
    num=A[i]
    if num>=0:B.append(num)
    else:C.append(num)

B.sort(reverse=True)
C.sort()
B,C=deque(B),deque(C)

ans,flag=1,1
while k!=0:
    num=0
    length_B,length_C=len(B),len(C)
    if k>=2:
        if length_B>=2 and length_C>=2:
            plus=B[0]*B[1]
            negative=C[0]*C[1]
            if plus>negative:
                ans *=B.popleft()
                num=1
            else:ans *=C.popleft()*C.popleft()
        elif length_C>=2:ans *=C.popleft()*C.popleft()
        elif length_B>=2:ans *=B.popleft()*B.popleft()
        else:
            ans *=B.popleft()*C.popleft()
            flag=0
        k -=2-num
    else:
        if 0<length_B:ans *=B.popleft()
        elif 0<length_C:
            ans *=C.popleft()
            flag=0
        k -=1
    ans %=mod

if flag:print(ans);exit()

ans=1
A=sorted(A,key=lambda x:abs(x))
for i in range(cnt):
    ans *=A[i]
    ans %=mod
print(ans)

Measured memory_bytes: 116216
'use strict'

function main(s) {

  s = s.split('\n');
  const H = Number(s[0].split(' ')[0]);
  const W = Number(s[0].split(' ')[1]);
  const table = s.slice(1, -1).map(line => line.split(''));

  const dh = [-1, -1, -1, 0, 0, 1, 1, 1];
  const dw = [-1, 0, 1, -1, 1, -1, 0, 1];

  for (let h = 0; h < H; h++) {
    for (let w = 0; w < W; w++) {
      if (table[h][w] === '#') continue;

      let count = 0;

      for (let d = 0; d < 8; d++) {
        const nh = h + dh[d]
        const nw = w + dw[d]

        if (nh < 0 || H <= nh) continue;
        if (nw < 0 || W <= nw) continue;

        if (table[nh][nw] === '#') count += 1;
      }

      table[h][w] = count;
    }
  }

  const ans = table.map(line => line.join('')).join('\n');
  console.log(ans);
}

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


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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

#define INTSPACE 12
char _buf[INTSPACE*1000000 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}
int loadvec(vector<int>& v, int N=-1) {
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    // assert(i <= N);
    return i;
}

ll solve(int N, vi& a) {
    vector<ll> ac(N+1, 0);
    rep(i,N) ac[i+1] = ac[i] + a[i];
    // cerr << ac << endl;
    ll ans = 0x7fffffffffffffffLL;
    rep(i,N-1) {
        ll x = ac[i+1] - ac[0], y = ac[N] - ac[i+1];
        ll diff = x-y; if (diff < 0) diff = -diff;
        // cerr << i << " " << x << " " << y << " " << diff << endl;
        ans = min(ans, diff);
    }
    return ans;
}

int main() {
    vi a;
    int N=loadvec(a);
    cout << solve(N,a) << endl;
    return 0;
}


Measured memory_bytes: 3840
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

ll n,A,B,C,D;

const int N = 1e5;
ll f[N+10];
bool vis[N+10];
priority_queue<PA>q;
inline void init(){
	For(i,0,N) vis[i]=0,f[i]=1e18;
	f[0]=0,q.push(mp(0,0));
	while (!q.empty()){
		int u=q.top().se;q.pop();
		if (vis[u]) continue;vis[u]=1;
		if (u&&f[u]+D<f[u-1]) f[u-1]=f[u]+D,q.push(mp(-f[u-1],u-1));
		if (u+1<=N&&f[u]+D<f[u+1]) f[u+1]=f[u]+D,q.push(mp(-f[u+1],u+1));
		if (u*2<=N&&f[u]+A<f[u*2]) f[u*2]=f[u]+A,q.push(mp(-f[u*2],u*2));
		if (u*3<=N&&f[u]+B<f[u*3]) f[u*3]=f[u]+B,q.push(mp(-f[u*3],u*3));
		if (u*5<=N&&f[u]+C<f[u*5]) f[u*5]=f[u]+C,q.push(mp(-f[u*5],u*5));
	}
}
map<ll,ll>g;
inline ll Query(ll n){
	if (n<=N) return f[n];
	if (g.count(n)) return g[n];
	__int128 ret=Query(n/2)+min((__int128)n%2*D+A,(__int128)(n-n/2)*D); 
	ret=min(ret,Query(n/2+1)+min((__int128)(2-n%2)*D+A,(__int128)(n-n/2-1)*D));
	ret=min(ret,Query(n/3)+min((__int128)n%3*D+B,(__int128)(n-n/3)*D));
	ret=min(ret,Query(n/3+1)+min((__int128)(3-n%3)*D+B,(__int128)(n-n/3-1)*D));
	ret=min(ret,Query(n/5)+min((__int128)n%5*D+C,(__int128)(n-n/5)*D));
	ret=min(ret,Query(n/5+1)+min((__int128)(5-n%5)*D+C,(__int128)(n-n/5-1)*D));
	return g[n]=ret;
}
inline void solve(){
	n=read(),A=read(),B=read(),C=read(),D=read();
	init(),g.clear(),printf("%lld\n",Query(n));
}

int main(){
	int T=read();
	while (T--) solve();
}

Measured memory_bytes: 6716
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, X;
    cin >> N >> X;
    
    int ans = 0;
    int D = 0;
    while(D <= X && ans <= N) {
        int N;
        cin >> N;
        D += N;
        ans++;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,mmx,avx")
#include "bits/stdc++.h"
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
const int MOD=1000000007;
#define endl "\n"
#define fst first
#define snd second
const int UNDEF = -1;
const int INF=1<<30;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;typedef vector<ll> vll;typedef pair<int,int> pii;typedef vector<int> vi;typedef vector<vi> vvi;
#ifdef ONLINE_JUDGE
#define assert(...) /* nothing */
#endif
#define DEBUG_CAT
#ifdef DEBUG_CAT
#define dbg(...)   printf( __VA_ARGS__ )
#else 
#define dbg(...)   /****nothing****/
#endif
// mt19937 rng; rng.seed(std::chrono::high_resolution_clock::now().time_since_epoch().count());
// template<typename T> int bins(vector<T> &v, T key) {int imin=0,imax=v.size();while(imin<imax) {int imid=(imin+imax)>>1;if (v[imid]<key) imin=imid+1;else imax=imid;}return imin;}


ll n,m,v,p;
vll a;

bool f(ll wanti) {
  ll level=a[wanti]+m;
  ll above=p-1;
  ll belowabsorb=0;
  for (int i=n-1;i>=0;i--) {
    if (i==wanti) continue;
    if (above>0) {
      above--;
    } else {
      if (a[i] > level) return false;
      if (a[i]<level) {
        belowabsorb += min(m,level-a[i]);
      }
    }
  }
  ll needabsorb = m*(v-p);
  return belowabsorb >= needabsorb;
}

int main(){	
	cin>>n>>m>>v>>p; a.reserve(n);
  for (int i=0;i<n;i++) {ll x; cin>>x; a.PB(x);}
  sort(a.begin(),a.end());
  ll imin=0; ll imax=n;
  while(imin<imax) {
    ll imid=(imin+imax)/2;
    if (!f(imid)) imin=imid+1;
    else imax=imid;
  }
  ll cnt=n-imin;
  printf("%lld\n",cnt);
}



Measured memory_bytes: 1024
import random


def mid_1(X):
    return X[(len(X)) // 2]


def mid(X):
    return X[(len(X)) // 2 - 1]


def main():
    N = int(input())

    X = list(map(int, input().split()))
    # N = 200000
    # X = [random.randint(0, 1000000000) for _ in range(N)]
    X_ = X[:]
    X_.sort()
    X__ = X_[:N // 2]
    X__ = X__[-1]

    x_1 = mid_1(X_)
    x = mid(X_)

    ans = []
    # print(X_)
    # print(X__)
    for i in range(N):
        if X[i] <= X__:
            print(x_1)
            # ans.append(x_1)
        else:
            print(x)
            # ans.append(x)


if __name__ == '__main__':
    main()

Measured memory_bytes: 26256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, l;
	cin >> n >> l;
	int mn = inf;
	int res = 0;
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		int tmp = l + i - 1;
		ans += tmp;
		if (abs(tmp) < mn) {
			mn = abs(tmp);
			res = tmp;
		}
	}
	cout << ans - res << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
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; }
#define ll long long
#define rep(i,n) for (int i = 0; i < (n); i++)
const long long INF = 1LL << 60;
int main()
{
	string s;
	cin>>s;
	ll n = s.length();
	ll sum=0;
	for(ll i=0;i<n;i++)
	{
		sum+= s[i]-'0';
	}
	if(sum%9==0)
	{
		cout<<"Yes" << endl;
	}
	else
	{
		cout<<"No" << endl;
	}
} 

Measured memory_bytes: 3668