akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ in >> p.first >> p.second; return in; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
template <char d = ' ', class T>
ostream& operator << (ostream& out, vector<T>& v){ for(auto& e : v){ out << e << d; } return out; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> as(n), bs(n);
    cin >> as >> bs;
    int ans = 0;
    for(int i = 28; i >= 0; i--){
        for(auto& a : as){ a &= (2 << i) - 1; }
        for(auto& b : bs){ b &= (2 << i) - 1; }
        sort(bs.begin(), bs.end());
        int num = 0;
        for(auto& a : as){
            int x = lower_bound(bs.begin(), bs.end(), (1 << i) - a) - bs.begin();
            int y = lower_bound(bs.begin(), bs.end(), (2 << i) - a) - bs.begin();
            int z = lower_bound(bs.begin(), bs.end(), (3 << i) - a) - bs.begin();
            num += y - x + n - z;
        }
        ans |= num & 1 ? 1 << i : 0;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<set>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
#define INF 1000000100
#define rep(i,n) for (int i=0;i<n;i++)

int main(){
    int N;
    cin >> N;
    int H[N];
    rep(i,N) cin >> H[i];
    int max=0;
    rep(i,N){
        if(H[i]>max) max=H[i];
        if(max-H[i]>=2){
            puts("No");
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3456
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}
int n;
typedef pair<int, int>p;
vector<vector<p>>G;
vector<int>dist;
queue<int>que;

void dfs(int v) {
	dist[v] = 0;
	que.push(v);
	while (!que.empty()) {
		int next = que.front();
		que.pop();
		int d = dist[next];
		rep(i, G[next].size()) {
			int pi = G[next][i].first;
			int di = G[next][i].second;
			if (dist[pi] != -1)continue;
			dist[pi] = (d + di)%2;
			que.push(pi);
		}
	}
}


signed main(void) {
	cin >> n;
	G.resize(n);
	dist.resize(n);
	rep(i, n) {
		dist[i] = -1;
	}
	rep(i, n - 1) {
		int u, v, w;
		cin >> u >> v >> w;
		u--;
		v--;
		w = w % 2;
		G[u].pb(make_pair(v, w));
		G[v].pb(make_pair(u, w));
	}
	dfs(0);
	rep(i, n) {
		println(dist[i]);
	}
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

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

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int l[26];
int r[26];

void solve(long long N, std::string S){
    l[S[0]-'a']++;
    REP1(i, N) {
        r[S[i]-'a']++;
    }

    int ans = 0;
    REP1(i, N) {
        int tmp = 0;
        REP(j, 26) {
            tmp += (l[j] > 0 && r[j] > 0);
        }

        ans = max(ans, tmp);
        l[S[i]-'a']++;
        r[S[i]-'a']--;
    }

    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


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

#define int long long
int n, a, b;

signed main(){
    cin >> n >> a >> b;
    if((b - a) % 2){
        int tmp1 = (b - a - 1) / 2 + a;
        int tmp2 = (b - a - 1) / 2 + (n - b) + 1;
        cout << min(tmp1, tmp2);
    }
    else cout << (b - a) / 2;
}

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

using namespace std;

typedef vector<int> vi;

#define PB push_back

const int inf = 1e9;

int dp[1000000], dp_odd[1000000];

int main()
{
	vi tet;

	for (int i = 1; ; ++i) {
		tet.PB(i * (i + 1) * (i + 2) / 6);
		if (tet.back() > 1000000) break;
	}

	for (int i = 1; i < 1000000; ++i) dp[i] = dp_odd[i] = inf;

	for (int i = 0; i < tet.size(); ++i) {
		for (int j = tet[i]; j < 1000000; ++j) {
			dp[j] = min(dp[j], dp[j - tet[i]] + 1);
			if (tet[i] & 1) {
				dp_odd[j] = min(dp_odd[j], dp_odd[j - tet[i]] + 1);
			}
			if (j < tet[i]) break;
		}
	}

	int N;
	while (scanf("%d", &N), N) printf("%d %d\n", dp[N], dp_odd[N]);
}

Measured memory_bytes: 8864
/**
 * Created by hiramekun at 01:55 on 2020-05-07.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    string s;
    cin >> s;
    ll q;
    cin >> q;

    deque<char> que(all(s));
    bool rev = false;
    while (q--) {
        ll t;
        cin >> t;
        if (t == 1) {
            rev = !rev;
        } else {
            ll f;
            char c;
            cin >> f >> c;
            if (rev) f = 3 - f;
            if (f == 1) {
                que.push_front(c);
            } else {
                que.push_back(c);
            }
        }
    }
    string ans = string(all(que));
    if (rev) reverse(all(ans));
    cout << ans << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<tuple>
using namespace std;
int main(void){
    int N;
    cin >> N;
    vector<tuple<string,int,int>> a;

    for(int i = 1;i <= N;i++){
        string s;
        int p;
        cin >> s >> p;
        p = -p;
        a.push_back(tie(s,p,i));
    }
    sort(a.begin(),a.end());
    for(int i = 0;i < N;i++){
        cout << get<2>(a[i]) << endl;
    }
}

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

int main(){
    int n;
    cin>>n;
    vector<long long> z(n),w(n);
    for(int i=0;i<n;++i){
        long long x,y;
        cin>>x>>y;
        z[i]=x+y;
        w[i]=x-y;
    }
    sort(z.begin(),z.end());
    sort(w.begin(),w.end());
    long long res=max(z[n-1]-z[0],w[n-1]-w[0]);
    
    cout<<res<<endl;
}

Measured memory_bytes: 6440
#include<stdio.h>  
#include<math.h>
  
int main(void)
{  
	//入力変数
    int n = 0;  
	//素数判定flag
    bool isPrime = true;
	//素数カウント変数
    int count = 0;  
	//素数格納配列
    int prime[100000];  
	//ループの最高回数
	int imax = 0;
  
    while(scanf("%d", &n) != EOF) 
	{  
        count = 0;  
  
		//2は特別扱い
		if (n >= 2)
		{
	        prime[0] = 2;  
			count++;
		}

		//2の倍数はいらない
        for(int j = 3; j <= n; j += 2) 
		{  
			//素数かそうでないかの判断をするflag
			isPrime = true;  
  
			//平方根を求める
			imax = sqrt(double(j));

			//ここでエラトステネスのふるいで使った平方根の考え方を利用
            for(int i = 0; prime[i] <= imax; i++)
			{  
                if(j % prime[i] == 0)
				{  
                    isPrime = false;  
                    break;  
				}  
			}

			//素数だった場合
		    if(isPrime == true) 
			{  
				prime[count++] = j;  
			}  
		}  
  
		printf("%d\n", count);  
  
    }  
  
    return 0;  
}  

Measured memory_bytes: 1336
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll

int32_t main()
{
  #ifndef ONLINE_JUDGE
  freopen("in","r",stdin);
  freopen("out","w",stdout);
  #endif
  string s;
  cin>>s;
  int n=s.length();
  vector<int> ans(n,1);
  for(int i=0;i<n;i++)
  {
   // cout<<s.substr(i,2)<<" ";
    if(s.substr(i,2)=="RR")
    {

      ans[i+2]+=ans[i];ans[i]=0;
    }
  }
  for(int i=n-1;i>=0;i--)
  {
    if(s[i]=='L' and s[i-1]=='L')
    {
      ans[i-2]+=ans[i];ans[i]=0;

    }
  }

  for(auto i:ans)cout<<i<<" ";

  

  

}

Measured memory_bytes: 4312
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main() {
	int n, h[20], c = 1, a = 0;
	cin >> n;
	for (int i = 0; i < n; ++i)cin >> h[i];
	for (int i = 1; i < n; ++i) {
		for (int j = 0; j < i; ++j) {
			if (h[j] > h[i]) {
				a = 1;
				break;
			}
		}
		if (a == 0)c = c + 1;
		a = 0;
	}
	cout << c << endl;

}

Measured memory_bytes: 256
#include <stdio.h>

int N;
int x, y, z;

int min(int a, int b) {
    if(a <= b) {
        return a;
    } else {
        return b;
    }
}

int max(int a, int b) {
    if(a >= b) {
        return a;
    } else {
        return b;
    }
}

int main() {
    scanf("%d", &N);

    for(int i = 0; i < N; ++i) {
        scanf("%d %d %d", &x, &y, &z);
        int a = min(x, min(y, z));
        int c = max(x, max(y, z));
        int b = (x + y + z) - (a + c);

        if(a*a + b*b == c*c) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }
}


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

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int happy = 0;
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    if (x - a[i] < 0) break;
    if (i == n - 1 && x - a[i] != 0) break;
      x -= a[i];
      happy++;
  }
  cout << happy;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200005,M=200005,inf=0x3f3f3f3f;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int n,m,cnt,S,T,ans,a[N],b[N],bela[N],belb[N];
int fir[N],firr[N],siz;
struct edge{int u,v,w,nex;}e[M*2];
void add(int u,int v,int w){
	e[++siz]=(edge){u,v,w,fir[u]};fir[u]=siz;
	e[++siz]=(edge){v,u,0,fir[v]};fir[v]=siz;
}
int dist[N],que[N];
void dec(int x,int fl){e[x].w-=fl;e[x^1].w+=fl;}
bool bfs(int S,int T){
	memset(dist,0x3f,4*(cnt+1));
	int l=1,r=1;que[l]=S;dist[S]=0;
	while (l<=r){
		int x=que[l];
		for (int i=fir[x];i;i=e[i].nex)
		if ((e[i].w)&&(dist[e[i].v]>dist[x]+1)){
			que[++r]=e[i].v;
			dist[e[i].v]=dist[x]+1;
		}
		l++;
	}
	return dist[T]!=inf;
}
int dfs(int x,int flow){
	if (x==T) return flow;
	int fl=0,t=0;
	for (int i=firr[x];i;i=e[i].nex)
	if (e[i].w&&(dist[e[i].v]>dist[x])){
		assert(dist[e[i].v]==dist[x]+1);
		t=dfs(e[i].v,min(flow-fl,e[i].w));
		dec(i,t);fl+=t;
		if (fl==flow) {firr[x]=i;return fl;}
	}
	firr[x]=0;
	return fl;
}
int dinic(){
	int flow=0;
	while (bfs(S,T)){
		for (int i=0;i<=cnt;i++) firr[i]=fir[i];
		flow+=dfs(S,inf);
		//cerr<<flow<<endl;
	}
	return flow;
}
int main(){
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	siz=1;
	n=read();
	for (int i=1;i<=n;i++) a[i]=read()+1;
	for (int i=1;i<=n;i++) b[i]=read()+1;
	for (int i=1;i<=n;i++)
	if ((a[i]!=i)&&(!bela[i])){
		cnt++;int x=i;
		while (!bela[x]){bela[x]=cnt;x=a[x];}
	}
	for (int i=1;i<=n;i++)
	if ((b[i]!=i)&&(!belb[i])){
		cnt++;int x=i;
		while (!belb[x]){belb[x]=cnt;x=b[x];}
	}
	S=0;T=cnt+1;cnt++;ans=n;
	for (int i=1;i<=n;i++)
	if (bela[i]&&belb[i]) {
		add(bela[i],belb[i],1);
		if (a[i]==b[i]) add(belb[i],bela[i],1);
	}
	else if (bela[i]) add(bela[i],T,1);
	else if (belb[i]) add(S,belb[i],1);
	else ans--;
	ans-=dinic();
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 15616
DELTA = { 'N'=>[0, 1],
          'E'=>[1, 0],
          'S'=>[0, -1],
          'W'=>[-1, 0] }

loop{
  # ???????????´???
  n = readline.to_i
  exit if n == 0

  jewel_map = Array.new(21){ Array.new(21, 0) }
  n.times{
    x, y = readline.split.map(&:to_i)
    jewel_map[y][x] = 1
  }

  # pp jewel_map

  # ??????????????????
  jewel_count = n
  m = readline.to_i
  rx, ry = [10, 10]
  m.times{
    d, l = readline.split
    l.to_i.times{
      rx += DELTA[d][0]
      ry += DELTA[d][1]
      if jewel_map[ry][rx] == 1
        jewel_count -= 1
        jewel_map[ry][rx] = 0
      end
    }
  }
  if jewel_count == 0
    puts "Yes"
  else
    puts "No"
  end
}

Measured memory_bytes: 9060
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
char str[30005];
int main() {
	int n;
	scanf("%d%s", &n, str);
	vector<int> dp(10), dp2(100), dp3(1000);
	for (int i = 0; i < n; ++i) {
		int d = str[i] - '0';
		for (int j = 0; j < 100; ++j) {
			dp3[j * 10 + d] |= dp2[j];
		}
		for (int j = 0; j < 10; ++j) {
			dp2[j * 10 + d] |= dp[j];
		}
		dp[d] |= 1;
	}
	printf("%d\n", accumulate(dp3.begin(), dp3.end(), 0));
}


Measured memory_bytes: 256
// abc163_a
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  int r;
  cin>>r;
  cout<<PI*2*r<<endl;
  return 0;
}


Measured memory_bytes: 3736
h, w = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
    print(0)
else:
    ans = min(w, h)
    for w1 in range(w//3, w//3+3):
        s1 = w1 * h
        w2 = w-w1
        for h1 in range(h//2, h//2+2):
            s2 = w2 * h1
            s3 = w2 * (h-h1)
            ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
    h, w = w, h
    for w1 in range(w//3, w//3+3):
        s1 = w1 * h
        w2 = w-w1
        for h1 in range(h//2, h//2+2):
            s2 = w2 * h1
            s3 = w2 * (h-h1)
            ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
    print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

const lint mod = 1e9 + 7;
lint emod(lint a) { return (a % mod + mod) % mod; }

lint powm(lint a, lint n) { return n ? powm(a * a % mod, n >> 1) * (n & 1 ? a : 1) % mod : 1; }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  lint m, n; cin >> m >> n;
  cout << emod(powm(m, n)) << '\n'; 
}


Measured memory_bytes: 3228
#include <iostream>
#include <vector>
using namespace std;
typedef int64_t int64;
#define print(x) cout << (x) << '\n'
 
int main(){
 int n, k; cin >> n >> k;
 int64 a[n];
 for (int i = 0; i < n; ++i) cin >> a[i];
 
 int64 s[n]; s[0] = a[0];
 for (int i = 1; i < n; ++i) s[i] = s[i - 1] + a[i];
 vector<int64> v;
 
 for (int i = 0; i < n; ++i) v.push_back(s[i]);
 for (int i = 0; i < n; ++i){
   for (int j = i + 1; j < n; ++j) v.push_back(s[j] - s[i]);
 }
 
 int64 ans = 0;
 for (int bit = 38; bit >= 0; --bit){
   int64 p = ((int64)1<<bit);
   int cnt = 0;
   
   for (int i = 0; i < (int) v.size(); ++i){
     if (((ans + p) & v[i]) == ans + p) ++cnt;
   }
   if (cnt >= k) ans += p;
 }
 print(ans);
 
 return 0;
}

Measured memory_bytes: 6512
class Solver:

    def __init__(self):
        pass

    def solve(self, a, b, c):
        n1 = b // a
        return min(n1, c)

if __name__ == '__main__':

    solver = Solver()

    a, b, c = map(int, input().split())

    n = solver.solve(a, b, c)
    print(n)


Measured memory_bytes: 2940
# -*- coding: utf-8 -*-
import numpy as np

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
for i in range(n):
    if a[i] == b[i]:
        ans += a[i]
    elif a[i] <= b[i]:
        ans += a[i]
        m = b[i]-a[i]
        if a[i+1] >= m:
            a[i+1] -= m
            ans += m
        else:
            ans += a[i+1]
            a[i+1] = 0
    else:
        ans += b[i]

print(ans)

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

int main() {
	ll A,V,B,W,T;cin>>A>>V>>B>>W>>T;
  	if(V<=W) cout << "NO" <<endl;
  	else{
      if((V-W)*T>=abs(A-B)) cout << "YES" << endl;
      else cout << "NO" << endl;
    }
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
 
using namespace std;


int main(int argc, char* argv[])
{
    int n,K; ll S;
    scanf("%d%d%lld", &n, &K, &S);
    ll mm=1000000000;
    int i;
    if(S<mm) {
        for(i=0; i<K; i++) {
            printf("%lld ", S);
        }
        for(i=K; i<n; i++) {
            printf("%lld ", S+1);
        }
        printf("\n");
    }
    else {
        for(i=0; i<n-K; i++) {
            printf("%lld ", (ll)1);
        }
        for(i=n-K; i<n; i++) {
            printf("%lld ", S);
        }
        printf("\n");
    }


    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
using namespace std;
 
#define N 2
void InsertionSort(int* a, int n, int g);
void ShellSort(int* a, int n);
 
int a[1000005];
int cnt = 0;
 
int main(void){
    int n;
    cin >> n;
 
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
 
    ShellSort(a, n);
 
 
    cout << cnt << endl;
 
    for(int i=0; i<n; i++){
        printf("%d\n", a[i]);
    }
 
    return 0;
}
 
void InsertionSort(int* a, int n, int g){
    for(int i=g; i<n; i++){
        int v = a[i];
        int j = i - g;
        while(j >= 0 && a[j] > v){
            a[j+g] = a[j];
            j = j - g;
            cnt++;
        }
        a[j+g] = v;
    }
}
 
void ShellSort(int* a, int n){
    int g[100001];
    g[0] = 1;
    int i=0;
    while(g[i] <= n && i<100){
        g[i+1] = g[i] * 3 + 1;
        i++;
    }
    int m = i;
    for(int i=m-1; i>=0; i--){
        InsertionSort(a, n, g[i]);
    }
 
    cout << m << endl;
    for(int i=m-1; i>0; i--){
        printf("%d ", g[i]);
    }
    printf("%d\n", g[0]);
}

Measured memory_bytes: 5104
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//またはかかつか
//例外処理は最初にする
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll M = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1)) % M;
}

int main() {
	ll N; cin >> N;
	vector<ll> a(N); rep(i, N) cin >> a[i];

	sort(ALL(a));
	ll ans = 1e14;
	for (int x = a[0]; x <= a[N - 1]; x++) {
		ll sum = 0;
		for (int i = 0; i < N; i++) sum += pow(x - a[i], 2);
		ans = min(ans, sum);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_end().to_owned()
}

fn main() {
    let (a, b, c, d) = read!(usize, usize, usize, usize);
    let mut takahasi = a / d;
    if a % d != 0 {
        takahasi += 1;
    }
    let mut aoki = c / b;
    if c % b != 0 {
        aoki += 1;
    }

    if takahasi >= aoki {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2112
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static long Mod = (long)1e9 + 7;
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }
        static void Solve()
        {
            //満点解法2
            var a = Sarray()[0];
            var b = Sarray()[0];
            var h = Sarray()[0];
            WriteLine((a + b) * h / 2);
        }
    }
}

Measured memory_bytes: 27900
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;


int n, a, b, c, d, tmp1, tmp2, tmp3, tmp4;

int main(){

	cin >> n >> a >> b >> c >> d;

	while (n > tmp1) {
		tmp2 += b;
		tmp1 += a;
	}
	while (n > tmp3) {
		tmp4 += d;
		tmp3 += c;
	}
	cout << min(tmp4, tmp2) << endl;



	return 0;
}


Measured memory_bytes: 3112
import numpy as np
import functools
import math
import scipy
import fractions
import itertools

def solve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    hoge, huga = 0, 0
    piyo = 10**9+7
    for i in range(n-1):
        for j in range(i, n):
            if a[i] > a[j]:
                hoge += 1
    hoge *= k
    for i in range(n):
        for j in range(n):
            if i != j:
                if a[i] > a[j]:
                    huga += 1
    huga *= (k*(k-1))//2
    print((hoge+huga)%piyo)
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 14176
N,M = map(int, input().split())
L = [[int(x) for x in input().split()] for _ in range(M)]
P = [int(p) for p in input().split()]


ans = 0
for i in range(2**N, 2**(N+1)):
    b = bin(i)
    temp = [0]*M
    for j in range(3, N+3):
        if b[j] == "1":
            for k in range(M):
                switch = L[k][1:]
                if j-2 in switch:
                    temp[k] += 1
    jud = 0
    for j in range(M):
        if temp[j]%2 != P[j]:
            jud = 1
    if jud == 0:
        ans += 1
        
print(ans)

Measured memory_bytes: 3188
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while(true){
			int h = Integer.parseInt(br.readLine());

			if(h == 0){
				break;
			}

			int matrix[][] = new int[h][5];

			for(int i = h - 1; i >= 0; i--){
				String[] tmpArray = br.readLine().split(" ");
				for(int j = 0; j < 5; j++){
					matrix[i][j] = Integer.parseInt(tmpArray[j]);
				}
			}

			System.out.println(solve(matrix));
		}
	}

	static int solve(int[][] matrix){
		int score = 0;
		int h = matrix.length;
		while(true){
			if(matrix[0][0] == 0 && matrix[0][1] == 0 && matrix[0][2] == 0 && matrix[0][3] == 0 && matrix[0][4] == 0 ){
				break;
			}

			int tmpScore = 0;
			for(int i = 0; i < h; i++){
				int left = 0;
				int right = 0;
				for(int j = 0; j <= 2; j++){
					left = j;
					right = j;
					for(int k = j + 1; k < 5; k++){
						if(matrix[i][k] == matrix[i][j]){
							right = k;
						}
						else {
							break;
						}
					}
					//連鎖成立
					if(right - left >= 2){
						break;
					}
				}

				//連鎖処理
				if(right - left >= 2){
					for(int j = left; j <= right ; j++){
						tmpScore += matrix[i][j];
						matrix[i][j] = 0;
					}
				}

			}

//			System.out.println("befor");
//			show(matrix);
			//ドロップ処理
			if(h != 1){

				for(int j = 0; j < 5; j++){
					int target = 0;
					for(int k = 0; k < h; k++){
						if(matrix[k][j] != 0){
							matrix[target][j] = matrix[k][j];
//							System.out.println("k = "+k+" target = "+target);
							target++;
						}
					}

					for(int k = target; k < h ; k++){
						matrix[k][j] = 0;
					}
				}
			}

//			System.out.println("after");
//			show(matrix);
			if(tmpScore == 0){
				break;
			}
			else {
				score += tmpScore;
			}
		}

		return score;
	}

	//for debug
	static void show (int[][] matrix){
		for(int i = matrix.length - 1; i >= 0; i--){
			for(int j = 0; j < 5; j++){
				System.out.print(matrix[i][j] + " ");
			}
			System.out.println();
		}
		System.out.println();
	}

}



Measured memory_bytes: 32108
import java.util.*;

class Main {
   public static void main(String[] args)
   {
      Scanner       scan = new Scanner(System.in);
      String        sca  = scan.next();
      int           X    = Integer.parseInt(sca);
      StringBuilder str  = new StringBuilder(sca);
      int           Fx   = 0;

      int[] a = new int[str.length()];
      for(int i = 0; i < str.length(); i++){
          a[i] = Integer.parseInt("" + str.charAt(i));
          Fx  += a[i];
          }
      if(X % Fx == 0){
         System.out.println("Yes");
         }
      else{
          System.out.println("No");
          }
   }
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll n; cin >> n;

    cout << n * (n-1) / 2 << endl;
}

Measured memory_bytes: 256
import java.io.InputStream
import java.io.PrintStream
import java.util.*

class Abc083B(
    val input: InputStream,
    val output: PrintStream
) {
    fun proc() {
        val sc = Scanner(input)
        val n = sc.nextInt() // 10,000
        val a = sc.nextInt() // 1 <= a <= 36
        val b = sc.nextInt()

        var sum = 0
        for (i in 1..n) {
            val input = i.toString().toCharArray().map { it.toString().toInt() }
            val subSum = input.sum()
            if (subSum in a..b) {
                sum += i
            }
        }
        output.print(sum)
    }
}

fun main(args: Array<String>) {
    Abc083B(System.`in`, System.out).proc()
}


Measured memory_bytes: 35488
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  string s[100000];
  long long mm=0;
  long long aa=0;
  long long rr=0;
  long long cc=0;
  long long hh=0;
  for(int i=0;i<n;i++){
    cin >> s[i];
    if(s[i][0]=='M'){
      mm++;
    } else if (s[i][0]=='A'){
      aa++;
    } else if (s[i][0]=='R'){
      rr++;
    } else if (s[i][0]=='C'){
      cc++;
    } else if (s[i][0]=='H'){
      hh++;
    }
  }
  long long ans = 0;
  if(mm!=0&&aa!=0&&rr!=0){
    ans = ans+mm*aa*rr;
  }
  if(mm!=0&&aa!=0&&cc!=0){
    ans = ans+mm*aa*cc;
  }
  if(mm!=0&&aa!=0&&hh!=0){
    ans = ans+mm*aa*hh;
  }
  if(mm!=0&&rr!=0&&cc!=0){
    ans = ans+mm*rr*cc;
  }
  if(mm!=0&&rr!=0&&hh!=0){
    ans = ans+mm*rr*hh;
  }
  if(mm!=0&&cc!=0&&hh!=0){
    ans = ans+mm*cc*hh;
  }
  if(aa!=0&&rr!=0&&cc!=0){
    ans = ans+aa*rr*cc;
  }
  if(aa!=0&&rr!=0&&hh!=0){
    ans = ans+aa*hh*rr;
  }
  if(aa!=0&&cc!=0&&hh!=0){
    ans = ans+cc*aa*hh;
  }
  if(rr!=0&&cc!=0&&hh!=0){
    ans = ans+hh*cc*rr;
  }
  cout << ans << endl;
}


Measured memory_bytes: 6144
import sys
n, m = map(int, input().split())

min_id = 1
max_id = n
for i in range(m):
    l, r = map(int, input().split())

    if min_id < l <= max_id:
        min_id = l
    elif max_id < l:
        print(0)
        sys.exit()

    if min_id <= r < max_id:
        max_id = r
    elif r < min_id:
        print(0)
        sys.exit()

print(max_id - min_id + 1)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,x,min=1001;
	cin>>n>>x;
	int m[n];
	for(int i=0;i<n;i++){
		cin>>m[i];
		x-=m[i];
		if(min>m[i])min=m[i];
		//cout<<"x:"<<x<<endl;
	}
	int res=n;
	//cout<<x<<endl;
	//cout<<"res:"<<res<<endl;
	//cout<<"min:"<<min<<endl;
	res+=(x/min);
	//cout<<x/min<<endl;
	cout<<res<<endl;
}


Measured memory_bytes: 256
import java.io.{BufferedReader, InputStream, InputStreamReader}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}

object Main {
  val MOD = 1000000007
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N = sc.nextInt()
    val ans = if (N < 1000) "ABC" else "ABD"

    println(ans)
  }


  def main(args: Array[String]): Unit = {
    solve()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }
}


Measured memory_bytes: 25388
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

ll N, M, K;
ll A[200010], B[200010];

signed main(){
    cin >> N >> M >> K;
    REP(i, N) cin >> A[i];
    REP(i, M) cin >> B[i];
    ll T = 0;
    ll a = 0, b = 0;
    while(T <= K && a < N){
        if(T + A[a] > K) break;
        T += A[a];
        a++;
    }
    while(T <= K && b < M){
        if(T + B[b] > K) break;
        T += B[b];
        b++;
    }
    ll ans = a + b;
    // cerr << a << " " << b << endl;
    while(a > 0 && b < M){
        a--;
        T -= A[a];
        while(T + B[b] <= K && b < M){
            T += B[b];
            b++;
        }
        ans = max(ans, a + b);
    }
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 6756
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int a,b,k;

int main()
{
	cin>>a>>b>>k;
	if(k*2>=b-a+1) for(int i=a;i<=b;i++) cout<<i<<endl;
	else
	{
		for(int i=a;i<=a+k-1;i++) cout<<i<<endl;
		for(int i=b-k+1;i<=b;i++) cout<<i<<endl; 
	}
	rt0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N,M;
vector<int> A;
void input(){
    fast_io();
    cin >> N >> M;
    for (size_t i = 0; i < M; i++)
    {
        int a; cin >> a;
        A.push_back(a);
    }
    
}

int solve(){
    const ll mod =1e9+7;
    ll dp[100010];
    bool used[100010];
    memset(dp,0,sizeof(dp));
    memset(used,true,sizeof(used));
    for (size_t i = 0; i < M; i++) used[A[i]] = false;
    
    dp[0] = 1LL;
    for (size_t i = 0; i < N; i++)
    {
        if(used[i+1] && i+1<=N) {dp[i+1] += dp[i]; dp[i+1]%=mod;}
        if(used[i+2] && i+2<=N) {dp[i+2] += dp[i]; dp[i+2]%=mod;}
    }
    cout << dp[N] << endl;
    
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 1656
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

const MOD = 10^^9 + 7;

void naive(long k, int[] a) {
    int[] b;
    for (int i = 0; i < k; i++) {
        for (int j = 0; j < a.length; j++) {
            b ~= a[j];
        }
    }

    long ans = 0;
    for (int i = 0; i < b.length; i++) {
        for (int j = i + 1; j < b.length; j++) {
            if (b[i] > b[j]) {
                ans++;
                ans %= MOD;
            }
        }
    }
    writeln("ans ", ans);
}

long calc(long k, int[] a) {
    long ans = 0;
    for (int i = 0; i < a.length; i++) {
        long left = 0;
        long right = 0;
        for (int j = i + 1; j < a.length; j++) {
            if (a[i] > a[j]) right++;
        }
        for (int j = i - 1; j >= 0; j--) {
            if (a[i] > a[j]) left++;
        }

        long t = (k * (k + 1) / 2) % MOD;
        long x = right * t % MOD;
        x += left * (((k - 1) * k) / 2 % MOD) % MOD;
        ans = (ans + x) % MOD;
    }
    return ans;
}

void main() {
    int n, k; scan(n, k);
    auto a = readints;
    writeln(calc(k, a));
}


Measured memory_bytes: 380
using System;
using System.Linq;

namespace CDivideTheProblems
{
    class Program
    {
        static void Main(string[] args)
        {
            // 入力の取得
            var n = int.Parse(Console.ReadLine());
            var difficulties = Console.ReadLine().Split().Select(int.Parse).ToArray();

            Array.Sort(difficulties);
            var left = difficulties[n / 2 - 1];
            var right = difficulties[n / 2];
            var answer = right - left;

            // 解答の出力
            Console.WriteLine(answer);
        }
    }
}


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

int main() {
    int N, K;
    cin >> N >> K;
    int hist[N] = {0};
    int A;
    for (int i = 0; i < N; i++) {
        cin >> A;
        hist[A - 1]++;
    }
    sort(hist, hist + N);
    int l = 0;
    for (int i = 0; i < K; i++) {
        l += hist[N - 1 - i];
    }
    cout << N - l << endl;
}

Measured memory_bytes: 4308
#include <stdio.h> 
#include <stdlib.h> 
#include <limits.h> 
#include <bits/stdc++.h> 
using namespace std;
 
int dpminCost(int a[], int n, int k){
  int d[n];
  d[0]=0;
  d[1]=abs(a[1]-a[0]);
  int m= min(n,k);
  
  for(int i=2;i<m;i++){
  	int min_cost = INT_MAX;
  	for(int j=1;j<i+1 ;j++){
  		if(min_cost>abs(a[i-j]-a[i])+d[i-j]){
  			min_cost = abs(a[i-j]-a[i])+d[i-j];
  		}
  	}
      d[i]=min_cost;
  }
  
  for(int i=k;i<n;i++){
  	int min_cost = INT_MAX;
  	for(int j=1;j<=k;j++){
  		if(min_cost>abs(a[i-j]-a[i])+d[i-j]){
  			min_cost = abs(a[i-j]-a[i])+d[i-j];
  		}
  	}
      d[i]=min_cost;
  }
  
  return d[n-1];
}
 
int main(){
  int n;
  int k;
  cin>>n;
  cin>>k;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  cout<<dpminCost(a,n,k);
  return 0;
}







Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int K = sc.nextInt();
		int X = sc.nextInt();

		int start = X - (K - 1);
		int end   = X + (K - 1);

		for (int i=start; i<=end; i++){
			if (i > start){
				System.out.print(" ");
			}
			System.out.print(i);
		}

	}
}

Measured memory_bytes: 23760
#include <iostream>
using namespace std;
int main () {
    char a, b, c;
    cin >> a >> b >> c;
    if (a=='1') a='9';
    else a='1';
    if (b=='1') b='9';
    else b='1';
    if (c=='1') c='9';
    else c='1';
    cout << a << b << c;
}

Measured memory_bytes: 3632
sx, sy, tx, ty=map(int, input().split())

dif_x=tx-sx
dif_y=ty-sy

cmd1 = 'R'*(dif_x) + 'U'*(dif_y)
cmd2 = 'L'*(dif_x) + 'D'*(dif_y)
cmd3 = 'D' + 'R'*(dif_x + 1) + 'U'*(dif_y+1) + 'L'
cmd4 = 'U' + 'L'*(dif_x + 1) + 'D'*(dif_y+1) + 'R'

ans = cmd1 + cmd2 + cmd3 + cmd4
print(ans)

Measured memory_bytes: 3060
a, b, k = [int(i) for i in input().split()]

if k < b-a+1:
    tmp1 = list(range(a, a+k))
    tmp2 = list(range(b-k+1, b+1))
    tmp1.extend(tmp2)
    tmp = sorted(list(set(tmp1)))
    
else:
    tmp = list(range(a, b+1))
    
for i in tmp:
    print(i)


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> primeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

int main() {
	ll n, m, x, y,ans=0;
	std::cin >> n >> m;
	vll b(n + 1, 1);
	vector<bool> a(n+1, false);
	a[1] = true;
	bool flg = false;

	rep(i, 0, m) {
		std::cin >> x >> y;
		b[x]--;
		b[y]++;
		if (a[x]==true) {
			a[y] = true;
			if (b[x] == 0) {
				a[x] = false;
			}
		}
	}

	repeq(i, 1, n) {
		if (a[i] && b[i]>0) {
			ans++;
		}
	}
	outn(ans);
	return 0;
}


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

using ll = long long;

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

   for (int a = 0; a <= 2000; a++) {
      for (int b = 0; b <= 2000; b++) {
         int c = N - a - b;
         int sum = 10000*a + 5000*b + 1000*c;
         if (c >= 0 && c <= N && sum == Y) {
            printf("%d %d %d\n", a, b, c);
            return 0;
         }
      }
   }
   printf("%d %d %d\n", -1, -1, -1);

   return 0;
}


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

#define N_MAX 200000
#define MODVAL 1000000007

int main(void){
	int n;
	int a[200000];
	int i,j;
	long long int ret = 0;
	int b[2000000] = {};
	int bias = 1000000;
	int diff;

	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(a[i]<=200000){
			diff = i - a[i] + bias;
			b[diff]++;
		}
	}

	if(a[0]<=200000){
		ret+=b[a[0]+bias];
	}

	for(i=1;i<n;i++){
		if(a[i]<=200000){
			ret+=(long long int)(b[a[i]+bias+i]);
		}
	}



	printf("%lld\n",ret);

	return 0;
}


Measured memory_bytes: 10324
/*
AizuOnline A0217
Title Walking in the Hospital
@kankichi573
*/
#include <stdio.h>
int n;

main()
{
        int i,pn,d1,d2,d,max_,max_pn;

        while(EOF!=scanf("%d",&n) && n)
        {
                max_pn=0;max_=0;
                for(i=0;i<n;i++)
                {
                        scanf("%d %d %d\n",&pn,&d1,&d2);
                        d=d1+d2;
                        if(d>max_)
                        {
                                max_ = d;
                                max_pn =pn;
                        }
                }
                printf("%d %d\n",max_pn,max_);
        }
        return(0);
}

Measured memory_bytes: 604
n,k = map(int,input().split())
dic = {}
for i in range(n):
  a,b = map(int,input().split())
  if a in dic:
  	dic[a] += b
  else:
    dic[a] = b

for i in range(1,100001):
  if i in dic:
    k -= dic[i]
    if k <= 0:
      print(i)
      break



Measured memory_bytes: 10472
#include <iostream>
using namespace std;
typedef long long ll;

ll em[4000];
int flag[4000];

int main(){
	int n;
	while(true){
		int id,p,q;
		cin >> n;
		if(!n) return 0;
		for(int i = 0; i < n; i++){
			cin>>id>>p>>q;
			em[id-1] += (ll)p * q;
			flag[i] = id;
		}
		int f = 1;
		for(int i = 0; i < n; i++){
			if(em[flag[i]-1] >= 1000000){
				cout << flag[i] << endl;
				f = 0;
			}
			em[flag[i]-1] = 0;
		}
		if(f) cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 60;

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

int digit(long long x) {
  int ret = 0;
  while (x != 0) {
    x /= 10;
    ++ret;
  }
  return ret;
}

int main() {
  long long n; cin>>n;
  int ans = INF;
  for (long long i = 1; i * i <= n; ++i) {
    long long b = n / i;
    if (i * b == n) {
      ans = min(ans, max(digit(i), digit(b)));
    }
  }
  print(ans);

  return 0;
}


Measured memory_bytes: 256