akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>



using namespace std;



using ll = long long;



int main(){

  int a, b, x;

  double theta;

  cin >> a >> b >> x;

  cin.ignore();



  int full = a * a * b;

  double ans_rad, ans;

  double tang;



  double h; // 高さ どっちかは場合による



  if(x * 2 == full){

    tang = b / (double) a;

    ans_rad = atan(tang);

    //cout << "ans_rad = " << ans_rad << endl;

    ans = ans_rad * 180 / M_PI;

    printf("%.10f\n", ans);

  } else if(x * 2 > full){ // 半分以上



    //高さa

    //三角形の面積を求める

    h = (full - x) / (double)a * 2 / (double)a;

    ans_rad = atan(h / (double) a);

    ans = ans_rad * 180 / M_PI;

    printf("%.10f\n", ans);

  } else { // 半分未満

    h = x / (double)a * 2 / (double)b;

    ans_rad = atan((double)b / h);

    ans = ans_rad * 180 / M_PI;

    printf("%.10f\n", ans);

  }

  return 0;

}



Measured memory_bytes: 256
#include<iostream>

using namespace std;

#define N 10000

int serach(int A[],int n,int key){
  int i=0;
  A[n]=key;
  while (A[i]!=key) {
    i++;
  }
  return i != n;
}

int main(){
int n,A[N+1],q,key,sum=0;

cin >> n;
for(int i=0;i<n;i++) cin >> A[i];

cin >> q;

for(int i=0;i<q;i++){
  cin >> key;
  if(serach(A,n,key)) sum++;
}

cout << sum << endl;

  return 0;
}



Measured memory_bytes: 3136
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;


int n, k;
int a[200010];

int main()
{
	scanf("%d%d", &n, &k);
	for (int i = 0 ; i < n ; i++) {
		scanf("%d", &(a[i]));
	}
	
	for (int i = k ; i < n ; i++) {
		if (a[i] > a[i - k]) {
			printf("Yes\n");
		} else {
			printf("No\n");
		}
	}
	
	
	return 0;
}



Measured memory_bytes: 2440
#include<bits/stdc++.h>
using namespace std;
string s;
int main( ){
	int x,y,z,k;
	cin>>s;
	int n=s.size( );
	for(register int i=0;i<n;i+=2)
		if(s[i]=='L'){
			printf("No\n");return 0;
		}
	for(register int i=1;i<n;i+=2)
		if(s[i]=='R'){
			printf("No\n");return 0;
		}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 256
H,W = map(int,input().split())
a = [list(map(int,input().split())) for i in range(H)]
def next(i,j):
    if i%2==0:
        if j == W-1:
            return i+1,j
        else:
            return i,j+1
    else:
        if j == 0:
            return i+1,j
        else:
            return i,j-1
ans = []
i,j = 0,0
while True:
    i_,j_ = next(i,j)
    if i_ == H:
        break
    if a[i][j]%2==1:
        a[i][j] -= 1
        a[i_][j_] += 1
        ans.append('{} {} {} {}'.format(i+1,j+1,i_+1,j_+1))
    i,j = i_,j_
print(len(ans))
for s in ans:
    print(s)

Measured memory_bytes: 16472
#include <bits/stdc++.h>
#define itn int
#define gI gi
#define int long long

using namespace std;

typedef long long ll;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline ll gl()
{
	ll f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int maxn = 200004;

int n, d, a, x[maxn], h[maxn];
struct Node
{
	int x, y;
} b[maxn];
int ans, f[maxn << 2], tag[maxn << 2];

inline bool cmp(Node x, Node y)
{
	return x.x < y.x;
}

inline int work(int ss)
{
	int l = 1, r = n, sum = -1;
	while (l <= r)
	{
		int mid = (l + r) >> 1;
		if (b[mid].x <= ss) l = mid + 1, sum = mid;
		else r = mid - 1;
	}
	return sum;
}

inline int ls(int p) {return p << 1;}
inline int rs(int p) {return p << 1 | 1;}

inline void pushup(int p)
{
	f[p] = max(f[ls(p)], f[rs(p)]);
}

void build(int p, int l, int r)
{
	if (l == r) {f[p] = b[l].y; return;}
	int mid = (l + r) >> 1;
	build(ls(p), l, mid);
	build(rs(p), mid + 1, r);
	pushup(p);
}

inline void pushdown(int p)
{
	if (tag[p])
	{
		f[ls(p)] += tag[p];
		f[rs(p)] += tag[p];
		tag[ls(p)] += tag[p];
		tag[rs(p)] += tag[p];
		tag[p] = 0;
	}
}

inline void add(int x, int y, int l, int r, int p, int k)
{
	if (x <= l && y >= r) {f[p] += k, tag[p] += k; return;}
	pushdown(p);
	int mid = (l + r) >> 1;
	if (x <= mid) add(x, y, l, mid, ls(p), k);
	if (y > mid) add(x, y, mid + 1, r, rs(p), k);
	pushup(p); 
}

int getans(int x, int y, int l, int r, int p)
{
	if (x <= l && y >= r) return f[p];
	pushdown(p);
	int mid = (l + r) >> 1, sum = 1 << 31;
	if (x <= mid) sum = max(sum, getans(x, y, l, mid, ls(p)));
	if (y > mid) sum = max(sum, getans(x, y, mid + 1, r, rs(p)));
	return sum;
}

signed main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	n = gi(), d = gi(), a = gi();
	for (int i = 1; i <= n; i+=1)
	{
		x[i] = gi(), h[i] = gi();
		b[i].x = x[i], b[i].y = h[i];
	}
	sort(b + 1, b + 1 + n, cmp);
	build(1, 1, n);
	int i = 1;
	while (i <= n)
	{
		int s = b[i].x + d * 2, id = work(s), g = getans(i, i, 1, n, 1), ci = (g + a - 1) / a;
		ans += ci;
		add(i, id, 1, n, 1, -(ci * a));
		int l = i, r = id, sum = i;
		while (l <= r)
		{
			int mid = (l + r) >> 1;
			if (getans(i, mid, 1, n, 1) <= 0) l = mid + 1, sum = mid;
			else r = mid - 1;
		}
		i = sum + 1;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 18688
#include <iostream>
#include <cstdint>
#include <algorithm>
 
using namespace std;
 
int main() {
  ios_base::sync_with_stdio(false);
  int64_t n, a, b;
  cin>>n>>a>>b;
  int64_t res = 0;
  int64_t cnt = n / (a + b);
  res += cnt * a;
  int64_t m = n % (a + b);
  res += min(m, a);
  cout<<res<<endl;
  return 0;
}

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

//逆元(素数MOD)
long long inverse(long long b){
    /*
    Copyright (c) 2020 0214sh7
    https://github.com/0214sh7/library/
    */
  long long r=1,e=MOD-2;
  while(e){
      if(e&1){
          r=(r*b)%MOD;
      }
      b=(b*b)%MOD;
      e >>=1;
  }
  return r;
}

signed main(void){
    
    long long S;
    cin >> S;
    
    //dp[i]:=i桁の数列で条件を満たすものの数
    vector<long long> dp(S+1,0);
    
    for(long long i=3;i<=S;i++){
        //dp[i]=sum(dp[0],..,dp[i-3])+1
        for(long long j=0;j<=i-3;j++){
            dp[i]=(dp[i]+dp[j])%MOD;
        }
        dp[i] = (dp[i]+1)%MOD;
    }
    
    cout << dp[S] << endl;
    
    return 0;
}


Measured memory_bytes: 3632
while True:
    n = int(input())
    if n == 0: break
    y = int(input())
    dataset = {}
    for _ in range(n):
        b, r, t = map(int, input().split())
        dataset[b] = (1 + y * (r/100)) if t == 1 else pow((1 + r / 100), y)
    print(sorted(dataset.items(), key=lambda x: x[1])[-1][0])

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

 int main(void){
     int N;
     cin >> N;
     int x2=0, x4=0, x=0;
     for(int i=0;i<N;i++){
         int a;
         cin >> a;
         if(a % 4 == 0) x4++;
         else if(a % 2 == 0) x2++;
         else x++;
     }

     if(x2 != 0 && x4 >= x || x2 == 0 && x4+1 >= x){
         cout << "Yes" << endl;
     } else {
         cout << "No" << endl;
     }
     return 0;
 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ii>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 3003;
ll i,n;
ll a[N],dp[N][N][2];
ll solve(ll i,ll j,ll p)
{
    if(dp[i][j][p] != -1) return dp[i][j][p];
    
    if(i == j)
        return dp[i][j][p] = a[i] * (p == 0 ? 1 : -1);
    
    ll res;
    if(p == 0){
        res = a[i] + solve(i + 1,j,1 - p);
        res = max(res,a[j] + solve(i,j - 1,1 - p));
    }
    else{
        res = -a[i] + solve(i + 1,j,1 - p);
        res = min(res,-a[j] + solve(i,j - 1,1 - p));
    }
    return dp[i][j][p] = res;
}
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    memset(dp,-1,sizeof(dp));
    cin>>n;
    rep(i,1,n + 1) cin>>a[i];
    cout<<solve(1,n,0);
    return 0;
}

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

using namespace std;
using ll = long long;

int main() {
	ll h, n, ans = 0;
	cin >> h >> n;
	vector <ll> a(n), b(n);
	rep(i,n) cin >> a[i] >> b[i];
	vector<ll> dp(h + 1);
	rep(i,h + 1) dp[i] = ((i + a[0] - 1) / a[0]) * b[0];
	for (int i = 1; i < n; i++) {
		vector<ll> c(h + 1);
		swap(dp,c);
		rep(j,h + 1) {
			//　使わないか　全部使うか
			dp[j] = min(((j + a[i] - 1) / a[i]) * b[i], c[j]);

			if (j >= a[i]) dp[j] = min(dp[j], dp[j - a[i]] + b[i]);
		}
	}
	ans = dp[h];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3700
#include <iostream>
#include <algorithm>
#include <string>
#include <array>

class dice{
public:
    using val_t = unsigned;
    explicit dice(const std::array<val_t,6>& a):v(a){}
    void mov(const char c){
        val_t buf;
        switch(c){
            case 'N':{
                buf = v[0];
                v[0] = v[1];
                v[1] = v[5];
                v[5] = v[4];
                v[4] = buf;
                break;
            }
            case 'E':{
                buf = v[0];
                v[0] = v[3];
                v[3] = v[5];
                v[5] = v[2];
                v[2] = buf;
                break;
            }
            case 'W':{
                buf = v[0];
                v[0] = v[2];
                v[2] = v[5];
                v[5] = v[3];
                v[3] = buf;
                break;
            }
            case 'S':{
                buf = v[0];
                v[0] = v[4];
                v[4] = v[5];
                v[5] = v[1];
                v[1] = buf;
                break;
            }
        }
    }
    val_t top(){
        return v[0];
    }
private:
    std::array<val_t,6> v;
};

int main(){
    std::array<dice::val_t,6> in;
    for(auto &v : in) std::cin >> v;

    dice d(in);

    std::string s;
    std::cin >> s;
    for(auto &&v : s){
        d.mov(v);
    }
    std::cout << d.top() << std::endl;
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

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

  vector<int> v(3);
  cin>>v[0]>>v[1]>>v[2];;
  sort(v.begin(), v.end());


  int a = v[0];
  int b = v[1];
  int c = v[2];

  if (a==c) out(0);

  int target = c;
  int work = c-a + c-b;

  if (work%2 == 1) target++;

  int ans = 0;
  if (target > c) {
    ans++; c++;
    if ((target-a)%2 == 1) {
      a++;
    } else {
      b++;
    }
  }

  //watch(target);

  int dx = min(target-a,target-b);
  ans += dx;
  a+=dx; b+=dx;

  if (a<target) {
    assert((target-a)%2 == 0);
    ans += (target-a)/2;
  }
  if (b<target) {
    assert((target-b)%2 == 0);
    ans += (target-b)/2;
  }

  out(ans);

  
  return 0;
}


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

Measured memory_bytes: 128
#include <iostream>
using namespace std;
//ユークリッドの互除法を再帰で解くプログラム

int gcd(int a,int b,int count){
    if(b != 0){
        gcd(b,a%b,count+1);
    }else{
        cout << a << " " << count << endl;
    }
    return 0;
}

int main(){
    int a,b;
    while (cin >> a >> b) {
        if (a == 0 && b == 0){
            break;
        }else{
            gcd(max(a,b),min(a,b),0);
        }
    }
    return 0;
}


Measured memory_bytes: 3088
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long li;

const int maxn = 100;

int n;
vector<int> a, b;

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    a.push_back(x - 1);
  }
  while (n) {
    int x = -1;
    for (int i = a.size() - 1; i >= 0; --i) {
      if (i == a[i]) {
        x = i;
        break;
      }
    }
    if (x == -1) {
      puts("-1");
      return 0;
    }
    b.push_back(x);
    a.erase(a.begin() + x);
    --n;
  }
  reverse(b.begin(), b.end());
  for (int x : b) {
    printf("%d\n", x + 1);
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
bool h[1000010]={false};
int main(){
	int n;
	while(cin>>n){
		int co=0;
		rep(i,10)rep(j,10)rep(k,10)rep(q,10)if(i+j+k+q==n)co++;
		cout<<co<<endl;
	}
}

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

using namespace std;

int main(void){
    int N;
    float x, sum=0;
    string u;

    cin >> N;
    for(int i=0; i<N; i++){
        cin >> x >> u;
        if(u == "JPY") sum += x;
        else sum += x * 380000;
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int N;
    cin >> N;
    vector<int> a;
    vector<int> b;
    vector<int> c;
    int tmp;
    for (int i = 0; i < N; i++) {
        cin >> tmp;
        a.push_back(tmp);
    }
    for (int i = 0; i < N; i++) {
        cin >> tmp;
        b.push_back(tmp);
    }
    for (int i = 0; i < N; i++) {
        cin >> tmp;
        c.push_back(tmp);
    }
    
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    
    long long  res=0;
    for (int i = 0; i < N; i++) {
        long long  a_j = distance(a.begin(), lower_bound(a.begin(), a.end(), b[i]));
        long long c_j = distance(upper_bound(c.begin(), c.end(), b[i]),c.end());
        res+=(a_j)*(c_j);
    }
    cout << res << endl;
}


Measured memory_bytes: 1784
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) (a*a)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

const int N = 8001;
int x[N], y[N];
int _dpx[2][2*N], _dpy[2][2*N];

int main() {
	int *dpx[2] = { &_dpx[0][N], &_dpx[1][N] };
	int *dpy[2] = { &_dpy[0][N], &_dpy[1][N] };
	string str;
	int gx, gy;
	cin >> str >> gx>>gy;
	str += "T";
	int n = str.length();
	
	int t = 0, cnt = 0, xidx = 0, yidx = 0;
	for (int i = 0; i < n; i++) {
		if (str[i] == 'F')cnt++;
		else {
			if (t == 0)gx -= cnt;
			else if (cnt != 0) {
				if (t % 2)y[yidx++] = cnt;
				else x[xidx++] = cnt;
			}
			cnt = 0;
			t++;
		}
	}
	dpx[0][0] = 1;
	dpy[0][0] = 1;
	REP(i, xidx) {
		memset(_dpx[(i + 1) % 2], 0, sizeof(_dpx[(i + 1) % 2]));
		FOR(j, -N, N + 1) if (dpx[i % 2][j])dpx[(i + 1) % 2][j - x[i]] = dpx[(i + 1) % 2][j + x[i]] = 1;
	}
	REP(i, yidx) {
		memset(_dpy[(i + 1) % 2], 0, sizeof(_dpy[(i + 1) % 2]));
		FOR(j, -N, N + 1) if (dpy[i % 2][j])dpy[(i + 1) % 2][j - y[i]] = dpy[(i + 1) % 2][j + y[i]] = 1;
	}
	if (dpx[xidx % 2][gx] == 1 && dpy[yidx % 2][gy] == 1)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 512
n,k=map(int,input().split())

a=k
b=n
count=0
halfcount=0
while(k>0.5):
    if b>=k and k%1==0:
        count+=(b-int(k)+1)/(2**halfcount)/n
        b=int(k)-1
    elif b>=k:
        count+=(b-int(k))/(2**halfcount)/n
        b=int(k)
    halfcount+=1
    k/=2
#     print(k)
#     print(count)
# print(k)
# print(int(k))
print(count)

Measured memory_bytes: 3064
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        String a = in.next();
        String b = in.next();
        int n = a.length();
        int m = b.length();
        int ans[][] = new int[n+1][m+1];
        for(int i=0;i<n;i++){
            ans[i][0] = 0;
        }
        for(int i=0;i<m;i++){
            ans[0][i] = 0;
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                if(a.charAt(i-1)==b.charAt(j-1)){
                    ans[i][j] = ans[i-1][j-1] + 1;
                }else{
                    ans[i][j] = Math.max(ans[i-1][j],ans[i][j-1]);
                }
            }
        }
        String str = "";
        int r = n;
        int c = m;
        while(true){
            if(r==0 || c==0){
                break;
            }
            if(a.charAt(r-1)==b.charAt(c-1)){
                str+=a.charAt(r-1);
                r--;
                c--;
            }else{
                if(ans[r-1][c]>ans[r][c-1]){
                    r--;
                }else{
                    c--;
                }
            }
        }
        StringBuilder temp = new StringBuilder(str);
        System.out.println(temp.reverse());
    }

}

Measured memory_bytes: 97868
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

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

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;
	
	char buf[L], *S , *T, c;
	 
	char getchar() {
		if(__builtin_expect(S == T, 0)) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}
	
	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	unsigned inpu()
	{
		unsigned x = 0; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar());
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x;
	}
	
	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	char B[25], *outs=B+20, *outr=B+20;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;
		
		if(!a)*--outs = '0';
		else 
			while(a)
				*--outs = (a % 10) + 48, a /= 10;
		
		if(x)
			*--outs = x;
		
		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inpu;
using io :: inp_ll;

using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

const int MAXN = 100010;
const int MAXP = 10000000;
const u64 MOD = 1000000007;
const f80 MI = f80(1)/MOD;
const int INF = 1000000010;

int n, q;
int a[MAXN];
ll s[MAXN], t[MAXN];

bool check(int m, int x)
{
	if (x >= a[n-m+1]) return false;
	int d = abs(x-a[n-m+1]);
	int L = lower_bound(a+1, a+n+1, x-d)-a;
	int R = upper_bound(a+1, a+n+1, x+d)-a-1;
	if (R-L >= m-1) return true; else return false;
}

void solve(int x)
{
	int L = 2, R = n, pos = 1;
	while (L <= R)
	{
		int m = (L+R)/2;
		if (check(m, x))
		{
			pos = m;
			L = m+1;
		}
		else
			R = m-1;
	}
	ll ans = s[n]-s[n-pos];
	ans += t[n-pos-pos];
	printf("%lld\n", ans);
}

int main()
{
	
	scanf("%d%d", &n, &q);
	for (int i = 1; i <= n; ++ i)
		scanf("%d", &a[i]);
	
	for (int i = 1; i <= n; ++ i)
		s[i] = s[i-1]+a[i];
	t[1] = a[1];
	t[2] = a[2];
	for (int i = 3; i <= n; ++ i)
		t[i] = t[i-2]+a[i];
	
	while (q --)
	{
		int x;
		scanf("%d", &x);
		solve(x);
	}
	
	return 0;
}


Measured memory_bytes: 3712
#define _USE_MATH_DEFINES //円周率を使用
#include <math.h>
#include <iomanip> //小数点以下を表示
#include <iostream>
#include <cstring> //文字列操作
using namespace std;

//【関数の定義】

int main(void)
{
	int a; //ログイン（1日1回のみ）の枚数
	int b; //月曜日から日曜日まで7日連続でログインの追加枚数
	int c; //c枚のコインを得るためにログインしなければならない日の最小値、のc枚
	int total = 0; //合計枚数
	int day = 0; //日
	int i, j, k; //カウンタ変数

	cin >> a >> b >> c; //A,B,Cを入力
	if (a < 1 || a > 1000 || b < 0 || b > 1000 || c < 1 || c > 1000000)
	{
		return 0;
	}

	while (1)
	{
		day++;
		total += a; //ログインボーナス
		
		if (day % 7 == 0)
		{
			total += b; //1週間連続ログインボーナス
		}

		if (total >= c) //c枚のコインを得るためにログインしなければならない日の最小値を達成した場合
		{
			cout << day << endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 3100
import sys
from collections import defaultdict
from collections import deque
import numpy as np
import heapq
from heapq import heappush, heappop


#read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

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

mn = N+1
cnt = 0
for i in range(N):
    #print(i, mn, cnt)
    a = A[i]

    if a < mn:
        mn = a
        cnt += 1

print(cnt)


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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

const int N = 100005;

int main() {

	FAST;

	int x, y;
	cin >> x >> y;
	if (y % 2) {
		cout << "No\n";
	}
	else {
		y /= 2;
		if (x <= y && y <= 2 * x) {
			cout << "Yes\n";
		}
		else {
			cout << "No\n";
		}
	}
	return 0;
}

Measured memory_bytes: 3612
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];

    auto min_i = 1, max_i = M;
    auto mid_i = (min_i + max_i) / 2;
    while (max_i - min_i > 1) {
        mid_i = (min_i + max_i) / 2;
        if (M / mid_i < N) {
            max_i = mid_i;
        } else {
            min_i = mid_i;
        }
    }
    mid_i += 1000;
    for (;;) {
        if (M % mid_i == 0 && M / mid_i >= N ) {
            writeln(mid_i);
            break;
        }
        --mid_i;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int i,a,ans;
  i=0;
  a=0;
  ans=0;
  int x[i];
  for(i=0;i<5;i++)
  {
    scanf("%d",&a);
    x[i]=a;
    ans++;
    if(a==0)
    break;
  }
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
#include <vector>
#include <math.h>

using namespace std;



int main(){

 string s; cin>>s;
  int n = s.length(),flag = 0;

  if(s[0] != 'A'){
    flag = 1;
    cout<<"WA"<<endl;
    return 0; }

    int cnt=0,pos=-1;
    for(int i=2;i<n-1;i++){
        if(s[i] == 'C'){
            cnt++;
            pos = i;}
    }

  if(cnt!=1){
     flag = 1;
    cout<<"WA"<<endl;
    return 0;}

    if(pos == -1){
            flag = 1;
        cout<<"WA"<<endl;
        return 0; }

 for(int i=0;i<n;i++)
    if( (s[i] >= 'a' && s[i]<='z') && s[i] != 'C' && s[i]!= 'A')
     continue;
   else if(i != 0 && i!= pos){
        //cout<<i<<endl;
    cout<<"WA";
    return 0;}

  if(flag == 0)
  cout<<"AC"<<endl;


return 0;

}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll w, h;
    cin >> w >> h;
    vector<ll> p(w), q(h);
    rep(i, w) cin >> p[i];
    rep(i, h) cin >> q[i];

    ll ans = 0;
    rep(i, w) {
        ans += ll(h+1)*p[i];
    }
    rep(i, h) {
        ans += ll(w+1)*q[i];
    }

    sort(rall(p));
    sort(rall(q));
    int cntp = 0, cntq = 0;
    ll cnt = 0;
    while(cnt != h*w) {
        if(p[cntp] > q[cntq]) {
            if(cnt + h-cntq > h*w) {
                ans -= p[cntp++]*(h*w-cnt);
                cnt = h*w;
            } else {
                ans -= p[cntp++]*(h-cntq);
                cnt += h-cntq;
            }
        } else {
            if(cnt + w-cntp > h*w) {
                ans -= q[cntq++]*(h*w-cnt);
                cnt = h*w;
            } else {
                ans -= q[cntq++]*(w-cntp);
                cnt += w-cntp;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4692
#include<iostream>
using namespace std;
#define R(i,n) for(int i=0;i<n;i++)
int n,a=1e9,c[2][20],p[1<<18][51];main(){cin>>n;R(i,n*2)cin>>c[i/n][i%n];fill(p[1],p[1<<n],1e9);R(B,1<<n){int o=0,d[n];R(i,n)d[i]=~B&1<<i?o++:0;R(i,n){int k=c[(i-n+o)&1][i],&t=p[B|1<<i][k];R(j,k+1)t=min(t,p[B][j]+d[i]);a=min(a,(B|1<<i)<(1<<n)-1?a:t);}}cout<<(a>1e8?-1:a);}

Measured memory_bytes: 52480
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;

struct DSU
{
	int par[N], sz[N];

	void init(int n) 
	{
		for(int i=1;i<=n;i++)
		{
			par[i]=i;
			sz[i]=1;
		}
	}

	int getPar(int k)
	{
		while(k!=par[k])
		{
			par[k]=par[par[k]];
			k=par[k];
		}
		return k;
	}

	bool unite(int u, int v)
	{
		int par1=getPar(u), par2=getPar(v);

		if(par1==par2)
			return false;


		if(sz[par1]>sz[par2])
			swap(par1, par2);

		sz[par2]+=sz[par1];
		sz[par1]=0;
		par[par1]=par[par2];
        return true;
	}
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    DSU dsu;
    int n,m;
    cin >> n >> m;
    dsu.init(n);
    int ans = n;
    while(m--)
    {
        int x,y,z;
        cin >> x >> y >> z;
        ans-=dsu.unite(x,y);    
    }
    cout << ans;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <string>
#include <vector>
using namespace std;

int main(int argc, char const *argv[]) {
  string a, result;
  std::cin >> a;
  // a = "hello";
  for (size_t i = a.size(); i > 0; i--) {
    result += a[i - 1];
  }
  std::cout << result << '\n';
  return 0;
}



Measured memory_bytes: 3144
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int w, q;
    cin >> w >> q;
    vector<vector<int>> a(w);
    int n, t, x;
    rep(i, q) {
        cin >> n >> t;
        if (n == 0) {
            cin >> x;
            a[t].push_back(x);
        }
        else if (n == 1) {
            if (a[t].empty()) {
                cout << endl;
                continue;
            }
            if (a[t].size() >= 2)
                rep(i, a[t].size() - 1) {
                    cout << a[t][i] << ' ';
                }
            cout << a[t].back() << endl;
        }
        else
            a[t].clear();
    }
}


Measured memory_bytes: 5896
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(s: usize);

    let mut buff: usize = s;
    let mut set = std::collections::HashSet::new();
    set.insert(buff);

    let mut count = 1;
    loop {
        if buff % 2 == 0 {
            buff /= 2;
        } else {
            buff = 3 * buff + 1;
        }
        count += 1;
        if set.contains(&buff) {
            break;
        }
        set.insert(buff);
    }

    println!("{}", count);
}


Measured memory_bytes: 2176
#include<stdio.h>
int main(void)
{
    int a1,a2,a3,a4,a5,a6,a7,a8,a9,b1,b2,b3,b4,b5,b6,b7,b8,b9;
	char c1[16],c2[16],c3[16],c4[16],c5[16],c6[16],c7[16],c8[16],c9[16];
	scanf("%s %d %d",&c1,&a1,&b1);
	scanf("%s %d %d",&c2,&a2,&b2);
	scanf("%s %d %d",&c3,&a3,&b3);
	scanf("%s %d %d",&c4,&a4,&b4);
	scanf("%s %d %d",&c5,&a5,&b5);
	scanf("%s %d %d",&c6,&a6,&b6);
	scanf("%s %d %d",&c7,&a7,&b7);
	scanf("%s %d %d",&c8,&a8,&b8);
	scanf("%s %d %d",&c9,&a9,&b9);
	printf("%s %d %d\n",c1,a1+b1,a1*200+b1*300);
	printf("%s %d %d\n",c2,a2+b2,a2*200+b2*300);
	printf("%s %d %d\n",c3,a3+b3,a3*200+b3*300);
	printf("%s %d %d\n",c4,a4+b4,a4*200+b4*300);
	printf("%s %d %d\n",c5,a5+b5,a5*200+b5*300);
	printf("%s %d %d\n",c6,a6+b6,a6*200+b6*300);
	printf("%s %d %d\n",c7,a7+b7,a7*200+b7*300);
	printf("%s %d %d\n",c8,a8+b8,a8*200+b8*300);
	printf("%s %d %d\n",c9,a9+b9,a9*200+b9*300);
	return 0;
}

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

using namespace std;

int main(){
	int a, b, c, d, e, f, total = 0;
	cin >> a >> b >> c >> d >> e >> f;
	total += a * 1 + b * 5 + c * 10 + d * 50 + e * 100 + f * 500;
	if(total >= 1000) cout << 1 << endl;
	else cout << 0 << endl;
}

Measured memory_bytes: 3044
/*
2017_03_02_AC
??????????????????
????¬????????????????????????????i???A?????§????????????????????????????????§???????????????*i???A????¶??????????????????§?????????
????´???????????????????????????????????????£??????(a/b)+(c/d)??????(a*d+c*b)/(b*d)??¨??????????????§?????????
???????????????????????¨LTE???
????????????????????????????????´??\?????????????????§??????????????§?¢?????????????
??????????????°?????????????¨????????????????
???(sum/pro) + (1/i) = (sum*d+pro)/(pro*i)
	?????????????????§???????§???????????????¨??????????????????
????????????
???pair???????????????????????????
????´??????????????????¬????????§?????????
?????????????????¨???????????????????????????????????°?????????????????????A??\?????¨???????????¶????????§???
????????????pro??????????´???????????????????????????§???????????????????????????
*/

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int P,Q,A,N,ans;

void dfs(int term, int minnum, int prod, int sum){
  if(A < prod || N < term) return;
	if(sum*Q == prod*P){  /* (sum/prod) = (P/Q) ????????????????????? */
	  ans++;
		return;
	}
	for(int i=minnum; prod*i <= A; i++){ /* ?¬?????¶???????????????°????????????????°??????????????????????????????????????????????minnum??\??? */
    dfs(term + 1, i, prod*i, sum*i + prod); /* ????????§??? (sum/prod)+(1/i)=(sum*i+prod)/(prod*i) ??????????????? */
  }
  return;
}

int main() {
  while(1){
    cin>>P>>Q>>A>>N;
    if(P==0&&Q==0&&A==0&&N==0) break;
    ans = 0;

    //REP(i,1,A+1){   /* ?????????(????°???????)???????±????????????? */
    //  dfs(1,i,i,1);
    //}
    dfs(0,1,1,0);

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

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

int main(int argc, char const *argv[])
{
	int n; cin >> n;
	vector<int> a(n + 1); rep(i, n) cin >> a[i + 1];
	set<int> st;
	for (int i = n; i >= 1; --i) {
		int cnt = 0;
		for (int j = 1; j <= n; ++j) {
			if (i * j <= n) {
				if (st.count(i * j)) cnt++;
			} else {
				break;
			}
		}
		if (cnt % 2 != a[i]) {
			st.insert(i);
		}
	}
	cout << st.size() << endl;
	for (auto u : st) {
		cout << u << endl;
	}
	return 0;
}


Measured memory_bytes: 7808
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define deb(x) cout<<#x<<" "<<x<<endl;
#define print(arr,n) for(int i=0;i<n;++i) { cout<<arr[i]<<" "; } cout<<endl;
#define ub(x,el) upper_bound(x.begin(),x.end(),el) - x.begin()
#define lb(x,el) lower_bound(x.begin(),x.end(),el) - x.begin();
#define bs(x,el) binary_search(x.begin(),x.end(),el)
#define MOD 1000000007
#define finish return 0
using namespace std;
using namespace __gnu_pbds; 
typedef long long int ll;
typedef tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
template<int D, typename T> struct Vec : public vector<Vec<D - 1, T>> { static_assert(D >= 1, "Vector dimension must be greater than zero!"); template<typename... Args> Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) { }}; template<typename T> struct Vec<1, T> : public vector<T> { Vec(int n = 0, T val = T()) : vector<T>(n, val) { } };
inline ll mod(ll x) { return (x%MOD + MOD)%MOD; }
ll gcd(ll a, ll b, ll &x, ll &y){if(a == 0){x = 0, y = 1; return b;} ll x1, y1;  ll d = gcd(b%a, a, x1, y1); x = y1 - (b/a) * x1; y = x1; return d;}
ll power(ll x,ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p;   } return res; } 
ll power(ll x,ll y) { ll res = 1; while (y > 0) { if (y & 1) res = (res*x); y = y>>1; x = (x*x);   } return res; } 
ll mod(ll num, ll den){ return mod(mod(num) * power(den,MOD-2,MOD)); }
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll a,b,n;
    cin>>a>>b>>n;
    if(n>(b-1)) n = b-1;
    ll ans = a*n;
    long double well = ans*1.0;
    well /= b;
    cout<<floor(well)<<endl;
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    ll n;
    cin>>n;
    ll ans=n*(n-1)/2;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
# define M_PI 3.14159265358979323846
# define epsi 1e-9
# define F first
# define S second
# define REP(i,a,b) for(int i=a;i<=b;i++)
using ll = long long int;
const int MOD = 1e9 + 7;
int main()
{
    int x,y,z;
    cin>>x>>y>>z;   
	cout<<z<<' '<<x<<' '<<y;
}

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

struct Node {
    ll r, L, R;
    bool operator < (const Node& rhs) const {
        if(r!=rhs.r)
            return r < rhs.r;
        return L < rhs.L;
    }
} a[200010];

int main() {
    ll n, x, d;
    scanf("%lld%lld%lld", &n, &x, &d);
    if(d==0) {
        if(x==0)
            printf("1\n");
        else
            printf("%lld\n", n+1);
        return 0;
    }
    if(d<0) {
        d = -d;
        x = -x;
    }
    ll ans = 0;
    int cnt = 0;
    a[cnt++] = (Node){0, 0, 0};
    for(ll i=1; i<=n; i++) {
        ll L = (i-1)*i/2;
        ll R = (2*n-i-1)*i/2;
        ll k = x*i/d;
        if(k*d>x*i)
            k--;
        a[cnt++] = (Node){x*i-k*d, L+k, R+k};
    }
    sort(a, a+cnt);
    ll last = -1e18;
    for(int i=0; i<cnt; i++) {
        if(i>0 && a[i].r!=a[i-1].r)
            last = -1e18;
        ll L = max(last, a[i].L);
        if(a[i].R>=L)
            ans += a[i].R-L+1;
        last = max(last, a[i].R+1);
    }
    printf("%lld\n", ans);
    return 0;
}


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

#define endl '\n'

using namespace std;

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

  int n, ans = 0;
  cin >> n;
  vector<int> num(n);
  for (int i = 0; i < n; i++) cin >> num[i];
  int parc = 0;
  for (int i = 0; i < n - 1; i++) {
    if (num[i] >= num[i + 1]) {
      parc++;
    } else {
      ans = max(ans, parc);
      parc = 0;
    }
  }
  ans = max(ans, parc);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
N, K = map(int, input().split())
*A, = map(int, input().split())
MOD = 10**9+7

smaller = [0]*N
reverse = [0]*N
for i in range(N):
    for j in range(N):
        if j == i: continue
        if A[i] > A[j]:
            smaller[i] += 1
            if i < j:
                reverse[i] += 1

ans = (K*sum(reverse)%MOD + ((K*(K-1)//2)%MOD)*sum(smaller))%MOD
print(ans)

Measured memory_bytes: 9356
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <stack>
#include <deque>
#define int llint
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, n) &((x)[0]), &((x)[n])
#define ADD(a, b) ((((a)%MOD)+((b)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define FLOOR(x) ((int)floor(((double)x)))
#define CEIL(x) ((int)ceil(((double)x)))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using VLL = std::vector<llint>;
using MCI = std::map<char, int>;
using namespace std;


int N, K;


int solve(){
	if(K == 0) return N*N;
	int ans = 0LL;
	repe(b, 1, N) ans += (N/b)*max(0LL, b-K)+max(0LL, N%b+1-K);
	return ans;
}


signed main(){
	cin >> N >> K;
	
	cout << solve() << endl;
	
	return 0;
}

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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayInt();
            var N = input[0];
            var A = input[1] - 1;
            var B = input[2] - 1;
            var C = input[3] - 1;
            var D = input[4] - 1;
            var S = Read();
            for (int i = A; i < C; i++)
            {
                var chk = S.Substring(i, 2);
                if (chk == "##") { Console.WriteLine("No"); return; }
            }
            for (int i = B; i < D; i++)
            {
                var chk = S.Substring(i, 2);
                if (chk == "##") { Console.WriteLine("No"); return; }
            }
            if (C > D)
            {
                var suc = false;
                for (int i = B; i <= D; i++)
                {
                    var chk = S.Substring(i - 1, 3);
                    if (chk == "...") { suc = true; break; }
                }
                if (!suc) { Console.WriteLine("No"); return; }
            }

            Console.WriteLine("Yes");
            Console.ReadLine();
        }

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

Measured memory_bytes: 18012
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef vector<LL> vl;
typedef pair<LL, LL> pl;
typedef vector<pair<LL, LL>> VP;
typedef tuple<LL, LL, LL> tl;
const LL N=pow(10, 9)+7;
#define endl "\n"
#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 WE(i) while(i--)
#define PB push_back
#define PF pop_front
#define MP make_pair
#define MT make_tuple
#define F first
#define S second

LL sod(LL a)
{
    LL sum=0;
    while(a!=0)
    {
        sum=sum+a%10;
        a=a/10;
    }
    return sum;
}

LL num1(LL a)
{
    LL s=0;
    while(a!=0){
        if(a%2==1){
            s++;
        }
        a=a/2;
    }
    return s;
}

LL bmod(string s, LL a)
{
    LL res=0;
    REP(i, 0, s.length()){
        res=(10*res+(LL)s[i]-'0')%a;
    }
    return res;
}

void pd(LL n) 
{ 
    LL ans=0, x=sqrt(n);
    if(x%1==0){
        REP(i, 1, x+1){
            if(n%i==0){
                ans+=2;
            }
            if(n==i*i){
                ans--;
            }
        }
    }
    else{
        REP(i, 0, x){
            if(n%i==0){
                ans+=2;
            }
        }
    }
    cout << ans << endl;
}

LL solve()
{
    LL n;
    float x;
    cin >> n;
    vector<float> v;
    REP(i, 0, n){
        cin >> x;
        v.PB(x);
    }
    sort(v.begin(), v.end());
    while(v.size()>1){
        v[0]=(v[0]+v[1])/2;
        v.erase(v.begin()+1);
    }
    cout << fixed << setprecision(5) << v[0] << endl;
    return 0;
}

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    
    LL T=1;
    //cin >> T;

    WE(T){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;


  int arr[1001];


int32_t main()
{


    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS

  string s;
  cin >> s;
  map<char,int> mp;

  for(int i = 0; i < s.size(); i++)mp[s[i]]++;

    for(auto i : mp)
    {
      if(i.second %2 == 1)
      {
        cout << "No";
        return 0;
      }
    }

    cout << "Yes";
    return 0;   
}


Measured memory_bytes: 3660
#include<iostream>
#include<string>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b <= b + c && a + b <= c + a)
	{
		cout << a + b << endl;
	}
	else if (b + c <= a + b && b + c <= c + a)
	{
		cout << b + c << endl;
	}
	else
	{
		cout << c + a << endl;
	}


}

Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#include<list>
#include<limits>
#include<bitset>
#define MOD 1000000007LL
#define INF 10000000000000LL
#define MAX 101
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
ll n,m;
struct edge{ll from,to,cost;};
edge es[2001];
ll d[1001];
bool check(){
    for(int i=0;i<1001;i++){
        d[i]=0;
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            edge e=es[j];
            if(d[e.to]>d[e.from]+e.cost){
                d[e.to]=d[e.from]+e.cost;
                if(i==n-1&&e.to==n-1){
                    return true;
                }
            }
        }
    }
    return false;
}
int main() {    
    cin>>n>>m;
    for(int i=0;i<m;i++){
        ll a,b,c;
        cin>>a>>b>>c;
        a--;b--;c*=-1;
        es[i]={a,b,c};
    }
    if(check()){
        cout<<"inf"<<endl;
        return 0;
    }
    for(int i=0;i<n;i++){
        d[i]=INF;
    }
    d[0]=0;
    for(int j=0;j<n;j++){
        for(int i=0;i<m;i++){
            edge e=es[i];
            if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){
                d[e.to]=d[e.from]+e.cost;
            }
        }
    }
    cout<<-d[n-1]<<endl;
}

                           


Measured memory_bytes: 256