akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    string s;
    cin >> s;
    int zero = 0;
    int one = 0;
    for (int i = 0; i < s.length(); i++) {
	if (s[i] == '1') one++;
	else zero++;
    }
    printf("%d\n", min(one, zero) * 2);
    return 0;
}


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

using namespace std;
#define IOS cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

using ll = long long;
using ld = long double;



int main(){ 
    IOS

    int n; cin>>n;
    vector<int> h(n);

    for(int &x : h)cin>>x;

    //dp[i] - min possible cost incurred to
    //         get to stone i, ans = dp[n]
    //dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]))

    int dp[n+5];

    dp[0] = 0;
    if(n >= 2){
        
        dp[1] = abs(h[1]-h[0]);

        for(int i = 2; i < n; i++){
            dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]),
            dp[i-2]+abs(h[i]-h[i-2]));
        }

    }
    cout<<dp[n-1]<<"\n";
    

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T> inline T sqr(T t) {return t*t;}
#define pb push_back
#define mp make_pair
#define endl "\n"

inline void files(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef _WIN32
        return;
    #endif // _WIN32
    //freopen("lca.in", "r", stdin);//freopen("output.out", "w", stdout);
}

ll n, ans;

int main(){
    files();
    cin >> n;
    cin >> ans;
    for (int i = 2; i <= n; i++){
        ll num;
        cin >> num;
        ans = ans*(num/__gcd(ans, num));
    }
    cout << ans;
}


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

int main(){
    int n;
    cin >> n;
    int max_val = 0;
    int sum_val = 0;
    for(int i = 0; i < n; i++){
        int l;
        cin >> l;
        sum_val += l;
        max_val = max(max_val, l);
    }
    sum_val -= max_val;
    if(sum_val > max_val){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;


}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
	long long x;
	long long n = 0;

	cin >> x;
	n += (x / 11) * 2;
	x -= 11 * (n / 2);

	if (x > 0) {
		x -= 6;
		n++;
	}
	if (x > 0) {
		x -= 5;
		n++;
	}

	cout << n << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

int manLength(int x1,int y1,int x2,int y2){
	return abs(x1-x2) + abs(y1-y2);
}
int main()
{
	int n,m;
	cin>>n>>m;
	vector<pair<int,int>> students(n);
	vector<pair<int,int>> points(m);
	for(int i = 0; i < n; i++){
		cin>>students[i].first>>students[i].second;
	}
	for(int i = 0; i < m; i++){
		cin>>points[i].first>>points[i].second;
	}
	for(int i = 0; i < n; i++){
		int length = manLength(students[i].first,students[i].second,points[0].first,points[0].second);
		int currentPoint = 0;
		for(int j = 1; j < m; j++){
			if(length > manLength(students[i].first,students[i].second,points[j].first,points[j].second)){
				currentPoint = j;
				length = manLength(students[i].first,students[i].second,points[j].first,points[j].second);
			}
		}
		cout<<currentPoint+1<<endl;
	}
	return 0;
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll ans = 0;
  rep(i,n) {
    for (ll j = i+1; j < n; ++j) {
      if (a[i] == a[j]) continue;
      for (ll k = j+1; k < n; ++k) {
        if (a[i] == a[k] || a[j] == a[k]) continue;
        if (a[i] < a[j]+a[k] && a[j] < a[i]+a[k] && a[k] < a[i]+a[j]) ++ans;
      }
    }
  }
  cout << ans << '\n';

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 3656
import heapq

n,m=map(int,input().split())
L=[[] for _ in range(m)]
for _ in range(n):
	a,b=map(int,input().split())
	if a<m+1:
		L[a-1].append(-b)
h=[]
heapq.heapify(h)

ans=0
for i in range(m):
	for j in L[i]:
		heapq.heappush(h,j)
	if len(h)==0:
		continue
	ans+=heapq.heappop(h)*(-1)
print(ans)

Measured memory_bytes: 17604
#include <bits/stdc++.h>
#include <boost/algorithm/string/join.hpp>
#include <boost/range/irange.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using boost::irange;
using boost::algorithm::join;

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/4;
constexpr int INF=inf<int>;
constexpr ll LINF=inf<ll>;

#define Sort(x) sort(begin(x),end(x))
#define Reverse(x) reverse(begin(x),end(x))
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ull<<(n))
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,(v).size())

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========
constexpr int N_MAX=100;

// dp[i+1][k][w]
// i番目までみたとき、k個入れて、重さの和がwのときの、価値の最大値
// dp[N]に最終結果がある
int dp[N_MAX+1][N_MAX+1][3*N_MAX+1] = {{{0}}};


int main(int argc, char** argv) {
  int N;
  ll W;
  cin >> N >> W;

  vll ws(N);
  vi vs(N);

  REP(i, N) {
    cin >> ws[i] >> vs[i];
  }

  ll w0 = ws[0];
  REP(i, N) {
    ws[i] -= w0;
  }

  REP(i, N) {
    REP(k, i+1) {
      REP(j, 3*k+1) {
        // 入れない場合
        chmax(dp[i+1][k][j], dp[i][k][j]);
        // 入れる場合
	if ((w0*(k+1)+j+ws[i])<=W) {
          chmax(dp[i+1][k+1][j+ws[i]], dp[i][k][j]+vs[i]);
	}
      }
    }
  }

  int ret = 0;
  REP(k, N+1) {
    REP(j, 3*k+1) {
      chmax(ret, dp[N][k][j]);
    }
  }

  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod


#include <bits/stdc++.h>
using namespace std;
signed main(){
    string S,T; cin>>S>>T;
    int N = T.size();
    bool ans = false;
    REP(i,N){
        S = S.back()+S.substr(0,N-1);
        if(S == T) ans = true;
    }
    if(ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a,b,s=0;
	cin >> a;
	b=a;
	while(b){
		s+=b%10;
		b/=10;
	}
	if(a%s==0)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> cnt(N);
  rep(i, N) {
    cin >> A[i];
    cnt[A[i]]++;
  }
  int begin = (N%2==0 ? 1 : 0);
  ll ans = 1;
  for(int i=begin; i<N; i+=2) {
    if(i == 0 && cnt[i] != 1) ans = 0;
    else if(i != 0 && cnt[i] != 2) ans = 0;
    else (ans *= cnt[i]) %= mod;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3920
#include <stdio.h>
int main(){
  int a,b,c;
  scanf("%d%d",&a,&b);
  if(a==b){
    printf("%d\n",a+b);
    return 0;
  }
  c=a;
  while(a<=b){
    a+=c;
    if(a==b){
      printf("%d\n",c+b);
      return 0;
    }
  }
  printf("%d\n",b-c);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
const int MAXN=200017;
using namespace std;

int a[MAXN], n;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    for(int i=0; i<n; i++) cin>>a[i];
    n++; a[n-1]=-1;
    
    if(n==1&&a[0]==0) {cout<<0<<endl; return 0;}
    if(a[0]!=0) {cout<<-1<<endl; return 0;}
    for(int i=1; i<n; i++) if(a[i]-a[i-1]>1) {cout<<-1<<endl; return 0;}
    
    long long ans=0ll;
    for(int i=0; i<n-1; i++)
    {
        if(a[i]==a[i+1]) ans+=a[i];
        else if(a[i]>a[i+1]) ans+=a[i];
    }
    
    cout<<ans<<endl;
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
#include <queue>
#define INF LONG_MAX
typedef long long ll;
struct edge{ll to, cost;};
typedef pair<ll,pair<ll,ll> >P;
ll L;
struct graph{
  ll V;
  vector<vector<edge> > G;

  VVLL d2;
  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d2.resize(V,VLL(400,INF));
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    VI border(V,400);
    for(int i = 0; i < V; i++){
      rep(j,400)
      d2[i][j] = -1;
    }
    d2[s][0] = L;
    priority_queue<P,vector<P>> que;
    que.push(P(L,{0,s}));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll times = p.second.first;
      ll v = p.second.second;
      if(d2[v][times] > p.first) continue;
      if(border[v] < times) continue;
      for(auto e : G[v]){
        if(d2[v][times] - e.cost >= 0){
          if(d2[e.to][times] < d2[v][times] - e.cost){
            d2[e.to][times] = d2[v][times]-e.cost;
            que.push(P(d2[e.to][times],{times,e.to}));
            border[e.to] = min<ll>(times+1,border[e.to]);
            // cout << v << "->"<< e.to << "=" << times << "," << d2[e.to][times] << endl;
          }
        }

        if( d2[e.to][times+1] < (L - e.cost) ){
          d2[e.to][times + 1] = L - e.cost;
          que.push(P(d2[e.to][times+1],{times+1,e.to}));
          border[e.to] = min<ll>(times+1,border[e.to]);
          // cout << v << "-> "<< e.to << "=" << times << "+1," << d2[e.to][times+1] << endl;
        }
      }
    }
  }
};


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m;
  cin >> n >> m >> L;
  VLL a(m),b(m),c(m);
  graph g(n);
  rep(i,m){
    cin >> a[i] >> b[i] >> c[i];
    a[i]--,b[i]--;
    if(c[i] > L){
      continue;
    }
    g.add_edge(a[i],b[i],c[i]);
    g.add_edge(b[i],a[i],c[i]);
  }
  int ans[n][n];
  rep(i,n)rep(j,n) ans[i][j]= -1;
  g.dijkstra(0);
  rep(i,n){
    g.dijkstra(i);
    rep(j,n){
      rep(k,400){
        if(g.d2[j][k] >= 0){
          ans[i][j] = k;
          break;
        }
      }
    }
  }
  int q;
  cin >> q;
  rep(i,q){
    int s,t;
    cin >> s >> t;
    s--,t--;
    cout << ans[s][t] << "\n";
  }
  return 0;
}


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

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

int three(int x) {
	int ans = 1;
	rep(i, x) ans *= 3;
	return ans;
}

signed main() {
	int a, b, q, s[114514], t[114514];
	cin >> a >> b >> q;
	rep(i, a) cin >> s[i];
	rep(i, b) cin >> t[i];
	rep(i, q) {
		int x;
		cin >> x;
		int su, sd, tu, td;
		if (s[a - 1] < x) su = -1145141919810;
		else su = *(lower_bound(s, s + a, x));
		if (s[0] > x) sd = -1145141919810;
		else sd = *(upper_bound(s, s + a, x) - 1);
		if (t[b - 1] < x) tu = -1145141919810;
		else tu = *(lower_bound(t, t + b, x));
		if (t[0] > x) td = -1145141919810;
		else td = *(upper_bound(t, t + b, x) - 1);
		su = abs(su - x);
		sd = abs(sd - x);
		tu = abs(tu - x);
		td = abs(td - x);
		int mi = max(su, tu);
		mi = min(mi, max(sd, td));
		mi = min(mi, su + td + min(su, td));
		mi = min(mi, tu + sd + min(tu, sd));
		cout << mi << endl;
	}

	return 0;
}


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

using namespace std;

// #define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
// #define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(20);

  double a, b, h, m;
  cin >> a >> b >> h >> m;

  double rad = M_PI * 2.0 * (h / 12.0 + m / 720.0 - m / 60.0);

  // double mang, hang, ang, ans;
  // mang = m * 360.0 / 60.0;
  // hang = h * 360.0 / 12.0;
  // hang += m * 360.0 / 720.0;

  // ang = max(mang, hang) - min(mang, hang);
  // if (ang > 180) {
  //   ang = 360 - ang;
  // }
  // ang = deg_to_rad(ang);

  double ans = sqrt((a * a + b * b) - (2.0 * a * b) * cos(rad));
  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 4224
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;


using lll = long long;
using ull = unsigned long long;
using namespace std;

const lll MOD = 1000000007;
int main(){

  lll ii,jj,kk;
  vector<int> ret;

  lll n;

  cin >> n;

  lll ans;
  lll minus;

  ans = 0;

  lll n10,n9,n8;
  n10 = 1;
  n9  = 1;
  n8  = 1;
    
  for(ii=0;ii<n;ii++){
    n10 = (n10 * 10) % MOD;
    n9  = (n9  *  9) % MOD;
    n8  = (n8  *  8) % MOD;
  }

  ans = (n10 - 2 * n9 + n8 + 2*MOD) % MOD;
  cout << ans << endl;
  
  //ans = n * (n-1);
  //ans %= MOD;
  //minus = ans;
  //for(ii=0;ii<n-2;ii++){
  //  ans *= 10;
  //  ans -= minus;
  //  ans %= MOD;
  //}
  //
  ////ans = 0;
  //bool zeroFlg,nineFlg;
  //
  //char buf[5];
  //
  //for(ii=0;ii<=999;ii++){
  //  sprintf(buf,"%03d",ii);
  //  zeroFlg = false;
  //  nineFlg = false;
  //  for(jj=0;jj<4;jj++){
  //    if(buf[jj] == '0'){
  //      zeroFlg = true;
  //    }
  //    if(buf[jj] == '9'){
  //      nineFlg = true;
  //    }
  //  }
  //  if(zeroFlg && nineFlg){
  //    cout << buf << endl;
  //    ans++;
  //  }
  //
  //}
  //cout << ans << endl;
  
  return 0;
}


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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


int main()
{
    int N,A,B;
    cin >> N >> A >> B;

    ll ans = 0;

    REP(i, 1, N+1)
    {
        string tmp = to_string(i);
        int key = 0;

        rep(j,tmp.size())
        {
            key += tmp[j]-'0';
        }
        //cout << key << endl;

        if( A <= key && key <= B ) ans += i;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AC
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var A = ReadArrayInt().OrderBy(i => i).ToArray();
            var dif = true;
            var chk = A[0];
            for (int i = 1; i < N; i++)
            {
                if (A[i] == chk)
                {
                    dif = false;
                    break;
                }
                else
                {
                    chk = A[i];
                }
            }

            Console.WriteLine(dif ? "YES" : "NO");
            Console.ReadKey();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 39348
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
//Function
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
lli sigma1(lli n){return n*(n+1)/2;}
lli sigma2(lli s, lli n){return sigma1(n) - sigma1(s -1);}
using namespace std;
// }}} End Header

lli body(lli a, lli b){
	return (a-b)*(a-b);
}
int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	int s, w;
	cin >> s >> w;
	if(w >= s) cout <<"unsafe" << endl;
	else cout << "safe" << endl;
	return 0;
}


Measured memory_bytes: 3604
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

const int NILL = -1;

typedef long int lint;

typedef struct node
{
  lint key;
  struct node* parent;
  struct node* left;
  struct node* right;
  
}TREE;

TREE* root = NULL;

void insert(TREE* t)
{
  TREE* x;
  TREE* y;

  y = NULL;
  x = root;

  while(x != NULL)
  {
    y = x;
    if(t->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  
  if(y == NULL) root = t;
  else if(t->key < y->key){
    y->left = t;
  }
  else{
    y->right = t;
  }
}

void PreOrder(TREE* n)
{
  if(n == NULL) return;
  printf(" %ld",n->key);
  PreOrder(n->left);
  PreOrder(n->right);
}

void InOrder(TREE* n)
{
  if(n == NULL) return;
  InOrder(n->left);
  printf(" %ld",n->key);
  InOrder(n->right);
}

void print()
{
  InOrder(root);
  printf("\n");
  PreOrder(root);
  printf("\n");
}

int main()
{
  int m;
  int i;
  char order[20];
  lint key;
  
  scanf("%d",&m);

  for(i = 0; i < m;i++){
    scanf("%s",order);
    
    if(order[0] == 'i'){
      scanf("%ld", &key);

      //if(i == 0) root = tree;
      TREE* t = (TREE *)malloc(sizeof(TREE));
      t->right = t->left = NULL;

      t->key = key;
      insert(t);
    }
    else if(strcmp(order,"print") == 0){
      print();
    }
  }
  return 0;
}


Measured memory_bytes: 26012
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mmax(a,b,c) max(a,max(b,c))
#define mmin(a,b,c) min(a,min(b,c))
#define M 1000000007
#define V vector
#define F(a,b,c) for (a=b;a<=c;++a)
#define I cin
#define O cout
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
const ll L=1e5+1;
V<bool> visited;
V<V<ll>>adj;
V<ll> in_degree, dist;
void dfs(ll a) {
    assert(!visited[a]);
    visited[a]=true;
    for (ll b: adj[a])
    {
        dist[b]=max(dist[b], dist[a]+1);
        --in_degree[b];
        if (!in_degree[b])
            dfs(b);
    }
}
int main() {
    I.sync_with_stdio(false);
    I.tie(0);
    ll n,m,q,i,j,k=0;
    I>>n>>m;
    visited.resize(n,false);
    adj.resize(n);
    in_degree.resize(n);
    dist.resize(n);
    F (q,0,m-1)
    {
        I>>i>>j;
        adj[i-1].pb(j-1);
        in_degree[j-1]++;
    }
    F (i,0,n-1)
        if (!visited[i] && !in_degree[i])
            dfs(i);
    F (i,0,n-1)
        k=max(k,dist[i]);
    O<<k<<'\n';
    return 0;
}

Measured memory_bytes: 10496
#include<iostream>
#include<cmath>
using namespace std;
int main( ){
  while(1){
    double D,E,min;
    cin>>D>>E;
    if(D==0&&E==0)break;
    for(int i=0;i<=D;i++){
      double l=fabs(sqrt(pow(D-i,2)+pow(i,2))-E);
      if(i==0)min=l;
      if(l<min)min=l;
    }
    cout<<min<<endl;
  }
  return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
#pragma warning(disable:4996)
using namespace std;
using ll = long long;
int D, G, p[11], c[11];
const int INF = 10000000;
int rec(int i,int sum,int num,int rest_max) {
	if (i == D) {
		if (sum < G) {
			//if(rest_max=-1)return 
			int s1 = 100 * (rest_max + 1);
			
				int need = (G - sum + s1 - 1) / s1;
				if (need >= p[rest_max]) {
					return INF;
				}
				num += need;
			
			return num;
		}
		else {
			return num;
		}
	}
	return min( rec(i + 1,sum,num,rest_max+1),rec(i + 1,sum + (i + 1) * 100*p[i] + c[i],num + p[i],rest_max) );
}
int main() {
	
	cin >> D >> G;
	for (int i = 0; i < D; i++) {
		cin >> p[i] >> c[i];
	}
	int ans = rec(0, 0, 0, -1);
	cout << ans << endl;
}




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

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (abs(a - c) > d) {
		if (abs(a - b) <= d&&abs(b - c) <= d) {
			cout << "Yes" << endl;
			return 0;
		}
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())

print(A[K-1])

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>

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

using namespace std;

int main()
{
	int n,m;

	while(cin >> n >> m)
	{
		if(n == 0 && m == 0) break;
		
		string s,temp;
		int p = 0;
		int size = n-1;
		bool can[1010];
		rep(i,1010) can[i] = true;
		
		getline(cin,temp);
		REP(i,1,m+1)
		{
			getline(cin,s);
			
			if(size)
			{
				while(!can[p%n]) p++;

				if(i%15 == 0) temp = "FizzBuzz";
				else if(i%3 == 0) temp = "Fizz";
				else if(i%5 == 0) temp = "Buzz";
				else
				{
					stringstream ss;
					ss << i;
					temp = ss.str();
				}

				if(s != temp)
				{
					can[p%n] = false;
					size--;
				}
				p++;
			}

		}

		bool flag = false;
		rep(i,n)
		{
			if(can[i]) 
			{
				if(flag) cout << " ";

				cout << i+1;
				flag = true;
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 1228
import fractions
a,b,c,d = map(int, input().split())

lcm = c*d//fractions.gcd(c, d)
count = b-a+1 - (b//c+b//d-b//lcm - ((a-1)//c+(a-1)//d-(a-1)//lcm))

print(int(count))

Measured memory_bytes: 5432
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n,q;
main()
{
	cin>>n;
	vector<int>a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	a.erase(unique(a.begin(),a.end()),a.end());
	for(int i=0;i<a.size();i++)cout<<(i?" ":"")<<a[i];
	cout<<endl;
}


Measured memory_bytes: 3096
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = [list(input()) for _ in range(N)]
for i in range(N):
	for j in range(N):
		S[i][j] = ord(S[i][j])
S = np.array(S, dtype=np.int32)

def is_symmetric(a):
    return np.array_equal(a, a.T)

ans = 0

for i in range(N):
	S_roll = np.roll(S, i, axis=0)
	if is_symmetric(S_roll): ans += 1

print(ans*N)

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

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

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int a = scan.nextInt();
        int b = scan.nextInt();

        HashSet<Integer> set = new HashSet();
        set.add(1);
        set.add(2);
        set.add(3);
        set.remove(a);
        set.remove(b);
        Integer ans = set.iterator().next();
        os.println(ans);
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree = 
//  tree<key, val, less<key>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = /*1'000'000'007;*/998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 400;

int n, m, k;
string a[N];
int was[N][N];
pair<int, int> q[N * N];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};

bool in(int x, int y)
{
  return 0 <= x && x < n
    && 0 <= y && y < m;
}

int64 bfs(int x, int y)
{
  int qb = 0, qe = 1;
  q[0] = make_pair(x, y);
  int b = 0, w = 0;
  was[x][y] = 1;
  while (qb < qe) {
    tie(x, y) = q[qb++];
    if (a[x][y] == '#')
      ++b;
    else
      ++w;
    for (int i = 0; i < 4; ++i) {
      int tx = x + dx[i];
      int ty = y + dy[i];
      if (in(tx, ty) && a[x][y] != a[tx][ty] && !was[tx][ty]) {
        was[tx][ty] = 1;
        q[qe++] = make_pair(tx, ty);
      }
    }
  }
  return b * 1ll * w;
}

void solve(int test)
{
  cin >> n >> m;
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  int64 ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (!was[i][j])
        ans += bfs(i, j);
    }
  }
  cout << ans << '\n';
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
      solve(i);
  //cerr << endl << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count();
  return 0;
}


Measured memory_bytes: 2304
package main

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

var sc = bufio.NewScanner(os.Stdin)

func min(A ...int) (ret int) {
  ret = A[0]
  for _, a := range A {
    if a < ret {
      ret = a
    }
  }
  return
}

func main() {
  var N int
  fmt.Scan(&N)
  H := make([]int, N)
  sc.Split(bufio.ScanWords)
  for i, _ := range H {
    sc.Scan()
    x, _ := strconv.Atoi(sc.Text())
    H[i] = x
  }
  cnt := 0
  var high, low int
  mode := 0
  for _, h := range H {
    if mode == 0 {
      if h >= high {
        high = h
      } else {
        low = h
        mode = 1
      }
    } else {
      if h <= low {
        low = h
      } else {
        cnt += high - low
        high = h
        mode = 0
      }
    }
  }
  cnt += high
  fmt.Println(cnt)
}

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

int pow2(int x, int n) {
  if (n == 0) return 1;
  if (n & 1) return x * pow2(x, n - 1);
  int m = pow2(x, n / 2);
  return m * m;
}

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

  vector<int> a(3);
  for (int i = 0; i < 3; i++) {
    cin >> a[i];
  }
  int k;
  cin >> k;
  sort(a.begin(), a.end());
  cout << a[0] + a[1] + a[2] * pow2(2, k) << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;

ll mov[13][4] = {
	{2,-1,-1,-1},
	{2,5,-1,-1},
	{0,1,3,6},
	{2,7,-1,-1},
	{5,-1,-1,-1},
	{1,4,6,9},
	{2,5,7,10},
	{3,6,8,11},
	{7,-1,-1,-1},
	{5,10,-1,-1},
	{6,9,11,12},
	{7,10,-1,-1},
	{10,-1,-1,-1},
};

ll sw(ll l, int i, int j) {
	int a, b;
	a = (l >> (4 * i)) & 0xfL;
	b = (l >> (4 * j)) & 0xfL;

	l &= ~(0xfL << (4*i));
	l &= ~(0xfL << (4*j));

	l |= (ll)b << (4 * i);
	l |= (ll)a << (4 * j);

	return l;
}

int main() {
	while(1) {
		ll in = 0;
		for(int i = 0; i < 13; i++) {
			int tmpin;
			cin >> tmpin;
			if(tmpin < 0)
				return 0;
			in |= ((ll)tmpin << (4*i));
		}

		queue<ll> q;
		set<ll> s;
		q.push(in);
		s.insert(in);
		int ans = -1;
		// debug
		int failcount = 0;
		for(int i = 0; i <= 20; i++) {
			queue<ll> next;
			while(!q.empty()) {
				ll l = q.front(); q.pop();
				if(l == 0xba9876543210) {
					ans = i;
					goto OUTPUT_ANSWER;
				}
				else {
					int cnt = 0;
					for(int j = 0; j < 13; j++) {
						ll t = 0xba9876543210;
						if(((l >> 4*j) & 0xfL) != ((t >> 4*j) & 0xfL)) {
							cnt++;
						}
					}
					if(cnt > 20 - i + 4)
						continue;
				}

				for(int j = 0; j < 13; j++) {
					if(((l >> (4*j)) & 0xfL) == 0) {
						for(int k = 0; k < 4; k++) {
							ll p;
							if(mov[j][k] < 0)
								break;
							p = sw(l, j, mov[j][k]);
							if(s.find(p) == s.end()) {
								s.insert(p);
								next.push(p);
							}
							else {
								failcount++;
							}
						}
					}
				}
			}
			q = next;
		}

OUTPUT_ANSWER:;
		if(ans < 0)
			cout << "NA" << endl;
		else
			cout << ans << endl;
//		cout << failcount << endl;
	}
}

Measured memory_bytes: 19220
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const ll mod = 1e9 + 7;

int sum[200010],num[200010];

int main(){

  int n;cin>>n;
  rep(i,0,n){
    ll a;cin>>a;
    sum[i+1]=num[i+1]=a;
    sum[i+1]+=sum[i];
    num[i+1]^=num[i];
  }

  ll ans=0;
  for(int i=1,j=1;i<=n;++i){
    for(;j<=n&&sum[j]-sum[i-1]==(num[j]^num[i-1]);++j);
    ans+=j-i;
  }
  
  out(ans);

  return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;


public class Main {
    Main(){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        String flg;
        if (a < b){
            if (b < c){
                flg = "Yes";
            }else {
                flg = "No";
            }
        }else{
            flg = "No";
        }
        System.out.printf("%s\n", flg);
    }

    public static void main(String[] args){
        new Main();
    }
}



Measured memory_bytes: 26328
n,w=map(int,input().split())
wvs=[list(map(int,input().split())) for _ in range(n)]

dp = [[0 for _ in range(w+1)]for j in range(n+1)]

for i in range(n):
	for j in range(w+1):
		if j-wvs[i][0]<0:
			dp[i+1][j] = dp[i][j]
		else:
			dp[i+1][j] = max(dp[i][j],dp[i][j-wvs[i][0]]+wvs[i][1])
print(dp[n][w])


Measured memory_bytes: 171656
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

const int N = 51;
const int M = 105;
const int S = 10003;
const long long Inf = 1e18;

int n, m, s;
vector<pair<int, int>> g[N];
int to[M], A[M], B[M];
int C[N], D[N];
long long cost[N][S];

struct state {
  int u, s;
  bool operator<(const state& o) const {
    return u < o.u;
  }
};

int main()
{
  cin >> n >> m >> s;
  for(int i = 0 ; i < m ; i++) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    --u, --v;
    g[u].pb({i, v});
    g[v].pb({i, u});
    A[i] = a;
    B[i] = b;
  }
  for(int i = 0 ; i < n ; i++) {
    cin >> C[i] >> D[i];
  }
  for(int i = 0 ; i < n ; i++)
    for(int j = 0 ; j < S ; j++)
      cost[i][j] = Inf;
  s = min(S - 1, s);
  cost[0][s] = 0;
  priority_queue<pair<long long, state>> pq;
  pq.push({0, {0, s}});
  while(!pq.empty()) {
    int u = pq.top().second.u;
    int h = pq.top().second.s;
    long long c = -pq.top().first;
    pq.pop();
    if(c > cost[u][h])
      continue;
    if(cost[u][min(S - 1, h + C[u])] > cost[u][h] + D[u]) {
      cost[u][min(S - 1, h + C[u])] = cost[u][h] + D[u];
      pq.push({- cost[u][min(S - 1, h + C[u])], {u, min(S - 1, h + C[u])}});
    }
    for(auto idx : g[u]) {
      int v = idx.second;
      int i = idx.first;
      if(h >= A[i] && cost[v][h - A[i]] > cost[u][h] + B[i]) {
        cost[v][h - A[i]] = cost[u][h] + B[i];
        pq.push({-cost[v][h - A[i]], {v, h - A[i]}});
      }
    }
  }
  for(int i = 1 ; i < n ; i++) {
    long long best = Inf;
    for(int j = 0 ; j < S ; j++)
      best = min(best, cost[i][j]);
    cout << best << endl;
  }
  return 0;
}


Measured memory_bytes: 15492
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
#define reps(i, n) for(int i = 1; i <= n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;


int main()
{
	int x, y, xx, yy, a, b;
	cin >> x >> y >> xx >> yy;
	a=xx-x;
	b=yy-y;
	rep(i, a) cout << 'R';
	rep(i, b+1) cout << 'U';
	rep(i, a+1) cout << 'L';
	rep(i, b+1) cout << 'D';
	cout << 'R' << 'D';
	rep(i, a+1) cout << 'R';
	rep(i, b+1) cout << 'U';
	rep(i, a+1) cout << 'L';
	rep(i, b) cout << 'D';
	cout << endl;
}

Measured memory_bytes: 256
import math
import fractions
import collections
import itertools
d=collections.deque()
N=int(input())
A=list(map(int,input().split()))
tree=[[] for _ in range(N)]
dirtree=[[] for _ in range(N)]
for i in range(N-1):
    tree[i+1].append(A[i]-1)
    tree[A[i]-1].append(i+1)
#print(tree)
d.append(0)
seen=[0]*N
while len(d)>0:
    v=d.popleft()
    seen[v]=1
    for j in tree[v]:
        if seen[j]==0:
            d.append(j)
            dirtree[v].append(j)
    #input()
    #print(d,dirtree)
for i in range(N):
    print(len(dirtree[i]))

Measured memory_bytes: 142064
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int a, b;
    cin >> a >> b;

    if(a <= b){
        cout << a << endl;
        return 0;
    }
    cout << a - 1 << endl;

    return 0;
}


Measured memory_bytes: 888
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <unordered_map>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    vector<ll> subseq_sum;
    int n, k;
    cin >> n >> k;
    ll a[n];
    for(int i=0;i<n;++i)
    {
        cin >> a[i];
    }

    for(int i=1;i<=n;++i)
    {
        // initial sum
        ll init = 0;
        for(int j=0;j<i;++j)
        {
            init += a[j];
        }
        subseq_sum.push_back(init);

        for(int j=0;j<n-i;++j)
        {
            init += a[i+j];
            init -= a[j];
            subseq_sum.push_back(init);
        }
    }

    ll ret = 0;
    for(int i=0;i<=40;++i)
    {
        int cnt = 0;
        for(auto val :subseq_sum)
        {
            ll mask = ret | (1ll << (40 - i));
            if((val & mask) == mask) cnt++;
        }

        if(cnt >= k)
        {
            ret |= (1ll <<(40 - i));
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 6128
#include<iostream>
#include<vector>
#include<cmath>
#define _GLIBCXX_DEBUG
using namespace std;

int main(){
  int N,C,sum=0;
  cin>>N>>C;
  std::vector<int> p(C);
  for(int i=0;i<C;i++){
    cin>>p[i];
    sum+=p[i];
  }
  int ave=sum/(N+1);
  if(sum<N+1) cout<<"1"<<endl;
  else if(sum%(N+1)==0) cout<<ave<<endl;
  else cout<<ave+1<<endl;
  return 0;
}



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

#define ull unsigned long long

#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))

bool isPalindrome(string s) {
    string t(s.rbegin(), s.rend());
    return s == t;
}

int main(void) {
    long K, N;
    long *A;
    long *distances;
    long maxDistance = 0;
    long maxIndex;
    long distance = 0;
    cin >> K >> N;
    A = new long[N];
    distances = new long[N];
    for(long i = 0;i < N;i++) {
        cin >> A[i];
        if(i != 0) {
            distances[i] = A[i] - A[i - 1];
            if(distances[i] > maxDistance) {
                maxDistance = distances[i];
                maxIndex = i;
            }
        }
    }
    distances[0] = A[0] + K - A[N - 1];
    if(distances[0] > maxDistance) {
        maxDistance = distances[0];
        maxIndex = 0;
    }
    for(long i = 0;i < N;i++) {
        if(i != maxIndex) distance += distances[i];
    }
    cout << distance << endl;
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <limits>
#include <string>
#include <bitset>
#include <functional>
#include <iomanip>

using namespace std;
using lint = long long;
using vb = vector<bool>;
using vi = vector<int>;
using vl = vector<int>;
using pii = pair<int, int>;
using pll = pair<lint, lint>;
using pqi = priority_queue<int>;
using pql = priority_queue<lint>;
#define mii = map<int, int>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define repf(i, f, n) for (int i = (f); i < (n); i++)
#define mp(x, y) make_pair((x), (y))
#define pb(x) push_back((x))
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define foreach(it, x) for (auto it = (x).begin(); it != (x).end(); it++)
#define space (char)0x20
#define yes "Yes"
#define no "No"

constexpr lint MOD = 1e9 + 7;
int A, B, C, D, E, F, G, H, I, J, K, L, M, N;
int O, P, Q, R, S, T, U, V, W, X, Y, Z;
// string s;
// int ans = 1;
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
 
	cin >> N >> M;
    vi a(N);
    rep(i, N) cin >> a[i];

    int sum = accumulate(all(a), 0);
    sort(allr(a));

    if (a[M - 1] * 4 * M >= sum) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

#define LL long long
#define fgx cerr<<"--------------"<<endl;
#define dgx cerr<<"=============="<<endl;

inline int read(){
	int x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
const int MAXN = 1000010;
const int INF = 2147483600;
const LL Mod = 1e9+7;

int N; LL fac[MAXN+1],inv[MAXN+1],ifac[MAXN+1],pw2[MAXN+1];
inline LL C(LL n,LL m){ if(n<m) return 0; return fac[n]*ifac[m]%Mod*ifac[n-m]%Mod; }
LL ans=0; LL f[MAXN+1][3];

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	N=read(); inv[1]=fac[0]=ifac[0]=1; LL pw3=1; pw2[0]=1;
	for(int i=2;i<=max(N,3);i++) inv[i]=(Mod-(Mod/i)*inv[Mod%i]%Mod)%Mod; LL iv=inv[3];
	for(int i=1;i<=N;i++) fac[i]=fac[i-1]*i%Mod,ifac[i]=ifac[i-1]*inv[i]%Mod,pw3=pw3*iv%Mod; f[0][0]=1;
	for(int i=1;i<=N;i++) for(int j=0;j<3;j++) for(int k=0;k<3;k++) if(k!=j) (f[i][j]+=f[i-1][k])%=Mod;
	for(int i=1;i<=N;i++){
		(ans+=C(N,i)*f[i][1]%Mod*inv[i]%Mod)%=Mod;
	} 
	ans=ans*inv[N]%Mod*pw3%Mod; printf("%lld\n",ans);
	return 0;
}




Measured memory_bytes: 50640
import numpy as np

n,m = list(map(int, input().split()))
a = []
b = []
for k in range(n):
    aa, bb = list(map(int, input().split()))
    a.append(aa)
    b.append(bb)


a = np.array(a)
b = np.array(b)

sort = np.argsort(a)

a_sorted = a[sort]
b_sorted = b[sort]

yen = 0
num = 0

for k in range(n):
    if num < m:
        if num + b_sorted[k] > m:
            num_buy = m - num
            yen += num_buy * a_sorted[k]
            num += num_buy
            break
        else:
            num += b_sorted[k]
            yen += b_sorted[k] * a_sorted[k]
#         print(num, yen)
    else:
        break
print(yen)

Measured memory_bytes: 20868
#define  REP(i, s, e) for (int i = s; i <= e; i++)
#define DREP(i, s, e) for (int i = s; i >= e; i--)
#define DEBUG fprintf(stderr, "Passing [%s] in Line %d\n", __FUmaxnCTIOmaxn__, __LImaxnE__)

#define chkmax(a, b) a = max(a, b)
#define chkmin(a, b) a = min(a, b)

#include <algorithm>
#include <iostream>
#include <cstdio>

using namespace std;
const int maxn = 600000 + 10, inf = 1e9, MOD = 1e9 + 7;
int n, m, f[maxn], siz[maxn], x;

int bg[maxn], cur[maxn], ne[maxn], to[maxn], e = 1;
inline void add(int x, int y)
{
	e++;
	to[e] = y;
	ne[e] = bg[x];
	bg[x] = e;
}

bool vis[maxn];
void dfs(int x)
{
	for (int &i = cur[x]; i ; i = ne[i])
	{
		if (vis[i]) continue;
		vis[i] = vis[i ^ 1] = 1;
		if (to[i] == x + n) f[x] = -1;
		if (to[i] == x - n) f[to[i]] = 1;
		dfs(to[i]);
	}
}
signed main()
{
#ifdef CraZYali
	freopen("F.in", "r", stdin);
	freopen("F.out", "w", stdout);
#endif
	cin >> n;
	REP(i, 1, n + n)
	{
		int x;
		scanf("%d", &x);
		x = x == -1 ? 0 : x;
		if (x && i > n) x += n;
		add(i, x);add(x, i);
		siz[x]++;
	}
	REP(i, 1, n) if ((siz[i] + siz[i + n]) & 1)
	{
		puts("IMPOSSIBLE");
		return 0;
	}
	REP(i, 1, n) if (!(siz[i] & 1))
		add(i, i + n), add(i + n, i);
	f[0] = -1;
	copy(bg, bg + n + n + 1, cur);
	dfs(0);
	puts("POSSIBLE");
	REP(i, 1, n) printf("%d%c", f[i], i == n ? '\n' : ' ');
	return 0;
}


Measured memory_bytes: 24192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;

//nCk
template <class T>
T comb(T n,T k){
    T ans=1;
    FOR(i,n-k+1,n+1){
        ans*=i;
    }
    FOR(i,1,k+1){
        ans/=i;
    }
    return ans;
}

map<int,int> ans;

//素因数分解
void prime_factor(int x){
    for(int i=2;i*i<=x;i++){
        while(x%i==0){
            x/=i;
            ans[i]++;
        }
    }
    if (x!=1){
        ans[x]++;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    FOR(i,1,n+1){
      prime_factor(i);
    }
    int a=0,b=0,c=0,d=0,e=0;
    for(auto itr:ans){
      if(itr.second>=4){
        a++;
      }
      if(itr.second>=2){
        b++;
      }
      if(itr.second>=14){
        c++;
      }
      if(itr.second>=24){
        d++;
      }
      if(itr.second>=74){
        e++;
      }
    }
    //cout<<a<<' '<<b<<'\n';
    //cout<<a<<' '<<b<<'\n';
    int ans=comb(a,2)*max(0,(b-2))+c*max(0,(a-1))+d*max(0,(b-1))+e;
    cout<<ans<<endl;
    /*
    for(auto itr:ans){
      cout<<itr.first<<' '<<itr.second<<'\n';
    }
    */
}

Measured memory_bytes: 256