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

int main() {
  int N;
  cin >> N;
  vector<int> A(N + 1), B(N + 1), C(N + 1), D(N + 1);
  for (int i = 0; i < N + 1; i++) cin >> A.at(i);
  for (int i = 1; i < N + 1; i++) cin >> B.at(i);
  C.at(0) = 0;
  D.at(0) = 0;
  for (int i = 1; i < N + 1; i++) {
    C.at(i) = min(A.at(i - 1) - D.at(i - 1), B.at(i));
    D.at(i) = min(B.at(i) - C.at(i), A.at(i));
  }
  long long int ans = 0;
  for (int i = 1; i < N + 1; i++) {
    ans = ans + C.at(i) + D.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
import random
class Dice:
    def __init__(self,surfaceNum):
        self.surface = surfaceNum
        
    def east(self):
        self.surface[0], self.surface[2], self.surface[5], self.surface[3] = self.surface[3], self.surface[0], self.surface[2], self.surface[5]
    def west(self):
        self.surface[0], self.surface[2], self.surface[5], self.surface[3] = self.surface[2], self.surface[5], self.surface[3], self.surface[0]
    def south(self):
        self.surface[0], self.surface[1], self.surface[5], self.surface[4] = self.surface[4], self.surface[0], self.surface[1], self.surface[5]
    def north(self):
        self.surface[0], self.surface[1], self.surface[5], self.surface[4] = self.surface[1], self.surface[5], self.surface[4], self.surface[0]
        
    def printTopSurface(self):
        print(self.surface[0])  
    def printRight(self):
        print(self.surface[2])

surfaceNum1 = [int(i) for i in input().split()]
surfaceNum2 = [int(i) for i in input().split()]
rollCommandList = ["E", "W", "S", "N"]
dice1 = Dice(surfaceNum1)
dice2 = Dice(surfaceNum2)
counter = 0
    
while True:
    counter += 1
    rollCommand = random.choice(rollCommandList)
    if rollCommand == "E":
        dice2.east()
    if rollCommand == "W":
        dice2.west()
    if rollCommand == "S":
        dice2.south()
    if rollCommand == "N":
        dice2.north()
    if counter == 10000:
        print('No')
        break
        
    if dice1.surface == dice2.surface:
        print('Yes')
        break



Measured memory_bytes: 8192
def count_combinations(n, d):
    if d == 0:
        if n == 0:
            return 1
        else:
            return 0
    else:
        r = 0
        for i in range(0, 10):
            r += count_combinations(n - i, d - 1)
        return r

while True:
    try:
        n = input()
        print count_combinations(n, 4)
    except EOFError:
        break


Measured memory_bytes: 4644
#include<algorithm>
#include<stdio.h>
#include<iostream>
using namespace std;

int main(){
	int R[100],n;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> R[i];
	}
	int min;
	int swap = 0;
        int tmp;
	for (int i = 0; i < n; i++){
		min = i;
		for (int j = i; j < n; j++){
			if (R[j] < R[min])
				min = j;
		}
		if (i != min){
                        tmp=R[i];
                        R[i]=R[min];
                        R[min]=tmp;
			swap++;
		}
	}
	for (int i = 0; i < n; i++){
		if (i != 0)
			cout << " ";
		cout << R[i];
	}
	cout << endl;
	cout << swap << endl;

}

Measured memory_bytes: 3072
#include <vector>
#include <iostream>
#include <map>
#include <algorithm>
#include <random>
#include <complex>
#include <unordered_map>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <bitset>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const int MN = 501*1000*1000;

ll gcd(ll a, ll b) {
    if (!a) return b;
    return gcd(b%a, a);
}
ll ext_gcd(ll a, ll b, ll &x, ll &y) {
    ll d = a;
    if (b) {
        d = ext_gcd(b, a%b, y, x);
        y -= a / b*x;
    } else {
        x = 1;
        y = 0;
    }
    return d;
}

int w, d, n, m, t, u, h;
int x;
void init() {
    m = t-m%t;
    u = gcd(t, w+d), h = gcd(t, m);
    ll xx, y;
    ext_gcd(m, t, xx, y);
    x = ((xx % t) + t) % t;
}
int solve() {
    init();
    int res = 0, c = 0;
    int l = 0;

    int tt = t/2;
    int s = 0;
    int i, j;
    int th = t/h;
    for (i = 0; i < t; i += h) {
        if (s<n) {
            l = (l+u-1) /u*u;
            res += max(0, (i-l - w + u) / u);
            l = i+1;
        }
        s += x; s %= th;
    }
    l = (l+u-1) / u * u;
    res += max(0, (t-l-w+u)/u);
    return res;
}

int main() {
    cin >> w >> d >> n >> m >> t; w++; d--;
    printf("%.20f\n", 1.0 * solve() / (t / u));
    return 0;
}

Measured memory_bytes: 1176
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	a, b := io.NextInt(), io.NextInt()
	max := 1000
	lb := sort.Search(max+1, func(i int) bool { return i*8/100 >= a })
	ub := sort.Search(max+1, func(i int) bool { return i*8/100 > a })
	for i := lb; i < ub; i++ {
		if i*10/100 == b {
			io.Println(i)
			return
		}
	}
	io.Println(-1)
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 1776
#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  
  int max_cnt = 0;
  int cnt = 0;
  for (int i = 0; i < N; ++i) {
    int d1, d2;
    cin >> d1 >> d2;
    if (d1 == d2) {
      max_cnt = max(++cnt, max_cnt);
    } else {
      cnt = 0;
    }
  }
  
  if (max_cnt >= 3) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int ans;
    if(k<=a)ans = k;
    else if(k<=a+b)ans = a;
    else if(k<=a+b+c)ans = a-(k-a-b);
    else ans = a-c;
    cout << ans << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
using namespace std;
int n,ok,x,mx,k,cnt;
string str, v[200100];
map < string , int> ms;
int main()
{
    cin>>n;
    for(int i=1; i<=n; ++i)
    {
        cin>>str;
        cnt=1;
        if(ms.find(str)!=ms.end())
        {
            cnt=ms.find(str)->second;
            ms.erase(ms.find(str));
            ms.insert({str, ++cnt});
        }
        else ms.insert({str,1});
        if(cnt>mx)
            mx=cnt, v[k=1]=str;
        else if(cnt==mx)
            v[++k]=str;
    }

    sort(v+1,v+k+1);
    for(int i=1; i<=k; ++i)
        cout<<v[i]<<'\n';
    return 0;
}


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

#define int long long

signed main() {
  int T;
  cin >> T;

  while ( T-- ) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if ( a < b || d < b ) {
      cout << "No" << endl;
      continue;      
    }
    if ( b <= c ) {
      cout << "Yes" << endl;
      continue;
    }

    int g = __gcd(b, d);
    int e = b-g+(a%g);    
    if ( c < e ) cout << "No" << endl;
    else cout << "Yes" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
/*
Author: Babin Dutta
*/
 
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,n) for(int i=0;i<n;i++)
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define inf 1e18
#define mm 998244353
 
ll power(ll x, ll y, ll p)
{
    ll res = 1;  
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; 
        x = (x*x) % p;  
    }
    return res;
}
ll modInverse(ll A,ll M)
{
    return power(A,M-2,M);
}

void solve(){
	int n,k; cin>>n>>k;
	int a[n];
	f(i,n) cin>>a[i];
	int ans = 0;
	sort(a, a+n);
	f(i,k) ans += a[i];
	cout<<ans<<endl;
}
 
int main(){
	#ifdef JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    #endif
	boost;
	int t=1; //cin>>t;
	for(int i=1;i<=t;i++) solve();
	return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll H, W;
    cin >> H >> W;
    vector<string> S(H+2);
    S[0] = string(W+2, '#');
    S[H+1] = string(W+2, '#');
    REP(i,1,H+1) {
        string s;
        cin >> s;
        S[i] = "#" + s + "#";
    }

    mat D(H+2, vec(W+2, INF));
    queue<pll> Q;
    D[1][1] = 0;
    Q.push({1, 1});
    while(!Q.empty()) {
        pll v = Q.front(); Q.pop();
        REP(i,-1,2) {
            REP(j,-1,2) {
                if(i*j != 0 || (i == 0 && j == 0)) continue;
                ll h = v.first, w = v.second;
                if(S[h+i][w+j] == '.' && D[h+i][w+j] > D[h][w] + 1) {
                    D[h+i][w+j] = D[h][w] + 1;
                    Q.push({h+i, w+j});
                }
            }
        }
    }

    ll b = 1;
    REP(i,1,H+1) {
        REP(j,1,W+1) b += (S[i][j] == '#');
    }
    if(D[H][W] < INF) PR(H*W-b-D[H][W]);
    else PR(-1);

    return 0;
}

/*



*/

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        double[] values = new double[N];
        double sum = 0.0;

        for (int i = 0; i < N; i++) {
            values[i] = sc.nextDouble();
            if (sc.next().equals("BTC")) {
                values[i] *= 380000;
            }
        }

        for (int i = 0; i < N; i++) {
            sum += values[i];
        }

        System.out.println(sum);

    }

}





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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  while(a>0 && c>0){
    c -= b;
    a -= d;
  }
  if(c<=0) cout << "Yes" << endl;
  else  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 40;
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    int N,M; cin >> N >> M;
    vector<pair<ll,ll>> v(M);
    ll a, b, c;
    FOR(i,0,M){
        cin >> a >> b;
        v[i].first = a;
        v[i].second=0;
        FOR(j,0,b){
            cin >> c;
            c--;
            v[i].second = v[i].second | (1<<c);
        }
    }
    vector<ll> dp(1<<N);
    FOR(i,0,1<<N) dp[i]=INF;
    dp[0]=0;

    FOR(i,0,1<<N){
        if(dp[i]==INF)continue;
        else{
            FOR(j,0,M){
                dp[i|v[j].second]=min(dp[i|v[j].second],dp[i]+v[j].first);
            }
        }
        
    }
    if (dp[(1<<N)-1]==INF) cout << -1 << endl;
    else cout << dp[(1<<N)-1] << endl;
    return 0;

}

Measured memory_bytes: 256
N = int(input())
A = [[int(h) for h in input().split()]]
m = 0
while A != []:
    for i in range(len(A[0])):
        if A[0][i] == 0:
            if i == 0:
                if A[0] == [0]:
                    del A[0]
                else:
                    del A[0][0]
            elif i != 0 and i == len(A[0]) - 1:
                del A[0][i]
            else:
                A.append([A[0][j] for j in range(i)])
                A.append([A[0][j] for j in range(i + 1, len(A[0]))])
                del A[0]
            break
    else:
        m = m + 1
        A.append([A[0][i] - 1 for i in range(len(A[0]))])
        del A[0]
print(m)


Measured memory_bytes: 3064
#include <stdio.h>

int main(void) {

  int d;
  scanf("%d", &d);
  long c[26];
  for (int i = 0; i < 26; i++) {
    scanf("%ld", &c[i]);
  }
  long s[d][26];
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      scanf("%ld", &s[i][j]);
    }
  }
  int t[d];
  for (int i = 0; i < d; i++) {
    scanf("%d", &t[i]);
  }
  int last[26];
  for (int i = 0; i < 26; i++) {
    last[i] = -1;
  }
  long score = 0;
  for (int i = 0; i < d; i++) {
    score += s[i][t[i]-1];
    last[t[i]-1] = i;
    for (int j = 0; j < 26; j++) {
      if (j == t[i]-1) {
        continue;
      }
      score -= c[j]*(i-last[j]);
    }
  }
  int m,q_d,q_q;
  scanf("%d", &m);
  for (int que = 0; que < m; que++) {
    scanf("%d %d", &q_d, &q_q);
    t[q_d-1] = q_q;
    for (int i = 0; i < 26; i++) {
      last[i] = -1;
    }
    score = 0;
    for (int i = 0; i < d; i++) {
      score += s[i][t[i]-1];
      last[t[i]-1] = i;
      for (int j = 0; j < 26; j++) {
        if (j == t[i]-1) {
          continue;
        }
        score -= c[j]*(i-last[j]);
      }
    }
    printf("%ld\n", score);
  }

  return 0;
}

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


int main() {
    int N;
    cin >> N;
    vector<int> V(N);
    rep(i,N) {
        cin >> V[i];
    }
    int sum = 0;
    sort(V.begin(),V.end());
    rep(j,N-1) {
        sum += V[j];
    }
    if (sum > V[N - 1]) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    
}


Measured memory_bytes: 3620
n,m=map(int,input().split())
lrd=[tuple(map(int,input().split())) for i in range(m)]

class WeightedUnionFind:
  def __init__(self,n):
    self.parent = [i for i in range(n)]
    self.rank = [0] * n
    self.count = 0
    self.weight = [0] * n
  def root(self,a):
    if self.parent[a] == a:
      return a
    else:
      pa = self.root(self.parent[a])
      self.weight[a] += self.weight[self.parent[a]]
      self.parent[a] = pa
      return pa
  def is_same(self,a,b):
    return self.root(a) == self.root(b)
  def unite(self,a,b,w):
    ra = self.root(a)
    rb = self.root(b)
    if ra == rb: return
    if self.rank[ra] < self.rank[rb]:
      self.parent[ra] = rb
      self.weight[ra] = w - self.weight[a] + self.weight[b]
    else:
      self.parent[rb] = ra
      self.weight[rb] = -w - self.weight[b] + self.weight[a]
      if self.rank[ra] == self.rank[rb]: self.rank[ra] += 1
    self.count += 1
  def diff(self,a,b):
    return self.weight[a] - self.weight[b]

uf=WeightedUnionFind(n)
for l,r,d in lrd:
  l,r=l-1,r-1
  if uf.is_same(l,r):
    if uf.diff(l,r)!=d:
      print('No')
      exit(0)
  else:
      uf.unite(l,r,d)
print('Yes')


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

int main(){
  ll a;
  cin >> a;
  ll A = sqrt(a);
  ll ans = a;
  for(int i = 1;i<= A;i++){
    if(a%i == 0){
      ans = min(ans,a/i + i -2);
    }
  }
  cout << ans << endl;
}

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

int main(){
	int a,b,c,f=0;
	
	scanf("%d%d%d",&a,&b,&c);
	if((a==1 && b==1 && c==0) || (a==0 && b==0 && c==1))f=1;
	printf("%s\n",(f==1)?"Open":"Close");
	
	return 0;
}

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

int main(){
	int m,f,r;
	while(true){
		cin>>m>>f>>r;
		if(m==-1&&f==-1&&r==-1)break;
		else if(m==-1||f==-1)cout<<"F"<<endl;
		else if(80<=m+f)cout<<"A"<<endl;
		else if(65<=m+f&&m+f<80)cout<<"B"<<endl;
		else if(50<=m+f&&m+f<65)cout<<"C"<<endl;
		else if(30<=m+f&&m+f<50){
			if(r<50)cout<<"D"<<endl;
			else cout<<"C"<<endl;
			}
		else if(m+f<30)cout<<"F"<<endl;
	}
	return 0;
}



Measured memory_bytes: 3000
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e9;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで


using namespace std;
int parent[200000];//親
int deep[200000];//木の深さ
int N;

void init(int n){
  for (int i = 0;i<n;i++){
    parent[i] = i;
    deep[i]= 0;
  }
}

//木の根を求める
int find(int x){
  if(parent[x] == x) return x;
  else {
    parent[x] = find(parent[x]);
    return parent[x];
  }
}

void unit(int x,int y){
  x = find(x);
  y = find(y);
  if(x==y) return;
  N --;
  if(deep[x]<deep[y]){
    parent[x] = y;
  }
  else{
    parent[y] = x;
    if(deep[x]==deep[y]) deep[x] ++;
  }
}

bool same(int x,int y){
  return find(x) == find(y);
}

signed main(){
  int n,m;
  cin >> n >> m;
  N = n;
  init(n);
  REP(i,m){
    int a1,a2,a3;
    cin >> a1 >> a2 >> a3;
    unit(a1-1,a2-1);
  }
  cout << N << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

bool binarySearch(std::vector<int> v,int key){
	int left = 0;
	int right = (int)v.size();
	
	while(left < right) {
		int mid = (left + right)/2;
		if(v[mid]==key){
			return true;
		}else if(key < v[mid]){
			right = mid;
		}else{
			left = mid + 1;
		}
	}
	return false;
}

int main() {
	int n; cin >> n;
	std::vector<int> v(n);
	for (int i = 0; i < n; ++i) cin >> v[i];
	
	int q; cin >> q;
	std::vector<int> t(q);
	for (int i = 0; i < q; ++i) cin >> t[i];

	int ans = 0;
	for (int i = 0; i < q; ++i)
	{
		if(binarySearch(v,t[i])) ans++;
	}

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


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

using namespace std;

#define int long long
int mod = 1e9 + 7;
int const maxn = 2e5 + 5;

inline int get_sum(int l, int r) {
    return r * (r + 1) / 2 - l * (l - 1) / 2;
}

main() {
#ifdef HOME
    //freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k, ans = 0;
    cin >> n >> k;
    for (int i = k; i <= n + 1; ++i) {
        ans = (ans + get_sum(n + 2 - i, n + 1) - get_sum(1, i) + 1) % mod;
    }
    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 3652
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0

from bisect import bisect_left
for i in range(N):
    for j in range(i+1, N):
        ab = L[i] + L[j]
        index = bisect_left(L, ab)
        num = index - j - 1
        ans += max(0, num)

print(ans)

Measured memory_bytes: 3188
import java.util.*;
class Main{
 public static void main(String args[])
 {
   Scanner sc=new Scanner(System.in);
   int x=sc.nextInt();
   int y=sc.nextInt();
   String ans="No";
   for(int i=0;i<=x;i++)
   {
     int c=x-i;
	if(2*i+4*c==y)
   {
     ans="Yes";
      break;
   }
   }
   System.out.println(ans);
 }
}


Measured memory_bytes: 35676
#include <stdio.h>

#define N 2000

int calc(int, int);

int n,A[N];

int main()
{
  int i;
  int q,mi[N];
  
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&A[i]);
    }

  scanf("%d",&q);
  for(i=0;i<q;i++)
    {
      scanf("%d",&mi[i]);
    }

  for(i=0;i<q;i++)
    {
      if(calc(0,mi[i]) == 1)printf("yes\n");
      else printf("no\n");
    }
  
  return 0;
}

int calc(int i,int m)
{
  if(m==0)return 1;
  if(i>=n)return 0;
  int res = calc(i+1,m)||calc(i+1,m-A[i]);
  return res;
}



Measured memory_bytes: 2104
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(ReadLine());
        var v = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        var evenV = v.Where((v, i) => i % 2 == 0).GroupBy(x => x).Select(g => (v: g.Key, c: g.Count())).OrderByDescending(x => x.c).ToArray();
        var oddV = v.Where((v, i) => i % 2 == 1).GroupBy(x => x).Select(g => (v: g.Key, c: g.Count())).OrderByDescending(x => x.c).ToArray();

        var ans = 0;

        if (evenV[0].v != oddV[0].v)
            ans = n - evenV[0].c - oddV[0].c;
        else if (1 < evenV.Length || 1 < oddV.Length)
            ans = Math.Min(
                (1 < evenV.Length) ? n - evenV[1].c - oddV[0].c : int.MaxValue,
                (1 < oddV.Length) ? n - evenV[0].c - oddV[1].c : int.MaxValue
            );
        else
            ans = n / 2;

        WriteLine(ans);
    }
}


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

int main() {
  string S, T;
  cin >> S ;
  cin >> T ;
  
  int count=0;
  for(int i=0;i<3;i++){
    if(S.at(i)==T.at(i)){
      count++;
    }
  }
  cout<< count<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include "atcoder/all"
#define rep(i,n)for(int i=0;i<(int)(n);i++)
using namespace std;
using namespace atcoder;
#define all(a) a.begin(),a.end()
typedef long long ll;
#define vi vector<ll>
typedef pair<ll,ll>P;
const ll inf=1ll<<61;
const ll mod=998244353;
ll pow10[200010];
ll _11[200010];
struct S{
	ll a;
	int digit;
};
S op(S l,S r){
	return S{(l.a+r.a*pow10[l.digit])%mod,l.digit+r.digit};
}
S e(){
	return S{0,0};
}

struct myseg{
	int n=1;
	vector<S>node;
	vector<int>lazy;
	vector<bool>lazyF;
	void init(int N){
		while(n<N)n*=2;
		node.resize(2*n);
		lazy.resize(2*n);
		lazyF.resize(2*n,false);
		for(int i=n-1;i<n+n;i++)node[i]={1,1};
		for(int i=n-2;i>=0;i--){
			node[i]=op(node[i*2+1],node[i*2+2]);
		}
	}
	void eval(int k,int l,int r){
		if(!lazyF[k])return;
		node[k]={lazy[k]*_11[node[k].digit-1]%mod,node[k].digit};
		if(k<n-1){
			for(int i=1;i<=2;i++)lazy[2*k+i]=lazy[k];
			for(int i=1;i<=2;i++)lazyF[2*k+i]=true;
		}
		lazyF[k]=false;
	}
	void upd(int a,int b,int x,int k,int l,int r){
		eval(k,l,r);
		if(r<=a||b<=l)return;
		if(a<=l&&r<=b){
			lazy[k]=x;
			lazyF[k]=true;
			eval(k,l,r);
			return;
		}
		upd(a,b,x,k*2+1,l,(l+r)/2);
		upd(a,b,x,k*2+2,(l+r)/2,r);
		node[k]=op(node[k*2+1],node[k*2+2]);
	}
	S calc(int a,int b,int k,int l,int r){
		eval(k,l,r);
		if(r<=a||b<=l)return e();
		if(a<=l&&r<=b)return node[k];
		S vl=calc(a,b,k*2+1,l,(l+r)/2);
		S vr=calc(a,b,k*2+2,(l+r)/2,r);
		return op(vl,vr);
	}
	void replace(int a,int b,int x){
		upd(a,b,x,0,0,n);
	}
	S get(int a,int b){
		return calc(a,b,0,0,n);
	}
};
myseg seg;
signed main(){
	pow10[0]=1;
	_11[0]=1;
	rep(i,200005){
		pow10[i+1]=pow10[i]*10%mod;
		_11[i+1]=(_11[i]+pow10[i+1])%mod;
	}
	int n,q;cin>>n>>q;
	seg.init(n);

	rep(i,q){
		int l,r,d;cin>>l>>r>>d;
		l=n-l;r=n-r;
		seg.replace(r,l+1,d);
		cout<<seg.get(0,n).a<<endl;
	}
}


Measured memory_bytes: 16776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define all(a) (a).begin(), (a).end()

ll N, M;
int main () {
  cin >> N >> M;

  ll ans = N * M;
  if(N == 1 && M == 1) {
  } else if (N == 1 || M == 1) {
    ans -= 2;
  } else {
    ans -= 2*N + 2*M - 4;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

const int N = 100005;

int i, n, h, curr, rs = 1, ans = 1e9;
pair<int, int> a[N];

int main() {
  scanf("%d %d", &n, &h);
  for(i = 1; i <= n; ++i) scanf("%d %d", &a[i].se, &a[i].fi);

  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);

  for(i = 1; i <= n; ++i) {
    curr += a[i].fi;
    if(curr >= h) ans = min(ans, i);
    swap(a[i].fi, a[i].se);
  }

  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);

  for(i = 2, curr = a[1].se; i <= n; ++i) if(a[1].fi < a[i].se) curr += a[i].se, ++rs;

  while(curr < h) curr += a[1].fi, ++rs;

  printf("%d\n", min(rs, ans));

  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#define N 100000

int partition(int,int);
int TW[N],n;

int main(){
  int i,q;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&TW[i]);
  }
  q=partition(0,n-1);

  for(i=0;i<n;i++){
    if(i)printf(" ");
    if(i==q)printf("[");
    printf("%d",TW[i]);
    if(i==q)printf("]");
  }
  printf("\n");

  return 0;
}

int partition(int p, int r){
  int x,i,j,t;
  x=TW[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(TW[j]<=x){
      i++;
      t=TW[i];TW[i]=TW[j];TW[j]=t;
    }
  }
  t=TW[i+1];TW[i+1]=TW[r];TW[r]=t;
  return i+1;
}



Measured memory_bytes: 2148
import sys
from collections import Counter
from collections import deque
import math
import bisect
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
grid=[[0]*10 for i in range(10)]
for i in range(1,n+1):
    a=int(str(i)[0])
    b=int(str(i)[-1])
    grid[a][b]+=1
ans=0
for i in range(10):
    for k in range(10):
        ans+=grid[i][k]*grid[k][i]
print(ans)

Measured memory_bytes: 3316
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int mod=1e9+7;
inline int addmod(int x)
{
	return x>=mod?x-mod:x;
} 
inline int submod(int x)
{
	return x<0?x+mod:x;
}
int fpow(int x,int y)
{
	int ans=1;
	while(y)
	{
		if(y&1) ans=1ll*ans*x%mod;
		x=1ll*x*x%mod;
		y/=2;
	}
	return ans;
}
struct edge
{
	int v,nxt;
}e[500005];
int n,a[100005],h[100005],t,vis[100005],ct,ct2;
int b[100005],bt,ans,sum,f[5005][5005],pw[100005],pn=1e5,fr[100005];
void add(int u,int v)
{
	e[++t].v=v;
	e[t].nxt=h[u];
	h[u]=t;
}
void dfs(int u)
{
	ct++;
	vis[u]=1;
	for(int i=h[u];i;i=e[i].nxt)
	{
		int v=e[i].v;
		ct2++;
		if(vis[v]) continue;
		dfs(v);
	}
}
int main()
{
	fr[0]=1;
	for(int i=1;i<=pn;i++)
		fr[i]=1ll*fr[i-1]*i%mod;
	scanf("%d",&n);
	pw[0]=1;
	for(int i=1;i<=pn;i++)
		pw[i]=1ll*pw[i-1]*(n-1)%mod;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]!=-1) add(i,a[i]),add(a[i],i);
		else sum++;
	}
	for(int i=1;i<=n;i++)
		if(!vis[i])
		{
			ct=ct2=0;
			dfs(i);
			ct2/=2;
			if(ct==ct2)
				ans=addmod(ans+pw[sum]);
			else b[++bt]=ct;
		}
	f[0][0]=1;
	for(int i=1;i<=bt;i++)
	{
	//	printf("i=%d,b=%d\n",i,b[i]);
		ans=addmod(ans+1ll*pw[sum-1]*(b[i]-1)%mod);
		for(int j=1;j<i;j++)
			ans=addmod(ans+1ll*pw[sum-j-1]*b[i]%mod*f[i-1][j]%mod*fr[j]%mod);
		f[i][0]=1;
		for(int j=1;j<=i;j++)
			f[i][j]=addmod(f[i-1][j]+1ll*b[i]*f[i-1][j-1]%mod);
	}
	//printf("%d\n",ans);
	ans=submod(1ll*pw[sum]*n%mod-ans);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 69308
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
y = []
for s, t in zip(x, x[1:]):
    y.append(t - s)
y.sort()
if n >= m:
    print(0)
else:
    print(sum(y[:-(n-m)]))


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

struct tree{
	int x,y;
	int num;
}tree[500000];
vector<int>ans;
bool cmpx(struct tree a , struct tree b){
	return a.x < b.x;
}

bool cmpy(struct tree a, struct tree b){
	return a.y < b.y;
}

void build(int begin,int end,int level){
	if(begin<end){
		if(!level)
			sort(tree+begin,tree+end,cmpx);
		else
			sort(tree+begin,tree+end,cmpy);
		int mid=(end+begin)/2;
		build(begin,mid,level^1);
		build(mid+1,end,level^1);
	}
}

void search(int begin ,int end, int sx , int tx ,int sy ,int ty ,int level ){
	if(begin<end){
		int mid=(end+begin)/2;
		if(!level){
			if(tree[mid].x>=sx&&tree[mid].x<=tx){
				if(tree[mid].y>=sy&&tree[mid].y<=ty)
					ans.push_back(tree[mid].num);
				search(begin,mid,sx,tx,sy,ty,level^1);
				search(mid+1,end,sx,tx,sy,ty,level^1);
			}
			else if(tx<tree[mid].x) search(begin,mid,sx,tx,sy,ty,level^1);
			else if(sx>tree[mid].x)	search(mid+1,end,sx,tx,sy,ty,level^1);
		}
		else{
			if(tree[mid].y>=sy&&tree[mid].y<=ty){
				if(tree[mid].x>=sx&&tree[mid].x<=tx)
					ans.push_back(tree[mid].num);
				search(begin,mid,sx,tx,sy,ty,level^1);
				search(mid+1,end,sx,tx,sy,ty,level^1);
			}
			else if(ty<tree[mid].y) search(begin,mid,sx,tx,sy,ty,level^1);
			else if(sy>tree[mid].y)	search(mid+1,end,sx,tx,sy,ty,level^1);
		}
	}
}

int main(){
	int n,p,x,y,sx,tx,sy,ty;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d %d",&x,&y);
		tree[i].x=x;
		tree[i].y=y;
		tree[i].num=i;
	}
	build(0,n,0);
	scanf("%d",&p);
	while(p--){
		scanf("%d %d %d %d",&sx,&tx,&sy,&ty);
		ans.clear();
		search(0,n,sx,tx,sy,ty,0);
		sort(ans.begin(),ans.end());
		for(int i=0;i<ans.size();i++)printf("%d\n",ans[i]);
		printf("\n");
	}
	
}


Measured memory_bytes: 8908
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    dic = {}
    for i in range(N):
        s = input().strip()
        if s in dic:
            dic[s] += 1
        else:
            dic[s] = 1
    
    dic = sorted(dic.items(), key=lambda x: (-x[1], x[0]))
    n = dic[0][1]
    for i in range(len(dic)):
        if dic[i][1] == n:
            print(dic[i][0])
        else:
            break


if __name__ == "__main__":
    main()

Measured memory_bytes: 57436
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

long data[100][100] = { 0 };
long N, D;

bool isOk(long i, long j) {
  long sq = 0;
  rep(d, D) {
    sq += (data[i][d] - data[j][d]) * (data[i][d] - data[j][d]);
  }
  for (long a = 0; a <= sq; a++) {
    if (a * a == sq) return true;
    if (a * a > sq) break;
  }
  return false;
}

void solve() {
  cin >> N >> D;
  rep (i, N) rep (j, D) {
    long x;
    cin >> x;
    data[i][j] = x;
  }
  long result = 0;
  for (long i = 0; i < N; i++) for (long j = i + 1; j < N; j++) {
    if (isOk(i, j)) result ++;
  }
  cout << result << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

void swap( int &a, int &b ){
	int tmp = a;
	a = b;
	b = tmp;
}

int main(){
	int a, b;
	while( cin >> a >> b, a||b ){
		if( a < b )
			swap(a,b);
		int c=0;
		for( ;b>0;c++ ){
			a = a%b;
			swap(a,b);
		}
		cout << a << " " << c << endl;
	}
	return 0;
}

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

using namespace std;

const int N = 4000 + 5;
int tree[N];
inline int lowbit (int u) { return u & (-u); }
inline void add (int u, int v)
{
	while (u <= N - 5)
		tree[u] += v,
		u += lowbit (u);
}
inline int query (int u)
{
	int res = 0;
	while (u)
		res += tree[u],
		u -= lowbit (u);
	return res;
}

int a[N], n;

int main ()
{
	scanf ("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf ("%d", &a[i]);
	sort (a + 1, a + n + 1);
	add (a[1] + a[2], 1);
	long long ans = 0;
	for (int i = 3; i <= n; ++i)
	{
		ans += query (N - 5) - query (a[i]);
		for (int j = 1; j < i; ++j)
			add (a[i] + a[j], 1);
	}
	printf ("%lld\n", ans);
	return 0;
}

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

using namespace std;

const int MAX_N = 100005;
const int MOD = 1000000007;

int n,dp[MAX_N][2];
vector<int> adjl[MAX_N];

int f(int i, int p, int c)
{
	if (dp[i][c]!=-1)
		return dp[i][c];
	int p0=1,p1=1;
	for (int g : adjl[i])
		if (g!=p)
		{
			p0=(p0*1LL*f(g,i,0))%MOD;
			p1=(p1*1LL*f(g,i,1))%MOD;
		}
	return dp[i][c]=(p0+(c==0?p1:0))%MOD;
}

int main()
{
	scanf("%d",&n);
	for (int i=1; i<n; i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		adjl[a].push_back(b);
		adjl[b].push_back(a);
	}
	for (int i=1; i<=n; i++)
		dp[i][0]=dp[i][1]=-1;
	printf("%d\n",f(1,0,0));
	return 0;
}


Measured memory_bytes: 13440
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const int INF = 100000000;

int main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    REP(i, n){
        cin >> a[i];
        b[i] = a[i];
    }
    sort(a.begin(), a.end());
    int tmp = a[n - 1];
    for(int i = n - 1; i >= 0; i--){
        if(a[i] != a[n - 1]){
            tmp = a[i];
            break;
        }
    }
    REP(i, n){
        if(b[i] != a[n - 1]){
            cout << a[n - 1] << endl;
        }else{
            if(tmp != a[n - 2]){
                cout << a[n - 1] << endl;
            }else{
                cout << tmp << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
    random_device seed_gen;
    mt19937_64 rnd(seed_gen());
    uniform_int_distribution<int> dist_d(0, 364), dist_q(0, 25);

    int d;
    cin >> d;
    vector<int> c(26);
    rep(i, 26)cin >> c[i];
    vector<vector<int>> s(d, vector<int>(26));
    rep(i, d)rep(j, 26)cin >> s[i][j];

    vector<int> t(d);
    rep(i, d){
        t[i] = dist_q(rnd);
    }

    int m = 1000000;

    vector<set<int>> last(26);
    rep(i, 26){
        last[i].insert(-1);
        last[i].insert(d);
    }
    rep(i, d)last[t[i]].insert(i);
    int sum = 0;
    rep(i, d){
        sum += s[i][t[i]];
        rep(j, 26){
            if(last[j].find(i) == last[j].end()){
                auto itr = lower_bound(last[j].begin(), last[j].end(), i);
                itr--;
                int day = i - *itr;
                sum -= c[j] * day;
            }
        }
    }
    int cnt = 0;
    while(true){
        int day = dist_d(rnd);
        int que = dist_q(rnd);
        int diff = 0;
        
        int cont;
        rep(j, 26){
            if(last[j].find(day) != last[j].end()){
                cont = j;
                break;
            }
        }
        diff += s[day][que] - s[day][cont];
        auto itr1 = last[cont].find(day);
        auto itr2 = lower_bound(last[que].begin(), last[que].end(), day);
        int x = *itr1;
        int y = *itr2;
        int dx = day - *(--itr1);
        int dy = day - *(--itr2);
        itr1++; itr1++;
        itr2++;
        diff -= c[cont] * dx * (*itr1 - day);
        diff += c[que] * dy * (*itr2 - day);
        if(diff > 0){
            last[cont].erase(day);
            last[que].insert(day);
            t[day] = que;
            sum += diff;
        }
        cnt++;
        end = chrono::system_clock::now();
        double time = static_cast<double>(chrono::duration_cast<chrono::milliseconds>(end - start).count());
        if(time > 1990)break;
    }
    
    rep(i, d){
        cout << t[i] + 1 << endl;
    }
    
    
}

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

using namespace std;

int main() {
    string str;
    cin >> str;
    const int len = str.length();

    int num = 0, max = 0;
    for (int i=0; i<len; i++) {
        const char chr = str[i];
        if (chr == 'A' || chr == 'T' || chr == 'G' || chr == 'C') 
            num++;
        else {
            if (num > max) max = num;
            num = 0;
        }
    }
    if (num > max) max = num;

    cout << max << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
int main(){
    ll n,a,b;
    ll c1=0,c2=0,c3=0;
    cin>>n>>a>>b;
    for(int i=0;i<n;i++){
        ll p;
        cin>>p;
        if(p<=a) c1++;
        else if(p>=b+1) c3++;
        else c2++;
    }
    cout<<min(c1,min(c2,c3))<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>

using namespace std;
using ll = long long ;
const int INF = 1001001001;

int main() {

    int n ;
    ll d ;
    cin >> n >> d;

    int ans = 0 ;

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

    cout << ans << endl;

    return 0 ;
}

Measured memory_bytes: 3644
class BIT:
    ''' binary indexed tree '''
    def __init__(self, size):
        self.size = size
        self.bit = [0] * (size + 1) # 1 indexed
    def add(self, pos, x):
        ''' bit の pos の位置に x を加える '''
        while pos <= self.size:
            self.bit[pos] += x
            pos += self.right_most_bit(pos)
    def sum(self, pos):
        ''' bit の 1...pos の和を返す '''
        ans = 0
        while pos > 0:
            ans += self.bit[pos]
            pos -= self.right_most_bit(pos)
        return ans
    def right_most_bit(self, x):
        return x & -x

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

# a の各要素から(順位-1)へ map する辞書を作る
aa = sorted(a)
d = {k:v for v, k in enumerate(aa)}
b = BIT(n)

cnt = 0
index = 0
for ai in a:
    cnt += index - b.sum(d[ai])
    b.add(d[ai]+1, 1)
    index += 1

print(cnt)



Measured memory_bytes: 38764
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

typedef long long ll;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e6 + 100;
vector<pair<ll, ll>> bst[SIZE];
vector<ll> pref;

int main()
{
    fastInp;

    ll n, m;
    cin >> n >> m;
    vector<ll> vec(n), pref(m * 2 + 1), inc(m * 2), val(m * 2);
    ll s = 0;
    for (int i = 0; i < n; i++) {
        cin >> vec[i];
        --vec[i];
    }

    for (int i = 1; i < n; i++) {
        ll u = vec[i], v = vec[i - 1];
        if (u < v) u += m;

        s += (u - v);
        inc[v + 1]++;
        pref[u + 1] -= (u - v - 1);
        inc[u]--;
    }

    ll ans = s;
    ll cur = 0, curInc = 0;

    for (int i = 0; i < m * 2; i++) {
        cur += curInc;
        cur += pref[i];
        curInc += inc[i];
        val[i % m] += cur;
        if (i >= m) {
            ans = min(ans, s - val[i % m]);

        }
    }

    cout << ans;
    return 0;    
}

Measured memory_bytes: 32152
def main(A,B,C,D):
    list = [A,B,C,D]

    tmp = ['+','-']


    for i in range(2**3):
        ans = A
        back = []
        for j in range(3):
            if ( (i>>j)&1 ):
                ans += list[j+1]
                back.append(tmp[0])
            else:
                ans -= list[j+1]
                back.append(tmp[1])
        if ans == 7:
            return back

tmp = int(input())
D = tmp%10
tmp = tmp//10
C = tmp%10
tmp = tmp//10
B = tmp%10
tmp = tmp//10
A = tmp%10
back = main(A,B,C,D)
print(str(A)+back[0]+str(B)+back[1]+str(C)+back[2]+str(D)+'=7')


Measured memory_bytes: 9080
#include <cmath>
#include <cstdio>

#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
typedef long long int ll;

int main() {
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s.at(i);

  vector<ll> v(26, 100000);
  rep(i, n){
    vector<ll> vt(26, 0);
    for(auto& c: s.at(i)) ++vt.at(c-'a');
    rep(j, 26) v.at(j) = min(v.at(j),vt.at(j));
  }
  string ans;
  rep(i, 26) rep(j, v.at(i)) ans.push_back('a'+i);
  cout << ans << endl;






  return 0;
}

Measured memory_bytes: 256
var lines = [];

var readline = require('readline');
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var S = lines[0];

    var S_split = S.split("");
    var v = Array(S_split.length);

    for (var i = 0; i < S_split.length; i++) {
        v[i] = Number(S_split[i]);
    }


    var result_A = 0; var result_B = 0;

    // 010101... or 10101....
    for (var i = 0; i < S_split.length; i++) {
        if (i % 2 === 0 && v[i] === 1) { result_A++; }
        if (i % 2 === 1 && v[i] === 0) { result_A++; }
    }

    for (var i = 0; i < S_split.length; i++) {
        if (i % 2 === 0 && v[i] === 0) { result_B++; }
        if (i % 2 === 1 && v[i] === 1) { result_B++; }
    }

    console.log(Math.min(result_A, result_B));

});

Measured memory_bytes: 11596
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	long long sum=0;
	for(int i=1;i<=n;i++)
	{
		int i1=i;
		if(i1%3!=0&&i1%5!=0)
		{
		sum+=i1;
	    }
	}
	cout<<sum;
}

Measured memory_bytes: 3636
def p(a):
    print(a)

s=int(input())

list=[s]

while True:
    if list[len(list)-1]%2==0:
        a=list[len(list)-1]/2
    else:
        a=3*list[len(list)-1]+1
    if a in list:
        p(len(list)+1)
        break
    else:
        list.append(a)
        # p(list)

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

template<class Val>
struct BinaryIndexedTree {
    int n;
    vector<Val> t;
    BinaryIndexedTree() {}
    BinaryIndexedTree(int _n) :n(_n + 1), t(_n + 1) {}
    void add(int k, Val val) {
        k++;
        while (k < n) {
            t[k] += val;
            k += (k&-k);
        }
    }
    void set(int k, Val val) {
        add(k, -sum(k, k + 1));
        add(k, val);
    }
    Val sum(int k) {
        Val r = 0;
        while (k > 0) {
            r += t[k];
            k -= (k&-k);
        }
        return r;
    }
    Val sum(int l, int r) {
        return sum(r) - sum(l);
    }
};

template<class Val>
struct SegmentSum {
    SegmentSum() {}
    SegmentSum(int n) : bit0(n), bit1(n) {}
    /*
    [l, r)にvalを加える
    */
    void add(int l, int r, Val val) {
        bit0.add(l, val*(-l));
        bit0.add(r, val*r);
        bit1.add(l, val);
        bit1.add(r, val*(-1));
    }
    /*
    [l, r)の和を求める
    */
    Val sum(int l, int r) {
        Val sumr = bit0.sum(r) + bit1.sum(r)*r;
        Val suml = bit0.sum(l) + bit1.sum(l)*l;
        return sumr - suml;
    }
    BinaryIndexedTree<Val> bit0, bit1;
};

template<class S, class T>
void psort(vector<S> &u, vector<T> &v, bool isGreater = false) {
    int n = (int)u.size();
    vector<pair<S, T>> vecP(n);
    for (int i = 0; i < n; ++i) {
        vecP[i].first = u[i];
        vecP[i].second = v[i];
    }
    if (isGreater) {
        sort(vecP.rbegin(), vecP.rend());
    } else {
        sort(vecP.begin(), vecP.end());
    }
    for (int i = 0; i < n; ++i) {
        u[i] = vecP[i].first;
        v[i] = vecP[i].second;
    }
}

void solve() {
    int N;
    ll D, A;
    cin >> N >> D >> A;
    vll X(N), H(N);
    rep(i, N) {
        cin >> X[i] >> H[i];
    }
    psort(X, H);
    SegmentSum<ll> sum(N);
    ll ans = 0;
    rep(i, N) {
        ll hp = sum.sum(i, i + 1) + H[i];
        if (hp > 0) {
            int bound = lower_bound(all(X), X[i] + 2 * D + 1) - X.begin();
            ll attacks = (hp + A - 1) / A;
            ans += attacks;
            sum.add(i, bound, -A * attacks);
        }
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 6528
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

template<typename T> T minimum(T head, T tail) { return std::min(head, tail); }
template<typename Head, typename... Tail> Head minimum(Head head, Tail... tail) {
  return std::min(head, minimum(tail...));
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  ll i = 0;
  for (auto x : v){os << " [" << i++ << "]" << x; if (i % 5 == 0) os << std::endl;}
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 5 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  //std::ostringstream oss;
  //oss << "ABC" << N;
  //std::string ans = oss.str();

  char X, Y;
  std::cin >> X >> Y;

  ll x = X - 'A';
  ll y = Y - 'A';
  if (x > y) print('>');
  else if (x < y) print('<');
  else print('=');

  return 0;
}


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

int n;
int a[110];

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

  int counter = 0;
  
  for (int i=0; i < n; ++i) {
    if (a[i] != a[i-1]) {
      ++counter;
    }
  }
  cout << counter << endl;
  return 0;
}


Measured memory_bytes: 256