akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

struct edge {
	int to;
	bool rev;
};

int N, M, a, b;
bool vis[100001];
vector<edge>v[100001];

bool dfs(int x,int bf) {
	vis[x] = true;
	bool c = false;
	for (edge e : v[x]) {
		if (!e.rev)c ^= true;
	}
	for (int i = 0; i < v[x].size(); ++i) {
		if (!vis[v[x][i].to]) {
			if (dfs(v[x][i].to, x)) {
				c ^= true;
				v[x][i].rev ^= true;
			}
		}
	}
	if (c) {
		for (edge &e : v[x]) {
			if (e.to == bf) {
				e.rev ^= true;
				break;
			}
		}
		return true;
	}
	return false;
}


int main() {
	cin >> N >> M;
	if (M & 1) {
		cout << -1 << endl;
		return 0;
	}
	for (int i = 0; i < M; ++i) {
		cin >> a >> b;
		v[a].push_back({ b, false });
		v[b].push_back({ a,true });
	}
	dfs(1, -1);
	for (int i = 1; i <= N; ++i) {
		for (edge e : v[i]) {
			if (!e.rev) {
				cout << i << sp << e.to << endl;
			}
		}
	}
}

Measured memory_bytes: 14720
#include <stdio.h>
int main(void) {
	double w, h, x, y, ans;
	scanf("%lf", &w);
	scanf("%lf", &h);
	scanf("%lf", &x);
	scanf("%lf", &y);
	ans = w * h / 2;
	printf("%.9lf ", ans);
	if (x == w / 2 && y == h / 2) {
		printf("1");
	}
	else {
		printf("0");
	}

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main(){
    int m;
    cin>>m;
    ll sum=0;
    ll cnt=0;
    int pre_num=0;
    for (int i = 0; i < m; i++)
    {
        int d,c;
        cin>>d>>c;
        sum += c;
       if(d==0){
           pre_num=0;
           continue;
       }
       cnt += c*d;
    }

    cout<<sum-1+(cnt-1)/9<<endl;
    
  
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
	x = 0;
	T f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -1;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	x *= f;
}
inline void d_read(double &x) {
	x = 0.0;
	int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -1;
	for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
	if (c == '.'){
		double num = 1.0;
		c = getchar();
		for (; isdigit(c); c = getchar()) x = x + (num /= 10) * (c ^ 48);
	}
	x *= f;
}

template <typename T>
inline void w(T x) {
	if (x > 9) w(x / 10);
	putchar(x % 10 + 48);
}
template <typename T>
inline void write(T x, char c) {
	if (x < 0){
		putchar('-');
		x = -x;
	}
	w(x);
	putchar(c);
}
int main(){
	string s;
	cin >> s;
	if (s[0] >= 'A' && s[0] <= 'Z') puts("A");
	else puts("a");
	return 0;
}


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

int N,A,B;

/*long long Combination(int n, int m) {
	int C[60][60] = {{0}};
	C[1][1] = 1;
	for(int i=1;i<50;i++){
		for(int j=1;j<=i+1;j++){
			if(j==1 || j==i+1) C[i][j] = 1;
			else{
				C[i+1][j] = C[i][j-1] + C[i][j]; 
			}
		}
	}
	cout << C[n+2][m+1] << endl;
}*/

int main(){
	long long  C[60][60] = {{0}};
	C[1][1] = 1;
	for(int i=1;i<53;i++){
		for(int j=1;j<=i+1;j++){
			if(j==1) C[i][j] = 1;
			else{
				C[i+1][j] = C[i][j-1] + C[i][j]; 
			}
		}
	}
	/*for(int i=1;i<10;i++){
		for(int j=1;j<10;j++){
			if(j!=9) cout << C[i][j] << " ";
			else cout << C[i][j] << endl;
		}
	}*/
	while(cin >> N >> A >> B && N > 0){
		vector<long long > v;
		for(int i=0;i<N;i++){
			long long  a;
			cin >> a;
			v.push_back(a);
		}
		sort(v.begin(),v.end());
		reverse(v.begin(),v.end());
		double sum = 0, ave = 0;
		for(int i=0;i<A;i++){
			sum += v[i];
		}
		ave = sum/A;
		long long  count = 0;
		if(v[0] != v[A-1]){
			int x = 0, y = 0;
			for(int i=0;i<N;i++){
				if(v[i] == v[A-1]) x++;
				if(v[i] == v[A-1] && i<=A-1) y++;
			}
			count = C[x+1][y+1];
		//	cout << x << endl;
		//	cout << y << endl;
		}else{
			int x = 0;
			for(int i=0;i<v.size();i++){
				if(v[i] == v[0]) x++;
			}
		//	cout << x << endl;
			for(int i=A;i<B+1;i++){
				count += C[x+1][i+1];
			}
		}
		printf("%.6f\n", ave);
		cout << count << endl;
	}
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <set>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
#include <regex>
#include <cmath>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>
#include <cassert>
#include <chrono>
#include <memory>

using namespace std;

#define int long long
//region TEMPLATE
////@formatter:off
#define double long double
typedef long long ll;
typedef unsigned long long ull;
template<typename T>void __read(T &a) { cin >> a; }
template<typename T, typename ... Args> void __read(T &a, Args &... args) { cin >> a;__read(args...);}
#define make(t, ...) t __VA_ARGS__; __read(__VA_ARGS__)
#define makev(a, n) VI a(n); FOR(n) cin >> a[i];
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define FORE(i, l, r) for(int i = (l); i < (r); i++)
#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
constexpr ll M7 = 1000000007ll;
constexpr ll M9 = 1000000009ll;
constexpr ll MFFT = 998244353ll;
template<class T> void outv(T &a) { for (auto &x : a) cout << x << ' '; }
static mt19937 rnd(static_cast<unsigned>(chrono::steady_clock::now().time_since_epoch().count())); // NOLINT(cert-err58-cpp)
auto __fast_io__ = (ios_base::sync_with_stdio(false), cin.tie(nullptr)); // NOLINT(cert-err58-cpp,cppcoreguidelines-interfaces-global-init)
////@formatter:on
//endregion



int32_t main() {
    make(int, a, b);
    cout << a * b;

    return 0;
}

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

using namespace std;
int main(){
    int n, n_swaps=0, temp;
    cin >> n;
    vector<int> array(n);
    for(int i=0;i<n;i++) cin >> array[i];
    
    //Bubble sort
    for(int i=0;i<n;i++){
        for(int j=n-1; j>i;j--){
            if(array[j-1] > array[j]){
                temp = array[j-1];
                array[j-1] = array[j];
                array[j] = temp;
                n_swaps++;
            }
        }
    }
    
    for(int i=0;i<n;i++) cout << array[i] << " \n"[i==n-1];
    cout << n_swaps << endl;
    
    return 0;
}


Measured memory_bytes: 3084
// Marcin Knapik
#include<bits/stdc++.h>

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;

// #include <ext/pb_ds/assoc_container.hpp> // order_of_key
// #include <ext/pb_ds/tree_policy.hpp> // find by order
// using namespace __gnu_pbds; 
// #define ordered_set tree< pair<int, int> , null_type,less<pair<int, int>>, rb_tree_tag,tree_order_statistics_node_update>  

// const ll MAX_LL = 0xFFFFFFFFFFFFFFFF;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define losuj(a, b) uniform_int_distribution<ull>(a, b)(rng)
#define losuj_real(a, b) uniform_real_distribution<long double>(a, b)(rng)

typedef long double             ld;
typedef long long               ll;
typedef unsigned long long      ull;
typedef pair<ll, ll>            pll;
typedef pair<int, int>          ii;
typedef vector<int>             vi;
typedef vector<ii>              vii;
typedef vector<vi>              vvi;
typedef vector<vector<ii>>      vvii;
typedef vector< ll >            vll;
typedef vector< pll >           vpll;
 
#define sz(a)                   (int)(a).size()
#define pb                      push_back
#define all(c)                  (c).begin(), (c).end()
#define rall(c)                 (c).rbegin(), (c).rend()
#define FOR(i, a)               for (int i = 0; i < (a); i++)
#define f                       first
#define s                       second
 
template <class T> inline bool setmin(T &a, T b){if (a > b)return a = b, 1;return 0;}
template <class T> inline bool setmax(T &a, T b){if (a < b)return a = b, 1;return 0;}
 
template<class T> inline T fast(T a,T b,T mod) {ll res = 1; while(b){if(b&1) res = (res*a)%mod;a = (a*a)%mod;b >>= 1;}return res;}
template<class T> inline T russian(T a, T b, T mod) {ll res = 0; while(b){if(b&1) res = (res + a)%mod; a = (a+a)%mod; b>>=1;}return res;}
template <class T> istream &operator>>(istream &os, vector<T> &container){for (auto &u : container)os >> u;return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &container){for (auto &u : container)os << u << " ";return os;}
template<typename T> inline T gcd(T a, T b) { while (b)swap(a %= b, b); return a; }
  
const ll INF = 1e9 + 7;
const ll mod = 998244353;
const ll N = 1e6+7;
const ll T = 1<<20;
const ll BIG_INF = 1e18 + 7;

ll n, m, k, q;
	
ld dp[3001][3001];

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

    cin >> n;

    dp[0][0] = 1.0;

    for(int i = 1; i <= n; i++){
    	ld p;
    	cin >> p;

    	for(int j = 0; j <= n; j++){
    		dp[i][j] += dp[i-1][j] * (1.0- p);
    		if(j)
    			dp[i][j] += dp[i-1][j-1] * p;
    	}
    }

    ld suma = 0;
    for(int i = n / 2 + 1; i <= n; i++)
    	suma += dp[n][i];
    cout << setprecision(10) << fixed << suma << '\n';
}

Measured memory_bytes: 140928
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>


#define fs first
#define sc second

using namespace std;


typedef long long ll;
typedef pair<ll, ll> P;


int a[1010][1010];
queue<int> q;
int index[1100];

int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N-1; j++) {
            cin >> a[i][j];
            a[i][j]--;
        }
        q.push(i);
    }

    fill(index, index+1100, 0);

    int num = 0;
    int res = 0;
    bool st_change[1100];
    fill(st_change, st_change+1100, false);

    while(num < N * (N-1) / 2){
        int q_size = q.size();
        bool change = false;
        for(int k = 0; k < q_size; k++){
            int i = q.front();
            q.pop();
            if(index[i] >= N-1){
                continue;
            }

            int op = a[i][index[i]];

            if(st_change[i] || st_change[op]){
                continue;
            }
            if(a[op][index[op]] == i){
                index[i]++;
                index[op]++;
                st_change[i] = true;
                st_change[op] = true;
                num++;
                q.push(i);
                q.push(op);
                change = true;
            }
        }

        int q_size2 = q.size();
        for(int k = 0; k < q_size2; k++){
            int i = q.front();
            q.pop();
            st_change[i] = false;
            q.push(i);
        }

        res++;
        if(!change){
            res = -1;
            break;
        }
    }

    cout << res << endl;


    return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    string s;
    cin >> s;
    int sum = 0;
    rep(i, s.size()) {
        sum += (s[i]-'0');
    }
    int n = stoi(s);
    string ans = "No";
    if (n%sum==0) ans = "Yes";

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N;
  cin >> N;
  vi p(N);
  rep(i,N) {
    cin >> p[i];
    p[i]--;
  }
  vi id(N);
  rep(i,N) {
    id[p[i]]=i;
  }
  vi a(N),b(N);
  int geta = 40000;
  rep(i,N) {
    a[i]=geta*(i+1);
    b[i]=geta*(N-i)+id[i];
  }
  rep(i,N) {
    cout << a[i] << " ";
  }
  cout << endl;
  rep(i,N) {
    cout << b[i] << " ";
  }
  cout << endl;
  return 0;
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int N;
    Scd(N);

    vector<int> d(N);

    Rep(i,N){
        Scd(d[i]);
    }
    sort(d.begin(), d.end() );

    printf ("%d\n", d[N/2] - d[N/2-1]);

    return 0;
}



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

int main(){
  int N;
  cin >> N;
  if(N==1){
    cout << "Hello World";
  }
  else if(N==2){
    int A, B;
    cin >> A >> B;
    cout << A+B;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
constexpr int gcd(int a,int b){return b?gcd(b,a%b):a;}
constexpr int lcm(int a,int b){return a*b/gcd(a,b);}

int main(){
	int n;
	vi dp(1000001,0);
	vi dp2(1000001,0);
	iota(all(dp),0);
	iota(all(dp2),0);
	for(int i=2;(i*(i+1)*(i+2)/6)<=1000000;i++){
	    int seisimentai=(i*(i+1)*(i+2)/6);
	    for(int j=0;j+seisimentai<=1000000;j++){
	        dp[j+seisimentai]=min(dp[j+seisimentai], dp[j]+1);
	    }
	    if(seisimentai%2==0)continue;
	    for(int j=0;j+seisimentai<=1000000;j++){
	        dp2[j+seisimentai]=min(dp2[j+seisimentai], dp2[j]+1);
	    }
	}
	
	
	while(cin>>n,n){
        cout<<dp[n]<<" "<<dp2[n]<<endl;
	}
	return 0;
}

Measured memory_bytes: 10544
#include<bits//stdc++.h>
using namespace std;
typedef long long ll;
typedef long long ld;
ll a[100001];
int main() {
	ll n,b,c,k;
	cin>>n>>k;
	for(ll i=0;i<n;i++){
		cin>>b>>c;
		a[b]+=c;
	}
	for(ll i=0;i<=100000;i++){
		k-=a[i];
		if(k<=0){
			cout<<i<<endl;
			break;
		}
	}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <cstring>
#define ll long long
const int mod = 1e9 + 7;
const int MAXN = 2e5+5;
const int INF = 0x3f3f3f3f;
using namespace std;
int a[MAXN],b[MAXN];
ll sum_a[MAXN],sum_b[MAXN];
int main()
{
    int n,m,k;
    cin>>n>>m>>k;
    for(int i = 1;i<=n;i++) cin>>a[i],sum_a[i] = sum_a[i-1] + a[i];
    for(int i = 1;i<=m;i++) cin>>b[i],sum_b[i] = sum_b[i-1] + b[i];
    
    int ans = 0;
    
    for(int i = 0,j = m;i<=n;i++) {
        if(sum_a[i] > k) break;
        while(sum_b[j] + sum_a[i] > k ) j--;
        ans = max(ans,i+j);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define endl 		"\n"
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define trace(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1) {std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " : " << arg1;
	ZZ(comma, args...);
}

void solve() {
	int x, n;
	cin >> x >> n;
	vi a(n);
	unordered_map<int, int> m;
	rep(i, 0, n) {
		cin >> a[i];
		m[a[i]]++;
	}
	int ans = 10000, num = 0;
	rep(i, -500, 500) {
		if (m[i]) {
			continue;
		}
		// trace(i)
		int dist = abs(x - i);
		if (dist < ans) {
			ans = dist;
			num = i;
		}
	}
	cout << num;
}
int main() {
	fast_io;
	int t = 1;
	// cin>>t;
	while (t--) {
		solve();
	}
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 3712
import os
import sys
from collections import defaultdict

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N, K = list(map(int, sys.stdin.buffer.readline().split()))
A = list(map(int, sys.stdin.buffer.readline().split()))

if K == 1:
    print(0)
    exit()
if K == 2:
    ans = sum([1 for a in A if a % 2 == 1], 0)
    # ans = (A % 2 == 1).sum()
    print(ans)
    exit()


def test():
    ans = 0
    for i, a in enumerate(A):
        if a % K == 1:
            ans += 1
        j = 1
        while i - j >= 0 and j + 1 < K:
            if (sum(A[i - j: i]) + a) % K == j + 1:
                ans += 1
            j += 1
    print(ans)


# 和-長さ を覚える
counts = defaultdict(int)
hist = [-1] * N
offset = 0
ans = 0
for i, a in enumerate(A):
    a %= K
    if a == 1:
        ans += 1
    ans += counts[(K - a + 1 - offset) % K]
    offset += a - 1
    offset %= K
    counts[(a - 1 - offset) % K] += 1

    if i - K + 2 >= 0:
        counts[hist[i - K + 2]] -= 1
    hist[i] = (a - 1 - offset) % K
print(ans)


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

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

    const std::string NS = std::to_string(N);

    int Sn = 0;
    for (size_t i = 0; i < NS.size(); ++i) {
        Sn += NS[i] - '0';
    }

    if (N % Sn == 0) {
        std::cout << "Yes\n";
    } else {
        std::cout << "No\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

s64 gcd(s64 x, s64 y)
{
    if (y == 0) return x;
    return gcd(y, x % y);
}

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

    s64 k;
    cin >> k;

    s64 ans = 0;
    for (s64 a = 1; a <= k; ++a)
    {
        for (s64 b = a + 1; b <= k; ++b)
        {
            for (s64 c = b + 1; c <= k; ++c)
            {
                ans += gcd(a, gcd(b, c));
            }
        }
    }
    ans *= 6;
    s64 temp = 0;
    for (s64 a = 1; a <= k; ++a)
    {
        for (s64 b = 1; b <= k; ++b)
        {
            if (a == b) continue;
            temp += gcd(a, b);
        }
    }
    ans += temp * 3;
    for (s64 a = 1; a <= k; ++a)
    {
        ans += a;
    }

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



Measured memory_bytes: 3652
#include <iostream>
#include <string>

using namespace std;

int getCode(char c) {
    switch (c)
    {
        case 'R':
            return 0;
        case 'G':
            return 1;
        case 'B':
            return 2;
        default:
            return 0;
    }
}

int main() {
    int N;
    string S;

    cin >> N >> S;

    long long counter[3] = {0, 0, 0};
    for(int i = 0; i < N; i++) {
        counter[getCode(S[i])]++;
    }

    if(N <= 3) {
        cout << 0 << endl;
        return 0;
    }

    long long ans = 0;

    for(int i = 1; i <= N / 2; i++) {
        int s_1 = 0;
        int s_2 = s_1 + i;
        int s_3 = s_2 + i;
        while(s_3 < N) {
            if(S[s_1] != S[s_2] && S[s_2] != S[s_3] && S[s_1] != S[s_3]) {
                ans++;
            }
            s_1++;
            s_2++;
            s_3++;
        }
    }

    cout << counter[0] * counter[1] * counter[2] - ans << endl;

    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

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

    for(int i=1;;i++){
        string t=s.substr(0,s.size()-i);
        if(t.size()&1)continue;
        if(t.substr(0,t.size()/2)==t.substr(t.size()/2,t.size()/2)){
            cout<<s.size()-i<<endl;
            return 0;
        }
    }
    return 0;
}


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

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
using ll = long long;
using pi = pair<int, int>;
const int INF = 0x3f3f3f3f;
const ll LINF = 1ll * INF * INF;

int main() {
	ll N; cin >> N;
	ll ans = (N / (6 + 5)) * 2;
	int rest = N % (6 + 5);
	if(rest == 0) ans += 0;
	else if(rest <= 6) ans += 1;
	else if(rest <= 6 + 5) ans += 2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <sstream>
#include <algorithm>
#include <bitset>
#include <limits>
#include <map>
#include <set>
#include <iomanip>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef std::numeric_limits<double> dbl;
const long long int LL_INF=1LL<<60;

vector<string> split(const string& input, char delimiter)
{
    stringstream stream(input);
    
    string field;
    vector<string> result;
    while (getline(stream, field, delimiter)) {
        result.push_back(field);
    }
    return result;
}

//#define DEBUG

ll A, B, M, N, D, K, Q, W, H, T, X, Y;

int main()
{
    cin >> X >> A >> B;

    if (abs(X-A) < abs(X-B))
    cout << "A" << endl; else cout << "B" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
   int a,b,c;
   
   scanf("%d %d %d", &a, &b, &c);
   
   if (a<b){
       if (b<c){
           printf ("Yes\n");
       }
       else{
           printf("No\n");
       }
   }
   else{
       printf("No\n");
   }
    return 0;
}



Measured memory_bytes: 2104
n = input()
R = []
for i in range(0, n):
   R.append(int(raw_input()))

maxv = R[1] - R[0]
minv = R[0]

for v in range(1, n):
   if minv > R[v]:
      minv = R[v]
   elif maxv < R[v] - minv:
      maxv = R[v] - minv
print maxv   

Measured memory_bytes: 18860
#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 long long mod = 1e9 + 7;

int main(){

  int r,g;cin>>r>>g;

  out(2*g-r);

  return 0;
}


Measured memory_bytes: 256
n=input().split()
n=[int(i) for i in n]
h=[0]*n[0]
for i in range(n[0]):
    h[i]=int(input())
h.sort()
q=-1
for i in range(0,len(h)-n[1]+1):
    a=h[i+n[1]-1]-h[i]
    if q==-1 or q>a:
        q=a
print(q)

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

int s1[100001], s2[100001];
int main() {
	string s, t; int q; cin >> s >> t >> q;
	rep(i, s.size()) {
		if (s[i] == 'A')s1[i + 1] = s1[i] + 1;
		else s1[i + 1] = s1[i] + 2;
	}
	rep(i, t.size()) {
		if (t[i] == 'A')s2[i + 1] = s2[i] + 1;
		else s2[i + 1] = s2[i] + 2;
	}
	rep(i, q) {
		int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d);
		puts((s1[b] - s1[a - 1]) % 3 == (s2[d] - s2[c - 1]) % 3 ? "YES" : "NO");
	}
}

Measured memory_bytes: 1664
/*
 * ARC080_c.cpp
 *
 *  Created on: Jun 5, 2018
 *      Author: 13743
 */
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;

#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end()
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}


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

	int N;
	cin >> N;
	int b0=0, b4=0;
	REP(i, N) {
		int a;
		cin >> a;
		if(a%4 == 0)b4++;
		if(a&2 != 0) b0++;
	}
	if(b4 >= b0) {
		cout << "Yes" << endl;
	}
	else if(b4 == b0-1 && b0+b4==N){
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}






Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int turnNum = sc.nextInt();
        int tPoint = 0;
        int hPoint = 0;

        for(int i = 0; i < turnNum; i++) {
        	String tStr = sc.next();
        	String hStr = sc.next();

        	int check = tStr.compareTo(hStr);
        	if(check < 0) {
        		hPoint += 3;
        	} else if(check == 0) {
        		tPoint += 1;
        		hPoint += 1;
        	} else if(check > 0) {
        		tPoint += 3;
        	}

        }

        System.out.println(tPoint + " " + hPoint);

    }
}


Measured memory_bytes: 29400
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(),x.end()
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
const int mod = 1e9+7;
const int INF = 2e9;
// const ll INF = 1e12;
const int MAX = 1e6;
// const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

struct edge {int to, cost;}; // 辺
vector<edge> graph[MAX]; // 隣接リスト
bool visited[MAX]; // 訪問状況
ll dist[MAX];

void bfs(int start) {
    queue<int> q;
    q.push(start);
    visited[start] = true;
    dist[start] = 0;
    while (not q.empty()) {
        int cur = q.front();
        q.pop();
        for (edge e : graph[cur]) {
            if (visited[e.to]) continue;
            q.push(e.to);
            dist[e.to] = dist[cur] + e.cost;
            visited[e.to] = true;
        }
    }
}

int main() {
    // input
    int n;
    cin >> n;
    rep(i, n-1) {
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        graph[u].push_back({v, w});
        graph[v].push_back({u, w});
    }
    // solve
    bfs(0);
    // output
    rep(i, n) {
        if (dist[i] % 2 == 0) printf("%d\n", 1);
        else printf("%d\n", 0);
    }
}

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

int comp_str(const string& lhs, const string& rhs) {
	const int max = lhs.size();
	int count = 0;
	for (int i = 0; i < max; i++) {
		if (lhs[i] != rhs[max - i - 1]) {
			count++;
		}
	}
	return count;
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	// int in[3] = {};
	string in;
	cin >> in;
	int count = 0;
	const int comp_size = in.size() / 2;
	if (in.size() % 2 == 0) { // 偶数
		count = comp_str(in.substr(0, comp_size), in.substr(comp_size, comp_size));
	} else {
		count = comp_str(in.substr(0, comp_size), in.substr(comp_size + 1, comp_size));
	}
	cout << count << endl;
	
	return 0;
}

Measured memory_bytes: 888
#ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#define DLOG_V(var)\
  cout << "#" << __LINE__ << ":" << #var << " : " << var << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#define DLOG_V(var)
#endif
using namespace std;

template <typename Iter, typename Cmp>
Iter partition(Iter begin, Iter end, Iter pivot, Cmp cmp) {
  if (distance(pivot, end) != 1) {
    iter_swap(end -1, pivot);
    pivot = end - 1;
  }
  auto x = end;
  for (auto it = begin; it != end; ++it) {
    if (it != pivot && cmp(*it, *pivot)) {
      x = (x == end) ? begin : x + 1;
      if (x != it) {
        iter_swap(x, it);
      }
    }
  }
  x = (x == end) ? begin : x + 1;
  iter_swap(x, pivot);
  return x;
}

template <typename Iter, typename Cmp>
void quickSort(Iter begin, Iter end, Cmp cmp) {
  auto p = partition(begin, end, end - 1, cmp);
  if (p != begin) {
    quickSort(begin, p, cmp);
    quickSort(p, end, cmp);
  }
}

struct Card {
  char kind;
  int value;
  size_t orig_index;
};

bool isStable(vector<Card>& before, vector<Card>& after) {
  int val = numeric_limits<int>::max();
  auto start = after.begin();
  for (auto it = next(after.begin()); it != after.end(); ++it) {
    auto p = prev(it);
    if (it->value == p->value && it->orig_index < p->orig_index) {
      return false;
    }
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  vector<Card> cards;
  auto cmp = [](const Card& c1, const Card& c2) {
    return c1.value <= c2.value;
  };
  for (int i = 0; i < n ; ++i) {
    Card c;
    cin >> c.kind >> c.value;
    c.orig_index = i;
    cards.push_back(move(c));
  }
  auto orig = cards;
  quickSort(cards.begin(), cards.end(), cmp);
  auto is_stable = isStable(orig, cards);
  cout << (is_stable ? "Stable" : "Not stable") << endl;
  for (auto it = cards.begin(); it != cards.end(); ++it) {
    cout << it->kind << " " << it->value << endl;
  }
}

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


Measured memory_bytes: 3200
N, A, B, C = map(int, input().split())
abc = [C, B, A]

l = [0] * N
for i in range(N):
    l[i] = int(input())

import numpy
mpp = 10**10
L = [0] * 3
t = [-10] * 3

for i in range(1, 4**N):
    b = numpy.base_repr(i, 4, N)[-N:]
    L = [A, B, C]
    t = [-10] * 3
    if "1" not in b or "2" not in b or "3" not in b:
        continue
    #print(b)
    for j in range(N):
        for k in range(3):
            if b[j] == str(k + 1):
                L[k] -= l[j]
                t[k] += 10
    mpp = min(mpp, sum(t) + sum([abs(x) for x in L]))

print(mpp)



Measured memory_bytes: 27104
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){

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

	sort(m,m+n);

	int sum=0;
	for(int i = 0; i < n; i++){
		if(i == n-1){
			sum += m[i]/2;
		}else{
			sum += m[i];
		}
	}

	cout << sum << endl;

	return 0;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	private static void p(String s) {System.out.println(s);}
	static Scanner sc = new Scanner(System.in);
	static int a,b,c,n,m;
	//<--main------------------------------------------------>
	public static void main(String[] args) {
		n=sc.nextInt();
		int h[]=new int[n];
		for(int i=0;i<n;i++)h[i]=sc.nextInt();
		int ans=0;

		for(int i=0;i<n;i++) {
			boolean flag=true;
			for(int j=0;j<i;j++) {
				if (h[i]<h[j])flag=false;
			}
			if(flag==true)ans++;
		}
		p(""+ans);

	}

}


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

int main() {
	long long N, X, Y;
	vector<long long> P, Q;
	cin >> N;
	P.resize(N), Q.resize(N);
	for (int i = 0; i < N; i++) cin >> P[i];
	for (int i = 0; i < N; i++) cin >> Q[i];
	vector<long long> V(N);
	for (int i = 0; i < N; i++) V[i] = i + 1;
	long long COUNT = 0;
	do {
		bool check1 = true, check2 = true;
		for (int i = 0; i < N; i++) {
			if (P[i] != V[i]) check1 = false;
			if (Q[i] != V[i]) check2 = false;
		}
		if (check1) X = COUNT;
		if (check2) Y = COUNT;
		COUNT++;
	} while (next_permutation(V.begin(), V.end()));
	cout << abs(X - Y) << endl;
}

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

int main(void){
	string S;
	cin >> S;
	string T ="";
	//Sを後ろから見ていく
	int Ssize = S.size();
	for(int i=Ssize-1;i>=0;i--){
		T+=S[i];
		if(T=="maerd" || T=="remaerd" || T=="esare" || T=="resare"){
			T="";
		}
	}
	if(T=="")cout <<"YES";
	else cout <<"NO";
	return 0;
}

Measured memory_bytes: 512
#include<cmath>
#include<iostream>
#include<algorithm>
#include <string>
#include <stdexcept>
using namespace std; 
int main(){
 long long int a,b,c=0,d,e; 
 	cin >>a;
b=log10(a);
  e=a;
  for(int i=b;i>=0;i--){
 d=e/pow(10,i);
    e=e-d*pow(10,i);
    c+=d;
  }
  if(a%c==0) cout << "Yes";
  else cout <<"No";
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=1e5+50;
const int mod=1e9+7;
using namespace std;
int n,m,i,v,u,x,y,t,p,j,b;
ll a[205][205],f[2][205][205];
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n>>m;
	for(i=1;i<=n;i++)for(j=1;j<=m;j++)cin>>a[i][j];
	for(i=1;i<=n+m-1;i++)
	{
		memset(f[i&1],0,sizeof(f[i&1]));
		for(x=1;x<=n;x++)
		{
			for(y=1;y<=n;y++)
			{
				v=i-x+1,u=i-y+1;
				if(v<=0 || u<=0)continue;
				for(t=-1;t<1;t++)
				{
					for(p=-1;p<1;p++)
					{
						f[i&1][x][y]=max(f[i&1][x][y],f[i&1^1][x+t][y+p]);
					}
				}
				f[i&1][x][y]+=a[x][v]+a[y][u];
				if(x==y && v==u)f[i&1][x][y]-=a[x][v];
			}
		}
	}
	cout<<f[(n+m-1)&1][n][n]<<endl;
    return 0;
}

Measured memory_bytes: 1280
n,a,b = gets.chomp.split(' ').map(&:to_i)
s = gets.chomp.split('')
dome = true
fore = true
a_count = 0
b_count = 0
s.each do |c|
  case c 
  when "a"
    if dome == true
      puts "Yes"
      a_count += 1
    else
      puts "No"
    end
  when "b"
    if fore == true
      puts "Yes"
      b_count += 1
    else
      puts "No"
    end
  else c == "c"
    puts "No"
  end
  #以下、通過者情報を更新
  if a_count + b_count >= a + b
    dome = false
  end
  if a_count + b_count >= a + b || b_count >= b
    fore = false
  end
end

Measured memory_bytes: 22696
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import copy


class Card:
  def __init__(self, suit, value):
    self.suit = suit
    self.value = value


def isStable(C1, C2, N):
  for i in range(N):
    if (C1[i].suit != C2[i].suit):
      return False
  return True


def printCard(C):
  out = [(c.suit + c.value) for c in C]
  print(' '.join(out))


def validate_num_input(C, N):
  if len(C) != N:
    print("[ERROR] Number of Card caracter is invalid")
    sys.exit()


def bubbleSort(C, N):
  for i in range(N):
    for j in range(N - 1, i, -1):
      if C[j].value < C[j - 1].value:
        C[j], C[j - 1] = C[j - 1], C[j]
  return C


def selectionSort(C, N):
  for i in range(N):
    minj = i
    for j in range(i, N):
      if C[j].value < C[minj].value:
        minj = j
    C[i], C[minj] = C[minj], C[i]
  return C


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

  validate_num_input(C, N)

  C1 = [Card(c[0], c[1]) for c in C]
  C2 = copy.deepcopy(C1)

  C1 = bubbleSort(C1, N)
  printCard(C1)
  print("Stable")

  C2 = selectionSort(C2, N)
  printCard(C2)
  if (isStable(C1, C2, N)):
    print("Stable")
  else:
    print("Not stable")


if __name__ == '__main__':
  main()



Measured memory_bytes: 6356
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int INF=2e9;
#define mp make_pair

vector <int> v;
int n;
int memo[100000];

int solve(int i)
{
 if(i==n-1) return 0;

 if(memo[i]!=-1) return memo[i];

 int ans=INF;
 ans=min(ans,solve(i+1)+abs(v[i+1]-v[i]));
 if(i!=n-2) ans=min(ans,solve(i+2)+abs(v[i+2]-v[i]));
 return memo[i]=ans;
}

int main()
{
 memset(memo,-1,sizeof(memo));
 cin>>n;
 for (int i=0;i<n;i++)
 {
     int x;cin>>x;
     v.pb(x);
 }
 
 cout << solve(0) << endl;
}

Measured memory_bytes: 7236
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
	ll n;
	cin >> n;
	vector<ll> a(10000001),isp;

	for(int i = 1;i<=10000000;i++)
	{
		for(int j = i;j<=10000000;j+=i)
		{
			a[j]++;
		}
	}
	ll ans = 0;
	for(int i = 1;i<=n;i++)
	{
		ans += i*a[i];
	}
	cout << ans << endl;

}


Measured memory_bytes: 81380
arr = list(map(int,input().split()))
arr.sort()

count = 0
while(True):
  if arr[1] < arr[2]:
    arr[1]+= 1
    arr[0]+=1
    count+=1
  else:
    break
    
while(True):
  if arr[0] < arr[2]:
    arr[0] +=2
    count+=1
  else:
    break
    
if arr[0] == arr[1] == arr[2]:
  print(count)
else:
  print(count+1)

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

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

	ll H=in(),W=in();
	if(!(H%3) || !(W%3)){
		out(0);
		return 0;
	}
	
	ll ans = 1LL<<60;
	ll S=H*W;

	ll x = round(S/(3.0*H));
	ll SS = H*(W-x);
	ll sx = round(SS/(2.0*H));
	ans = min(ans,max({H*x,H*sx,H*(W-x-sx)})-min({H*x,H*sx,H*(W-x-sx)}));
	ll sy = round(SS/(2.0*(W-x)));
	ans = min(ans,max({H*x,sy*(W-x),(H-sy)*(W-x)})-min({H*x,sy*(W-x),(H-sy)*(W-x)}));

	swap(H,W);
	x = round(S/(3.0*H));
	SS = H*(W-x);
	sx = round(SS/(2.0*H));
	ans = min(ans,max({H*x,H*sx,H*(W-x-sx)})-min({H*x,H*sx,H*(W-x-sx)}));
	sy = round(SS/(2.0*(W-x)));
	ans = min(ans,max({H*x,sy*(W-x),(H-sy)*(W-x)})-min({H*x,sy*(W-x),(H-sy)*(W-x)}));

	out(ans);
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 100000000;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 200010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    vector<ll> a(2*n),b(n),c(n);
    rep(i,n){
        cin >> a[i];
        c[i] = b[i] = a[i];
    }
    SORT(b);
    b.erase(unique(all(b)),b.end());
    unordered_map<ll,ll> v;
    rep(i,(int)b.size()){
        v[b[i]] = i;
    }
    rep(i,n){
        a[n+i] = a[i] = v[a[i]];
    }
    vector<vector<ll>> index(n);
    rep(i,2*n){
        index[a[i]].push_back(i);
    }
    ll cnt = 0,now = 0;
    vector<ll> order(200010);
    for(;;){
        //PRINT(now);
        order[cnt+1] = now;
        ll m = index[a[now]].size();
        ll i = lower_bound(all(index[a[now]]),now)-index[a[now]].begin();
        i = index[a[now]][(i+1)%m]%n;
        if (i <= now) cnt++;
        if (i == n-1){
            cnt++;
            break;
        }
        now = i+1;
    }
    k %= cnt;
    vector<ll> ans;
    order[0] = n;
    rep(i,order[k],n) ans.push_back(c[i]);
    b.clear();
    //array_output(all(ans));
    ll i = order[k];
    now = order[k];
    while(i < n){
        ll s = *upper_bound(all(index[a[i]]),i);
        if (s < n){
            rep(l,now-order[k],i-order[k]){
                b.push_back(ans[l]);
            }
            i = s+1;
            now = s+1;
        }
        else i++;
    }
    rep(j,now,n) b.push_back(ans[j-order[k]]);
    array_output(all(b));
}


Measured memory_bytes: 31940
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TypeFamilies #-}
import           Data.Maybe
import           Data.Int
import           Data.List
import           Data.Char
  -- import qualified Data.Vector.Unboxing as VU
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as BS
import           Data.List (scanl')
import           Data.IORef
import           Control.Monad
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Control.Applicative
import           Debug.Trace


readInt = BS.readInt . BS.dropWhile isSpace
getVector f = VU.unfoldr f <$> BS.getLine
getIntVector = getVector readInt
getBSVector = getVector BS.uncons

main = do
  n <- readLn
  ss <- replicateM n $ sort <$> getLine
  print . sum . map (comb' . (\n -> length n)) . group . sort $ ss

comb x y = (loop1 x y 1) `div` (loop2 y 1)
  where
    loop1 _ 0 n' = n'
    loop1 n r n' = loop1 (n-1) (r-1) (n*n')
    loop2 0 n' = n'
    loop2 n n' = loop2 (n-1) (n*n')

comb' x = comb x 2


Measured memory_bytes: 114044
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){ return (int)s.size(); }

int main(){
    int n; cin >> n;
    string s; cin >> s;
    if(n % 2 == 1) no();
    else {
        int k = SIZE(s)/2;
        if(s.substr(0,k) == s.substr(k,k)) yes();
        else no();
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;
int main(int argc, char const *argv[]) {
  int N;
  cin >> N;
  vector<int> T(N), A(N);
  for (size_t i = 0; i < N; i++) {
    cin >> T[i];
  }
  for (size_t i = 0; i < N; i++) {
    cin >> A[i];
  }
  long int M = 1E9 + 7;
  vector<pair<int, int>> t(N), a(N);
  t[0] = pair<int, int>(T[0], T[0]);
  a[N-1] = pair<int, int>(A[N-1], A[N-1]);
  for (int i = 1; i < N; i++) {
    if (T[i-1] < T[i]) t[i] = pair<int, int>(T[i], T[i]);
    else t[i] = pair<int, int>(1, T[i-1]);
    if (A[N-i] < A[N-i-1]) a[N-i-1] = pair<int, int>(A[N-i-1], A[N-i-1]);
    else a[N-i-1] = pair<int, int>(1, A[N-i-1]);
  }

  long int ans = 1;
  int b;
  for (int i = 0; i < N; i++) {
    b = max(min(t[i].second, a[i].second) - max(t[i].first, a[i].first) + 1, 0) % M;
    ans *= b;
    ans %= M;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2688