akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define SZ 1234567
typedef long long ll;
int n,g=0; ll A,B,s[SZ],x[SZ];
const int MOD=1e9+7;
struct Bit{
int ts,b[SZ],t[SZ]; void clr() {++ts;}
Bit() {ts=0; memset(t,0,sizeof t);}
void edt(int x,int y)
{
	for(;x<=g;x+=x&-x)
	{if(t[x]!=ts) t[x]=ts,b[x]=0; (b[x]+=y)%=MOD;}
}
int sum(int x)
{
	int s=0;
	for(;x>=1;x-=x&-x)
	{if(t[x]!=ts) t[x]=ts,b[x]=0; (s+=b[x])%=MOD;}
	return s;
}
ll ss(ll p)
{return sum(upper_bound(x+1,x+1+g,p)-x-1);}
ll ss(ll l,ll r)
{
	if(l<=r)
		return (ss(r)-ss(l-1))%MOD;
	return 0;
}
}ba,bb;
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
int main()
{
	scanf("%d%lld%lld",&n,&A,&B);
	for(int i=1;i<=n;++i)
		scanf("%lld",s+i),x[i]=s[i];
	g=n; x[++g]=-1e18;
	sort(x+1,x+1+g);
	ba.clr(); bb.clr();
	ba.edt(1,1); bb.edt(1,1);
	for(int i=2;i<=n;++i)
	{
		int r=lower_bound(x+1,x+1+g,s[i-1])-x;
		int s1=ba.sum(g)-ba.ss(s[i]-B+1,s[i]+B-1),
		s2=bb.sum(g)-bb.ss(s[i]-A+1,s[i]+A-1);
		s1%=MOD; s2%=MOD;
		if(abs(s[i]-s[i-1])<A) ba.clr();
		if(abs(s[i]-s[i-1])<B) bb.clr();
		ba.edt(r,s2); bb.edt(r,s1);
	}
	ll ans=ba.sum(g)+bb.sum(g);
	ans=(ans%MOD+MOD)%MOD;
	printf("%d\n",int(ans));
}

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

using namespace std;

int main(){
    int r, D, x_2000;
    cin >> r >> D >> x_2000;
    int next = x_2000;
    for (int i=0;i<10;i++){
        next = r * next - D;
        cout << next << endl;
    }

    return 0;
}



Measured memory_bytes: 256
N = int(input())
X = list(map(int, input().split()))

M = max(X)
m = min(X)
total = [0] * (M - m + 1)
for i in range(m, M + 1, 1):
    for j in range(N):
        total[i - m] += (X[j] - i) ** 2

print(min(total))

Measured memory_bytes: 3064
import java.io.*;
class Main{
public static void main(String[] args)throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
boolean i=true;
while(i){
String str=br.readLine();
String[] arr=str.split(" ");
int h=Integer.parseInt(arr[0]);
int w=Integer.parseInt(arr[1]);
if(h==0 && w==0)  i=false;
else{
for(int k=0; k<h; k++){
for(int j=0; j<w; j++){
System.out.print("#");
}
System.out.println();
}
System.out.println();
}
}
br.close();
}
}

Measured memory_bytes: 30732
import { isRegExp } from "util";

class AtCoder {
  // 入力系
  input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);
  input_i=-1;

  n(){
    this.input_i++;
    return Number(this.input[this.input_i]);
  }
  nn(n:number):number[]{
    const a=[];
    for(let i=0;i<n;i++){
      a.push(this.n());
    }
    return a;
  }
  s(){
    this.input_i++;
    return String(this.input[this.input_i]);
  }
  ss(n:number):string[]{
    const a=[];
    for(let i=0;i<n;i++){
      a.push(this.s());
    }
    return a;
  }

  // コンソール
  o(...a:any){
    console.log(...a);
  }

  // Math
  abs(a:number){
    return Math.abs(a);
  }
  min(...a:number[]){
    return Math.min(...a);
  }
  max(...a:number[]){
    return Math.max(...a);
  }
  floor(a:number){
    return Math.floor(a);
  }
  ceil(a:number){
    return Math.ceil(a);
  }
  round(a:number){
    return Math.round(a);
  }

  // ソート
  asc(ar:number[]){
    const t=[...ar];
    ar.sort((a,b)=>{return a-b});
  }
  desc(ar:number[]){
    const t=[...ar];
    ar.sort((a,b)=>{return b-a});
  }

  // 自作
  gcd(...arr:number[]):number{
    for(let i=0;i<arr.length-1;i++){
      let [x,y]=[arr[i],arr[i+1]];
      while(y){
        [x,y]=[y,x%y];
      }
      arr[i+1]=x;
    }
    return arr[arr.length-1];
  };
  lcm(...arr:number[]):number{
    for(let i=0;i<arr.length-1;i++){
      let [x,y]=[arr[i],arr[i+1]];
      while(y){
        [x,y]=[y,x%y];
      }
      arr[i+1]=arr[i]*arr[i+1]/x;
    }
    return arr[arr.length-1];
  };
  isPrime(n:number):boolean{
    if(n < 2) return false;
    const suq=Math.sqrt(n);
    for(let i=2;i<=suq;i++){
      if(n%i==0){
        return false;
      }
    }return true;
  };
  deduplicate(a:any[]):any[]{
    return Array.from(new Set(a));
  };
  f(roop:number, callback:any){
    for(let i=0;i<roop;i++){
      callback(i);
    }
  };
  Yes(){
    console.log('Yes');
  }
  No(){
    console.log('No');
  }
  YES(){
    console.log('YES');
  }
  NO(){
    console.log('NO');
  }
}
const m = () => {
  const o = new AtCoder();
  let s=o.s()
  let ans= ''
  for(let i=0;i<s.length;i++){
    ans += (s[i] == '?' ? 'D' : s[i]);
  }
  o.o(ans)
}
m();

Measured memory_bytes: 40088
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

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

  int ans = 0;
  int m = INF;
  rep(i, n) {
    m = min(m, p[i]);
    if(p[i] == m) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4020
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        String[] list = new String[N];
        output(0);
        list[0] = scan.next();
        if (is_finished(list[0])) {
            return;
        }
        output(N-1);
        list[N-1] = scan.next();
        if (is_finished(list[N-1])) {
            return;
        }
        int left = 0;
        int right = N - 1;
        while (left < right) {
            int mid = (left + right) / 2;
            output(mid);
            list[mid] = scan.next();
            if (is_finished(list[mid])) {
                break;
            }
            if (list[mid].equals(list[right]) &&  (right - mid) % 2 == 1) {
                left = mid;
                continue;
            }
            if (!list[mid].equals(list[right]) &&  (right - mid) % 2 == 0) {
                left = mid;
                continue;
            }
            right = mid;
        }
    }
    private void output(int x) {
        System.out.println(x);
        System.out.flush();
    }
    private boolean is_finished(String x) {
        return "Vacant".equals(x);
    }
}


Measured memory_bytes: 24228
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A,B,C;
    cin >> A >> B >> C;
    if(((A==B)&& B!=C) || (B==C && B!=A) ||(A==C && C!=B) ){
        cout << "Yes" <<endl;
    }else{
        cout << "No" <<endl;
    }
    
    
}


Measured memory_bytes: 256
import math

def main():
    a, b, x = map(float, input().split())

    if x <= a*a*b*0.5:
        y = 2*x/(a*b)
        p = y/((b**2 + y**2)**0.5)
        ans = math.degrees(math.acos(p))
    elif x < a*a*b:
        k = (2*a*x - a*a*a*b)/(2*a*a*b -2*x)
        ans = math.degrees(math.atan(b/(a+k)))
    else:
        ans = 0
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
n = int(input())
x = list(map(int,input().split()))


maxi = max(x)
mini = min(x)

tairyoku_1=1000000000000
tairyoku_2=0

for i in range(mini,maxi+1):
    tairyoku_2=0
    for j in x:
        tairyoku_2 += (j-i)**2
        
    tairyoku_1 = min(tairyoku_1,tairyoku_2)

print(tairyoku_1)

Measured memory_bytes: 3064
#if 0

#endif
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <assert.h>
#include <complex>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
ll dp[50001];
ll n, m;
ll C[20];
void solve() {
    for (ll money = 1; money < n + 1; ++money) {
        ll min_coin = numeric_limits<ll>::max();
        for (ll coin_i = 0; coin_i < m; ++coin_i) {
            if (money < C[coin_i]) {
                continue;
            }
            min_coin = min(dp[money - C[coin_i]] + 1, min_coin);
        }
        dp[money] = min_coin;
    }
    cout << dp[n] << endl;
}
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    #define ll int

    cin >> n >> m;
    for (int mm = 0; mm < m; ++mm) {
        cin >> C[mm];
    }

    solve();

    return 0;
}


Measured memory_bytes: 3572
n=int(input())
S=[]

for _ in range(n):
    S.append(input())
sum_=0
a=0
b=0
c=0
for s in S:
    sum_ += s.count("AB")
    if s[0] =="B" and s[-1] =="A":
        c+=1
    elif s[0] =="B" and s[-1] !="A":
        b+=1
    elif s[-1] =="A" and s[0] !="B":
        a+=1
if c == 0:
    print(sum_+min(a,b))
else:
    if a+b ==0:
        print(sum_+ c-1)
    else:
        print(sum_+ c+min(a,b))

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

using namespace std;

int main(int argc, char *argv[]) {
	int N, K;
	cin >> N >> K;
	vector<int> xpoints;
	int point = 0;
	for (int i = 0; i < N; i++) {
		cin >> point;
		xpoints.push_back(point);
	}

	int answer = 0;
	for (int j = 0; j < N; j++) {
		int min_dist = min(K - xpoints[j], xpoints[j]); 
		answer += (min_dist * 2);
	} 

	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int [] number = new int[n + 1];
        for (int i = 0; i < n + 1; ++i) {
            number[i] = -1;

        }
        for (int i = 0; i < m; ++i) {
            int c = scanner.nextInt();
            int digit = scanner.nextInt();
            if (number[c] == -1 || number[c] == digit) {
                number[c] = digit;
            } else {
                System.out.println(-1);
                return;
            }
        }
        if (number[1] == 0 && n > 1) {
            System.out.println(-1);
            return;
        }
        if (n == 1) {
            if (number[1] == -1) {
                System.out.print(0);
                return;
            } else {
                System.out.print(number[1]);
                return;
            }
        }
        boolean hasFirst = false;
        for (int i = 1; i <= n; ++i) {
            if (!hasFirst && number[i] == -1) {
                System.out.print(1);
                hasFirst = true;
                continue;
            }
            if (number[i] == -1) {
                System.out.print(0);
            } else {
                System.out.print(number[i]);
                hasFirst = true;
            }
        }
        System.out.println();
    }
}


Measured memory_bytes: 21844
import std.stdio;
import std.string;
import std.array;
import std.conv;
void main() {
  int A=to!int(chomp(readln()));
  int B=to!int(chomp(readln()));
  int C=to!int(chomp(readln()));
  int X=to!int(chomp(readln()));
  int ans=0;
  for(int i=0;i<=A;i++) {
    for(int j=0;j<=B;j++) {
      for(int k=0;k<=C;k++){
        if(500*i+100*j+50*k==X) ans++;
      }
    }
  }
  writeln(ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,c;
    cin>>n>>m>>c;
    vector<int> b(m,0);
    vector<vector<int> >a(n,vector<int>(m));
    for(int i=0;i<m;i++)cin>>b[i];
    int ans=0;
    for(int i=0;i<n;i++){
        int sum=0;
        for(int j=0;j<m;j++){
            cin>>a[i][j];
            sum+=a[i][j]*b[j];
        }
        sum+=c;
        if(sum>0)ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

int main() {
  int N;
  std::cin >> N;
  int temp_N = N;
  int sum = 0;
  while (temp_N!=0) {
    sum += temp_N%10;
    temp_N /= 10;
  }
  if (N % sum == 0) {
    std::cout << "Yes" << std::endl;
  }
  else {
    std::cout << "No" << std::endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const int MAX_N = 100000;
ll fact[MAX_N + 1];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll ans;
    fact[0] = 0;
    fact[1] = 1;
    ll fs = 1;
    for (int i = 2; i < MAX_N + 1; i++){
        fs = (fs*i) % MOD;
        fact[i] = (fact[i-1] + fs) % MOD;
    }
    while (1){
        int N, R;
        cin >> N;
        if (N == 0) break;
        vector<int> word(N);
        for (int i = 0; i < N; i++) word[i] = i;
        word.push_back(0);
        ans = 0;
        cin >> R;
        vector<int> s(2*R+2, 0);
        s[2 * R + 1] = N;
        for (int i = 0; i < R; i++){
            cin >> s[i] >> s[i+R];
            s[i]--; s[i+R]--;
            s.push_back(s[i] + 1);
            s.push_back(s[i+R] + 1);
            swap(word[s[i]], word[s[i+R]]);
        }
        sort(s.begin(), s.end());
        s.erase(unique(s.begin(), s.end()), s.end());
        for (int i = 0, R = s.size() - 1; i < R; i++){
            ll tmp = fact[N - s[i] - 1] - fact[N - s[i+1] - 1];
            tmp = (tmp * word[s[i]]) % MOD;
            ans =(ans + tmp) % MOD;
            int dif = s[i+1] - s[i];
            for (int j = i + 1; j < R; j++){
                word[s[j]] -= (word[s[j]] > word[s[i]] ? dif : 0);
            }
        }
        cout << (ans + MOD) % MOD << endl;
    }
    return 0;
}

Measured memory_bytes: 2792
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    list<int> b;
    int n;
    cin >> n;
    rep(i,n){
        char c[20];
        int n;
        cin >> c;
        if(c[0] == 'i'){
            cin >> n;
            b.push_front(n);
        }else if(c[6] == 'F'){
            b.pop_front();
        }else if(c[6] == 'L'){
            b.pop_back();
        }else{
            list<int>::iterator ps;
            cin >> n;
            int ct = 0;
            for(auto x:b){
                if(x == n){
                    b.erase(next(b.begin(), ct));
                    break;
                }else{
                    ct++;
                }
            }
        }
    }

    int size = b.size();
    int ct = 0;

    //list<int>::iterator ps;

    for(auto x:b){
        cout << x;
        ct++;
        if(ct != size) cout << " ";
    }
    cout << endl;
}


Measured memory_bytes: 34236
#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;}
const int INF = 1e18;

signed main() {
    int K;
    string S;
    cin >> K >> S;

    if(S.size() <= K) cout << S << endl;
    else {
        rep(i, K) {
            cout << S[i];
        }
        cout << "..." << endl;
    }


    return 0;
}

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int n;
  cin >> n;
  map<string, int> mp;
  rep(i, n) {
    string s;
    cin >> s;
    mp[s]++;
  }
  cout << "AC x " << mp["AC"] << endl;
  cout << "WA x " << mp["WA"] << endl;
  cout << "TLE x " << mp["TLE"] << endl;
  cout << "RE x " << mp["RE"] << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

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

int main()
{
  int a[5];
  int k=0;
  int b=0;
  
  for(int i=0;i<5;i++)
  {
    cin>>a[i];
  }
  cin>>k;
  
  for(int j=0;j<5;j++)
  {
    for(int s=0;s<5;s++)
    {
      if(a[s]-a[j]<=k)
      {
      }
      else
      {
        b=1;
      }
    }
  }
  
  if(b==0)
  {
    cout<<"Yay!"<<endl;
  }
  else
  {
    cout<<":("<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

K = int(input())
S = input()

if len(S) > K:
    print(S[:K] + "...")
else:
    print(S)

Measured memory_bytes: 9636
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var s string
	fmt.Scan(&s)

	m, _ := strconv.Atoi(s)

	res := m / 500 * 1000
	res += (m % 500) / 5 * 5
	fmt.Println(res)
}


Measured memory_bytes: 512
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let x: usize = iterator.next().unwrap().parse().unwrap();
    let y: usize = iterator.next().unwrap().parse().unwrap();

    let mut ans: usize = 0;
    if x <= 3 {
        ans += (4 - x) * 100000;
    }
    if y <= 3 {
        ans += (4 - y) * 100000;
    }
    if x == 1 && y == 1 {
        ans += 400000;
    }
    return ans.to_string();
}


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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

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

    int all = 1, bad = 1;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        all *= 3;
        if (v[i] %2 == 0) bad *= 2;
    }

    cout << all - bad << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
double dp[110];
int b[110];
double val[10100];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++)scanf("%d",b+i+1);
		a++;
		double t,v,e,f;
		int r;
		scanf("%lf%d%lf%lf%lf",&t,&r,&v,&e,&f);
		for(int i=0;i<a;i++)dp[i]=999999999;
		dp[0]=0;
		for(int i=0;i<10050;i++){
			double tmp=0;
			if(i>=r)tmp=1.0/(v-e*(i-r));
			else tmp=1.0/(v-f*(r-i));
			val[i+1]=val[i]+tmp;
		}
		for(int i=0;i<a;i++){
			for(int j=i+1;j<a;j++){
				dp[j]=min(dp[j],dp[i]+t+val[b[j]-b[i]]);
			}
		}
		printf("%.12f\n",dp[a-1]-t);
	}
}

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

int N;
int A[100006];
void swap(int& a, int& b){
	int tmp = a;
	a = b;
	b = tmp;
}

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


int main(){
	cin >> N;
	for(int i=0;i<N;i++)cin >> A[i];
	int cu = partition(0,N-1);
	for(int i=0;i<N;i++){
		if(i)cout << " ";
		if(i == cu)cout << "[";
		cout << A[i];
		if(i == cu)cout << "]";
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 3480
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
bool pairCompare2(const pll firstElof, pll secondElof)
{
    return firstElof.second < secondElof.second;
}
bool pairCompare3(const pll firstElof, pll secondElof)
{
    return firstElof.second > secondElof.second;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, Npow, divisor, modinv, bitSearch, bitList, dfs, bfs//
//dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = 0;
vl flag, color; vll path;
//***********//
int main() {
	string S;
	cin >> S;
	ll N = S.length();
	vl alpha(26);
	for (i = 0; i < N; i++) {
		alpha[S[i] - 'a']++;
	}
	ans = N * (N - 1) / 2 + 1;
	for (i = 0; i < 26; i++) {
		ans -= alpha[i] * (alpha[i]-1) / 2;
	}
	cout << ans;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
    long long ans;
    string s;
    vector<long long> S(10);//sの数字変換
    vector<long long> memo(11);//そこまでの計算結果メモする用
    long long n;
    void dfs(int i){
        S.at(i) = s.at(i) - '0';
        memo.at(i) += S.at(i);
        if(i == n){
            for(int j = 0; j < s.size(); j++){
                ans += memo.at(j);
            }
            memo.at(i + 1) = 0;
        }//最終桁になったら+の有無判定はないので最後の結果を足しておしまい
        else{
            for(int j = 0; j < 2; j++){
            if(j == 0){//"+"を挿入するとき
                memo.at(i + 1) = 0;
                dfs(i + 1);
            }
            else{//"+"を挿入しないとき、そこまでのメモの結果を10倍しておく
                memo.at(i + 1) = memo.at(i) * 10;
                memo.at(i) = 0;
                dfs(i + 1);
            }
            }
        }
    }
    int main(){
        cin >> s;
        n = s.size() - 1;//配列の順番で用いるために-1している
        ans = 0;
        dfs(0);
        cout << ans << endl;
        return 0;
}


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

int main(){
	int n,s=0;
  	cin >> n;
  	int a[n];
  	rep(i,n) cin >> a[i];
  	
  	for(int i=0;i<n;i++)
      for(int j=i+1;j<n;j++)
        s+=a[i]*a[j];
  
  cout << s;
      
	return 0;}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int N, M, a, b;
vector<vector<int>> G(200200, vector<int>());
vector<int> group(200200, inf);

void dfs(int st, int gnum){
	for(auto x:G[st]){
		if(group[x] == inf){
			group[x] = gnum;
			dfs(x, gnum);
		}
	}
}

int main(){
	cin >> N >> M;
	rep(i,M){
		cin >> a >> b;
		--a; --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	group.resize(N);
	int num = 0;
	rep(i,N){
		if(group[i] == inf)dfs(i, num++);
	}
	map<int,int> cnt;
	rep(i,N)cnt[group[i]]++;
	int ans = 1;
	for(auto x:cnt)if(x.first != inf)ans = max(ans, x.second);
	cout << ans << endl;
	return 0;
}


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

int main(){
  int N, D, X;
  cin >> N >> D >> X;
  vector<int> V(N);
  for (int i = 0; i < N; i++) cin >> V.at(i);
  int ans = 0, cnt;
  for (int i = 0; i < N; i++){
    cnt = 0;
    for (int j = 0; j * V.at(i) + 1 <= D; j++){
      cnt++;
    }
    ans += cnt;
  }
  cout << ans + X << endl;
}

Measured memory_bytes: 3612
import java.util.*;
import java.io.*;

public class Main {
	int[] ans = new int[120];
	
	public int judge(int[] seat, int i){
		int key = -1;
		int[] dp = new int[18];
		int num = (i%5 == 1) ? 5 : 2;
		for(int j = 1; j < 18; j++){
			if( seat[j-1] == -1 ){
				dp[j] = dp[j-1] + 1;
				if( dp[j] >= num ){
					key = j-num;
					break;
				}
			}
		}
		return key;
	}
	public void simulate(){
		Queue<Integer> queue = new PriorityQueue<Integer>();
		Queue<Integer> time = new PriorityQueue<Integer>();
		Map<Integer, Set<Integer>> map = new HashMap<Integer, Set<Integer>>();
		int[] seat = new int[17];
		for(int i = 0; i < 17; i++){
			seat[i] = -1;
		}
		for(int i = 0; i < 120; i++){
	/*		writer.println(queue);
			writer.println(time);
			writer.println(map);
			for(int a : seat){
				writer.print(a + " ");
			}
			writer.println();*/
			int t = (time.peek() == null) ? 5*i+1 : time.peek();
			while( 5*i >= t ){
				for(int j = 0; j < seat.length; j++){
					if( map.get(t).contains(seat[j]) ){
						seat[j] = -1;
					}
				}
				while( queue.peek() != null ){
					int check = queue.peek();
					int key = judge(seat, check);
					if( key >= 0 ){
						int num = (check%5 == 1) ? 5 : 2;
						for(int j = key; j < key+num; j++){
							seat[j] = check;
						}
						ans[check] = t-check*5;
						int x = 17*(check%2) + 3*(check%3) + 19 + time.peek();
						time.offer(x);
						Set<Integer> temp = (map.get(x) != null) ? map.get(x) : new HashSet<Integer>();
						temp.add(check);
						map.put(x, temp);
						queue.remove();
					} else {
						break;
					}
				}
				time.remove();
				t = (time.peek() == null) ? 5*i+1 : time.peek();
			}
			if( queue.peek() != null ){
				queue.offer(i);
				continue;
			}
			int key = judge(seat, i);
			if( key >= 0 ){
				int num = (i%5 == 1) ? 5 : 2;
				for(int j = key; j < key+num; j++){
					seat[j] = i;
				}
				int x = 17*(i%2) + 3*(i%3) + 19 + i*5;
				time.offer(x);
				Set<Integer> temp = (map.get(x) != null) ? map.get(x) : new HashSet<Integer>();
				temp.add(i);
				map.put(x, temp);
			} else {
				queue.offer(i);
			}
		}
	}
				
	public  void solve() throws IOException{
		simulate();
		while( stdIn.hasNext() ){
			int n = stdIn.nextInt();
			writer.println(ans[n]);
			writer.flush();
		}
		writer.flush();				
	}
	public static void main (String args[]) throws IOException{
		new Main().run();
	}
	
	Scanner stdIn;
	PrintWriter writer;
	
	public void run() throws IOException{
		stdIn = null;
		try{
			stdIn = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
			writer = new PrintWriter(System.out);
			solve();
			stdIn.close();
			writer.close();
		} catch (Exception e){
			e.printStackTrace();
			System.exit(1);
		}
	}	
}

Measured memory_bytes: 12000
main = interact $ unlines . show' . itp1_6_d . read' . lines
 where
  read' (nm:xs) = (map (map read . words) mat, map read vec)
   where
    n = read $ head $ words nm
    (mat,vec) = splitAt n xs
  show' = map show

itp1_6_d (mat,vec) = map (sum . zipWith (*) vec) mat

Measured memory_bytes: 7580
#include <iostream>
#include <cstdio>

using namespace std;

int main(){
  int n;
  while(scanf("%d", &n), n){
    int A = 0;
    int B = 0;

    for(int i = 0; i < n; i++){
      int a, b;
      scanf("%d%d", &a, &b);
      if(a < b) B += a + b;
      if(a > b) A += a + b;
      if(a == b){ A += a; B += b; }
    }

    printf("%d %d\n", A, B);
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	int x;
	cin >> x;
	int cur = 100, ans = 0;
	while(cur < x) {
		cur = (long double)cur * 101 / 100;
		ans++;
	}
	cout << ans << endl;
	
}





Measured memory_bytes: 3652
#include<iostream>
using namespace std;
int main()
{
  int W,H,x,y,r; 
  cin >>W>>H>>x>>y>>r;  
  if(0>x-r || x+r>W || 0>y-r || y+r>H){  
    cout<<"No"<<endl;
    }
  else cout<<"Yes"<<endl;
 return 0;
}

Measured memory_bytes: 3100
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;



int main(){
	string a;
	string b;
	cin >> a;
	cin >> b;

	if(a.length() > b.length()) cout << "GREATER" << endl;
	else if(a.length() < b.length()) cout << "LESS" << endl;

	else {
		int i = 0;
		while(a[i] == b[i] && i != a.length()){
			i++;
		}
		if(a[i] > b[i]) cout << "GREATER" << endl;
		else if(a[i] < b[i]) cout << "LESS" << endl;
		else cout << "EQUAL" << endl;
	}
}

Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=3e2+10;
const int INF=1e9;
const double eps=1e-9;
ll dis[maxn][maxn];
inline ll read(){
	ll x=0,flag=1;
	char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')flag=-1,ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return x*flag;
}
int main(){
	ll i,j,k,m,n;
	n=read();
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			dis[i][j]=read();
	ll ans=0;
	for(i=1;i<=n;i++)
		for(j=i+1;j<=n;j++){
			ll flag=0;
			for(k=1;k<=n;k++){
				if(k!=i && k!=j && dis[i][k]+dis[k][j]==dis[i][j])
					flag=1;
				if(dis[i][k]+dis[k][j]<dis[i][j]){
					printf("-1");
					return 0;
				}
			}
			if(!flag)ans+=dis[i][j];
		}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;



int main(){
	for (int n; cin >> n; ) {
		int ans = 0;
		rep(a, 10) rep(b, 10) rep(c, 10) rep(d, 10) if(a + b + c + d == n) ans++;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
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; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向

ll n;

void input(){
    cin >> n;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    ll mx = 1;
    ll mn;
    vector<ll> yakusu;
    vector<ll> soinsu;
    for(ll i=2;i*i<=n;i++){
        while(n%i==0){
            soinsu.push_back(i);
            n/=i;
        }
    }
    if(n != 1) soinsu.push_back(n);
    yakusu = soinsu;
    sort(soinsu.begin(), soinsu.end());
    soinsu.erase(unique(soinsu.begin(), soinsu.end()), soinsu.end());
    mn = soinsu.size();
    map<ll, ll> cnt;
    for(int i=0;i<yakusu.size();i++){
        cnt[yakusu[i]]++;
    }
    for(auto p:cnt){
        mx *= p.second+1;
    }
    cout << mn << ' ' << mx-1 << endl;
    return 0;
}


Measured memory_bytes: 3216
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <map>
#include <functional>
using namespace std;
int main() {
	int n,ans = 0,k = 0,cnt = 0;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n;i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	for (int i = 0; i < n; i++) {
		if (a[i] != k) {
			if (cnt > 0) {
				ans += k - cnt;
			}
			k = a[i];
			cnt = k;
		}
		if (cnt == 0) {
			ans++;
		}
		else {
			cnt--;
		}
	}
	if (cnt > 0) {
		ans += k - cnt;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
require 'prime'
N = gets.to_i
prime_division = Prime.prime_division((1..N).reduce { |acc, n| acc * n })
el = prime_division.map { |_, v| v }
def e_gt_n(el, n)
  el.count { |e| e >= n }
end
answer = (
  e_gt_n(el, 74) +
  e_gt_n(el, 24) * (e_gt_n(el, 2) - 1) +
  e_gt_n(el, 14) * (e_gt_n(el, 4) - 1) +
  e_gt_n(el, 4) * (e_gt_n(el, 4) - 1) * (e_gt_n(el, 2) - 2) / 2
)
puts answer


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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};


int main(){
  
  vector<string> s(3);
  REP(i,3)cin >> s[i];
  cout << s[0][0] << s[1][1] << s[2][2] << endl;


  return 0;
}

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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

using ll = long long;
using namespace std;

int main() {
    ll n;
    string s;

    cin >> n >> s;

    ll c = 0;
    REP(i, n-2){
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
            c++;
        }
    }

    cout << c << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,x;
    cin>>a>>b>>x;
    long double da=(long double)a;
    long double db=(long double)b;
    if(x*2<a*a*b){
        long double n=(long double)(x)/(long double)a;
        long double p=n*2.0/db;
        long double q=sqrt(db*db+p*p);
        long double theta=asin(db/q);
        theta=(theta*180.0/M_PI);
        cout<<setprecision(10)<<theta<<endl;
    }else if(x*2>a*a*b){
        long double n=(long double)(a*a*b-x)/(long double)a;
        long double p=n*2.0/da;
        long double q=sqrt(da*da+p*p);
        long double theta=acos(da/q);
        theta=(theta*180.0/M_PI);
        cout<<setprecision(10)<<theta<<endl;
    }else cout<<setprecision(10)<<(long double)45<<endl;
    
    return 0;
}

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

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

typedef long long ll;
using namespace std;

int main() {
  int a1,a2;
  int a[4];
  rep(i,0,4){
    scanf("%d", &a[i]);
  }
  a1 = a[0]+a[1];
  a2 = a[2]+a[3];
  if(a1 > a2){
    printf("Left");
  }
  else if(a1 < a2){
    printf("Right");
  }
  else printf("Balanced");
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
    #define ll long long
    #define int long long
    #define lb long double
    #define pb push_back
    #define f(i,a,b) for(int i=a;i<b;i++)
    #define fd(i,a,b) for(int i=a-1;i>=b;i--)
    #define pf push_front
    #define fi first
    #define se second
    #define take(a,n) f(i,0,n)cin>>a[i];
    #define show(a,n) f(i,0,n){cout<<a[i]<<" ";}
    #define ashow(a)  for(auto i:a)cout<<i<<" ";
    #define khtm     cout<<endl;
    #define all(s) s.begin(),s.end()
    #define len(a) a.length()
    #define INF 1e18
    #define MAXN 2000009
    const double pi=3.14159265358979323;
    const int mod=1e9+7;
    bool isPrime(int n) 
{ 
    // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
    // This is checked so that we can skip 
    // middle five numbers in below loop 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
} 
     signed main() {

        ios_base::sync_with_stdio(false);
        cin.tie(NULL);  
        cout.tie(0);  
     // -------------------------------------Code starts here--------------------------------------------------------------------- 
    int t=1;
    // cin>>t;
    while(t--)
    {
      

        int n,k,x=1,y=0;
        int mx=-1,mi=INF,mn=INF;
        int tm=0;
         char c;
         cin>>c;
         
         if(c-'a'>=0)cout<<"a"<<endl;
         else cout<<"A"<<endl;

}

 }

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 998244353;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	string X;
	cin >> X;

	int sum = 1;
	int a = 1;
	for (int i = 0; i < X.size(); i++) {
		if (X[X.size() - 1 - i] == '1') {
			sum += a;
			if (sum >= MOD)sum -= MOD;
		}
		a = (a * 2) % MOD;
	}
	a = N;
	for (int i = 0; i < X.size(); i++) {
		if (X[i] != X[0]) {
			a = i;
			break;
		}
	}

	int cnt = 0;
	int res = 0;
	int t = (int)'1' + '0';
	vector<int> D(N + 1, 0);
	for (int i = 1; i < N; i++) {
		if (N % (2 * i) == i) {
			int tmp = 0;
			int s = 0;
			int k = 1;
			for (int j = 0; j < i; j++) {
				if (X[i - j - 1] == '1')s += k;
				k = (k * 2) % MOD;
			}

			tmp += s;
			bool ok = true;
			for (int j = i; j < N; j++) {
				if (j % (2 * i) < i) {
					if (X[j] > X[j % i]) {
						break;
					}else if (X[j] < X[j % i]) {
						ok = false;
						break;
					}
				}
				else {
					if (X[j] > t - X[j % i]) {
						break;
					}
					else if (X[j] < t - X[j % i]) {
						ok = false;
						break;
					}
				}
			}
			if (ok)tmp++;

			tmp = (tmp - D[i]) % MOD;
			tmp = (tmp + MOD) % MOD;

			for (int j = i; j <= N; j += i) {
				D[j] = (D[j] + tmp) % MOD;
			}


			res = (res + tmp * (2 * i)) % MOD;
			cnt = (cnt + tmp) % MOD;
			//cerr << i << " " << tmp << endl;
		}
	}
	//cnt = 0;
	res = (res + (sum - cnt)*(2 * N)) % MOD;
	res = (res + MOD) % MOD;
	cout << res << endl;
}

Measured memory_bytes: 2196
#include <bits/stdc++.h>
using namespace std;
using lint = long long;

signed main(){
  lint N; cin >> N;
  vector<lint> a(N);
  for(lint i = 0; i < N; i++) cin >> a[i];
  vector<lint> num(2010, 0);
  for(lint i = 0; i < N; i++){
    for(lint j = a[i]; j < num.size(); j++) num[j]++;
  }
  lint ans = 0;
  for(lint i = 0; i < N - 1; i++){
    for(lint j = i + 1; j < N; j++){
      lint ma = a[i] + a[j], mi = max(a[j] - a[i], a[i] - a[j]);
      ans += num[ma - 1] - num[mi];
      if(ma > a[i] && mi < a[i]) ans--;
      if(ma > a[j] && mi < a[j]) ans--;
    }
  }
  cout << ans/3 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

long cnt=0;

void merge(int s[],int n,int left,int mid,int right){
	int i,j,k;
	long L[n];
	long R[n];
	int n1 = mid - left;
	int n2 = right - mid;
	
	for(i = 0;i<n1;i++){
		L[i] = s[left + i];
	}
	for(i = 0;i<n2;i++){
		R[i] = s[mid+i];
	}
	L[n1]=2000000000;
	R[n2]=2000000000;
	i = 0;
	j = 0;
	for(k = left;k<right;k++){
		if(L[i]<R[j]){
			s[k] = L[i++];
		}
		else{ 
			cnt=cnt+(n1-i);
			s[k] = R[j++];
		}
	}
}
	
void mergeSort(int s[],int n,int left,int right){
	if(left+1< right){
		int mid; 
		mid= (left + right)/2;
		mergeSort(s,n,left, mid);
		mergeSort(s,n,mid, right);
		merge(s,n,left,mid, right);
	}
}
	
int main(void){
	int i,n;
	int s[500000];
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&s[i]);
	}
	
	mergeSort(s,n,0,n);
	
	
//	for(i=0;i<n;i++){
//		if(i==n-1){
//			printf("%d\n",s[i]);
//		}
//		else{
//			printf("%d ",s[i]);
//		}
//	}
	
	printf("%ld\n",cnt);
	
	return 0;
}


Measured memory_bytes: 4160
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

printList [a] = print a
printList (a:as) = putStr ( show a ) >> putChar ' ' >> printList as

main = do
	[ a, b, c, d ] <- readIntegers
	print $ maximum $ do
		x <- [ a, b ]
		y <- [ c, d ]
		return $ x * y

Measured memory_bytes: 3844
A, B, C, K = [int (x) for x in (input().split())]

count = 0
x = 0

if K - A >= 0:
    x = K - A
    count = A * 1
else:
    count = K * 1

if x >= 0:
    x = x - B
    if x >= 0 and C != 0:
        C = K - A - B
        count = count + C * -1

print(count)

Measured memory_bytes: 9200
var a,b,s,c:longint;
    s1,s2,s3:ansistring;
 begin
  readln(a,b);
  str(a,s1);
  str(b,s2);
  s3:=s1+s2;
  val(s3,c);
  s:=trunc(sqrt(c));
  if s*s=c then 
   writeln('Yes')
           else 
   writeln('No');
 end.


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

int top = 0;
vector<int> Stack(101);

void initialize(){
    top = 0;
}
bool isFull(){
    return top >= 100;
}

bool isEmpty(){
    return top == 0;
}

void push(int x){
    if (isFull()) cout << "over flow" << endl; 
    top++;
    Stack.at(top) = x;
}

int pop(){
    if (isEmpty()) cout << "under flow" << endl;
    top--;
    return Stack.at(top+1);
}

int main(){
    string input;
    while((cin >> input)){
        int ans;
        if ((input=="+")|(input=="-")|(input=="*")) {
            int a = pop();
            int b = pop();
            if (input=="+") ans = a+b;
            else if (input=="-") ans = -a+b;
            else if (input=="*") ans = a*b;
            push(ans);
        }
        else push(atoi(input.c_str()));
    }
    cout << Stack.at(top) << endl;     
    return 0;
}


Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N,X; cin>>N>>X;
  vi A(N);
  rep(i,0,N) cin>>A[i];
  int ans=INF;
  vii dp(N,vi(N));
  rep(i,0,N){
    dp[i][0]=A[i];
    for(int j=i-1;0<=j;j--) dp[i][i-j]=min(dp[i][i-j-1],A[j]);
    for(int j=N-1;i<j;j--) dp[i][i+N-j]=min(dp[i][i+N-j-1],A[j]);
  }
  rep(i,0,N){
    int sum=0;
    rep(j,0,N){
      sum+=dp[j][i];
    }
    ans=min(ans,sum+X*i);
  }
  cout<<ans<<endl;
  }



Measured memory_bytes: 33152
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		double a = sc.nextDouble();
        double b = sc.nextDouble();
        double h = sc.nextDouble();
        double m = sc.nextDouble();
		double ans = 0;
        double H = Math.toRadians(90-30*h-m/2);
        double M = Math.toRadians(90-6*m);
        double x1 = a*Math.cos(H);
        double y1 = a*Math.sin(H);
        double x2 = b*Math.cos(M);
        double y2 = b*Math.sin(M);
        ans = Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
		System.out.println(ans);
	}
}

Measured memory_bytes: 37480
#include <iostream>
#include <cstdio>
#include <vector>
#define N 1005
using namespace std;

typedef long long ll;
ll n, mx, x[N], y[N];
vector<ll> a;

ll Abs(ll p) {return p > 0 ? p : -p;}

int main()
{
	ll i, j, t;
	cin >> n;
	for (i = 0; i < n; i++) {
		scanf("%lld %lld", &x[i], &y[i]);
		t = Abs(x[i]) + Abs(y[i]);
		if (i > 0 && t % 2 != mx % 2) {cout << "-1"; return 0;}
		mx = max(mx, t);
	}
	for (i = 1; i < mx; i *= 2);
	for (; i > 0; i /= 2) a.push_back(i);
	if (mx % 2 == 0) a.push_back(1);
	cout << a.size() << endl;
	for (i = 0; i < a.size(); i++) printf("%lld ", a[i]);
	puts("");
	for (i = 0; i < n; i++) {
		for (j = 0; j < a.size(); j++) {
			if (Abs(x[i]) > Abs(y[i])) {
				if (x[i] < 0) {
					printf("L");
					x[i] += a[j];
				} else {
					printf("R");
					x[i] -= a[j];
				}
			} else {
				if (y[i] < 0) {
					printf("D");
					y[i] += a[j];
				} else {
					printf("U");
					y[i] -= a[j];
				}
			}
		}
		puts("");
	}
    return 0;
}

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

using namespace std;

typedef long long ll;

int N, A[200005];
int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; i++) {
		scanf("%d", &A[i]);
		A[i] -= i;
	}
	sort(A + 1, A + N + 1);
	ll res = 0;
	for (int i = 1; i <= N; i++) {
		res += abs(A[i] - A[(N + 1) / 2]);
	}
	printf("%lld\n", res);
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long long n,a,b,ans;
int main()
{
     cin>>n;
	 for(int i=0;i<n;i++)
	 {
		 cin>>a>>b;
		 ans=ans+(b-a+1);
	 }
	 cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256