akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            int pocketMoney = Integer.parseInt(br.readLine()) - Integer.parseInt(br.readLine());
            int donutsFee = Integer.parseInt(br.readLine());
            
            while (pocketMoney >= donutsFee){
                pocketMoney -= donutsFee;
            }

            System.out.println(pocketMoney);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 22484
#include<iostream>
#include<cmath>

using namespace std;
int main()
{
    int a,b;
    cin >> a >> b;
    int n;
    cin >> n;
    int cnt=0;
    int x,y;
    for(int i=0;i<n;i++){
        cin >> x >> y;
        if(y>a and b>x){
            cnt=1;
            break;
        }
    }
    cout << cnt << endl;
    return 0;
}



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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

vector< bool > prime_table(int n) {
    vector< bool > prime(n + 1, true);
    if(n >= 0) prime[0] = false;
    if(n >= 1) prime[1] = false;
    for(int i = 2; i * i <= n; i++) {
        if(!prime[i]) continue;
        for(int j = i + i; j <= n; j += i) {
            prime[j] = false;
        }
    }
    return prime;
}


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

    ll Q;
    cin>>Q;
    vector<bool> pt = prime_table(1e5+10);
    vector<ll> vok(1e5+10,0);
    REP(i,1,1e5+5){
        vok[i] = vok[i-1];
        if(i%2==0)continue;
        if(pt[i]&&pt[(i+1)/2]){
            vok[i]++;
        }
    }
   // dbg(vok);
    while(Q--){
        ll l,r;
        cin>>l>>r;
        cout<<vok[r]-vok[l-1]<<endl;
    }
    return  0;
}


Measured memory_bytes: 1408
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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



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

  ll N; cin>>N;
  vector<ll> a(N); rep(i,N) cin>>a[i];
  int judge=0;
  rep(i,N) if(a[i]%2!=0) judge=1;
  
  if(judge) cout<<"first"<<endl;
  else cout<<"second"<<endl;
  return 0;
}

Measured memory_bytes: 4000
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h.at(i);
    }
    int ans = 0;
    int count = 0;
    for (int i = 0; i < n; i++) {
        count = 0;
        for (int j = i + 1; j < n; j++) {
            if (h.at(j - 1) >= h.at(j)) {
                count++;
            }
            else goto next;
        }
        next:
        ans = max(ans, count);
        i += count;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }



int main() {
    ll a, b, c, k; cin >> a >> b >> c >> k;
    ll res = -1;
    if(k < a) res = k;
    else if(k <= a+b) res = a;
    else res = a - (k-(a+b));
    cout << res << ln;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define pb(a) push_back(a)
#define pr(a) cout<<(a)<<endl
#define PR(a,b) cout<<(a)<<" "<<(b)<<endl
#define R cin>>
#define F first
#define S second
#define ll long long
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

string s[1001];
vector<int> v[1001];

void dfs(int i, int k) {
  rep(j,k) cout << ".";
  pr(s[i]);
  rep(j,v[i].size()) dfs(v[i][j],k+1);
}
int main() {
  int n;
  R n;
  REP(i,1,n+1) {
    int x;
    cin >> x >> s[i];
    v[x].pb(i);
  }
  dfs(1,0);
  return 0;
}


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

#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

struct Node {
	Node *l = 0, *r = 0;
	int val, y;
	int first, max;
	bool monotone;
	Node(int val) : val(val), y(rand()) {
		first = max = val;
		monotone = 1;
	}
	void reset() {
		first = max = val;
		monotone = 1;
	}
	void recalc();
	void recalc3();
};

inline void Node::recalc() {
	first = l ? l->first : val;
	int max = val;
	bool mon = 1;
	if (l) {
		max = std::max(max, l->max);
		if (!l->monotone || l->max > val) mon = 0;
	}
	if (r) {
		max = std::max(max, r->max);
		if (mon && (!r->monotone || r->first < val)) mon = 0;
	}
	this->max = max;
	monotone = mon;
}

inline void Node::recalc3() {
	first = l ? l->first : val;
	max = r ? r->max : val;
	monotone = 1;
}

Node* merge2(Node* l, Node* r) {
	if (l->y > r->y) {
		l->r = l->r ? merge2(l->r, r) : r;
		l->recalc();
		return l;
	} else {
		r->l = r->l ? merge2(l, r->l) : l;
		r->recalc();
		return r;
	}
}

inline Node* merge(Node* l, Node* r) {
	if (!l) return r;
	if (!r) return l;
	return merge2(l, r);
}

Node* merge32(Node* l, Node* r) {
	if (l->y > r->y) {
		l->r = l->r ? merge32(l->r, r) : r;
		l->recalc3();
		return l;
	} else {
		r->l = r->l ? merge32(l, r->l) : l;
		r->recalc3();
		return r;
	}
}

inline Node* merge3(Node* l, Node* r) {
	if (!l) return r;
	if (!r) return l;
	return merge32(l, r);
}

pair<Node*, Node*> split2(Node* n, int lo) {
	if (!n) return {0, 0};
	if (n->max < lo) return {0, n};
	if (n->monotone) {
		if (lo < n->first) return {n, 0};
		if (!n->l) {
			if (!n->r) return {0, n};
			assert(lo >= n->val);
			auto pa = split2(n->r, lo);
			n->r = 0;
			n->reset();
			pa.second = merge(n, pa.second);
			return pa;
		}

		if (lo < n->val) {
			auto pa = split2(n->l, lo);
			n->l = 0;
			n->recalc();
			pa.first = merge3(pa.first, n);
			return pa;
		}
		else {
			// if (!n->r) return {0, n};
			auto pa = split2(n->r, lo);
			n->r = 0;
			n->recalc();
			pa.second = merge(n, pa.second);
			return pa;
		}
	}

	Node *left = n->l, *right = n->r;
	n->l = n->r = 0;
	n->recalc();
	auto pa = split2(left, lo);
	if (pa.first) lo = pa.first->max;
	if (n->val > lo) {
		pa.first = merge3(pa.first, n);
		lo = n->val;
	}
	else {
		pa.second = merge(pa.second, n);
	}
	auto pa2 = split2(right, lo);
	return {merge3(pa.first, pa2.first), merge(pa.second, pa2.second)};
}

int main() {
	srand(2);
	cin.sync_with_stdio(false);
	cin.exceptions(cin.failbit);
	int N;
	cin >> N;
	vector<Node> nodes;
	rep(i,0,N) {
		int p;
		cin >> p;
		nodes.emplace_back(p);
	}

	Node* t = 0;
	rep(i,0,N)
		t = merge(t, &nodes[i]);

	int res = 0;
	while (!t->monotone) {
		++res;
		auto pa = split2(t, 0);
		t = merge(pa.second, pa.first);
	}

	cout << res << endl;
	exit(0);
}


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

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

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

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

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


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

    vector<ll> H(N);
    rep(i,N) cin >> H[i];

    ll smaller = INF_LL;

    for( int i = N-1; i >= 0; i-- )
    {
        chmin(smaller, H[i]);
        if( H[i] - smaller > 1 )
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Collections.Generic;


class Program
{
    static void Main(string[] args)
    {
        var p = new Program();
        var N = int.Parse(Console.ReadLine());
        var count = 0;

        for (var i = 1; i <= N; i++)
        {
            var digit = i.ToString().Length;
            if (digit == 1 || digit == 3 || digit == 5)
            {
                count++;
            }

        }
        Console.WriteLine(count);

    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i) sort((i).begin(),(i).end(), greater<int>());
#define YES(i) cout << ((i) ? "Yes" : "No") << endl;
#define INF = 1000000000;
#define LLINF = 1LL << 62;
#define mod = 1000000007;
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; }

int v[1001];
int main() {
    int a, b, n;
    cin >> a >> b >> n;
    int s, f;
    FOR(i, n){
        cin >> s >> f;
        v[s]++, v[f]--;
    }
    FOR(i, 1000)v[i + 1] += v[i];
    int ans = 0;
    for (int i = a; i < b; i++)if (v[i])ans = 1;
    cout << ans << endl;
}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){
    ll n, t;
    cin >> n >> t;

    pair<ll, ll> a[n];
    rep(i, 0, n){
        cin >> a[i].first >> a[i].second;
    }
    sort(a, a + n);

    ll dp[n + 1][t + 1];
    dp[0][0] = 0;
    ll sum = 0;

    rep(i, 0, t + 1){
        dp[0][i] = 0;
    }

    rep(i, 1, n + 1){
        rep(j, 0, t){
            if(j - a[i - 1].first < 0){
                dp[i][j] = dp[i - 1][j];
                sum = max(sum, dp[i][j] + a[i - 1].second);
            }else{
                sum = max(sum, dp[i - 1][j] + a[i - 1].second);
                if(dp[i - 1][j - a[i - 1].first] + a[i - 1].second <= dp[i - 1][j]){
                dp[i][j] = dp[i - 1][j];
                }else{
                dp[i][j] = dp[i - 1][j - a[i - 1].first] + a[i - 1].second;
                }
            }
        }
    }
    cout << sum << endl;

    return 0;
}


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

int main(void) {

	int a, b;
	cin >> a >> b;
	if(a < b) {
		cout << "a < b" << endl;
	} else if(a > b) {
		cout << "a > b" << endl;
	} else {
		cout << "a == b" << endl;
	}


	return 0;
}

Measured memory_bytes: 1156
# R*r + G*g + B*b == N の数
R, G, B, N = map(int, input().split())
R, G, B = list(sorted([R, G, B], reverse=True))
ans = 0
for r in range(N + 1):
    for g in range(N + 1):
        if (N - (r * R + g * G)) % B != 0:
            continue
        b = (N - (r * R + g * G))/B
        if b < 0:
            break
        if r * R + g * G + b * B == N:
            ans += 1
        elif r * R + g * G + b * B > N:
            break

print(ans)


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

template<typename T>
void fin (T a){
    cout<<a<<endl;
    exit(0);
}
template<typename S>
void print(S a){
    cout<<a<<endl;
}

int main(){
    int x,y;
    cin >>x>>y;
    if(y%2==0){
        int a = 2*x-y/2;
        if((a>=0)&&(a<=x)){
            fin("Yes");
        }else{
            fin("No");
        }
    }else{
        fin("No");
    }
}



Measured memory_bytes: 3636
n=int(input())
A=[]
cnt=0
add=0
for i in range(4472):
    cnt +=i+1
    A.append((cnt,i+1))
for i in range(len(A)-1):
    if A[i][0]<=n<=A[i+1][0]:
        add=(A[i+1][1],A[i+1][0]-n)
        break

for i in range(add[0]):
    if i+1==add[1]:
        continue
    print(i+1)

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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define fdiv(a, b) ((a) + (b) - 1) / (b)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

template<typename T>
struct fenwick_tree {
    int n;
    T zero;
    std::vector<T> data;
    fenwick_tree(int n, T zero = T()) : n(n), zero(zero), data(n + 1, zero) {}
    void add(int i, T x) { for (i++; i <= n; i += i & -i) { data[i] += x; }}
    T get_sum(int i) const {
        if (i > n) { i = n; }
        T ret = zero;
        for (; i > 0; i -= i & -i) { ret += data[i]; }
        return ret;
    }
    T get_sum(int l, int r) const {
        if (l < r) { return get_sum(r) - get_sum(l); }
        else { return zero; }
    }
};

int N, D, A;
int X[220000], H[220000];
pint XH[220000];
signed main() {
    cin >> N >> D >> A;
    rep(i, N) {
        cin >> X[i] >> H[i];
        XH[i] = {X[i], H[i]};
    }
    sort(XH, XH + N);
    fenwick_tree<int> ft(N);
    int ans = 0;
    rep(i, N) {
        int r = upper_bound(XH + i, XH + N, pint(XH[i].first + 2 * D, LLONG_MAX)) - XH;
        int t = max(fdiv(XH[i].second + ft.get_sum(i + 1), A), 0LL);
        ans += t;
        ft.add(i, -A * t);
        ft.add(r, A * t);
    }
    cout << ans << endl;
}

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

using namespace std;

long long int dp[21][100];
int k[100];
int n;

int main()
{
    cin >> n;
    for(int i=0;i<21;++i)
    {
        for(int j=0;j<100;++j)
        {
            dp[i][j] = 0;
        }
    }
    for(int i=0;i<n;++i)
    {
        cin >> k[i];
    }
    dp[k[0]][0] = 1;
    for(int i=1;i<n-1;++i)
    {
        for(int j=0;j<21;++j)
        {
            if(dp[j][i-1])
            {
                if(j-k[i] >= 0) dp[j-k[i]][i] += dp[j][i-1];
                if(j+k[i] <= 20) dp[j+k[i]][i] += dp[j][i-1];
            }
        }
    }
    cout << dp[k[n-1]][n-2] << endl;
}

Measured memory_bytes: 1172
#include <iostream>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <vector>

using namespace std;

const long long int MAX_N = 200000;

int main(int argc, char const *argv[]) {
  long long int n, a[MAX_N];
  vector<long long int> t;
  cin >> n;
  for (size_t i = 0; i < n; i++) {
    cin >> a[i];
    t.push_back(a[i]-(i+1));
  }
  sort(t.begin(),t.end());
  long long int b = 0;
  if (n%2==0) b=(t[n/2]+t[n/2-1])/2;
  else b = t[(n-1)/2];

  long long int ans = 0;
  for (long long int i = 0; i < n; i++) {
    if (a[i]-(b+i+1) > 0) ans += a[i]-(b+i+1);
    else ans -= a[i]-(b+i+1);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3444
#include<stdio.h>

int main(void)
{
  int N,K;
  int p[1000];
  int min[3];
  int sum = 0,temp;
  int i,j;

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

  for(i = 0; i < N;i++)
  {
    for(j = N-1;j > i;j--)
    {
      if(p[j] < p[j-1])
      {
        temp = p[j];
        p[j] = p[j-1];
        p[j-1] = temp;
      }
    }
  }

  for(i = 0;i < K;i++)
  {
    sum += p[i];
  }

  printf("%d",sum);

  
  return 0;
}

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

typedef pair< int , pair<int,int> > cube;

int main(){
	int n,h,a,b;
	string str;
	
	while( cin >> n >> h , n||h ){
		set<cube> s;
		cube t;
		
		for(int i= 0 ;i < h ; i++ ){
			cin >> str >> a >> b;
			for(int c=1 ; c <= n ; c++ ){
				if( str == "xy" ){
					t = make_pair( a , make_pair(b,c) );
				}else if( str == "xz" ){
					t = make_pair( a , make_pair(c,b) );
				}else if( str == "yz" ){
					t = make_pair( c , make_pair(a,b) );
				}
				s.insert(t);
			}
		}
		int ans = n*n*n - s.size();
		cout << ans << endl;
	}
}

Measured memory_bytes: 2332
#include<stdio.h>
int main(){
  int n,m,i,c,mi,d[10010];
  while(scanf("%d %d",&n,&m),n||m){
    for(i=c=mi=0;i<n;i++)scanf("%d",&d[i]);
    for(i=1;i<n;i++){
      if(m%d[mi]==m%d[i]){
	if(d[i]==d[mi])c++;
	if(d[i]<d[mi]){
	  mi=i;
	  c=0;
	}
      }
      if(m%d[mi]<m%d[i]){
	mi=i;
	c=0;
      }
    }
    printf("%d\n",c?n:mi+1);
  }
  return 0;
}
    

Measured memory_bytes: 608
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

import java.io.BufferedReader;
import java.io.FileReader;

public class Main{
	
	public static void main(String[] args) throws IOException, InterruptedException {
		
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		
		int n= sc.nextInt();
		
		int[] a = new int[n];
		
		for (int i = 0; i < a.length; i++) {
			a[i]= sc.nextInt(); 
		}
		boolean possibe = true;
		for (int i = 0; i < a.length-1; i++) {
			if (a[i] > a[i+1]) {
				a[i]--;
			}
			else {
				if (i > 0 && a[i-1] <= a[i]-1 && a[i] == a[i+1]) {
					a[i]--;
				}
			}
		}
		
		for (int i = 0; i < a.length-1; i++) {
			if (a[i] > a[i+1]) {
				possibe = false;
			}
		}
		
		if (possibe) {
			out.print("Yes");
		}
		else {
			out.print("No");
		}
		
		out.flush();
	}
		
}	
	
class Scanner {
	StringTokenizer st;
	BufferedReader br;

	public Scanner(InputStream system) {
		br = new BufferedReader(new InputStreamReader(system));
	}
	
	public Scanner (String file) throws IOException{
        br=new BufferedReader(new FileReader(file));
	}

	public String next() throws IOException {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

	public String nextLine() throws IOException {
		return br.readLine();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	public char nextChar() throws IOException {
		return next().charAt(0);
	}

	public Long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	public boolean ready() throws IOException {
		return br.ready();
	}

	public void waitForInput() throws InterruptedException {
		Thread.sleep(3000);
	}


}



Measured memory_bytes: 40092
#include<stdio.h>
#include <stdlib.h>
#include <string.h>
#define MOD 1000000007
int dp[101][6][6][6][6];//
int N;
//1=A,2=C,3=G,4=T


int cnt(int num,int a,int b,int c,int d){
	if(dp[num][a][b][c][d] != -1) return dp[num][a][b][c][d];
	if(a == 1&& c == 3&& d == 2)return 0;
	if(a == 1&& b == 3&& d == 2)return 0;
	if(b == 1&& c == 3&& d == 2)return 0;
	if(b == 1&& c == 2&& d == 3)return 0;
	if(b == 3&& c == 1&& d == 2)return 0;
	if(num == N) return 1;

	long ans = 0;
	for(int i = 1; i < 5; i++) ans += cnt(num+1,b,c,d,i);
	return dp[num][a][b][c][d]=ans%MOD;

}

int main(){
	if(scanf("%d",&N)==1){
		memset(dp,-1,sizeof(dp));
		printf("%d\n",cnt(0,5,5,5,5));
	}else{
		printf("ERROR\n");
	}

	return 0;
}


















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

using namespace std;

#define ll long long
constexpr ll inf = 1e9+7;

ll binarySearch(ll ng, ll ok, function<bool(ll)> isOK) {
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if (isOK(mid)) ok = mid;
        else ng = mid;
    }
    return ok;
}

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

    ll N, A, B;
    cin>>N>>A>>B;
    vector<ll> H(N);
    for (ll n = 0; n < N; n++) cin>>H[n];

    ll ans = binarySearch(0, inf, [&] (ll index) {
        ll count = 0;
        for (ll n = 0; n < N; n++) if (H[n] - B * index > 0) count += (ll)ceil((double)(H[n] - B * index) / (A - B));
        return index >= count;
    });

    cout<<ans<<endl;

    return 0;
}

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

#define F                   first
#define S                   second
#define int                 long long int
#define pb                  push_back
#define mp                  make_pair
#define pii                 pair<int,int>
#define vi                  vector<int>
#define mii                 map<int,int>
#define pqb                 priority_queue<int>
#define pqs                 priority_queue<int,vi,greater<int> >
#define mod                 1000000007
#define endl                '\n'
#define rep(i,a,b)            for(int i=a;i<b;i++)
void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
void solve() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ans = -1e18;
    ans = max(ans, max(a, b) * max(c, d));
    ans = max(ans, min(a, b) * min(c, d));
    ans = max(ans, min(a, b) * max(c, d));
    ans = max(ans, max(a, b) * min(c, d));

    cout << ans << endl;
}
int32_t main()
{
    c_p_c();
    solve();


    return 0;
}

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

int main() {

	int N, K;
	cin >> N >> K;
	vector<long> v_enemies(N);

	for (int i = 0; i < N; i++) {
		int H;
		cin >> H;
		v_enemies[i] = H;
	}
	sort(v_enemies.begin(), v_enemies.end());

	long ans = 0;
	for (int i = 0; i < N - K; i++) {
		ans += v_enemies[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int l, r;
  cin >> l >> r;
  if(r - l + 1 >= 2019){
    cout << 0 << endl;
    return 0;
  }

  ll ans = 2019;
  rep2(i, l, r+1){
    rep2(j, i+1, r+1){
      ll now = (ll)i * j;
      now %= 2019;
      // if(now == 1) cerr << i << " " << j << endl;
      ans = min(ans, now);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define p(s) cout<<(s)<<endl
#define REP(i,n,N) for(int i=n;i<N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const ll inf = 1e18;

int N;
int K;
ll a[100010];
ll nsum[100010];//only -
ll psum[100010];//only +
ll ans;
int main(){
    cin>>N>>K;
    REP(i,1,N+1) {
        cin>>a[i-1];
        nsum[i]= nsum[i-1] + min<ll>(0,a[i-1]);
        psum[i]= psum[i-1] + max<ll>(0,a[i-1]);
    }
    REP(i,0,N-K+1){
        ll kuro = psum[N] + (nsum[i+K] - nsum[i]) ;
        ll siro = psum[N] - (psum[i+K] - psum[i]) ;
        ans = max({ans,siro,kuro});
    }
    p(ans);
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>

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

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <functional>
using namespace std;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n, m, a[60], b[60], c[60], d[60];
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> c[i] >> d[i];
    }
    for (int i = 0; i < n; i++) {
        int point = 1, min = abs(a[i] - c[0]) + abs(b[i] - d[0]);
        for (int j = 1; j < m; j++) {
            if (abs(a[i] - c[j])+abs(b[i] - d[j]) < min) {
                min = abs(a[i] - c[j]) + abs(b[i] - d[j]);
                point = j+1;
            }
        }
        cout << point << endl;
    }
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int A,B,V,W,T;
int x;
int main(){
	scanf("%d%d%d%d%d",&A,&V,&B,&W,&T);
	x=(A-B);
	if(x<0)x=-x;
	if(1ll*T*(V-W)>=1ll*x)puts("YES");
	else puts("NO");
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

int main() {
  int a, b;
  cin >> a >> b;
  if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    for (int i=0; i<(((int)(v).size())); ++i) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}
template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}
template<class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;
/*
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    // ifstream in("in.txt");
    // cin.rdbuf(in.rdbuf());

    return 0;
}
*/
template<typename T>
struct edge {
    int src, to;
    T cost;
};
template<typename T>
using Graph = vector<vector<edge<T>>>;
/**
 * @brief
 * 全点対間最短経路(ワーシャルフロイド)
 * O(V^3)
 * @author ?
 * @date ?
 *
 * @param[in] g グラフ(隣接行列)
 * @param[in] inf 到達不可能を表す無限値
 * @param[out] g 最短距離(隣接行列)
 *
 * @details
 * 2020/05/04 コメント追加, inf に使う値を明示的に渡す. by habara-k
 */
template<typename T>
void warshall_floyd(vector<vector<T>> &g, T inf) {
    int n = g.size();
    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (g[i][k] == inf or g[k][j] == inf) continue;
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }
}
int main() {
    int V, E;
    cin >> V >> E;
    vector<vector<ll>> G(V, vector<ll>(V, LINF));
    for (int i = 0; i < V; ++i) G[i][i] = 0;
    for (int i = 0; i < E; ++i) {
        int x, y, z;
        cin >> x >> y >> z;
        G[x][y] = z;
    }
    warshall_floyd(G, LINF);
    for (int i = 0; i < V; ++i) {
        if (G[i][i] < 0) {
            puts("NEGATIVE CYCLE");
            return 0;
        }
    }
    for (int i = 0; i < V; ++i) {
        for (int j = 0; j < V; ++j) {
            if (j > 0) putchar(' ');
            if (G[i][j] == LINF) printf("INF");
            else printf("%d", G[i][j]);
        }
        putchar('\n');
    }
}


Measured memory_bytes: 3336
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin>> N;
    
    if (N==2||N==1){
        cout << 2 <<endl;
        return 0;
    }
    
    if (N%2==0){
        cout << N << endl;
    }else{
        cout << N*2 <<endl;
    }
}


Measured memory_bytes: 256
n=int(input())
w=input().split()
w=[int(i) for i in w]
key=10000
for i in range(n-1):
    tmp=i
    s1=w[:i+1]
    s2=w[i+1:]
    if abs(sum(s1)-sum(s2))<key:
        key=abs(sum(s1)-sum(s2))
    
print(key)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<string>
#include<math.h>
#include<vector>
using namespace std;
typedef long long ll;
int main()
{
	double a,b,i,c,d;
	cin >> a >> b;
	
	double H;
	H=1;
	while(1){
		d=floor(H/10);
		c=floor(H*2/25);
	if(c==a&&d==b) {
		cout<<H<<endl;
		return 0;;
	}
		if(c>100){
			break;
		}
		H++;
	}
		cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include"vector"
#include"cmath"
#include"iostream"
#include"list"
#include"stack"
#include "queue"
#include"set"
#include "unordered_set"
#include "map"
#include"unordered_map"
#include"algorithm"
#include "cstring"
#include"string"
using namespace std;
#define all(v) v.begin(),v.end()
#define forn(n) for(auto i=n;i<n;++i)
typedef long long ll;
typedef long double ld;
string x;int n;
bool solv(int m)
{
    multiset<char>my;
    for(char ch='a';ch<='z';++ch)
    {
        my.clear();
        bool a=true;
        for(int i=0;i<m;++i)
        {
            my.insert(x[i]);
        }
        for(int i=m;i<n;++i)
        {
            if(my.find(ch)==my.end())
            {
                a=false;break;
            }
            my.erase(my.find(x[i-m]));
            my.insert(x[i]);
        }
        if(my.find(ch)==my.end())
        {
            a=false;
        }
        if(a)return true;
    }
    return false;
}
class TaskA {
public:
	void solve(std::istream& cin, std::ostream& cout) {
		ios_base::sync_with_stdio(false);
        cin>>x;
        n=x.length();
        int l=0,h=n,m;
        while(l<h-1)
        {
            m=(l+h)/2;
            if(solv(m))
            {
                h=m;
            }
            else
            {
                l=m;
            }
        }
        cout<<h-1<<'\n';
	}
};


int main() {
	TaskA solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n,C;
    cin>>n>>C;
    vector<pair<int,int>> v[C];
    for(int i=0;i<n;i++){
        int s,t,c;
        cin>>s>>t>>c;
        v[c-1].push_back({s,t});
    }
    int cnt[100002]={};
    for(int i=0;i<C;i++){
        sort(v[i].begin(),v[i].end());
        for(int j=0;j<v[i].size();j++){
            int l=v[i][j].first;
            while(j+1<v[i].size()&&v[i][j].second==v[i][j+1].first)j++;
            int r=v[i][j].second;
            cnt[l-1]++,cnt[r]--;
        }
    }
    int ans=cnt[0];
    for(int i=1;i<=100000;i++){
        cnt[i]+=cnt[i-1];
        ans=max(ans,cnt[i]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1920
import collections

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


def main(n: int, a: list):
    counter = collections.Counter(a)
    pairs = {k: v * (v - 1) / 2 for k, v in counter.items()}
    pairs_all = sum(pairs.values())

    for i in range(N):
        k = a[i]
        v = counter[k] - 1
        pair_cnt = pairs_all - pairs[k] + (v * (v - 1) / 2)

        print(int(pair_cnt))


main(N, A)


Measured memory_bytes: 33948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}
const int MOD = 1000000007;


int main() {
    int n,m;
    cin >> n >> m;
    int a[n];
    for(int i =0;i < n;i++){
        a[i] = 0;
    }
    for(int i = 0;i < m;i++){
        int x,y;
        cin >> x >> y;
        a[x-1]++;
        a[y-1]++;
    }
    for(int i = 0;i < n;i++){
        cout << a[i] << endl;;
    }
}




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

int main() {

    int K;
    int i[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    cin >> K;
    cout << i[K-1];
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
string s;
int X,Y;
int x[8000],y[8000],cx,cy;
bool f(int a[],int n,int u)
{
	bool dp[2][17500]={};
	int p=8500;int w=0;
	dp[w][p]=1;int f=p,l=p;
	for(int i=0;i<n;i++)
	{
		for(int j=f;j<=l;j++)
		{
			dp[1-w][j-a[i]]|=dp[w][j];
			dp[1-w][j+a[i]]|=dp[w][j];
			dp[w][j]=0;
		}
		f-=a[i];l+=a[i];w=1-w;
	}
	return dp[w][u+p];
}
main()
{
	cin>>s>>X>>Y;bool flag=true;int cnt=0;
	int it=0;
	while(it<s.size()&&s[it]!='T')it++;
	X-=it;
	for(it++;it<s.size();it++)
	{
		if(s[it]=='T')
		{
			flag?y[cy++]=cnt:(x[cx++]=cnt);
			cnt=0;flag=!flag;
		}
		else cnt++;
	}
	flag?y[cy++]=cnt:(x[cx++]=cnt);
	cout<<(f(x,cx,X)&&f(y,cy,Y)?"Yes":"No")<<endl;
}

Measured memory_bytes: 384
#include <stdio.h>
#define sq(x) (x)*(x)
int main(void)
{
	int i,d,w,S;
	while(scanf("%d",&d) != EOF)
	{
		S = 0;
		w = 600/d;
		for(i=0;i<w-1;i++)
		{
			S += sq((i+1)*d)*d;
		}
		printf("%d\n",S);
	}
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#define all(c) c.begin(), c.end()
#define pb push_back
#define ll long long
const int MAXN = 1e5 + 5;
const int mod = 1e9 + 7;

using namespace std;

ll dp[MAXN];

ll po(ll a, ll p) {
  if (!p) return 1;
  ll x = po(a,(p>>1));
  x = (x*x)%mod;
  if ((p&1)) x = (x*a)%mod;
  return x;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  for (ll i = k; i >= 1; i--) {
    ll sub = 0;
    ll nb = 0;
    for (ll j = i; j <= k; j += i) {
      nb++;
      sub += dp[j];
      sub %= mod;
    }
    dp[i] = po(nb,n);
    dp[i] = (dp[i]-sub+mod)%mod;
    ans += (i*dp[i])%mod;
    ans %= mod;
  }
  cout << ans;
  return 0;
}

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


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

ll d[MAXn],dp[MAXn],pre[MAXn];

inline ll sq(ll x){
  return x * x;
}

int main()
{
    IOS();
    ll n,X;
    cin>>n>>X;
    REP1(i,n)cin>>d[i],pre[i] = d[i] + pre[i-1];
    ll mn = INF;
    for(ll i = n;i > 0;i--)
    {
      ll tt = X * i + X * n,it = n;
      for(ll j = 0;;j++)
      {
        ll ct = i;
        if(j==0)ct += i;
        if(ct >= it){
          tt += (pre[it] - pre[0]) * (2 * j + 5);
          break;
        }
        else{
          tt += (pre[it] - pre[it - ct]) * (2 * j + 5);
          it -= ct;
        }
        if(tt > INF)
        break;
      }
      mn = min(mn,tt);
    }
    cout<<mn<<endl;
}


Measured memory_bytes: 4480
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
#define nl "\n"
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define fl(a,x) memset(a,x,sizeof(a));
#define pt(a,x) cout << get<x>(a) << " " ;
#define mt make_tuple
#define vec vector

#define int long long

const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18 ;

typedef vector<int> vii;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

const int N = 1e5 + 5; 
vii g[N]; 
bool vis[N]; 
int ans ; 

void dfs(int node) {
	if(vis[node])return ; 
	vis[node] = 1;
	for(auto i : g[node]) {
		if(not vis[i]) dfs(i); 
	}
}

void solve() {
	int n, m; cin >> n >> m ;
	rep(i,0,m) {
		int u,v; cin >> u >> v; 
		g[u].eb(v) ; 
		g[v].eb(u); 
	}
	rep(i,1,n+1) {
		if(not vis[i]) ++ans, dfs(i); 
	}
	cout << ans-1 ; 
}

int32_t main() {

#ifdef LOCAL
    freopen("error.txt", "w", stderr);
#endif

    fast;

	// int t; cin >> t; while(t--)
		solve() ;

	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 10344
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
  long long int n;cin>>n;
  if(n%10==2||n%10==4||n%10==5||n%10==7||n%10==9)
    cout<<"hon";
    else if(n%10==1||n%10==8||n%10==6||n%10==0)
      cout<<"pon";
  else
    cout<<"bon";
  return 0;
}

Measured memory_bytes: 3672
from sys import stdin,stdout
LI=lambda:list(map(int,input().split()))
MAP=lambda:map(int,input().split())
IN=lambda:int(input())
S=lambda:input()
import math
from collections import Counter,defaultdict


n=IN()
a=LI()
ans=0
for i in range(n):
    ans^=a[i]
for i in range(n):
    print(ans^a[i],end=" ")


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

using std::string;

int main()
{
    string ring;
    string target;
    std::cin >> ring >> target;

    string ringring = ring.append(ring);

    size_t idx = ringring.find(target, 0);
    if (idx != string::npos) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1192
#if 1
#include <iostream>
#include <string>

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

#if DEBUG_ON
    freopen("input", "r", stdin);
#endif

    std::string str;
    std::cin >> str;
    if (str[0] == str[1] && str[1] == str[2]) {
        std::cout << "No\n";
    } else {
        std::cout << "Yes\n";
    }
    return 0;
}
#endif

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <map>

using namespace std;
typedef long long LL;
const int INF = int(1e9);
const int MAX = 1000020;
LL N;
LL a[MAX],b[MAX],c[MAX];

void Cin(LL a[])
{
    for(int i = 1;i<=N;i++)
        scanf("%lld",&a[i]);
}

int main()
{
    cin>>N;
    Cin(a),Cin(b),Cin(c);
    sort(a+1,a+1+N),sort(b+1,b+1+N),sort(c+1,c+1+N);
    LL sum = 0;
    LL ai = 0,ci = 0;
    for(int i = 1;i<=N;i++){
        while(a[ai+1]<b[i]&&ai+1<=N)
            ai++;
        while(c[ci+1]<=b[i]&&ci+1<=N)
            ci++;
       // cout<<ai<<" "<<ci<<endl;
        sum += ai*(N-ci);
    }

    cout<<sum<<endl;

    return 0;
}



Measured memory_bytes: 9216
mod = 10**9 + 7

N = int(input())

# NG = {AGC,GAC,ACG,ATGC,AGGC,AGTC}
# (A,C,G,T) = (0,1,2,3)
# dp[i][j]: 長さiの条件を満たす文字列のうち、末尾がjとなるものの場合の数
# 初期条件 dp[1] = [1,1,1,1]
# ans = dp[0] + dp[1] + dp[2] + dp[3]

dp = [[0]*4 for _ in range(N+1)]

# A,C,G,T それぞれ1通りずつ
dp[1] = [1]*4


for i in range(2,N+1):
    for j in range(4):
        # ひとまず長さi-1の文字列にjを足して良いとする
        dp[i][j] += sum(dp[i-1])
        dp[i][j] %= mod
    # ダメなパターンを引いて補正する
    # 後ろ二文字が"AG","GA"の場合はCを付け足せない
    # ~AG, ~GA となる場合の数はそれぞれ dp[i-2][0]*1とdp[i-2][2]*1
    dp[i][1] -= dp[i-2][0] + dp[i-2][2]
     # 後ろ二文字が"AC"の場合はGを付け足せない
    # ~AC となる場合の数は dp[i-2][0] (- dp[i-3][2])
    dp[i][2] -= dp[i-2][0]
    if i >= 3:
        # 後ろ三文字が"ATG","AGG","AGT"となる場合はCを付け足せない
        # ~ATG, ~AGG, ~AGT となる場合の数は 合わせて dp[i-3][0]*3
        dp[i][1] -= dp[i-3][0]*3
        # ----------------------注意--------------------------
        # dp[i-2][0]は後ろから~ACとなる場合の数だから
        # これには~GACとなる場合の数も含まれている
        # しかし~GACというのは既に除外しているので
        # ~ACとなる場合の数は dp[i-2][0]-dp[i-3][2]
        # 余分に引いている分を+dp[i-3][2]することで補正
        dp[i][2] += dp[i-3][2]

ans = sum(dp[N]) % mod
print(ans)

Measured memory_bytes: 3064
N=int(input())
A=[int(i) for i in input().split()]
ans=0
flag=1
while flag:
    flag=0
    for j in range(1,N)[::-1]:
        if A[j]<A[j-1]:
            A[j],A[j-1]=A[j-1],A[j]
            flag=1
            ans+=1

print(" ".join([str(i) for i in A]))
print(ans)



Measured memory_bytes: 5608
# E - Sum of gcd of Tuples (Hard)
MOD = 10**9+7

def pow_mod(x,n):
    if n==0:
        return 1
    elif n%2==0:
        return (pow_mod((x**2)%MOD,n//2))%MOD
    else:
        return (x*pow_mod((x**2)%MOD,n//2))%MOD

N,K = map(int,input().split())
ans = 0
rec = [0]*(K+1)
for X in range(K,0,-1):
    rec[X] = pow_mod(K//X,N)
    for i in range(2,K//X+1):
        rec[X] = (rec[X]-rec[i*X])%MOD
    ans = (ans+X*rec[X])%MOD
print(ans)

Measured memory_bytes: 11240