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

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define bit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  int N;
  cin >> N;
  vi H(N);
  for (int i=0; i<N; i++) {
    cin >> H[i];
  }

  vi mm(N);
  mm[0] = H[0];
  for (int i=1; i<N; i++) {
    mm[i] = max({mm[i-1], H[i]});
  }

  int ret = 0;
  for (int i=0; i<N; i++) {
    if (H[i] == mm[i]) ret++;
  }

  cout << ret << endl;


  return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptor/reversed.hpp>
namespace adaptor = boost::adaptors;
template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;
using graph_t = std::vector<std::map<std::size_t, std::int64_t>>;

void set_color(int i, int p, graph_t const& edge, std::vector<int>& color)
{
	color[i] = color[p] ^ (edge[i].at(p) % 2 != 0);
	for (auto q : edge[i])
	{
		if (q.first == p)
		{
			continue;
		}
		set_color(q.first, i, edge, color);
	}
}

void Main()
{
	int N;
	std::cin >> N;
	graph_t tree(N + 1);
	std::vector<int> color(N + 1);
	for (int i : boost::irange(0, N - 1))
	{
		std::size_t a, b;
		std::int64_t w;
		std::cin >> a >> b >> w;
		--a; --b;
		tree[a][b] = tree[b][a] = w;
	}
	tree[0][N] = tree[N][0] = 0;
	set_color(0, N, tree, color);
	for (int i : boost::irange(0, N))
	{
		std::cout << color[i] << std::endl;
	}
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 19840
h,w = map(int,input().split())
sl = [input() for _ in [0]*h]
l = []
for i in range(len(sl)):
  if sl[i].count('#') > 0:
    l.append(i)
sl = [sl[i] for i in l]
l = []
for j in range(len(sl[0])):
  flag = False
  for i in range(len(sl)):
    if sl[i][j] == '#':
      flag = True
  if flag == True:
    l.append(j)
for s in sl:
  s = [s[j] for j in l]
  print(''.join(s))

Measured memory_bytes: 3064
# D - Lucky PIN
import itertools

N = int(input())
S = str(input())

# 文字列Sから3文字選ぶ組み合わせを数え上げるとTLE
# 暗証番号の組み合わせが高々1,000通りしかないので、
# それごとに条件に該当するかをチェックしてカウントする。
ans = 0
for i, j, k in itertools.product(range(10),repeat=3):
    # i, j, kの組み合わせが起き得るか
    chk = str(i)+str(j)+str(k)
    p = S.find(chk[0])
    q = S.find(chk[1], p+1)
    r = S.find(chk[2], q+1)
    if p!=-1 and q!=-1 and r!=-1:
        ans += 1       
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>

using namespace std;
using ll = int64_t;

struct arc067_d{
  ll N, A, B;
  vector<ll> X;
  void init(){
    cin >> N >> A >> B;
    X.resize(N);
    for(auto&& x:X)cin >> x;
  }
  void solve(){
    init();
    ll ans = 0;
    for(int i=0;i<N-1;i++){
      ans += min((X[i+1] - X[i])*A, B); 
    }
    cout << ans << endl;
  }
};

int main(){
  arc067_d ins;
  ins.solve();
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

vector<ll> dup;
ll size,start,last;
vector<int> a(5);
int k;
int res = 0;

void dfs(ll i){
    if(i == size){
        if( abs(a[dup[0]]-a[dup[1]]) > k ) res = 1;
    }else{
        if(i == 0){
            for(int j=start;j<=last;j++){
                dup[i] = j;
                dfs(i+1);
            }
        }else{
            for(int j=dup[i-1];j<=last;j++){
                dup[i] = j;
                dfs(i+1);
            }
        }
    }
}



int main(){
    FIN;
    rep(i,0,5) cin >> a[i];
    cin >> k;

    size = 2; start = 0; last = 4;
    dup.resize(size);
    dfs(0);

    if(res == 0) cout <<"Yay!" << endl;
    else cout << ":(" << endl;
    return 0;
}



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

int main()
{
	double a,b,c,d,e,f;
	double x,y;
	while(cin >> a >> b >> c >> d >> e >> f)
	{
		double l = a*e-d*b;
		x=(c*e-b*f)/l+0;
		y=(a*f-c*d)/l+0;
		cout << fixed << setprecision(3)<< x << " " << y << endl;
	}
	return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>
#include <string.h>
int main()
{
	int n;
	char bur[4];
	char out[7] = {"ABC"};
	scanf("%d", &n);
	snprintf(bur, 4, "%d", n);
	strcat(out, bur);
	printf("%s", out);
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;

typedef pair<int, int> P;

int main() {
    string s;
    cin >> s;
    int m = 1000;
    for (int i = 0; i + 2 < s.length(); i++) {
        m = min(m, abs(753 - ((s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0'))));
    }
    cout << m << endl;
    return 0;
}


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

#define ll long long

#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define fill(a,b) memset(a,b,sizeof(a))

#define f first
#define s second
#define pb push_back

#define inf 1e17
#define ninf -1*1e17
#define mod 1000000007
#define N 500005
#define Ns 5005

string s;
ll n,m,o,x,y,z,d,k,l,r;
unsigned long long power(unsigned long long x, int y, int p)
{
   unsigned long long res = 1; // Initialize result
    x = x % p; // Update x if it is more than or
   // equal to p
    while (y > 0) {
       // If y is odd, multiply x with result
       if (y & 1)
           res = (res * x) % p;
        // y must be even now
       y = y >> 1; // y = y/2
       x = (x * x) % p;
   }
   return res;
}
 // Returns n^(-1) mod p
unsigned long long modInverse(unsigned long long n, int p)
{
   return power(n, p - 2, p);
}
ll ncr(ll n,ll r){
   if(n<r)
   return 0;
   if(n==r)
   return 1;
   ll ans=1;
  
   for(ll i=n;i>n-r;i--){
       ans=(ans*i)%mod;
   }
   for(ll i=2;i<=r;i++){
       //ans=(ans/i);
       ans=(ans*modInverse(i,mod))%mod;
   }
   return ans;
}




int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
	int t=1;
	//cin>>t;
	while(t--){
	    
	    ll ans=0;
	    cin>>n;
	    for(int r=1;r<n;r++){
	        int total=n-2*r;
	        if(total<0){
	            break;
	        }
	        ans=(ans+ncr(total-1,r-1))%mod;
	    }
	   
	    cout<<ans<<"\n";
	    
	    
	}
	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main()
{
int n,r,rev=0,temp;
  cin>>n;
 temp=n;
 while(n>0)
{
 r=n%10;
 rev=(rev*10)+r;
 n=n/10;
}
if(temp==rev)
cout<<"Yes \n";
else
cout<<"No \n";
}


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

int main() {
  int N,M,C,cnt=0;
  cin>>N>>M>>C;
  vector<int> B(M);
  vector<vector<int>> data(N,vector<int>(M));
  rep(i,M){cin>>B[i];}
  rep(i,N){
    rep(j,M){
      cin>>data[i][j];
    }
  }
  rep(i,N){
    int s=0;
    rep(j,M){s+=data[i][j]*B[j];}
    if(s+C>0){cnt++;}
  }
  cout<<cnt<<endl;
}

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

using namespace std;

int main(){
    long long n;
    cin>>n;
    long long sum = 0;
    long long mn = 1e9;
    for(long long i=1;i<=n;i++){
        long long x;
        cin>>x;
        sum+=x;
        if(x%10!=0){
            mn = min(mn,x);
        }
    }
    if(sum%10){
        cout<<sum<<endl;
    }else{
        if(mn == 1e9){
            cout<<0<<endl;
        }else{
            cout<<sum-mn<<endl;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <map>

using namespace std;

int main() {
    int n, w[100000];
    cin >> n;
    for (int i = 0; i < n; i++) { cin >> w[i]; }

    int min = 10000000;
    for (int k = 0; k < n-1; k++) {
        int s1 = 0;
        int s2 = 0;
        for (int i = 0; i <= k; i++) {
            s1 += w[i];
        }
        for (int i = k+1; i < n; i++) {
            s2 += w[i];
        }
        int sub = (s1 - s2 > 0) ? s1 - s2 : s2 - s1;
        if (min > sub) { min = sub; }
    }
    cout << min << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    ll K;
    cin >> K;

    ll N = 50;
    ll n = (K - 1) / N;
    ll h = (N - (K % N));
    if (K % N == 0) h = 0;

    cout << 50 << endl;
    if (K == 0) {
        rep(i, N - 1) {
            cout << 49 << " ";
        }
        cout << 49 << endl;
    }
    else {
        rep(i, N) {
            ll o = N + n + h;
            if (K % N != 0 && i >= K % N) o -= N + 1;
            if (i < N - 1) cout << o << " ";
            else cout << o << endl;
        }
    }

    return 0;
}

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

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++) {
        cin >> p[i];
    }
    int ans = 0;
    for(int i = 1; i < n-1; i++) {
        if(p[i-1] < p[i] && p[i] < p[i+1]) {
            ans++;
        } else if(p[i-1] > p[i] && p[i] > p[i+1]) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> a(2*N);
    vector<long long> ans(2*N);
    for(int i=0; i<M; i++){
	cin >> a[i];
    }
    int tmp=0;
    ans[0]=1;
	
    if(a[tmp] ==1){
	ans[1]=0;
	tmp ++;
    }
    else
	ans[1]=1;
	
	
    for(int i=0; i<N; i++){
    	if(a[tmp]==i+2){
    	    ans[i+2]=0;
    	    tmp++;
    	}
    	else{
	    ans[i+2]=ans[i]+ans[i+1];
	    ans[i+2] %= 1000000007;	    
	}	    
    }


    cout << ans[N]<<endl;

}


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

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

  int n, m;
  cin >> n >> m;
  wi a(n, vi(m));
  vi b(m), c(n);
  rep(i, n)rep(j, m)cin >> a[i][j];
  rep(i, m)cin >> b[i];

  rep(i, n){
    int sum=0;
    rep(j, m){
      sum+=a[i][j]*b[j];
    }
    c[i]=sum;
  }

  rep(i, n)cout << c[i] << endl;

  return 0;
}


Measured memory_bytes: 3192
#include<cstdio>
#include<iostream>
#include<vector>
#include<cmath>

using namespace std;

int main(){
	
	while(1)
	{
		int n;
		cin>>n;
		
		if(n==0)break;
		
		int t = 1000 - n;
		
		int a[] = {500, 100, 50, 10, 5, 1};
		int cnt = 0;
		for(int i=0;i<6;i++){
			while(1){
				if(t < a[i])break;
				t -= a[i];
				cnt++;
			}
		}
		
		cout<<cnt<<endl;
	}
	
	
}

Measured memory_bytes: 1160
S = list(input())

if S[0]!="A":
    print("WA")
    exit()

if S[2:len(S)-1].count("C")!=1:
    print("WA")
    exit()

count = 0
for i in range(0,len(S),1):
    if ord(S[i])<95:
        count+=1

if count !=2:
    print("WA")
    exit()

print("AC")

Measured memory_bytes: 8876
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
long mod=1e9+7,B,W;
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
long fac[2<<17],inv[2<<17];
long C(long a,long b){
	return fac[a]*inv[a-b]%mod*inv[b]%mod;
}
main()
{
	cin>>B>>W;
	fac[0]=inv[0]=1;
	for(int i=1;i<2<<17;i++)fac[i]=fac[i-1]*i%mod;
	inv[(2<<17)-1]=power(fac[(2<<17)-1],mod-2);
	for(int i=(2<<17)-1;--i;)inv[i]=inv[i+1]*(i+1)%mod;
	long I=inv[2];
	cout<<I<<endl;
	long L=0,R=0;
	long p=1;
	for(int i=1;i<B+W;i++)
	{
		p=p*2%mod;
		if(i>=B)
		{
			L=L*2-(i>B)*C(i-1,i-1-B)+C(i,i-B);
			L=(L%mod+mod)%mod;
		}
		if(i>=W)
		{
			R=R*2-(i>W)*C(i-1,i-1-W)+C(i,i-W);
			R=(R%mod+mod)%mod;
		}
		long ret=(p-L+R+mod)%mod*I%mod*power(p,mod-2)%mod;
		cout<<ret<<endl;
	}
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
#define ALL(a) (a).begin(), (a).end()
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int dy8[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dx8[] = {0, 1, 0, -1, 1, 1, -1, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

unsigned GetDigit(unsigned num) { return to_string(num).length(); }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//素因数分解
vector<ll> decom;

void decompositPrime(ll n)
{
    ll a = 2;
    while (n >= a * a)
    {
        if (n % a == 0)
        {
            decom.push_back(a);
            n /= a;
        }
        else
        {
            a++;
        }
    }
    decom.push_back(n);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{

    int N,K; cin >> N >> K;
    vector<int> p(N);
    REP(i,N) cin >> p[i];

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

    ll ans=0;
    REP(i,K){
        ans += p[i];
    }
    
    cout << ans << endl;

    return 0;
}


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

int main(){
    int n;
    cin >> n;
    int c[n][n];
    for(int i = 0; i < n*n; i++)    cin >> c[i/n][i%n];
    ll ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            ans += min(c[i][j], c[j][i]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3108
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>

using namespace std;
typedef long long int ll;

#define repi(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(int i=a-1;i>=0;i--)

int* arrmax(int arr1[], int arr2[]){
  rrep(i, 10){
    if(arr1[i] > arr2[i]) return(arr1);
    if(arr1[i] < arr2[i]) return(arr2);
  }
  return arr1;
}

void arrcpy(int* dst, int* src){
  rep(i, 10) dst[i] = src[i];
}

int main(){
  int N, M;
  scanf("%d %d", &N, &M);
  int cost[] = {-2,-5,-5,-4,-5,-6,-3,-7,-6};
  int a;
  rep(i, M){
    cin >> a;
    cost[a-1] *= -1;
  }

  int dp[N+7][10] = {};
  rep(i, N){
    if(dp[i][9] == 0 && i > 0) continue;
    rep(a, 9){
      if(cost[a] < 0) continue;
      int arr[10];
      arrcpy(arr, dp[i]);
      arr[9]++;
      arr[a]++;
      rrep(b, 10){
        if(arr[b] > dp[i+cost[a]][b]){
          arrcpy(dp[i+cost[a]], arr);
          break;
        }else if(arr[b] < dp[i+cost[a]][b]){
          break;
        }
      }
    }
  }
  rrep(a, 9){
    rrep(i, dp[N][a]) cout << (a+1);
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
long ans,a,b,c;
main()
{
	cin>>a>>b>>c;
	if(c>=b)ans+=b*2,c-=b,b=0;
	else ans+=c*2,b-=c,c=0;
	if(c>a)ans+=a+1;
	else ans+=c;
	cout<<ans+b<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<climits>
using namespace std;
int main(){
  int x,y,z,i,j,k;
  cin >> x >> y >> z >> k;
  vector<long int>a(x);
  vector<long int>b(y);
  vector<long int>c(z);
  vector<long int>fsum(x*y);
  vector<long int>ssum(k*z);
  for(i=0;i<x;i++){
    cin >> a.at(i);
  }
  for(i=0;i<y;i++){
    cin >> b.at(i);
  }
  for(i=0;i<z;i++){
    cin >> c.at(i);
  }
  for(i=0;i<x;i++){
    for(j=0;j<y;j++) fsum.at(y*i+j)=a.at(i)+b.at(j);
  }
  sort(fsum.begin(),fsum.end());
  reverse(fsum.begin(),fsum.end());
  for(i=0;i<min(x*y,k);i++){
    for(j=0;j<z;j++) ssum.at(z*i+j)=fsum.at(i)+c.at(j);
  }
  sort(ssum.begin(),ssum.end());
  reverse(ssum.begin(),ssum.end());
  for(i=0;i<k;i++){
    cout << ssum.at(i) << endl;
  }
}

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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; i++){
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  int alice=0, bob=0;
  for(int i=0; i<N; i++){
    if(i%2==0)
      alice+=a.at(i);
    else
      bob+=a.at(i);
  }
  cout << alice-bob << endl;
}

Measured memory_bytes: 256
// D - Banned K
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int A[200000+1], C[200000+1];

int main(){
	int N; cin>>N;
	long long all = 0;
	rp(i, 0, N){
		scanf("%d",A+i);
		all += C[A[i]];//パスカルの三角形より
		C[A[i]]++;
	}
	rp(k, 0, N) printf("%lld\n",all - C[A[k]] + 1);
}

Measured memory_bytes: 3712
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>

    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    using namespace std;
    
    int main(){
      int n;
      cin>>n;
      if(n%2 == 1){
        cout<<0<<endl;
        return 0;
      }
      VEC(int,d,n);
      sort(d.begin(),d.end());
      int ans = d[n/2]-d[n/2-1];
      
      cout<<ans<<endl;
    }


Measured memory_bytes: 640
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

using namespace std;

bool ans = false;
int length,e_loc[501],e_index = 0;
int memo[500][500];

char buf[501];

bool recursive(int left,int right){
    if(ans)return true;
    if(buf[left] != 'm' || buf[right] != 'w')return false;

    bool FLG = false;
    for(int i = 0; i < e_index; i++){
        if(left < e_loc[i] && right > e_loc[i]){ //m??¨w???????????????e???????´¢
            FLG = true;
            if(((e_loc[i] == left+1) || memo[left+1][e_loc[i]-1] == 1 || (memo[left+1][e_loc[i]-1] != 99 && recursive(left+1,e_loc[i]-1) == true)) && //m??¨e???????????????????????????????????????????????????true
             ((e_loc[i] == right-1) || memo[e_loc[i]+1][right-1] == 1 || (memo[e_loc[i]+1][right-1] != 99 &&recursive(e_loc[i]+1,right-1)) == true)){ //e??¨w???????????????????????????????????????????????????true
                if(left == 0 && right == length-1){ //?????????????????°
                	ans = true;
                }
                memo[left][right] = 1;
                return true;
            }
        }
    }
    memo[left][right] = 99; //false??§???????????¨????¨????
    return false; //??£???????????°???????????§??§true????????£???????????????????????§false?????????
}


int main(){

    scanf("%s",buf);

    for(length = 0;buf[length] != '\0';length++){
        if(buf[length] == 'e'){
            e_loc[e_index++] = length;
        }
    }

    for(int i = 0; i < length; i++){
    	for(int k = 0; k < length; k++)memo[i][k] = -1;
    }

    recursive(0,length-1);
    if(ans){
        printf("Cat\n");
    }else{
        printf("Rabbit\n");
    }

    return 0;
}

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int x;cin>>x;
    if(x>=30){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i,n) cin >> p[i];

    sort(p.begin(), p.end());
    int ans = 0;
    rep(i, k){
        ans+=p[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
main = interact $ unlines . map (show' . intersection_of_rect . map (read::String->Float) . words) . lines
 where show' p = case p of {True -> "YES"; False -> "NO"}
 
intersection_of_rect [xa1, ya1, xa2, ya2, xb1, yb1, xb2, yb2] =
 intersection_of_line xa1 xa2 xb1 xb2 && intersection_of_line ya1 ya2 yb1 yb2
  where
   intersection_of_line a1 a2 b1 b2
    | a2 >= b1 && a1 <= b2 = True
    | otherwise = False

Measured memory_bytes: 4308
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1LL<<60;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  int N,M;
  cin >> N >> M;
  vector<vector<int>> G(N);
  vector<P> id(M);
  for(int i=0; i<M; i++){
    int P,Y;
    cin >> P >> Y;
    P--;
    G[P].push_back(Y);
    id[i] = make_pair(P,Y);
  }
  for(int i=0; i<N; i++){
    sort(G[i].begin(),G[i].end());
  }
  for(int i=0; i<M; i++){
    id[i].second = lower_bound(G[id[i].first].begin(),G[id[i].first].end(),id[i].second) - G[id[i].first].begin();
  }
  for(int i=0; i<M; i++){
    cout << setfill('0') << right << setw(6) << id[i].first+1;
    cout << setfill('0') << right << setw(6) << id[i].second+1 << endl;
  }
  return 0;
}


Measured memory_bytes: 7808
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * AtCoder Beginner Contest 130<br>
 * B - Bounding<br>
 * <br>
 * https://atcoder.jp/contests/abc130/tasks/abc130_b<br>
 */
public class Main {

    public static void main(String[] args) {

        // 入力
        InputValues value = input(System.in);

        // 計算
        int result = calc(value);

        // 出力
        System.out.println(result);
    }

    private static InputValues input(InputStream in) {
        InputValues inputs = new InputValues();

        try (Scanner sc = new Scanner(System.in)) {
            String[] input1 = sc.nextLine().split(" ");
            String[] input2 = sc.nextLine().split(" ");

            inputs.N = Integer.parseInt(input1[0]);
            inputs.X = Integer.parseInt(input1[1]);

            for (String str : input2) {
                inputs.list.add(Integer.parseInt(str));
            }
        }
        return inputs;
    }

    private static int calc(InputValues inputs) {
        int ans = 0;
        int count = 1;
        for (int i = 0; i < inputs.N; i++) {
            ans = ans + inputs.list.get(i);
            if (inputs.X < ans) {
                break;
            }
            count++;
        }
        return count;
    }

    private static class InputValues {
        int N;
        int X;
        List<Integer> list = new ArrayList<Integer>();
    }
}


Measured memory_bytes: 21972
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

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

const ll MOD = ll(1e9) + 7;
const ll INF = LLONG_MAX;
const ll MAX_N = 1 << 20;
const double EPS = 10e-8;
const double PI = 3.14159265359;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

ll n;
P dat[2 * MAX_N - 1];

void init(ll n_) {
    n = 1;
    while (n < n_) {
        n *= 2;
    }
    REP(i, 2 * n - 1) dat[i] = {-INF, -INF};
    REP(i, n_) {
        ll k = i + n - 1;
        dat[k] = {0, i};
    }
}

P comp(P d1, P d2) {
    if (d1.first > d2.first) {
        return d1;
    } else if (d1.first < d2.first) {
        return d2;
    } else {
        return min(d1, d2);
    }
}

void update(ll k, ll a) {
    k += n - 1;
    dat[k].first += a;
    while (k > 0) {
        k = (k - 1) / 2;
        dat[k] = comp(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
}

P query(ll a, ll b, ll k, ll l, ll r) {
    if (r <= a || b <= l) 
        return {-INF, -INF};
    if (a <= l && r <= b)
        return dat[k];
    else {
        P vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
        P vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return comp(vl, vr);
    }
}

int main() {
    ll N, Q;
    cin >> N >> Q;
    init(N);
    REP(i, Q) {
        ll ai, vi;
        cin >> ai >> vi;
        ai--;
        update(ai, vi);
        P ans = query(0, N, 0, 0, n);
        cout << ans.second + 1 << " " << ans.first << endl;
    }

    return 0;
}



Measured memory_bytes: 35864
#include <bits/stdc++.h>
using namespace std ;
 
int main() {
  
 int n ; 
 cin >> n;  
 long long sum = 0 ; 

 for ( int i = 1 ; i <= n ; i ++ ) {
	 if( i % 3 ==  0 || i%5 == 0 )
	 continue ; 
		else
		sum+= i ;
	
 }
 cout << sum << endl;  
  
}
  



Measured memory_bytes: 3632
parseInt(x) = parse(Int, x)
parseArray(x::Array{SubString{String}, 1}) = map(parseInt, x)

function main()
  n = readline() |> parseInt

  m = 10_000_000
  a = collect(1:m)
  f = zeros(Int, m)
  for i in 1:m
    for j in 1:m
      i * j > m && break
      f[i * j] += 1
    end
  end

  ans = map(1:n) do i
    i * f[i]
  end |> sum

  println(ans)
end

main()


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


int main() {
  vector<int> a(100);
  vector<int> b(100);
  for(int i = 0 ; i<100;i++){
    cin >> a.at(i);
    cin >> b.at(i);
    if( a.at(i)==0){
      break;
    }
    for(int j = 0 ; j< a.at(i) ; j++){
      for(int k = 0 ; k< b.at(i) ; k++){
        cout << "#" ;
      }
      cout << endl;
    }
    cout << endl;
  }
}
    


Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
const double PI = acos(-1);
const long long INF = (1 << 30);
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

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

  ll n;
  cin >> n;
  vector<ll> a(n+1);
  vector<ll> ans(n+2, 0);
  for(ll i = 2; i <= n; i++){
    cin >> a[i];
    ans[a[i]]++;
  }
  for(ll i = 1; i <= n; i++){
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 6368
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;
typedef pair<int, int> p_ii;


int main() {
	int i, n, x;
	cin >> n >> x;
	vector<ll>a(n), mn(n);
	for (i = 0; i < n; i++) cin >> a[i];
	mn = a;
	ll ans = INF * INF;
	for (int rotate = 0; rotate < n; rotate++) {
		ll tmp = (ll)rotate * x;
		for (i = 0; i < n; i++) {
			mn[i] = min(mn[i], a[(i - rotate + n) % n]);
			tmp += mn[i];
		}
		ans = min(ans, tmp);
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
MAX_X = 100000

a = [True] * MAX_X
a[0] = a[1] = False

for (i, isprime) in enumerate(a):
    if isprime:
        for n in range(i*i, MAX_X, i):
            a[n] = False

pre = [0, 0]

for i in range(3, MAX_X + 1, 2):
    if a[i] and a[(i + 1) // 2]:
        pre.append(pre[-1] + 1)
    else:
        pre.append(pre[-1])

q = int(input())

for i in range(q):
    l, r = [int(i) for i in input().split()]
    print(pre[(r + 1) // 2] - pre[(l + 1) // 2 - 1])


Measured memory_bytes: 4756
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int n,x;
	cin>>n>>x;
	if(x==1||x==2*n-1){
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	if(x<=n){
		for(int i=n;i>0;i--)if(x!=i)printf("%d\n",i);
		printf("%d\n",x);
		rep(i,n-1)printf("%d\n",n+i+1);
	}else{
		loop(i,n,2*n)if(x!=i)printf("%d\n",i);
		printf("%d\n",x);
		for(int i=n-1;i>0;i--)printf("%d\n",i);
	}
}








Measured memory_bytes: 1536
package main

import "fmt"

func main() {
	var Card [9]int
	for i := 0; i < 9; i++ {
		Card[i] = readInt()
	}

	N := readInt()
	for i := 0; i < N; i++ {
		b := readInt()
		for i, v := range Card {
			if b == v {
				Card[i] = -1
			}
		}
	}

	for i := 0; i < 3; i++ {
		//縦
		if Card[i] == -1 && Card[i+3] == -1 && Card[i+6] == -1 {
			goto Bingo
		}

		//横
		if Card[i*3] == -1 && Card[i*3+1] == -1 && Card[i*3+2] == -1 {
			goto Bingo
		}
	}

	//斜め
	if Card[0] == -1 && Card[4] == -1 && Card[8] == -1 {
		goto Bingo
	}

	if Card[2] == -1 && Card[4] == -1 && Card[6] == -1 {
		goto Bingo
	}

	fmt.Println("No")
	return

Bingo:
	fmt.Println("Yes")
	return
}

func readInt() int {
	var v int
	fmt.Scan(&v)
	return v
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder N = new StringBuilder(sc.nextLine());
        sc.close();

        String[] match = { "dream", "dreamer", "erase", "eraser" };

        boolean next = true;
        int length = N.length();
        while (next && length > 0) {
            next = false;
            for (int i = 0; i < match.length; i++) {
                int lastIndex = N.lastIndexOf(match[i]);
                if (lastIndex>=0 && lastIndex + match[i].length() == length) {
                    N.setLength(length - match[i].length());
                    next = true;
                    length = N.length();
                    break;
                }
            }
        }
        if (next) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 27580
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define REP_AB(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define REP_IN(i, n, x) for (ll i = 0; i < n; i++)in>>x;
#define REP_OUT(i, n, x) for (ll i = 0; i < n; i++)out<<x<<endl;
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
#define endl '\n'
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
// template end
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N;
    in >> N;
    //vector<ll> X(N);

    out << N/2 + N%2 << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int A, B;
    cin >> A >> B;

    for(double i=1;i<=1000;i++){   // i : 税抜き価格
        if(int(i*0.08) == A && int(i*0.1) == B){
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;

}

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

vector<int> square;
int n;

int f(int s, int b, int i) {
  int r = s == n;
  if (i < 4 && s + square[b] <= n) {
    for (int j = b; j < square.size(); j++) {
      r += f(s + square[j], j, i + 1);
    }
  }
  return r;
}

int main() {
  for (int i = 1; i * i < 1 << 15; i++) {
    square.push_back(i * i);
  }
  while (cin >> n, n) {
    cout << f(0, 0, 0) << endl;
  }
}



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

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

#define mem(a, b) memset(a, b, sizeof(a))
#define MOD 1000000007
#define MAX (int) 1e9
#define PI 3.141592653589793238462643383279502884

template <typename T, typename U>
T max(T x, U y) {
    return x > y ? x : y;
}

template <typename T, typename U>
T min(T x, U y) {
    return x < y ? x : y;
}

template<typename T>
void debug(string msg, T t) {
	cout << msg << ": " << t << "\n";
}

int toDigit(char c) { return c - '0'; }

int n, ans;
ll x, y, d;

int main() {

	cin >> n >> d;
	d *= d;

	for(int i = 0; i < n; i++) {
		cin >> x >> y;
		if((x * x) + (y * y) <= d) {
			ans++;
		}
	}

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

Measured memory_bytes: 3640
//20190619
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n,m,c;
    cin >> n >> m >> c;

    int count = 0;
    int b[m];
    int i,j;
    for(i = 0; i < m; i++){
        cin >> b[i];
    }

    int tmp;
    int total;
    for(i = 0; i<n; i++){
        total = 0;
        for(j = 0; j<m; j++){
            cin >> tmp;
            total += tmp * b[j];
        }
        if(total+c > 0) count++;
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

ll exp(ll b, ll e) {
    ll ans = 1LL;
    while (e) {
        if (e&1) ans = ans * b % MOD;
        e >>= 1;
        b = b*b % MOD;
    }
    return ans;
}

int main(void) {
    ll N, K;
    vector<ll> A(2010,0LL);
    cin >> N >> K;
    for (int i=0;i<N;i++) cin >> A[i];
    vector<ll> L(2010), R(2010);
    for (int i=0;i<N;i++) {
        L[i] = count_if(A.begin(), A.begin()+i, [&](ll x) { return x < A[i]; });
        R[i] = count_if(A.begin()+i+1, A.begin()+N, [&](ll x) { return x < A[i]; });
    }
    
    ll ans = 0;
    ll Ksum1 = K;
    Ksum1 = Ksum1 * (K+1) % MOD;
    Ksum1 = Ksum1 * exp(2LL,MOD-2) % MOD;
    ll Ksum2 = K;
    Ksum2 = Ksum2 * (K-1) % MOD;
    Ksum2 = Ksum2 * exp(2LL,MOD-2) % MOD;
    for (int i=0;i<N;i++) {
        ans = (ans + R[i] * Ksum1 % MOD) % MOD;
        ans = (ans + L[i] * Ksum2 % MOD) % MOD;
    }
#ifdef DEBUG
    cout << Ksum1 << endl;
    cout << Ksum2 << endl;
    for (int i=0;i<N;i++) cout << L[i] << " ";
    cout << endl;
    for (int i=0;i<N;i++) cout << R[i] << " ";
    cout << endl;
#endif
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define upperlimit 1000100
#define INF 1000000100
#define INFL 1000000000000000100LL
#define eps 1e-8
#define endl '\n'
#define sd(n) scanf("%d",&n)
#define slld(n) scanf("%lld",&n)
#define pd(n) printf("%d",n)
#define plld(n) printf("%lld",n)
#define pds(n) printf("%d ",n)
#define pllds(n) printf("%lld ",n)
#define pdn(n) printf("%d\n",n)
#define plldn(n) printf("%lld\n",n)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define pb push_back
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define F first
#define S second
#define clr(a) memset(a,0,sizeof(a))
#define FILEIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);

using namespace std;

ll gcd(ll n1,ll n2){
    if(!n1)return n2;
    if(!n2)return n1;
    if(n1%n2==0)return n2;
    return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent){
    base%=mod;
    ll ans=1;
    while(exponent){
        if(exponent&1)ans=(ans*base)%mod;
        base=(base*base)%mod;
        exponent/=2;
    }
    ans%=mod;
    return ans;
}
int arr[upperlimit+1];
int dp[upperlimit+1];
int main()
{
	int n,i,j,k,answer=0;
	sd(n);
	for(i=1;i<=n;i++){
		sd(arr[i]);
		dp[arr[i]]=max(dp[arr[i]],1+dp[arr[i]-1]);
		answer=max(answer,dp[arr[i]]);
	}
	answer=n-answer;
	pdn(answer);
	return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
#define re register 
#define ll long long
#define in inline
using namespace std;
inline ll read(){
	int t=0;
	char v=getchar();
	while(v<'0'||v>'9')v=getchar();
	while(v>='0'&&v<='9'){
		t=(t<<3)+(t<<1)+v-'0';
		v=getchar();
	}
	return t;
}
char s[100002];
ll n,m;
int main(){
	
	cin>>n;
	cin>>s;
	for(re ll i=1;i<strlen(s);++i){
		if(s[i]!=s[i-1])m++;
	}
	printf("%lld",m+1);
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (a < b) {
            if (b < c) {
                System.out.printf("%d %d %d\n", a, b, c);
            } else if (a < c) {
                System.out.printf("%d %d %d\n", a, c, b);
            } else {
                System.out.printf("%d %d %d\n", c, a, b);
            }
        } else {
            if (a < c) {
                System.out.printf("%d %d %d\n", b, a, c);
            } else if (b < c) {
                System.out.printf("%d %d %d\n", b, c, a);
            } else {
                System.out.printf("%d %d %d\n", c, b, a);
            }
        }
    }
}


Measured memory_bytes: 26424
n, k = map(int, input().split())
a = [i-1 for i in list(map(int, input().split()))]

l = []
used = [0 for _ in range(n)]

c = 0
flag = True
while 1:
    if not flag:
        l.append(c)
    if used[c] == 1 and l:
        break
    if not flag:
        used[c] = 1
    c = a[c]
    flag = False

p = 0
length = len(l)
b = []
for i in range(length):
    if l[i] == l[-1]:
        b = l[:i]
        l = l[i:-1]
        p = i
        break


if len(b) >= k:
    print(b[k - 1]+1)
else:
    print(l[(k - p - 1) % len(l)] + 1)


Measured memory_bytes: 122064
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;
template<class T>
T gcd(T x, T y) {
	return y ? gcd(y, x % y) : x;
}

template<class T>
vector<T> enum_div(T n) {
	vector<T> ret;
	for (T i = 1; i * i < n; ++i) {

		if (n % i == 0) {
			ret.push_back(i);

			if (i != 1 && i * i != n) {
				ret.push_back(n / i);
			}
		}
	}
	return ret;
}

template<class T>
map<T, int> prime_factorization(T n) {
	map<T, int> ret;

	for (long long i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}

	if (n != 1)ret[n] = 1;
	return ret;
}

template<class T>
long long C(T n, T r) {
	static map<pair<T, T>, long long> _map;
	if (n < r) return 0;

	if (n == r || r == 0) {
		_map[make_pair(n, r)] = 1ll;
	}
	else if (_map[make_pair(n, r)] == 0) {
		_map[make_pair(n, r)] = (C(n - 1, r) + C(n - 1, r - 1));
	}

	_map[make_pair(n, r)] %= MOD;
	return _map[make_pair(n, r)];
}

int main() {
	int N;
	long long minDiffN = 1ll << 60;
	long long length = 0;
	long long _length = 0;

	vector<long long> A;

	cin >> N;
	for (int i = 0; i < N; ++i) {
		long long a;
		cin >> a;
		A.push_back(a);
		length += a;
	}

	for (int i = 0; i < A.size(); ++i) {
		_length += A[i];
		length -= A[i];
		minDiffN = min(minDiffN, abs(length - _length));
	}

	cout << minDiffN << endl;
	

	return 0;
}

Measured memory_bytes: 2420