akhauriyash/Code-Regression huggingface dataset:
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD = 1e18;
ll INF = 1e18;


// 二項係数計算
long long COM(ll n, ll k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    ll res=1LL;
    for(ll i=n,index=1;index<=k;i--,index++){
        res*=i;
        res/=index;
    }
  //  cout<<res<<endl;
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ld n,a,b;
    cin>>n>>a>>b;
    V vec(n);
    rep(i,n)cin>>vec[i];
    sort(all(vec),greater<ll>());
   // COMinit();
    set<ll> st;
    rep(i,a){
        st.insert(vec[i]);
    }
    if(st.size()!=1){
        ld sum=0;
        rep(i,a){
            ld k=vec[i];
            sum+=k;
        }
        sum/=a;
        cout<<setprecision(10)<<sum<<endl;
        ll temp=vec[a-1];
        ll res=0;
        ll sum1=0;
        rep(i,n){
            if(vec[i]==temp){
                if(i<a){
                    sum1++;
                }
                res++;
            }
        }
        cout<<COM(res,sum1)<<endl;
        return 0;
    }
    cout<<vec[0]<<endl;
    ll s=vec[0];
    ll sum=0;
    rep(i,n){
        if(s==vec[i]){
            sum++;
        }else{
            break;
        }
    }
    ll res=0;
    rep3(i,a,b+1){
      //  cout<<sum<<" "<<i<<" "<<COM(sum,i)<<endl;
        res+=COM(sum,i);
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int W = sc.nextInt(), H = sc.nextInt(), N = sc.nextInt();

		int xmax = W, ymax = H; //xy平面最大の座標
		int xmin = 0, ymin = 0; //xy平面最小の座標
		
		for(int i=0; i<N; i++){
			int x = sc.nextInt(), y = sc.nextInt(), a = sc.nextInt();
			
			if(a==1){//xminが変わる可能性
				xmin = Math.max(xmin, x);
			}
			else if(a==2){//xmaxが変わる可能性
				xmax = Math.min(x, xmax);
			}
			else if(a==3){//yminが変わる可能性
				ymin = Math.max(ymin, y);
			}
			else if(a==4){//ymaxが変わる可能性
				ymax = Math.min(y, ymax);
			}
		}
		System.out.println(Math.max(0,xmax-xmin) * Math.max(0,ymax-ymin));//0になることも考慮
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <set>
using namespace std;

vector<int> res;
class DisjointSet {
    public:
        vector<int> rank, p;
        
        DisjointSet() {}
        DisjointSet(int size){
            rank.resize(size, 0);
            p.resize(size, 0);
            for(int i = 0; i < size; i++) makeSet(i);
        }
        
        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }
        
        bool same(int x, int y){
            return findSet(x) == findSet(y);
        }
        
        int findSet(int x){
            if(x != p[x]){
                p[x] = findSet(p[x]);
            }
            
            return p[x];
        }
        
        void unite(int x, int y){
            link(findSet(x), findSet(y));
        }
        
        void link(int x, int y){
            if(rank[x] > rank[y]){
                p[y] = x;
            } else {
                p[x] = y;
                if(rank[x] == rank[y]){
                    rank[y]++;
                }
            }
        }
};

int main(void){
    // Your code here!
    int N, M;
    cin >> N >> M;
    DisjointSet ds = DisjointSet(N);
    int x, y, z;
    for(int i = 0; i < M; i++){
        cin >> x >> y >> z;
        x--;
        y--;
        ds.unite(x, y);
        
    }
    
    for(int i = 0; i < N; i++){
        res.push_back(ds.findSet(i));
    }
    
    set<int> S(res.begin(), res.end());
    cout << S.size() << endl;
}


Measured memory_bytes: 6136
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
ll gcd(ll a, ll b){
  if(b==0) return a;
  else gcd(b,a%b);
}
ll lcm(ll a, ll b){
  return a/gcd(a,b)*b;
}
int main(){
  int a,b,c,k;
  cin >>a >> b >> c >> k;
  int ans=0;
  ans=a+b+c-max({a,b,c});
  ans+=max({a,b,c})*pow(2,k);
  cout << ans<< endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <tuple>
typedef long long ll;
#define N_MAX 101
using namespace std;
int main(){
    int n;
    int b[N_MAX];
    int sum_a=0;
    cin>>n;
    for(int i=0;i<n-1;i++){
        cin>>b[i];
    }
    for(int i=0;i<n;i++){
        if(i==0){
            sum_a+=b[0];
        }else if(i==n-1){
            sum_a+=b[n-2];
        }else{
            sum_a+=min(b[i-1],b[i]);
        }
    }
    cout<<sum_a<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

//世界は天才だなぁ

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	int pn = 1;
	if (ci - cn + 16 > cm) {
		if ((ct = getcha()) == '-') { pn = -1; ct = getcha(); }
		A = ct - '0';
		while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
	else {
		if ((ct = *ci++) == '-') { pn = -1; ct = *ci++; }
		A = ct - '0';
		while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
}

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


	int N = getint();
	int S[100000];
	rep(i, N) S[i] = getint();

	ll kotae = 0;
	rep1(ab, N / 2 - 1) {
		int n = ab;
		ll kari = 0;
		bool yoyuu = (N - 1) % n;
		while (n < N - 1 - ab && (yoyuu || n * 2 < N - 1)) {
			kari += S[n] + S[N - 1 - n];
			kotae = max(kotae, kari);
			n += ab;
		}
	}
	co(kotae);



	Would you please return 0;
}

Measured memory_bytes: 768
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  int h,w;
  while(scanf("%d%d",&h,&w) != EOF){
    int k;
    scanf("%d",&k);
    static short int J[1000][1000], O[1000][1000], I[1000][1000];
    static short int size_j[1000], size_o[1000], size_i[1000];
    static short int J2[101][10000], O2[101][10000], I2[101][10000];
    static short int size_j2[101], size_o2[101], size_i2[101];
    for(int i=0;i<h;i++){
      size_j[i] = size_o[i] = size_i[i] = 0;
      if(i % 10 == 0) size_j2[i/10] = size_o2[i/10] = size_i2[i/10] = 0;
      char str[1001];
      scanf("%s",str);
      for(int j=0;j<w;j++){
	if(str[j] == 'J'){
	  J[i][size_j[i]++] = j;
	  J2[i/10][size_j2[i/10]++] = j;
	}
	else if(str[j] == 'O'){
	  O[i][size_o[i]++] = j;
	  O2[i/10][size_o2[i/10]++] = j;
	}
	else if(str[j] == 'I'){
	  I[i][size_i[i]++] = j;
	  I2[i/10][size_i2[i/10]++] = j;
	}
      }
    }
      
    for(int i=0;i<=h;i+=10){
      sort(J2[i/10], J2[i/10]+size_j2[i/10]);
      sort(O2[i/10], O2[i/10]+size_o2[i/10]);
      sort(I2[i/10], I2[i/10]+size_i2[i/10]);
    }

    int y1,x1,y2,x2;
    for(int i=0;i<k;i++){
      int ans_j = 0, ans_o = 0, ans_i = 0;
      scanf("%d%d%d%d",&y1,&x1,&y2,&x2);
      y1--;
      x1--;
      y2--;
      x2--;

      int j;
      for(j=y1;j<=y2;j++){
	if(j % 10 == 0) break;
	ans_j += upper_bound(J[j],J[j]+size_j[j],x2) - lower_bound(J[j],J[j]+size_j[j],x1);
	ans_o += upper_bound(O[j],O[j]+size_o[j],x2) - lower_bound(O[j],O[j]+size_o[j],x1);
	ans_i += upper_bound(I[j],I[j]+size_i[j],x2) - lower_bound(I[j],I[j]+size_i[j],x1);
      }

      
      for(;j+10<=y2;j+=10){
	ans_j += upper_bound(J2[j/10],J2[j/10]+size_j2[j/10],x2) - lower_bound(J2[j/10],J2[j/10]+size_j2[j/10],x1);
	ans_o += upper_bound(O2[j/10],O2[j/10]+size_o2[j/10],x2) - lower_bound(O2[j/10],O2[j/10]+size_o2[j/10],x1);
	ans_i += upper_bound(I2[j/10],I2[j/10]+size_i2[j/10],x2) - lower_bound(I2[j/10],I2[j/10]+size_i2[j/10],x1);
      }

      for(;j<=y2;j++){
	ans_j += upper_bound(J[j],J[j]+size_j[j],x2) - lower_bound(J[j],J[j]+size_j[j],x1);
	ans_o += upper_bound(O[j],O[j]+size_o[j],x2) - lower_bound(O[j],O[j]+size_o[j],x1);
	ans_i += upper_bound(I[j],I[j]+size_i[j],x2) - lower_bound(I[j],I[j]+size_i[j],x1);
      }

      printf("%d %d %d\n",ans_j,ans_o,ans_i);
    }
  }
  return 0;
}

Measured memory_bytes: 9620
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int count[] = new int[200];
    String s;
    char c;

    while (sc.hasNext()) {
      s = sc.nextLine().toLowerCase();
      for (int i = 0; i < s.length(); i++) {
        count[s.charAt(i)]++;
      }
    }

    for (int i = 'a'; i <= 'z'; i++) {
      System.out.printf("%c : %d\n", i, count[i]);
    }

    sc.close();
  }
}

/*
A:65
Z:90
a:97
z:122
*/



Measured memory_bytes: 26316
// 解説を見た
// う〜ん、思いつかねえ！w

#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <numeric>

using namespace std;
using ll = long long;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int chs['z' - 'a' + 1];

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

    for (int i = 0; i < S.size() - 1; i++) {
        if (S[i] == S[i+1]) {
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
    }
    for (int i = 0; i < S.size() - 2; i++) {
        if (S[i] == S[i+2]) {
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }

    cout << "-1 -1" << endl;

    return 0;
}

Measured memory_bytes: 512
split :: String -> (Int,String)
split text =
        let Just i = lookup ',' $ zip text [0..]
            a = read $ take i text
            b = drop (i+1) text
        in
          (a,b)

takeIf :: (a -> Bool) -> [a] -> [a]
takeIf _ [] = []
takeIf c (x:xs) =
  if c x
  then x:(takeIf c xs)
  else (takeIf c xs)

main = do
  c <- getContents
  let i = map snd $ map split $ lines c
      o = map (\b -> length $ takeIf (==b) i ) ["A","B","AB","O"]
  mapM_ print o

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

int main() {
  int Ahp, Aat, Bhp, Bat, countA=0, countB=0;
  cin >> Ahp >> Aat >> Bhp >> Bat;
  
  while (Ahp>0) {
    Ahp-=Bat;
    countA++;
  }
  
  while (Bhp>0) {
    Bhp-=Aat;
    countB++;
  }
  
  if (countA>=countB) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<functional>
#include<map>
#include<stack>
#include<queue>
#include<vector>
using namespace std; 
typedef long long ll;
typedef pair<int, int> P;
//Library
/*//Union-Find木
int par[20], rankh[20];
void init(int n) {
	for (int i = 0; i <= n; i++) {
		par[i] = i;
		rankh[i] = 0;
	}
}
int find(int x) {
	if (par[x] == x)return x;
	else return par[x] = find(par[x]);
}
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rankh[x] < rankh[y])par[x] = y;
	else {
		par[y] = x;
		if (rankh[x] == rankh[y])rankh[x]++;
	}
}
bool same(int x, int y) {
	return find(x) == find(y);
}
//Union-Find木end*/
template<typename t>
t GCD(t a, t b) {
	while (max(a, b) % min(a, b)) {
		if (a > b)a %= b;
		else b %= a;
	}
	return min(a, b);
}
template<typename t>
t LCM(t a, t b) {
	return a / GCD(a, b) * b;
}
//Library end
int main() {
	ll n, t, a;
	cin >> n >> t >> a;
	ll g, h;
	for (int i = 1; i < n; i++) {
		cin >> g >> h;
		ll x, y;
		if (t <= g) {
			if (a <= h) {
				x = g;
				y = h;
			}
			else {
				x = (a + h - 1) / h * g;
				y = (a + h - 1) / h * h;
			}
		}
		else {
			if (a <= h) {
				x = (t + g - 1) / g * g;
				y = (t + g - 1) / g * h;
			}
			else {
				x = max((a + h - 1) / h, (t + g - 1) / g)*g;
				y = max((a + h - 1) / h, (t + g - 1) / g)*h;
			}
		}
		t = x; a = y;
	}
	cout << t + a << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;using pld=pair<ld,ld>;
const ll INF=1LL<<60;void solve();int main(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();}
#define fi first
#define se second
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d!=0&&d>0?i<n:i>n;i+=d)
template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b; return 1;} return 0;}
template<class T> void contout(const T &v){for(auto it=v.begin();it!=v.end();++it,cout<<(it!=v.end()?" ":"\n"))cout<<*it;}

void solve(){
  ll n,k; cin>>n>>k;
  k++; // どこかの桁で必ずlt=trueにする必要がある
  vector<ll> cnt(40);
  rep(i,n){
    ll a; cin>>a;
    rep(d,40) cnt[d]+=(a>>d)&1;
  }
  ll ans=0;
  rep(j,39,-1,-1){ // j 桁目でltをtrueにする
    if(!((k>>j)&1)) continue;
    ll res=0;
    rep(d,39,-1,-1){
      if(d>j){
        res+=((k>>d)&1?(n-cnt[d])*((ll)1<<d):cnt[d]*((ll)1<<d));
      }else if(d==j){
        res+=cnt[d]*((ll)1<<d);
      }else{
        res+=max(cnt[d],n-cnt[d])*((ll)1<<d);
      }
    }
    chmax(ans,res);
  }
  cout<<ans<<"\n";
}

Measured memory_bytes: 384
#include <bits/stdc++.h> 
using namespace std;
long long a[200001],qian[200001],hou[200001];
long long GCD(long long a,long long b)
{
	if(a%b==0)
		return b;
	return GCD(b,a%b);
}
int main()
{
    long long n,i,j,maxx;
    scanf("%lld",&n);
    for(i=0;i<n;i++)
		scanf("%lld",&a[i]);
    qian[0]=a[0];
	hou[n-1]=a[n-1];
    for(i=1;i<n;i++)
		qian[i]=GCD(qian[i-1],a[i]);
    for(i=n-2;i>=0;i--)
		hou[i]=GCD(hou[i+1],a[i]);
    maxx=qian[n-1];
    for(i=0;i<n;i++)
    {
        if(i==0)
			maxx=max(maxx,hou[1]);
        else if(i==n-1)
			maxx=max(maxx,qian[n-2]);
        else
			maxx=max(maxx,GCD(qian[i-1],hou[i+1]));
    }
    printf("%lld",maxx);
    return 0;
}

Measured memory_bytes: 3584
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    int N;
    string s;
    read(N, s);

    int cnt = 0;
    rep(i, N) {
        if (s.substr(i, 3) == "ABC") ++cnt;
    }

    print(cnt);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
const int N=1000005;
char s[N];
int n;
bool check(int v){
	int l0=0,r0=v,l1=1,r1=v;
	v&1?r0--:r1--;
	For(i,1,n){
		int nl0=1e9,nr0=-1e9;
		int nl1=1e9,nr1=-1e9;
		if (s[i]!='1'){
			if (l1<=r1){
				nl0=min(nl0,l1-1);
				nr0=max(nr0,r1-1);
			}
			if (l0<=r0){
				nl1=min(nl1,l0-1);
				nr1=max(nr1,r0-1);
			}
		}
		if (s[i]!='0'){
			if (l1<=r1){
				nl0=min(nl0,l1+1);
				nr0=max(nr0,r1+1);
			}
			if (l0<=r0){
				nl1=min(nl1,l0+1);
				nr1=max(nr1,r0+1);
			}
		}
		if (nl0<0) nl0+=2;
		if (nr0>v) nr0-=2;
		if (nl1<0) nl1+=2;
		if (nr1>v) nr1-=2;
		//cout<<l0<<' '<<l1<<' '<<r0<<' '<<r1<<endl;
		l0=nl0; l1=nl1; r0=nr0; r1=nr1;
		//cout<<l0<<' '<<l1<<' '<<r0<<' '<<r1<<endl;
	}
	return l0<=r0||l1<=r1;
}
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	int l=1,r=n,ans=-1;
	while (l<=r){
		int mid=(l+r)/2;
		if (check(mid))
			ans=mid,r=mid-1;
		else l=mid+1;
	}
	cout<<ans;
	
}
/*
>_<
*/ 

Measured memory_bytes: 4744
//include
//------------------------------------------
#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>


using namespace std;

//conversion
//------------------------------------------
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(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {

	int n; cin >> n;

	vector<int> a(n);

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

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

	LL sum = a[0];

	int last = 0;
	for (int i = 1; i < n; i++) {
		
		if (2 * sum < a[i]) {
			last = i;
		}

		sum += a[i];

	}

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

Measured memory_bytes: 640
import java.io.*;
import java.util.*;

 
public class Main{

	public void solve(){
		String str = next();
		int[] dp = new int[str.length()];
		
		int ans = 0;
		dp[0] = 0;
		for(int i = 1; i < str.length(); i++){
			if(str.charAt(i) == 'S'){
				dp[i] = i;
			}else{
				if(dp[i - 1] >= 0 && str.charAt(dp[i - 1]) == 'S'){
					ans++;
					if(dp[i - 1] > 0){
						dp[i] = dp[dp[i - 1] - 1];
					}else{
						dp[i] = -1;
					}
				}else{
					dp[i] = i;
				}
			}
		}
		
		out.println(str.length() - ans * 2);
	}
	
	private static PrintWriter out;
	public static void main(String[] args){
		out = new PrintWriter(System.out);
		new Main().solve();
		out.flush();
	}
	
	
	
	public static int nextInt(){
		int num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10 + (c - '0');
		}
		return minus ? -num : num;
	}
	
	public static long nextLong(){
		long num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10l + (c - '0');
		}
		return minus ? -num : num;
	}
	public static String next(){
		int c;
		while(!isAlNum(c = read())){}
		StringBuilder build = new StringBuilder();
		build.append((char)c);
		while(isAlNum(c = read())){
			build.append((char)c);
		}
		return build.toString();
	}
	
	
	private static byte[] inputBuffer = new byte[1024];
	private static int bufferLength = 0;
	private static int bufferIndex = 0;
	private static int read(){
		if(bufferLength < 0) throw new RuntimeException();
		if(bufferIndex >= bufferLength){
			try{
				bufferLength = System.in.read(inputBuffer);
				bufferIndex = 0;
			}catch(IOException e){
				throw new RuntimeException(e);
			}
			if(bufferLength <= 0) return (bufferLength = -1);
		}
		return inputBuffer[bufferIndex++];
	}
	
	private static boolean isAlNum(int c){
		return '!' <= c && c <= '~';
	}
}

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main() {
    int N; cin >> N;
    vector<int> a(N);
    vector<pii> minus;
    for(int i = 0; i < N; ++i) {
        cin >> a[i];
        if(a[i] < 0) {
            minus.emplace_back(a[i], i);
        }
    }
    sort(begin(minus), end(minus));
    vector<int> ans;
    while(minus.size() >= 2 && minus[0].first == -2) {
        ans.emplace_back(minus[0].second);
        ans.emplace_back(minus[1].second);
        minus.erase(minus.begin());
        minus.erase(minus.begin());
    }
    for(int i = 0; i < N; ++i) {
        if(a[i] == 2) {
            ans.emplace_back(i);
        }
    }
    sort(begin(ans), end(ans));
    cout << ans.size() << endl;
    for(auto x : ans) {
        cout << x + 1 << endl;
    }
}



Measured memory_bytes: 3164
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.C_Challenge
{
    class ABC_088
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            var marchCnt = new ulong[5];
            for(int i = 0; i < n; i++)
            {
                string s = Console.ReadLine();
                switch (s[0])
                {
                    case 'M':
                        marchCnt[0]++;
                        break;
                    case 'A':
                        marchCnt[1]++;
                        break;
                    case 'R':
                        marchCnt[2]++;
                        break;
                    case 'C':
                        marchCnt[3]++;
                        break;
                    case 'H':
                        marchCnt[4]++;
                        break;
                }
            }

            ulong allCnt = 0;
            for(int i = 0; i < 3; i++)
            {
                for(int j = i + 1; j < 4; j++)
                {
                    for(int k = j + 1; k < 5; k++)
                    {
                        /*Console.WriteLine(string.Format("{0},{1},{2}",
                            i, j, k));*/
                        allCnt += marchCnt[i] * marchCnt[j] * marchCnt[k];
                    }
                }
            }

            Console.WriteLine(allCnt);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<queue>
#include <cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<ctime>
#define rep(i,n) for (int i=0;i<n;i++)
//#include <bits/stdc++.h>
using namespace std;

int N,A,B,C;
vector<int> l;
const long int INF=100000;

int dfs(int n,int a,int b,int c){
    if (n==N){
        if (a==0||b==0||c==0) return INF;
        else return abs(A-a)+abs(B-b)+abs(C-c);
    }
    return min({dfs(n+1,a,b,c),dfs(n+1,a+l[n],b,c)+(a?10:0),dfs(n+1,a,b+l[n],c)+(b?10:0),dfs(n+1,a,b,c+l[n])+(c?10:0)});
}

int main(){
    cin>>N>>A>>B>>C;
    for (int i=0;i<N;i++){
        int x;
        cin>>x;
        l.push_back(x);
    }
    cout<<dfs(0,0,0,0)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 #define MAX 1000000000005
 #define ll long long int
 int main()
 {    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   ll t;

        long long int m,sum=0,k=0,i,j,x=0,sum1=0,l,kk,y,z,e,f,q=MAX,r=MAX,n;
           ll a,b,c=0,d,zz=1;
             cin>>n;
              for(i=0;i<n;i++)
                 { cin>>a>>b;
                   if(a==b)
                     c++;
                     else if(c<3)
                        c=0;
                 }
                 if(c>=3) 
                    cout<<"Yes";
                 else
                    cout<<"No";
    }


Measured memory_bytes: 3648
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include <string.h>
using namespace std;
int bd[3][3];
int a[3], b[3];
int main() {
	for (int i = 0; i < 9; i++) {
		cin >> bd[i / 3][i % 3];
	}
	for (int i = 0; i < 3; i++) {
		b[i] = bd[0][i];
	}
	a[1] = bd[1][0] - b[0];
	a[2] = bd[2][0] - b[0];
	for (int i = 0; i < 9; i++) {
		if (a[i / 3] + b[i % 3] != bd[i / 3][i % 3]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
//stringray

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

/*#ifndef __LOCAL__ 
#pragma comment(linker,"/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif*/ 

using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ost;

typedef pair<int,int> pii;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<set<int>> vsi;

#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(),x.end()
#define pb emplace_back
#define F first
#define S second
#define fori(i,n) for(int i=1;i<=n;++i)
#define forn(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define error(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(0)


const int N=100*1000;
const int mod=1e9+7;

int min3(int a,int b,int c){return min(a,min(b,c));}
int max3(int a,int b,int c){return max(a,max(b,c));}
int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T>
istream& operator >> (istream& is,vector<T>& vec){
  for(T &x:vec)is>>x;
  //for(int i=0;i<vec.size();++i)is>>x[i];
  return is;
}

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

ll mpow(ll a, ll b){
  ll ret=1;
  while(b>0){
    if(b&1)ret=(ret*a)%mod;
    (a=a*a)%=mod;
    b>>=1LL;
  }
  return ret;
}

//#define int int64_t
int a[2*N+2];
int pref[2*N+2];
int suff[2*N+2];
void solve(){
  int n;cin>>n;
  fori(i,n)cin>>a[i];
  fori(i,n){
    pref[i]=a[i];
    if(i>1)pref[i]=max(pref[i-1],a[i]);
  }
  for(int i=n;i>=1;--i){
    suff[i]=a[i];
    if(i!=n)suff[i]=max(suff[i],suff[i+1]);
  }
  fori(i,n){
    if(i==1)cout<<suff[2]<<endl;
    else if(i==n)cout<<pref[n-1]<<endl;
    else cout<<max(pref[i-1],suff[i+1])<<endl;
  }
}
int32_t  main(){
  IOS;
  solve();
  return 0;
}



Measured memory_bytes: 3968
import bisect
n=int(input())
x=[int(input())for _ in range(n)]
a=[-x[0]]
l=1
for i in range(1,n):
  b=-x[i]
  if a[-1]>b:
    if a[0]>b:a[0]=b;continue
    a[bisect.bisect_right(a,b)]=b
  else:a.append(b);l+=1
print(l)

Measured memory_bytes: 56152
# vim: fileencoding=utf-8


def main():
    n = int(input())
    t, x, y = 0, 0, 0
    for i in range(n):
        a, b, c = map(int, input().split())
        d = a - t
        m = abs(x - b) + abs(y - c)
        if d - m < 0 or (d - m) % 2 == 1:
            print("No")
            return
        t, x, y = a, b, c
    print("Yes")


if __name__ == "__main__":
    main()


Measured memory_bytes: 69720
n = input()
s = [0] * 13
h = [0] * 13
c = [0] * 13
d = [0] * 13
for i in range(n):
    x = map(str, raw_input().split())
    if x[0] == 'S':
        s[int(x[1]) - 1] = 1
    if x[0] == 'H':
        h[int(x[1]) - 1] = 1
    if x[0] == 'C':
        c[int(x[1]) - 1] = 1
    if x[0] == 'D':
        d[int(x[1]) - 1] = 1
for i in range(13):
    if s[i] == 0:
        print 'S', (i+1)
for i in range(13):
    if h[i] == 0:
        print 'H', (i+1)
for i in range(13):
    if c[i] == 0:
        print 'C', (i+1)
for i in range(13):
    if d[i] == 0:
        print 'D', (i+1)

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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using uint=unsigned int;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}

void No(){
	cout<<"No"<<endl;
	exit(0);
}

template<class T>
void chmax(T& a,T b){
	a=max(a,b);
}

template<class T>
void chmin(T& a,T b){
	a=min(a,b);
}

template<class T>
void ResetVector(vector<T>& v,int n,const T& t){
	v.clear();
	v.resize(n,t);
}

int main(){
	string s;
	cin>>s;
	string ans;
	for(auto c:s){
		if(!ans.empty()&&c=='T'&&ans.back()=='S')
			ans.pop_back();
		else
			ans+=c;
	}
	cout<<ans.size()<<endl;
}


Measured memory_bytes: 1152
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
	private static final int MOD = (int)Math.pow(10, 9);
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		
		if (Math.abs(c - a) <= d) {
			System.out.println("Yes");
		} else {
			if (Math.abs(b - a) <= d && Math.abs(c - b) <= d) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}

    static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


Measured memory_bytes: 23124
from itertools import combinations_with_replacement as combr

ii = lambda:int(input())
li = lambda:list(map(int,input().split()))

def main(n,m,q,l):
    res = 0
    for item in combr(range(1,m+1),n):
        res = max(res, calc(item, l))
    return res

def calc(item,l):
    res = 0
    for i in l:
        a,b,c,d = i[0],i[1],i[2],i[3]
        if item[b-1] - item[a-1] == c:
            res += d
    return res

n,m,q = li()
l = list(li() for _ in range(q))

print(main(n,m,q,l))

Measured memory_bytes: 9128
#include <string>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>


using namespace std;

int main(void) {
	for(int i = 1; i < 10; i++){
		for(int j = 1; j < 10; j++){
			cout << i << "x" << j << "=" << i*j << endl;
		}
	}
}

Measured memory_bytes: 0
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#define  M  50010
#define  N  600
using namespace std;
struct Edge {
       int u, v, weight, earse;
       Edge () {}
       Edge (int a,int b,int c): u(a), v(b), weight(c), earse(0) {}
} edge[M];
int visit[M], parent[N], n, m, first, cnt, sum;
bool operator<(const Edge &a,const Edge &b) { return a.weight<b.weight; }
int find(int x) {
    int r,t;
    for (r=x;parent[r]>0;r=parent[r])
        ;
    while (parent[x] > 0) {
          t = parent[x];
          parent[x] = r;
          x = t;
    }    
    return r;
}
void weight_union(int u,int v) {
    int i = find(u);
    int j = find(v);
    if (i == j) 
      return ;
    if (parent[i] < parent[j]) {
       parent[i] += parent[j];
       parent[j] = i; 
    }  
    else  {
       parent[j] += parent[i];
       parent[i] = j;
    }
}
int kruskal (void) {
     memset (parent,-1,sizeof(parent));
     int mst = 0;
     for (int i=0,j=0;i<n-1;++i) {
         while (j<m && (edge[j].earse || find(edge[j].u) == find(edge[j].v))) ++j;
         if (j == m)
            return mst;
         mst += edge[j].weight;
         weight_union(edge[j].u,edge[j].v);
         if (first) 
            visit[j] = 1;
         ++j;   
     }
     return mst;
}
void solve (void) {
    memset (visit,0,sizeof(visit));
    sort (edge,edge+m);
    first = 1;
    int mst = kruskal();
    first = 0;
    cnt = sum = 0;
    for (int i=0;i<m;++i)
        if (visit[i]) {
           edge[i].earse = 1;
           int tmp = kruskal();
           if (tmp != mst) {
              cnt++;
              sum+=edge[i].weight;
           } 
           edge[i].earse = 0;
        }
}
int main(void) {
    int u, v, w;
    while ( scanf("%d%d",&n,&m)==2 ) {
          for (int i=0;i<m;++i) {
              scanf ("%d%d%d",&u,&v,&w);
              edge[i] = Edge(u,v,w);     
          }
          solve ();
          printf ("%d %d\n",cnt,sum);
    }
    return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define INF 1125899906842624
i64 C[10][10];
i64 d[10][10];

int main() {
    i64 H, W; cin >> H >> W;
    REP(i, 10) REP(j, 10) {
        cin >> C[i][j];
        d[i][j] = C[i][j];
    }

    REP(k, 10) {
        REP(i, 10) {
            REP(j, 10) {
                chmin(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    i64 cost = 0;
    REP(i, H) REP(j, W) {
        i64 a; cin >> a;
        if (a == -1) continue;
        cost += d[a][1];
    }
    cout << cost << endl;

    return 0;
}

Measured memory_bytes: 256
// E - Sum of gcd of Tuples (Hard)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define irp(i,s,e) for(int i=(s);i>(e);--i)

#define MOD 1'000'000'007

// a^n mod m を計算する(繰り返し二乗法,二分累乗法:O(logn)) (再帰版)
ll modpow(ll a,ll b){return b?modpow(a*a%MOD,b/2)*(b%2?a:1)%MOD:1;}

int main(){
	int N,K; cin>>N>>K;

	vector<ll> cnt_gcd(K+1);

	irp(g, K, 1-1){ // g:[K,1,-1] fixed gcd
		cnt_gcd[g] = modpow(K/g, N); // number of multiples of g
		rp(n, 2, K+1){ // n:[2,K]
			if(n*g > K) break;
			cnt_gcd[g] -= cnt_gcd[n*g];
		}
	}

	ll ans = 0;
	rp(g, 1, K+1) ans = (ans + (cnt_gcd[g] * g % MOD)) % MOD;
	cout<< ans <<endl;
}

Measured memory_bytes: 4044
n, m = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
a = [int(input()) for i in range(m)]
dp = [0 for i in range(n+1)]
dp[0] = 1
for i in range(m):
    dp[a[i]] = -1


for i in range(n):
    if dp[i] != -1:
        if dp[i+1] != -1:
            dp[i+1] += dp[i] % mod

        if i != n-1 and dp[i+2] != -1:
            dp[i+2] += dp[i] % mod

print(dp[-1] % mod)

Measured memory_bytes: 7856
class ModWorld:
    def __init__(self, mod):
        self.mod = mod

    def prepare_factorial(self, N):
        self.f = [1] # f[n] := n!
        p = 1
        for i in range(1,N+1):
            p = (p*i) % self.mod
            self.f.append(p)

    def modpow(self, x, k):
        x %= self.mod
        k %= self.mod-1 # a^(p-1) = 1
        retval = 1
        while k:
            if k&1: retval = retval * x % self.mod
            k>>=1
            x = x*x % self.mod
        return retval % self.mod

    def modcomb(self, n, k):
        return self.f[n] * self.modpow(self.f[n-k], -1) * self.modpow(self.f[k], -1) % self.mod

N = int(input())
X = list(map(int, input().split()))
D = [X[i+1]-X[i] for i in range(N-1)]

mw = ModWorld(mod=10**9+7)
mw.prepare_factorial(N=10**5)

ans = k = 0
for i, d in enumerate(D):
    k = (k + mw.f[N-1]*mw.modpow(i+1, -1)) % mw.mod
    ans = (ans + d*k) % mw.mod

print(ans)

Measured memory_bytes: 17008
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if(a<b){
    cout << "a < b" << endl;
  }else if(a>b){
    cout << "a > b" << endl;
  }else if(a==b){
    cout << "a == b" << endl;
  }
  return(0);
}



Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <vector>

using ll = long long;

int main() {
    int H, W, D;
    std::cin >> H >> W >> D;
    int N = H * W;
    std::vector<int> i_s(N), j_s(N);
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            int a;
            std::cin >> a;
            --a;
            i_s[a] = i;
            j_s[a] = j;
        }
    }
    std::vector<std::vector<ll>> anss(D);
    for (int st = 0; st < D; ++st) {
        ll ans = 0;
        anss[st].push_back(ans);

        int L = st;
        int i = i_s[L], j =  j_s[L];
        while (L + D < N) {
            L += D;
            int new_i = i_s[L], new_j = j_s[L];
            ans += std::abs(new_i - i) + std::abs(new_j - j);
            i = new_i;
            j = new_j;
            anss[st].push_back(ans);
        }
    }

    int Q;
    std::cin >> Q;
    while (Q--) {
        int L, R;
        std::cin >> L >> R;
        --L, --R;
        int st = L % D;
        std::cout << anss[st][(R - st) / D] - anss[st][(L - st) / D] << std::endl;
    }
}



Measured memory_bytes: 6016
#include <stdio.h>
#include <string.h>
#include <math.h>

int main(){

    int i,j,k;
    char line[256];
    int N;
    char v;
    int w,p,g,y;

    w=0;
    p=0;
    g=0;
    y=0;

    fgets(line,sizeof(line),stdin);
    sscanf(line,"%d",&N);

    for(i=0;i<N;i++){
        scanf("%c",&v);
        if(strncmp(&v,"W",1)==0){
            w += 1;
        }
        if(strncmp(&v,"G",1)==0){
            g += 1;
        }
        if(strncmp(&v,"Y",1)==0){
            y += 1;
        }
        if(strncmp(&v,"P",1)==0){
            p += 1;
        }
    }

    if(y >= 1){
        printf("Four");
        return 0;
    }
    else if(y == 0){
        printf("Three");
        return 0;
    }

    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>

int main()
{
  int len, i, cnt;
  char inp[200];
  scanf("%s", inp);
  len = strlen(inp);
  
  cnt = 0, i = 0;
  while(i < len / 2){
    if(inp[i] != inp[len-1-i]) cnt++;
    i++;
  }
  
  printf("%d", cnt);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    ll A,B;
    cin >> A >> B;
    ll K;
    if(A>B) K = (A-B)%2;
    else K = (B-A)% 2;
    
    if(K!=0) cout << "IMPOSSIBLE" << endl;
    else cout << abs(A - (A-B) / 2) << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define show(x) cout<<#x<<"="<<x<<"\n"
using namespace std;

int n,m;
string s;
map<int,int> mp;
vector<int> v;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;
#ifdef LOCAL_DEFINE
    FILE *stream1;
    //FILE *stream2;
    stream1=freopen("in","r",stdin);
    //stream2=freopen("out","w",stdout);
    if(stream1==NULL)return 0;
    //if(stream2==NULL)return 0;
#endif
    cin>>n>>m;
    for(int i=0;i<n;i++){
        int a;cin>>a;
        mp[a]++;
    }
    for(auto ite=mp.begin();ite!=mp.end();ite++){
        int temp=ite->se;
        v.push_back(temp);
    }
    sort(v.begin(),v.end());
    int ans=0;
    for(int i=0;i<(int)v.size()-m;i++){
        ans+=v[i];
    }
    cout<<ans<<endl;
#ifdef LOCAL_DEFINE
    cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
    fclose(stream1);
    //fclose(stream2);
#endif
    return 0;
}


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

using namespace  std;

int main()

{
    int k = 3;
    int arr[4];
    for(int i =0;i<k;i++)
        cin >> arr[i];
    sort(arr, arr+3);
    cout << (arr[2]*10 + arr[1]) + arr[0];
}


Measured memory_bytes: 256
/*=======================
Author    : Shounak Dey
Filename  : a.cpp
=======================	*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;

#define PB push_back
#define MK make_pair 
#define SZ(a) (int)(sizeof(a))
#define F first
#define S second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define read(n) scanf("%d",&n)
#define readl(n) scanf("%lld",&n)
#define readul(n) scanf("%llu",&n);


#define SORTV(a) sort(a.begin(),a.end())
#define TEST int Test;cin >> Test;while(Test--)
#define gcd(a,b) __gcd(a,b)
#define ffs(a) __builtin_ffs(a) // find first set
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)


#define error(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }

vector<string> split(const string& s, char c) {
	vector<string> v;
	stringstream ss(s);
	string x;
	while (getline(ss, x, c))
		v.emplace_back(x);
	return move(v);
}

void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

int main()
{
	fast_io;
	int a,b;
	cin >> a >> b;
	if((a<=9) && (b<=9))
		cout << a*b << endl;
	else
		cout << -1 << endl;	
	return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,sum=0;
    cin>>n;
    ll b[n-1];
    for(i=0;i<n-1;i++)
    {
    cin>>b[i];
    
    }
    sum+=b[0]+b[n-2];
    for(i=0;i<n-2;i++)
    {
        if(b[i]>b[i+1])
        sum+=b[i+1];
        else
        sum+=b[i];
        
    }

    cout<<sum;


     

  return 0;
    
}
    


Measured memory_bytes: 256