akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <climits> // INT_MAX, LONG_MAX, LLONG_MAX, UINT_MAX, ULONG_MAX, ULLONG_MAX
#include <cmath>
#include <cstdint>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
#define LOG(x) cout << #x << " = " << (x) << endl
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;

int main() {
    string s;
    cin >> s;

    int count = 0;
    int head = 0;
    int tail = s.size() - 1;

    while (head < tail) {
        if (s[head] == 'x' && s[tail] == 'x') {
            head++;
            tail--;
        } else if (s[head] == 'x') {
            count++;
            head++;
        } else if (s[tail] == 'x') {
            count++;
            tail--;
        } else if (s[head] == s[tail]) {
            head++;
            tail--;
        } else {
            count = -1;
            break;
        }
    }
            
    cout << count << endl;
    
    return 0;
}


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

using namespace std;

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

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (i >= k) {
      cout << (a[i] > a[i - k] ? "Yes" : "No") << '\n';
    }
  }

  return 0;
}


Measured memory_bytes: 3940
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {        
    int a, b;
    int n = 100;
    cin >> a >> b;
    a--, b--;
    vector<string> vs(n + 1, string(n + 1, '.'));
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            vs[i][j] = '#';
        }
    }

    for (int i = 1; i <= n; i += 2) {
        for (int j = i + 3; j <= n; j += 2) {
            if (a > 0) {
                a--;
                vs[i][j] = '.';   
            }
        }
    }

    for (int i = 1; i <= n; i += 2) {
        for (int j = 1; j + 2 < i; j += 2) {
            if (b > 0) {
                b--;
                vs[i][j] = '#';
            }
        }
    }
    cout << "100 100" << endl;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            cout <<vs[i][j];
        }
        cout << endl;
    }
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 200010;
int N;
int p[MC];
vector<int> V[MC];
vector<int> d[MC];
int a[MC];
bool b[MC];
bool c[MC];
int r;

int dfs(int q){
	for(auto u : V[q]){
		if(c[u]) continue;
		d[q].PB(dfs(u));
	}
	sort(d[q].begin(),d[q].end());
	a[q] = -1;
	for(auto u : d[q]){
		if(u > a[q]+1) break;
		a[q] = u;
	}
	return ++a[q];
}

int main(){
	scanf("%d" , &N);
	repp(i,1,N+1){
		scanf("%d" , p + i);
		V[p[i]].PB(i);
	}
	r = 1;
	while(!b[r]){
		b[r] = 1;
		r = p[r];
	}
	while(!c[r]){
		c[r] = 1;
		r = p[r];
	}
	int mn = 123456789;
	repp(i,1,N+1){
		if(c[i]) mn = min(mn , dfs(i));
	}
	bool t = 0;
	int y = 0;
	while(c[r]){
		c[r] = 0;
		if(a[r] != mn) t = 1;
		r = p[r];
		++y;
	}
	printf("%s\n" , t || y%2==0 ? "POSSIBLE" : "IMPOSSIBLE");
	return 0;
}


Measured memory_bytes: 17664
N = int(input())
A = []
A  = list(map(int,input().split()))	
if A.count(0)!=0:
    print("0")
    exit()
ans = 1
for i in A:
    ans = ans*i
    if ans > 1000000000000000000:
        print("-1")
        exit()
print(ans)

Measured memory_bytes: 84800
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	n, q := getInt(), getInt()

	fw := FenwickTree(n)
	for i := 0; i < n; i++ {
		a := getInt()
		fw.Add(i, a)
	}

	for i := 0; i < q; i++ {
		t := getInt()
		if t == 0 {
			p, x := getInt(), getInt()
			fw.Add(p, x)
		} else {
			l, r := getInt(), getInt()
			out(fw.Sum(l, r))
		}

	}

}

// ** copy from here to your source code **
//
// fenwick tree
//  1. go lang have no generics, so implement int(long long)
//  data type only.
//  2. do not care overflow
//

// BIT :
type BIT struct {
	n    int
	data []int
}

// FenwickTree :
func FenwickTree(n int) *BIT {
	var ret BIT
	ret.n = n
	ret.data = make([]int, n)
	return &ret
}

// Add :
func (b *BIT) Add(p, x int) {
	p++
	for p <= b.n {
		b.data[p-1] += x
		p += p & -p
	}
}

// Sum :
func (b *BIT) Sum(l, r int) int {
	return b.sum(r) - b.sum(l)
}

func (b *BIT) sum(r int) int {
	s := 0
	for r > 0 {
		s += b.data[r-1]
		r -= r & -r
	}
	return s
}


Measured memory_bytes: 12952
n=int(input())
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))

from itertools import permutations
dict_num=[]
for i in permutations(range(1,n+1)):
    dict_num.append(i)

ans=abs(dict_num.index(p)-dict_num.index(q))
print(ans)

Measured memory_bytes: 7924
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			scanner.nextLine();
			int[] a = new int[n];
			IntStream.range(0, n).forEach(i -> a[i] = scanner.nextInt());
			int max = 0;
			int count = 0;
			for (int i = 0; i < n; i++) {
				if (a[i] >= max) {
					max = a[i];
					count++;
				}
			}
			System.out.println(count);
		}
	}
}


Measured memory_bytes: 30548
#include <stdio.h>

int main(void)
{
	int A[3] = {0},i = 0,j = 0,k = 0;
	scanf("%d%d%d",&A[0],&A[1],&A[2]);
	for(i = 0;i < 2;i++){
		for(j = i + 1;j < 3;j++){
			if(A[i] > A[j]){
				k = A[i];
				A[i] = A[j];
				A[j] = k;
			}
		}
	}
	if(A[0] == A[1] && A[1] == 5 && A[2] == 7)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();

            out.println(Integer.toString(n, k).length());
        }

    }
}



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

int main(){
  int n;
  cin >> n;
  
  vector<int> h(n+1);
  vector<int> maxh(n+1);
  h[0] = 1; maxh[0] = 1;
  int ans = 0;
  for(int i=1; i<=n; i++){
    cin >> h[i];
    maxh[i] = max(maxh[i-1], h[i]);
    if (h[i] >= maxh[i]) ans++;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
bridge=[]
for i in range(M):
  a,b=map(int,input().split())
  bridge.append((a-1,b-1))
bridge.reverse()
par=[i for i in range(N)]
size=[1 for i in range(N)]
def find(x):
  if par[x]==x:
    return x
  else:
    par[x]=find(par[x])
    return par[x]
def union(a,b):
  x=find(a)
  y=find(b)
  if x!=y:
    if size[x]<size[y]:
      par[x]=par[y]
      size[y]+=size[x]
    else: 
      par[y]=par[x]
      size[x]+=size[y]
  else:
    return
now=int(N*(N-1)/2)
ans=[]
ans.append(now)
for i in range(M-1):
  a=bridge[i][0]
  b=bridge[i][1]
  if find(a)==find(b):
    ans.append(now)
  else:
    now-=size[find(a)]*size[find(b)]
    ans.append(now)
  union(a,b)
ans.reverse()
print(*ans)

Measured memory_bytes: 100028
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    static final long MOD = 1000000007;

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int d = scanner.nextInt();
        d = d + d + 1;
        if (n%d==0) {
            System.out.println(n / d);
        } else {
            System.out.println(n / d + 1);
        }
    }
}


Measured memory_bytes: 23124
def main():
  n,a,b=map(int,input().split())
  mod=pow(10,9)+7    
  def comb(n,r,mod):
    r=r if r<=n-r else n-r
    x,y=1,1
    for i in range(r):
      x=x*(n-i)%mod
      y=y*(i+1)%mod
    return (x*pow(y,mod-2,mod))%mod
  ans=(pow(2,n,mod)-comb(n,a,mod)-comb(n,b,mod)-1)%mod
  print(ans)
if __name__=='__main__':
  main()

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String x = sc.next();
        String y = sc.next();

        byte[] x_byte = x.getBytes();
        byte[] y_byte = y.getBytes();

        if (x_byte[0] > y_byte[0]) {
            System.out.println(">");
        } else if (x_byte[0] < y_byte[0]) {
            System.out.println("<");
        } else {
            System.out.println("=");
        }

    }
}



Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
int main(){
    int x[4], y[4];
    cin >> x[0] >> y[0] >> x[1] >> y[1];
    cout << x[1] - y[1] + y[0] <<" ";
    cout << y[1] + x[1] - x[0] <<" ";
    cout << x[0] - y[1] + y[0] <<" ";
    cout << y[0] + x[1] - x[0] <<"\n";
    return 0;
}


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

#define ll          long long
#define pb          push_back
#define pii         pair<ll,ll>
#define vpii        vector< pii >
#define vi          vector<ll>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			1'010'000'000'000'000'017LL
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define sz(x)       (ll)x.size()
#define rep(i,a,b)	for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )

using namespace std;

template<class T>
bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>
bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
ll DivisorCount(ll x) {
	ll ans = 1;
	for (int i = 2; i <= sqrt(x); i++) {
		int cnt = 0;
		while (x % i == 0) {
			cnt++;
			x /= i;
		}
		ans *= (cnt + 1);
		if (x == 1) break;
	}
	if (x != 1) ans *= 2;
	return ans;
}

void Main() {
	ll X;
	cin >> X;
	cout << 8 - ((X / 200) - 2) << endl;
}




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

	Main();
	return 0;
}


Measured memory_bytes: 3696
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
using namespace std;
typedef long long int ll;

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;}

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

int main() {
  int s, w;
  cin >> s >> w;
  if (w >= s) P("unsafe");
  else P("safe");
  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{	
	long long t=0,c=0;
	int n,i,k;
	cin>>n;
	for(i=0;i<n;i++) {
		cin>>k;
		if(k==0)
		{
			t+=c/2;
			c=0;
		}
		c+=k;
	}
	t+=c/2;
	cout<<t<<endl;
 	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n+1];
    string s[n+1];
    int p[n+1];
    int i,j;
    for(i=1;i<=n;i++){
        cin>>s[i]>>a[i];
        p[i]=i;
    }
    for(i=1;i<=n;i++){
        for(j=i+1;j<=n;j++){
            if(s[i]>s[j]){
                swap(s[i],s[j]);
                swap(a[i],a[j]);
                swap(p[i],p[j]);
            }
            if(s[i]==s[j]&&a[i]<a[j]){
                swap(s[i],s[j]);
                swap(a[i],a[j]);
                swap(p[i],p[j]);
            }
        }
    }
    for(i=1;i<=n;i++){
        cout<<p[i]<<endl;
    }
    return 0;
}

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

int main() {
    int m1,d1,m2,d2;
    cin >> m1 >> d1;
    cin >> m2 >> d2;
    if(m1 == m2){
        cout << "0";
    } else {
        cout << "1";
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#define LL long long
#define MAXN 100010

const LL P=1000000007;

LL n,m,lim=100000;
LL f1[MAXN],f2[MAXN];
LL p1[MAXN],p2[MAXN];

void init(){
	p1[0]=1;
	for(int i=1;i<=lim;i++)
		p1[i]=p1[i-1]*m%P;
	p2[0]=1;
	for(int i=1;i<=lim;i++)
		p2[i]=p2[i-1]*p1[lim]%P;
}

LL getP(LL x){ return p2[x/lim]*p1[x%lim]%P; }

LL dp(int x){
	if(x<=lim){
		if(~f1[x]) return f1[x];
	}else{
		if(~f2[n/x]) return f2[n/x];
	}
	LL res=getP((x+1)/2);
	for(int i=1;i*i<=x;i++){
		if(x%i) continue;
		int j=x/i;
		if(i!=x) res=(res-dp(i))%P;
		if(j!=i && j!=x) res=(res-dp(j))%P;
	}
	if(res<0) res+=P;
	if(x<=lim){
		return f1[x]=res;
	}else{
		return f2[n/x]=res;
	}
}

LL g(int x){
	if(x&1) return x;
	else return x>>1;
}

int main(){
#ifdef DEBUG
	freopen("F.in","r",stdin);
#endif
	memset(f1,-1,sizeof f1);
	memset(f2,-1,sizeof f2);
	scanf("%lld%lld",&n,&m);
	init();
	dp(n);
	LL ans=0;
	for(int i=1;i<=lim;i++)
		if(f1[i]!=-1)
			ans=(ans+f1[i]*g(i))%P;
	for(int i=1;i<=lim;i++)
		if(f2[i]!=-1)
			ans=(ans+f2[i]*g(n/i))%P;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
#include <chrono>
#include <cstdlib>
#include <bitset>
using namespace std;
int main(){
   int a, b;
   cin >> a >> b;
   if(a%2 != b%2) cout << "IMPOSSIBLE" << endl;
   else cout << (a+b)/2 << endl;
}

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

#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);

int main() {
    ios_base::sync_with_stdio(false);
    vector<ll> mini, maxi;
    int n; cin >> n;
    for(int i = 0; i < n; i++) {
        int a,b; cin >> a >> b;
        mini.pb(a);
        maxi.pb(b);
    }
    sort(mini.begin(),mini.end());
    sort(maxi.begin(),maxi.end());
    ll x = (n&1? maxi[n/2]-mini[n/2]+1 : (maxi[n/2-1]+maxi[n/2])-(mini[n/2-1]+mini[n/2])+1);
    cout << x << endl;
    return 0;
}



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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,k; cin>>a>>b>>k;
    if (k<=a){
        cout<<a-k<<" "<<b<<endl;
    }else{
        cout<<0<<" "<<max(0ll,b-(k-a))<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
use std::io::*;
fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let s = itr.next().unwrap();
    println!(
        "{}",
        match s {
            "SUN" => 7,
            "MON" => 6,
            "TUE" => 5,
            "WED" => 4,
            "THU" => 3,
            "FRI" => 2,
            _ => 1,
        }
    );
}


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

#include <unistd.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
 
 
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//const ll MOD = 1000000007;
const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
  fio();
  ll n, m;
  cin >> n >> m;
  vl a(n);
  rep (i, n) cin >> a[i];
  sort(all(a));

  //DEBUG_VEC(a);
  ll ok = 200001, ng = -1;
  while (ng + 1 < ok) {
    ll mid = (ok + ng) / 2;
    ll num = 0;
    rep (i, n) {
      int nokori = mid - a[i];
      auto itr = lower_bound(a.begin(), a.end(), nokori);
      num += a.end() - itr;
    }
    if (num > m) ng = mid;
    else ok = mid;
  }
  //DEBUG(ok);
  ll ans = 0;
  vl sum(n + 1);
  ll num = 0;
  rep (i, n) sum[i + 1] = sum[i] + a[i];
  rep (i, n) {
    int nokori = ok - a[i];
    auto itr = lower_bound(a.begin(), a.end(), nokori);
    num += a.end() - itr;
    int idx = itr - a.begin();
    //DEBUG(idx);
    ans += sum[n] - sum[idx];
    //DEBUG(ans);
    ans += a[i] * (n - idx);
    //DEBUG(ans);
  }
  if (num < m) {
    ans += (m - num) * ng;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using P=pair<int,int>;
using lint=long long;
using ll=long long;
const lint inf=1e18+7;
const int MOD=1000000007;
vector<P> d(int n){
  vector<P> res;
  if(n<2*1e6){
    int buf=n;
    rep1(i,n){
      if(i==1)continue;
      if(buf%i==0){
        res.push_back({i,0});
        int last=res.size()-1;
        while(buf%i==0){
          buf/=i;
          res[last].second+=1;
        }
      }
    }
    return res;
  }
  else{
    int buf=n;
    rep1(i,2*1e6){
      if(i==1)continue;
      if(i>n)break;
      if(buf%i==0){
        res.push_back({i,0});
        int last=res.size()-1;
        while(buf%i==0){
          buf/=i;
          res[last].second+=1;
        }
      }
    }
    if(buf!=1){
      res.push_back({buf,1});
    }
    return res;
  }
}
signed main(){
  int n;cin>>n;
  int res=0;
  vector<P> fac=d(n);
  vector<int> array(100,0);
  rep1(i,99){
    array[i]=i*(i+1)/2;
  }
  int t=fac.size();
  rep(i,t){
    int buf=fac[i].second;
    auto it=upper_bound(ALL(array),buf);
    int ind=it-array.begin()-1;
    res+=ind;
    //printf("val=%lld, num=%lld\n",fac[i].first,fac[i].second);
  }
  cout<<res<<"\n";
  return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
    int k,min_;
    int sum=0, mul=1;
    cin >> k;
    for (int i=1; i<=k; i++){
        for (int j=1; j<=k; j++){
            for (int l=1; l<=k; l++){
                int i1 = i;
                int j1 = j;
                int l1 = l;
                mul = 1;
                
                for (int m=2; m<=k;){
                    if( i1 % m == 0 && j1 % m == 0 && l1 % m == 0 ){
                        mul = mul*m;
                        i1 = i1 / m;
                        j1 = j1 / m;
                        l1 = l1 / m;
                    }
                    else m++;
                    if( i1 < m ) break;
                }
                sum += mul;
                
            }
        }
    }
    
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3588
N = int(input())
A = list(map(int, input().split()))

count = 0

for i in range(N):
    realnum = int(i+1)
    
    if A[i] == realnum:
        if A[i] == N:
            A[i-1],A[i] = A[i],A[i-1]
        else:
            A[i],A[i+1] = A[i+1],A[i]
        
        count = count + 1

print(count)


Measured memory_bytes: 20564
import sys
import numpy as np
#データ読み込み
H,W = list(map(int,input().split()))
data = [input().strip().split() for _ in range(H)]
data_ = np.array([list(str(data[i])) for i in range(H)])[:,2:-2]

#　上下左右ベクトル作成
vec = [[0,1],[1,0],[0,-1],[-1,0]]
# '#'の座標取得
where = np.where(data_ == '#')

# '#'の上下左右に'#'が存在するか否かを検索
for y,x in zip(where[0],where[1]):
	# '#'の上下左右の値('.' or '#')をcheckに代入
	check = [data_[y+vy, x+vx] for vy,vx in vec if (0 <= y+vy < H and 0 <= x+vx < W)]
	# checkに'#'が一つもなければ上下左右のいずれも'#'でない→２連続となっていない
	if '#' in  check:
		continue
	else:
		print('No')
		sys.exit()
print('Yes')

Measured memory_bytes: 12408
#include <stdio.h>
#include <string.h>

int main(void){
	int i,j,tmp,n[5];
	while(scanf("%d",&n[0])!=EOF){
		for(i=1;i<5;i++){
			scanf(",%d",&n[i]);
		}
		for(i=0;i<5;i++){
			for(j=i;j<5;j++){
				if(n[i]>n[j]){
					tmp=n[i];
					n[i]=n[j];
					n[j]=tmp;
				}
			}
		}
		if(n[1]==n[2]&&n[2]==n[3]&&(n[3]==n[4]||n[3]==n[0])){
			puts("four card");
		}else if(n[0]==n[1]&&n[1]==n[2]&&n[3]==n[4]||n[0]==n[1]&&n[2]==n[3]&&n[3]==n[4]){
			puts("full house");
		}else if(n[0]==n[1]-1&&n[1]==n[2]-1&&n[2]==n[3]-1&&n[3]==n[4]-1||n[0]==1&&n[1]==10&&n[2]==11&&n[3]==12&&n[4]==13){
			puts("straight");
		}else if(n[0]==n[1]&&n[1]==n[2]||n[1]==n[2]&&n[2]==n[3]||n[2]==n[3]&&n[3]==n[4]){
			puts("three card");
		}else if(n[0]==n[1]&&(n[2]==n[3]||n[3]==n[4])||n[1]==n[2]&&n[3]==n[4]){
			puts("two pair");
		}else if(n[0]==n[1]||n[1]==n[2]||n[2]==n[3]||n[3]==n[4]){
			puts("one pair");
		}else{
			puts("null");
		}
	}
	return 0;
}

Measured memory_bytes: 580
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<random>
#include<numeric>
#include<string>
#include<cstring>
typedef long long ll;
typedef long double ld;
using namespace std;
ll dx[] = { 0,0,1,-1 };
ll dy[] = { 1,-1,0,0 };

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
int main() {
	ll A, B, C, D;
	cin >> A >> B >> C >> D;
	ll x = A + B;
	ll y = C + D;
	if (x > y)
		cout << "Left" << endl;
	else if (x < y)
		cout << "Right" << endl;
	else
		cout << "Balanced" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    ll n,w;
    cin>>n>>w;
    vector<pair<ll,ll>> np(n);
    rep(i,n){
        cin>>np[i].first>>np[i].second;
    }

    vector<vector<ll>> dp(n+1,vector<ll>(w+1,-1));
    dp[0][0]=0;
    rep(i,n){
        dp[i][0]=0;
        ll wi = np[i].first;
        ll vi = np[i].second;
        rep(j,w+1){
            dp[i+1][j]=max(dp[i][j],dp[i+1][j]);
            if(dp[i][j]!=-1&&j+wi<=w) {
                dp[i + 1][j + wi] = max(dp[i + 1][j + wi], dp[i][j] + vi);
            }
        }
    }
    ll ans = 0;
    rep(i,w+1){
        if(ans<dp[n][i])ans=dp[n][i];
    }
    cout<<ans<<endl;







return 0;
}


Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int mex=10000000;
#define ll long long 
#define test int t;cin>>t;while(t--)
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(i,a,n) for(int i=a;i<n;i++)
#define rfo(i,a,b) for(int i=a;i>=b;i--)
#define bg begin()
#define en end()
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define pb push_back
#define veci vector<int>
#define veclli vector<long long int> 
#define all(x) x.begin(),x.end()
#define sci(x) scanf("%d",&x);
#define scc(x) scanf("%c",&x);
#define scs(x) scanf("%s",x);
#define debug(arr,n) for(int i=0;i<n;i++) printf("%d ",arr[i]);
#define sz(x) x.size()
#define loop(x) for(auto it=x.begin();it!= x.end();it++) 

int main()
{
   int n,fg=0;
   cin>>n;
   int arr[n];
   fo(i,0,n)
   {cin>>arr[i];
   if(arr[i]%2==0)
   {
       if(arr[i]%3&&arr[i]%5) fg=1;
   }
   }
   if(fg) cout<<"DENIED"<<endl;
   else cout<<"APPROVED"<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <string>

using namespace std;

struct Node {
    int key;
    Node* prev;
    Node* next;

    Node(int key) : key(key) { }
};

class DoublyLinkedList {
public:
    Node* nil;

    void insert(Node* x) {
        x->next = nil->next;
        nil->next->prev = x;
        nil->next = x;
        x->prev = nil;
    }

    Node* listSearch(int key) {
        Node *cur = nil->next;
        while (cur != nil && cur->key != key) {
            cur = cur->next;
        }
        return cur;
    }

    void deleteNode(Node* t) {
        if (t == nil) {
            return;
        }
        t->prev->next = t->next;
        t->next->prev = t->prev;
        free(t);
    }

    void deleteFirst() {
        deleteNode(nil->next);
    }

    void deleteLast() {
        deleteNode(nil->prev);
    }

    void deleteKey(int key) {
        deleteNode(listSearch(key));
    }

    DoublyLinkedList() {
        nil = (Node *)malloc(sizeof(Node));
        nil->next = nil;
        nil->prev = nil;
    }
};

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

    DoublyLinkedList list;
    for (int i = 0; i < n; i++) {
        char c[20];
        scanf("%s", c);
        string command = c;

        if (command == "insert") {
            int key;
            scanf("%d", &key);
            Node* x = new Node(key);
            list.insert(x);
        } else if (command == "delete") {
            int key;
            scanf("%d", &key);
            list.deleteKey(key);
        } else if (command == "deleteFirst") {
            list.deleteFirst();
        } else if (command == "deleteLast") {
            list.deleteLast();
        }
    }

    Node* cur = list.nil->next;
    while (cur != list.nil) {
        if (cur == list.nil->next) {
            printf("%d", cur->key);
        } else {
            printf(" %d", cur->key);
        }

        cur = cur->next;
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 34040
#include<bits/stdc++.h>
#include<string.h>
#define pb push_back
#define all(v) v.begin(),v.end()
#define see(x) cout<<#x<<" : "<<(x)<<endl;
#define ya cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define ff first
#define sc second
typedef long long ll;
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    //freopen("test.txt","r",stdin);
    ll n,ind=0,i,j,ans=0,ev=0,od=0;
    cin>>n;
    vector<ll>v(n);
    bool ok=1;
    for(i=0;i<n;i++)
    {
        cin>>v[i];
        ans=__gcd(v[i],ans);
    }
    cout<<ans<<endl;

    return 0;
}



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

int main() {

  int A, B, C, X, sum = 0;

  cin >> A >> B >> C >> X;

  for (int i = 0; i <= A; i++)
  {
    int X_dup = X;
    X_dup -= i * 500;
    for (int j = 0; j <= B;j++)
    {
      int X_dup2 = X_dup;
      X_dup2 -= j * 100;

      for (int k = 0; k <= C;k++)
      {
        int X_dup3 = X_dup2;
        X_dup3 -= k * 50;
        if(X_dup3 == 0)
        {
          sum++;
        }
      }
    }
  }

  cout << sum << endl;
  return 0;
}

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

#define rep(i,n) for(int i=0; i<n; i++)

const int INF = 1001001001;

using namespace std;

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

    int n; cin >> n;
    vector<int> h(n); rep(i,n) cin >> h[i];

    vector<int> dp(n+2,INF);

    dp[0] = 0;
    dp[1] = abs(h[0]-h[1]);

    /*for(int i=2; i<n; i++) {
        for (int j=0; j<j; j++) {
        }
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));

    }*/

    for(int i=0; i<n; i++) {
        dp[i+2] = min(dp[i+1]+abs(h[i+1]-h[i+2]), dp[i]+abs(h[i]-h[i+2]));
    }

    cout << dp[n-1] << "\n";

    return 0;
}

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

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

  vector<int> c(60001,0);

  for (int i = 1; i <= 100; i++) {
    for (int j = 1; j <= 100; j++) {
      for (int k = 1; k <= 100; k++) {
        c[i*i + j*j + k*k + i*j + j*k + k*i]++;
      }
    }
  }

  for (int i = 1; i <= n; i++) {
    cout << c[i] << endl;
  }

  return 0;
}

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

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

Measured memory_bytes: 3636
n = int(input())
apa = [[[0]*10 for i in range(3)] for j in range(4)]
for i in range(n):
    inp = list(map(int,input().split()))
    apa[inp[0]-1][inp[1]-1][inp[2]-1] += inp[3]

for j in range(4):
    for i in range(3):
        for k in range(10):
            print(" %d"%apa[j][i][k],end="")
        print("")
    if j <3:
        print("#"*20)


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

struct segtree
{
    vector<int> rows, cols;
    int sz;
    void init(int n)
    {
        sz = n;
        rows.assign(4*n, n);
        cols.assign(4*n, n);
    }
    void update_rows(int v, int tl, int tr, int l, int r, int x)
    {
        if (tl == l && tr == r)
        {
            rows[v] = min(rows[v], x); return;
        }
        if (l > r) return;
        int tm = (tl + tr) / 2;
        update_rows(2*v, tl, tm, l, min(r, tm), x);
        update_rows(2*v+1, tm+1, tr, max(l, tm+1), r, x);
    }
    void update_rows(int r, int x)
    {
        update_rows(1, 0, sz-1, 0, r, x);
    }
    int getMin_rows(int v, int tl, int tr, int x)
    {
        if (tl == tr) return rows[v];
        int tm = (tl + tr) / 2;
        if (x <= tm) return min(rows[v], getMin_rows(2*v, tl, tm, x));
        else return min(rows[v], getMin_rows(2*v+1, tm+1, tr, x));
    }
    int getMin_rows(int x)
    {
        return getMin_rows(1, 0, sz-1, x);
    }
    void update_cols(int v, int tl, int tr, int l, int r, int x)
    {
        if (tl == l && tr == r)
        {
            cols[v] = min(cols[v], x); return;
        }
        if (l > r) return;
        int tm = (tl + tr) / 2;
        update_cols(2*v, tl, tm, l, min(r, tm), x);
        update_cols(2*v+1, tm+1, tr, max(l, tm+1), r, x);
    }
    void update_cols(int r, int x)
    {
        update_cols(1, 0, sz-1, 0, r, x);
    }
    int getMin_cols(int v, int tl, int tr, int x)
    {
        if (tl == tr) return cols[v];
        int tm = (tl + tr) / 2;
        if (x <= tm) return min(cols[v], getMin_cols(2*v, tl, tm, x));
        else return min(cols[v], getMin_cols(2*v+1, tm+1, tr, x));
    }
    int getMin_cols(int x)
    {
        return getMin_cols(1, 0, sz-1, x);
    }

};
int main()
{
    long long n, q; cin >> n >> q; n-=2;
    segtree st; st.init(n); long long ans = 0;
    for (int i = 0; i < q; i++)
    {
        int op, x; cin >> op >> x; x-=2;
        if (op == 1)
        {
            int mini = st.getMin_cols(x);
            ans += mini;
            st.update_rows(mini-1, x);
        }
        else
        {
            int mini = st.getMin_rows(x);
            ans += mini;
            st.update_cols(mini-1, x);
        }
    }
    cout << n * n - ans << '\n';
    return 0;
}


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

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


int main(void)
{
	int n;

	while(scanf("%d", &n)==1)
	{
		vi d(n);

		for(int i=0;i<n;i++)
		{
			scanf("%d", &d[i]);
		}
		sort(d.begin(), d.end());

		int ans=d[n/2]-d[n/2-1];
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define angle(a) (atan2((a).imag(), (a).real()))
#define vec(a, b) ((b) - (a))
#define length(a) (hypot((a).imag(), (a).real()))
#define dot(a, b) ((conj(a) * (b)).real())
#define cross(a, b) ((conj(a) * (b)).imag())
#define lengthSqr(p) dot(p, p)
#define rotateO(p, ang) ((p) * exp(point(0, ang)))
#define rotateA(p, ang, about) (rotateO(vec(about, p), ang) + about)
#define reflectO(v, m) (conj((v) / (m)) * (m))
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define X() real()
#define Y() imag()
using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
typedef complex<double> point;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);


int main(){
	FAST_IO
	int k, s, count = 0, add = 1;
	cin >> k >> s;
	vector<int> mul = {1, 3, 3, 1};
	for(int itr = 0; itr < 4; ++itr){
		if(s < itr * (k + 1)) break;
		count += add * mul[itr] * (s - itr * (k + 1) + 2) * (s - itr * (k + 1) + 1) / 2;
		add *= -1;
	}
	
	cout << count << "\n";
	
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
l = [0]*9
cnt = 0
for i in a:
        if i <400:
                l[0] +=1
        elif i<800:
                l[1] +=1
        elif i < 1200:
                l[2] +=1
        elif i<1600:
                l[3] +=1
        elif i < 2000:
                l[4] +=1
        elif i<2400:
                l[5] +=1
        elif i < 2800:
                l[6] +=1
        elif i<3200:
                l[7] +=1 
        else:
                l[8] +=1
for i in range(8):
        if l[i] >=1:
                cnt +=1

if cnt == 0:
        print(1,l[8])
else:
        print(cnt,cnt+l[8])

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

int main(){
	while(1){
		int n;
		cin >> n;
		if(n==0) break;
		
		int a=0, b=0;
		for(int i=0; i<n; i++){
			int n,m;
			cin >> n >> m;
			if(n>m) a += n+m;
			if(n<m) b += n+m;
			if(n==m){
				a += n;
				b += m;
			}
		}
		cout << a << " " << b << endl;
	}
    return 0;
}

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

//再帰関数っぽい
//k段目に登る登り方をf(k)とする
//f(k) = f(k-1) + f(k-2)
//ただしf(a[i]) = 0
int N, M;
int a[100000];
long long func[100001];


long long f(int k) {
    if ( k == 0 ) return 1;
    else if (( k == 1 ) && ( func[1] == 0 )) return 0;
    else if (( k == 1 ) && ( func[1] == -1 )) return 1;
    else return (func[k-1] + func[k-2]) % 1000000007;
}
int main() {
    cin >> N >> M;
    for ( int i = 0; i < M; i++ ) cin >> a[i];
    for ( int i = 0; i < N+1; i++ ) func[i] = -1;
    for ( int i = 0; i < M; i++ ) func[a[i]] = 0;
    for ( int i = 0; i < N+1; i++ ) {
        if ( func[i] == -1 ) func[i] = f(i);
    }
    //for ( int i = 0; i < N+1; i++ ) cout << func[i] << endl;
    cout << func[N] << endl;

    return 0;
}

Measured memory_bytes: 1408
# -*- coding: utf-8 -*-
'''
所要時間は、分位であった。
'''


# ライブラリのインポート
#import re #正規表現
import sys
#import heapq
#import bisect
from collections import deque
#import math

def main():
    inf = 10000
    n = int(input())
    D = [inf for i in range(n)]
    L = [[] for i in range(n)]
    for i, line in enumerate(sys.stdin):
        L[i] = list(map(lambda x: int(x)-1, list(line.strip("\n").split())))

    q = deque([0])
    D[0] = 0
    while(len(q)):
        u = q.popleft()
        if L[u][1] == -1:
            continue
        for j in range(2,len(L[u])):
            if D[L[u][j]] == inf:
                q.append(L[u][j])
            D[L[u][j]] = min(D[L[u][0]] + 1, D[L[u][j]]) 

                      
    for i in range(n):
        print("{} {}".format(i+1,D[i])) if D[i] < inf else print("{} {}".format(i+1,-1))
            
if __name__ == '__main__':
    main()



Measured memory_bytes: 6028
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np

def main():
	s=input().rstrip().decode('utf-8')
	
	cnt=0
	ans=0
	
	for i in range(len(s)):
		if s[-i-1]=="W":
			cnt+=1
		else:
			ans+=cnt
	
	print(ans)
	
	
	
	
	
	
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 41456
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

int main(){FIN;
	ll n; cin>>n;
	ll a[n];
	fore(i,0,n)cin>>a[i],a[i]--;
	ll c[n];
	mset(c,0);
	fore(i,0,n)c[a[i]]++;
	ll resp=0;
	fore(i,0,n)resp+=c[i]*(c[i]-1)/2;
	ll res[n];
	mset(res,0);
	fore(i,0,n)res[i]=resp-c[a[i]]*(c[a[i]]-1)/2+(c[a[i]]-1)*(c[a[i]]-2)/2;
	fore(i,0,n)cout<<res[i]<<"\n";
	return 0;
}

Measured memory_bytes: 7296
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

int main(){
    ll a,b,k;
    cin>>a>>b>>k;
    set<ll> st;
    for(int i=a;i<a+k;i++){
        if(i<=b) st.insert(i);
    } 
    for(int i=b;i>b-k;i--){
        if(i>=a) st.insert(i);
    } 
    while(!st.empty()){
        ll m=*begin(st);
        st.erase(m);
        cout<<m<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>

int main() {
    int n; std::cin >> n;
    auto cnt = [&](int m) {
        int ret = 0;
        for (int i = 1; i <= m; i++) {
            ret += m % i == 0;
        }
        return ret;
    };
    int ans = 0;
    for (int i = 1; i <= n; i+=2) {
        ans += cnt(i) == 8;
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;

namespace atcorder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] strArray = Console.ReadLine().Split(' ').ToArray();
            string A = strArray[0];
            string B = strArray[1];
            string C = strArray[2];
            if((A == B && B == C) || (A != B && B != C && C != A))
            {
                Console.WriteLine("No");
            }
            else
            {
                Console.WriteLine("Yes");
            }
        }
    }
}

//文字配列の取得
//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];

//文字列の取得
//string s = Console.ReadLine();

//数字配列の取得
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];

//数字の取得
//int N = int.Parse(Console.ReadLine());

//リスト型(int)の取得
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());

//出力
//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.WriteLine(cnt);



Measured memory_bytes: 26264
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i)   
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 1e9;
const int nax = 85;
int n,a[nax];
void solve()
 {
   cin>>n;
   loop(i,0,n)
    cin>>a[i];
   int stocks = 0,cash = 1000;
   loop(i,0,n-1)
    {
     if(a[i]>=a[i+1])
       continue;
     stocks = cash/a[i];
     cash %= a[i];
     cash += a[i+1]*stocks;
    }
   cout<<cash;
 }
signed main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0); 
     solve();
 // cerr<<END<<1.0*clock()/CLOCKS_PER_SEC;
  return 0;
} 

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

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n >> m;
    cin >> i >> j;
    if(n!=i){
        cout << 1 << endl;
    }else {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

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

    ll L, R;
    cin >> L >> R;

    ll ans = 2019;
    for (ll i = L; i <= R; ++i) {
        for (ll j = i + 1; j <= R; ++j) {
            if (i * j % 2019 == 0) {
                cout << 0 << endl;
                exit(0);
            }
            ans = min(ans, i * j % 2019);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int h, n;
    cin >> h >> n;

    vi a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];

    vi dp(1e5, 1e10);
    dp[0] = 0;

    rep(i, n) {
        rep(j, h) {
            if(j+a[i] >= h) dp[h] = min(dp[h], dp[j]+b[i]);
            else dp[j+a[i]] = min(dp[j+a[i]], dp[j]+b[i]);
        }
    }

    cout << dp[h] << endl;
    
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

   static char[] k = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       String str = sc.next();
       int q = sc.nextInt();
       for(int i = 0; i < q; i++) {
           String stt = sc.next();
           int a = sc.nextInt();
           int b = sc.nextInt();
           if(stt.equals("print")) {
               String tmp = str.substring(a, b+1);
               System.out.println(tmp);
           }
           else if(stt.equals("reverse")) {
               String tmp = str.substring(a,b+1);
               String tmp2 = "";
               for(int j = tmp.length()-1; j >= 0; j--) {
                   tmp2 += String.valueOf(tmp.charAt(j));
               }
               String c1 = str.substring(0, a);
               String c2 = str.substring(b+1,str.length());
               str = c1 + tmp2 + c2;
           }
           else if(stt.equals("replace")) {
               String p = sc.next();
               String c1 = str.substring(0, a);
               String c2 = str.substring(b+1,str.length());
               str = c1 + p + c2;
           }
       }
       sc.close();
   }
}


Measured memory_bytes: 47308
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

int N, D, X, A[210];

int main() {
  while (cin >> N >> D >> X) {
	for (int i = 0; i < N; ++i) cin >> A[i];
	int all = 0;
	for (int i = 0; i < N; ++i) {
	  for (int j = 1; j <= D; j += A[i]) ++all;
	}
	cout << all + X << endl;
  }
}












Measured memory_bytes: 256