akhauriyash/Code-Regression huggingface dataset:
import sys
import heapq, functools, collections
import math, random
from collections import Counter, defaultdict

# from atcoder.fenwicktree import FenwickTree

# available on Google, not available on Codeforces
# import numpy as np
# import scipy


def solve(grid, n):  # fix inputs here
    console("----- solving ------")
    grid = [(x-1, y-1) for x,y in grid]
    
    grid = sorted(grid)
    console(grid, n)

    g = defaultdict(list)

    for x,y in grid:
        g[x].append(y)
        g[y].append(x)

    console(g)

    res = [0 for _ in range(n)]
    visited_1 = [0 for _ in range(n)]

    result = 0  # number of connected components

    for i in range(n):
        if visited_1[i]:  # if visited
            continue
        visited_1[i] = 1
        stack = [i]
        cnt = 1
        result += 1
        while stack:
            cur = stack.pop()
            for nex in g[cur]:
                if not visited_1[nex]:
                    cnt += 1
                    visited_1[nex] = 1
                    stack.append(nex)
                

    # console(res)
    console(result)
    console(visited_1)
    # res2 = [0 for _ in grid]
    # for i,x in m.items():
    #     res2[x] = res[i]

    return result - 1




def console(*args):  # the judge will not read these print statement
    # print('\033[36m', *args, '\033[0m', file=sys.stderr)
    return

# fast read all
inp = sys.stdin.readlines()

for case_num in [1]:
    # read line as a string
    # strr = input()

    # read line as an integer
    # nrows = int(inp[0])
    
    # read one line and parse each word as a string
    # lst = input().split()

    # read one line and parse each word as an integer
    k, nrows = list(map(int,inp[0].split()))

    # read matrix and parse as integers (after reading read nrows)
    # lst = list(map(int,input().split()))
    # nrows = lst[0]  # index containing information, please change
    grid = []
    for n in range(nrows):
        grid.append(list(map(int,inp[n+1].split())))

    res = solve(grid, k)  # please change
    
    # res = "\n".join(str(x) for x in res)
    # Google - case number required
    # print("Case #{}: {}".format(case_num+1, res))

    # Codeforces - no case number required
    print(res)


Measured memory_bytes: 66232
import heapq as hp

n,m=[int(x) for x in input().rstrip().split()]
a=[-int(x) for x in input().rstrip().split()]

hp.heapify(a)

for i in range(m):
  now=hp.heappop(a)
  hp.heappush(a,-(-now//2))
print(-sum(a))



Measured memory_bytes: 20472
import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.util.Arrays;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.Comparator;

public class Main {
    // 標準入力
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // 標準入力数値配列用 int
    static int[] inputval() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        int[] intarray = new int[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    // 標準入力数値リスト用 int
    static List<Integer> inputIntList() throws Exception {
        List<String> strList = Arrays.asList(br.readLine().trim().split(" "));
        List<Integer> intList = new ArrayList<Integer>();
        for (String elem : strList){
            intList.add(Integer.parseInt(elem));
        }
        return intList;
    }

    // 標準入力数値配列用 integer ソート用
    static Integer[] inputvalInteger() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        Integer[] intarray = new Integer[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    public static void main(String[] args) throws Exception {
        // write your code here
        String s = br.readLine();
        String ans = "";
        for (int i=0; i<s.length(); i++){
            if (i%2 == 0){
                ans += s.charAt(i);
            }
        }
        System.out.println(ans);

    }

}



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

int main() {
  int N; cin >> N;
  string S; cin >> S;
  
  int ans = 0;
  for (int i = 1; i < N; i++) {
    int count = 0;
    
    for (char s = 'a'; s <= 'z'; s++) {
      bool left, right;
      left = false;
      right = false;
      
      for (int j = 0; j < i; j++) {
        if (S[j] == s) left = true;
      }
      
      for (int j = i; j < N; j++) {
        if (S[j] == s) right = true;
      }
      
      if (left && right) count++;
    }
    if (ans < count) ans = count;
  }
  cout << ans << endl;
}
      
  

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

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    sort(S.begin(), S.end());
    if(S[0] == S[1] && S[2] == S[3] && S[0] != S[2]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <map>

using namespace std;

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

    int ans = 0;
    for (auto p : mp) ans = max(ans, p.second);

    cout << ans << endl;
}

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

int64_t solve(int64_t H, int64_t W){
  const int64_t S= H* W;

  int64_t slice= min(H, W);

  int64_t ans= slice;
  for(int Wcut= W/3; Wcut<= W/3+ 1; Wcut++){
    if(Wcut==0){ continue; }
    else{
      vector<int64_t> cross;

      cross.emplace_back(H* Wcut);
      int64_t Wremain= W- Wcut;
      cross.emplace_back(    (H/2)* Wremain);
      cross.emplace_back(((H+1)/2)* Wremain);

      int64_t Smax= *max_element(cross.begin(), cross.end());
      int64_t Smin= *min_element(cross.begin(), cross.end());
      ans= min(ans, Smax- Smin);
    }
  }
  for(int Hcut= H/3; Hcut<= H/3+ 1; Hcut++){
    if(Hcut==0){ continue; }
    else{
      vector<int64_t> cross;

      cross.emplace_back(Hcut* W);
      int64_t Hremain= H- Hcut;
      cross.emplace_back(Hremain* (    W/2));
      cross.emplace_back(Hremain* ((W+1)/2));
  
      int64_t Smax= *max_element(cross.begin(), cross.end());
      int64_t Smin= *min_element(cross.begin(), cross.end());
      ans= min(ans, Smax- Smin);
    }
  }

  return ans;
}

int main(){
  int64_t H,W;
  cin >> H >> W;

  int64_t ans= (H==2   && W==2  ) ? 1
              :(H%3==0 || W%3==0) ? 0
                                  : solve(H, W);
  cout << ans << endl;
}

Measured memory_bytes: 256
def merge(A,left,mid,right):
    '''n1 = mid - left
    n2 = right - mid
    L = []
    R = []
    for i in range(0,n1):
        L.append(A[left+i])
 
    for i in range(0,n2):
        R.append(A[mid+i])
    L.append(1000000001)
    R.append(1000000001)
    '''
    L = A[left:mid]+[1000000001]
    R = A[mid:right]+[1000000001]
 
    i = 0
    j = 0
    cnt = 0
    for k in range(left,right):
        if L[i] <= R[j]:
            A[k]=L[i]
            i += 1
        else:
            if L[i] < 1000000001:
                cnt += mid-left -i
            A[k] = R[j]
            j += 1
    return cnt
 
def mergeSort(A,left,right):
    if left+1 < right:
        mid = (left+right)//2
        v1 = mergeSort(A,left,mid)
        v2 = mergeSort(A,mid,right)
        v3 = merge(A,left,mid,right)
        return v1+v2+v3
    else:
        return 0
 
 
if __name__ == '__main__':
    n = (int)(input())
    a = list(map(int,input().split()))
     
    cnt = mergeSort(a,0,n)
#    print(*a)
    print(cnt)

Measured memory_bytes: 30388
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>

using namespace std;

int main() {
	int a, b, c, x;
	cin >> a >> b >> c >> x;

	long long ans = 0;

	for (int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			int xx = x - 500 * i - 100 * j;
			if (xx < 0) continue;
			if (xx / 50 <= c) ans++;
		}
	}

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


Measured memory_bytes: 888
#include <stdio.h>
#include <math.h>
double pot[100][3],xp,yp,xq,yq,d,a,ans;
int i,j,n;
void check(double x,double y){
	int i; double px,py,a=0.0;
	for(i=0;i<n;i++){
		px=pot[i][0];py=pot[i][1];
		if((px-x)*(px-x)+(py-y)*(py-y)<=1.000000000000005){a+=pot[i][2];}
	}
	if(a>ans)ans=a;
}
int main(void){
	while(scanf("%d",&n)*n){
		ans=1;i=0;
		for(;n>0;n--){
			scanf("%lf,%lf",&xp,&yp);
			pot[i][2]=0;
			for(j=0;j<i;j++){if(xp==pot[j][0] && yp==pot[j][1])break;}
			pot[j][2]++;if(pot[j][2]>ans)ans=pot[j][2];
			if(i==j){i++;pot[j][0]=xp;pot[j][1]=yp;}
		}
		n=i;

		for(i=0;i<n-1;i++){
			xp=pot[i][0];yp=pot[i][1];
			for(j=i+1;j<n;j++){
				xq=pot[j][0];yq=pot[j][1];
				d=(xp-xq)*(xp-xq)+(yp-yq)*(yp-yq);
				if(d==4)check((xp+xq)/2,(yp+yq)/2);
				else if (d<4){
					d=sqrt(1-d/4);
					a=atan2(xq-xp,yp-yq);
					check((xp+xq)/2+d*cos(a),(yp+yq)/2+d*sin(a));
					check((xp+xq)/2-d*cos(a),(yp+yq)/2-d*sin(a));
				}
			}
		}
		printf("%d\n",(int)ans);
	}
	return 0;
}

Measured memory_bytes: 720
import java.util.Scanner;

/**
 * Created by User on 2017/02/18.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();

        int x = n * 800;
        int y = 200 * (n / 15);

        System.out.println(x - y);
    }
}

Measured memory_bytes: 23892
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

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

func main() {
	defer stdout.Flush()
	n := readInt()
	b := make([]int, n)
	var i int
	if n%2 == 0 {
		i = 1
	} else {
		b[0] = 1
		i = 2
	}
	for ; i < n; i = i + 2 {
		b[i] = 2
	}

	for i := 0; i < n; i++ {
		v := readInt()
		if v >= n {
			println(0)
			return
		}
		b[v]--
	}
	for i := range b {
		if b[i] != 0 {
			println(0)
			return
		}
	}
	println(expMod(2, int64(n/2), 1000000007))
}

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

// newFactorial(n, p int64) returns 3 functions.
// 1. factorial(x int64) int64: returns factorial x modulo p (0 <= x <= n)
// 2. invFactorial(x int64) int64: returns inverse of factorial x modulo p (0 <= x <= n)
// 3. combination(x, r int64 int64: returns xCr modulo p (1 <= r <= x <= n)
func newFactorial(n, p int64) (factorial func(int64) int64, invFactorial func(int64) int64, combination func(int64, int64) int64) {
	if n < 1 {
		panic("newFactorial: n must be more than 0")
	}

	fact := make([]int64, n+1)
	fact[1] = 1
	for i := int64(2); i <= n; i++ {
		fact[i] = fact[i-1] * i % p
	}

	ifact := make([]int64, n+1)
	ifact[n] = expMod(fact[n], p-2, p)
	for i := int64(n - 1); i >= 0; i-- {
		ifact[i] = ifact[i+1] * (i + 1) % p
	}

	factorial = func(i int64) int64 {
		return fact[i]
	}
	invFactorial = func(i int64) int64 {
		return ifact[i]
	}
	combination = func(n, r int64) int64 {
		return fact[n] * ifact[n-r] % p * ifact[r] % p
	}
	return
}

func expMod(n, e, m int64) int64 {
	square := func(a int64) int64 {
		return a * a
	}
	if e == 0 {
		return 1
	}
	if e&1 == 1 {
		return n * expMod(n, e-1, m) % m
	} else {
		return square(expMod(n, e/2, m)) % m
	}
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

template<typename A,size_t N,typename T> void FILL(A (&array)[N],const T &val){fill((T*)array,(T*)(array+N),val);}
template<typename T> void FILL(vector<T> &v, const T &x) {fill(v.begin(), v.end(), x);}
template<typename T> void FILL(vector<vector<T>> &v, const T &x) {for(auto &i:v)fill(i.begin(), i.end(), x);}

vector<pair<int,int>> direction = {make_pair(1,0), make_pair(0,1), make_pair(-1,0), make_pair(0,-1)};

vector<pair<int,int>> direction5 = {
  make_pair(2,0), make_pair(0,2), make_pair(-2,0), make_pair(0,-2),
  make_pair(2,2), make_pair(-2,-2), make_pair(-2,2), make_pair(2,-2),
  make_pair(1,2), make_pair(-1,-2), make_pair(-1,2), make_pair(1,-2),
  make_pair(2,1), make_pair(-2,-1), make_pair(-2,1), make_pair(2,-1),
  make_pair(1,1), make_pair(-1,-1), make_pair(-1,1), make_pair(1,-1)
};

int main() {
  int h,w;  cin >> h >> w;
  int ch,cw;  cin >> ch >> cw;
  int dh,dw;  cin >> dh >> dw;
  --ch, --cw, --dh, --dw;

  vector<string> grid(h);
  rep(i,h) cin >> grid[i];

  const int INF = 1<<30;

  vector<vector<int>> dist(h, vector<int>(w, INF));
  dist[ch][cw] = 0;

  deque<tuple<int,int,int>> dq;
  dq.emplace_back(0, ch, cw);

  while(dq.size()){
    auto [d, hh, ww] = dq.front(); dq.pop_front();
    if(dist[hh][ww]<d) continue;
    for(auto [dhh, dww] : direction)  {
      int hhh = hh + dhh, www = ww + dww;
      if(hhh<0 || hhh >= h || www < 0 || www >= w) continue;
      if(grid[hhh][www]=='#') continue;
      if(dist[hhh][www]<=d) continue;
      dist[hhh][www] = d;
      dq.emplace_front(d, hhh, www);
    }
    for(auto [dhh, dww] : direction5)  {
      int hhh = hh + dhh, www = ww + dww;
      if(hhh<0 || hhh >= h || www < 0 || www >= w) continue;
      if(grid[hhh][www]=='#') continue;
      if(dist[hhh][www]<=d+1) continue;
      dist[hhh][www] = d+1;
      dq.emplace_back(d+1, hhh, www);
    }
  }
  if(dist[dh][dw]==INF) dist[dh][dw] = -1;
  cout << dist[dh][dw] << endl;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

bool getJudge(int x_n) {
    int cnt = 0;

    FOR(i, 1, x_n + 1) {
        if (x_n % i == 0) {
            cnt++;
        }
    }
    
    return cnt == 8;
}

int main(void) {
    int n, ans = 0;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    FOR(i, 1, n + 1) {
        if (i % 2 && getJudge(i)) {
            ans++;
        }
    }
    
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstdio>
int main()
{
    int a[10];
    int m;
    for(int i=0;i<=5;i++){
        std::cin>>a[i];
    }
    std::sort(a,a+4);
    m=std::max(a[4],a[5]);
    std:: cout<<a[3]+a[2]+a[1]+m<<std::endl;
    return 0;
    
    
}


Measured memory_bytes: 3124
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<climits>
#include<map>
#define ll long long
using namespace std;
int main() {
	ll n,x;
	cin >> n;
	for (ll i = 0; i*i <= n;i++) {
		x = i * i;
	}
	cout << x << endl;
}

Measured memory_bytes: 256
import bisect
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a=sorted(a)
b=sorted(b)
c=sorted(c)

sum=0
for i in range(n):
    bisect_a=bisect.bisect_left(a,b[i])
   
    
    bisect_c=bisect.bisect_right(c,b[i])
   

    sum+=bisect_a*(n-bisect_c)
print(sum)

Measured memory_bytes: 22516
#include<cstdlib>
#include<vector>
#include<string>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#include<stack>
#include<cstdio>
#include<iostream>
#include<vector>
#define MAXN 1000
using namespace std;
typedef long long ll;
int main()
{
	ios::sync_with_stdio(false);
	//freopen("../in", "r", stdin);
	//freopen("../out", "w", stdout);
	string s;
	while(cin>>s)
	{
		if(s=="Sunny")
			cout<<"Cloudy"<<endl;
		else if(s=="Cloudy")
			cout<<"Rainy"<<endl;
		else
			cout<<"Sunny"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
from collections import Counter

N, P = map(int, input().split())
Ss = input()

if P == 2 or P == 5:
    ans = 0
    for i, S in enumerate(Ss):
        if int(S)%P == 0:
            ans += i+1
else:
    As = [0]
    A = 0
    D = 1
    for S in Ss[::-1]:
        S = int(S)
        A = (A + S*D) % P
        As.append(A)
        D = D*10 % P

    cnt = Counter()
    ans = 0
    for A in As:
        ans += cnt[A]
        cnt[A] += 1

print(ans)


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

int main(void)
{
    int N;
    cin >> N;

    vector<int> l(N, 0);

    for(int i = 0; i < N; ++i)
    {
        cin >> l[i];
    }

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

    int ans = 0;

    for(int i = 0; i < N; ++i)
    {
        for(int j = i+1; j < N; ++j)
        {
            if(l[i] == l[j]) continue;
            vector<int>::iterator it1 = upper_bound(l.begin(), l.end(), l[j]);
            vector<int>::iterator it2 = lower_bound(l.begin(), l.end(), l[i]+l[j]);
            ans += it2 - it1;
        }

    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3628
N,M=map(int,input().split())
min=0
max=1e+6
for i in range(M):
    L,R=map(int,input().split())
    if(min<L):
        min=L
    if(max>R):
        max=R
        
if(max<min or min>max):
    print("0")
else:
    print(max-min+1)
    

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

int main() {
  long N, d, n, c;
  cin >> N;
  n = N;
  d = 0;
  c = 0;
  while(n != 0){
    n /= 10;
    d++;
  }
  for(int i; i < d; i++){
    if(i % 2 == 0){
      if(i == d-1){
        c += N - pow(10,i) + 1;
      }
      else{
        c += pow(10,i+1) - pow(10,i);
      }
    }
  }
  cout << c << endl;
}


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

dp = [[0] * (N + 1) for _ in range(N + 1)]
for l in range(1, N + 1):
  for i in range(N + 1 - l):
    j = i + l
    if (N - l) % 2 == 0:
      dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1])
    else:
      dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1])
print(dp[0][N])


Measured memory_bytes: 113244
n,k = map(int, input().split())
dice = list(map(int, input().split()))
dice_sum = [0]
for i in dice:dice_sum.append(dice_sum[-1]+(i+1)/2)
def SumArea(r, l):
    return dice_sum[l]-dice_sum[r]

ans = 0
for i in range(n-k+1):
    tmp = SumArea(i, i+k)
    if tmp >= ans:
        ans = tmp
print(ans)

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

int main(void){
    int N,d[100];
    int tmp;
    set<int> v;

    cin >> N;

    for(int i = 0;i < N;i++){
        cin >> tmp;
        v.insert(tmp);
    }

    cout << v.size() << endl;

    return 0;
}

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

vector<int> v,z;

int N,M;
int main () {
    cin >> N >> M;
    for(int i=0; i<M; i++) {
        int x;
        cin >> x;
        v.push_back(x);
    }
    long long int ans = 0;
    sort(v.begin(),v.end());
    for(int i=0;i<M-1; i++) z.push_back(abs(v[i+1]-v[i]));
    sort(z.rbegin(),z.rend());
    for(int i=0+N-1; i<z.size();i++) ans += z[i];
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main()
{
    int t=1;
    //cin>>t;
    while(t--){
        int a,b,c,k;
        cin>>a>>b>>c>>k;
        if(c>b && b>a) cout<<"Yes";
        else{
            while(k--){
                if(c<=b) c*=2;
                else if(b<=a) b*=2;
                else break;
            }
            if(c>b && b>a) cout<<"Yes";
            else cout<<"No";
        }
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
  int n; cin >> n;
  ll T; cin >> T;
  vector <ll> a(n + 1);
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  a[n] = 100000000000;
  ll ans = 0;
  for(int i = 0; i < n; i++) {
    if(a[i + 1] - a[i] <= T) {
      ans += a[i + 1] - a[i];
    }
    else {
      ans += T;
    }
  }
  cout << ans << '\n';
}


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

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

	vector<int> a(N);

	for(int i = 0; i < N; i++)
	{
		cin >> a[i];
	}

	//両端キュー、前からも値を入れることが可能
	//昇順に並べていく
	deque<int> d;

	for(int i = 0; i < N; i++)
	{
		//a[i]以上の値の中で一番小さい値のインデックスを返す
		int p = lower_bound(d.begin(), d.end(), a[i]) - d.begin();

		//a[i]以上の値が存在しないときはキューの一番最初に入れる（つまり別の色を塗る）
		if(p == 0)
		{
			d.push_front(a[i]);
		}
		//a[i]以上の値より一つ左隣り（インデックスが一つ小さい）値を書き換える
		//つまりa[i]より小さい値の中でで一番大きな値を書き換える
		//（同じ色で塗るということ）
		else
		{
			d[p-1] = a[i];
		}
	}

	//dの長さが色の数になっている
	//（別の色を塗るたびに先頭に挿入しているから）
	int ans = d.size();
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
# b, c =
# a = int(input())
#n = str(input())
from math import floor
A, B = [int(i) for i in input().split()]

# 判定
inc = floor(A / 0.08)
inc_max = (A + 1) / 0.08

while(1):
    if inc >= inc_max:
        print(-1)
        break
    elif floor(inc * 0.1) == B and floor(inc * 0.08) == A:
        print(inc)
        break
    else:
        inc += 1


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define eps 1e-3
#define pi acos(-1.0)
#define inf 0x3f
#define INF 0x3f3f3f3f
#define pb push_back
#define debug1 cout<<"&&";
#define debug2 cout<<"**";
#define ms(a, x) memset(a, x, sizeof(a))
#define for0(i, n) for(int i = 0; i < n; ++i)
#define for1(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;
typedef pair<long long, long long> pll;
const int mod = 1e9 + 7;
const int N = 2e5+10;
const int M = 1e6+10;
/*=================================================================================*/
#define mid ((l+r)>>1)

struct node {
    int id,h;
    ll s;
}arr[N];
ll dp[N],maxx[N<<2];
void up(int rt) {
    maxx[rt] = max(maxx[rt<<1],maxx[rt<<1|1]);
}
void update(int rt,int l,int r,int x,ll v)
{
    if(l==r)
    {
        maxx[rt] = max(maxx[rt],v);
        return ;
    }
    if(x<=mid) update(rt<<1,l,mid,x,v);
    else update(rt<<1|1,mid+1,r,x,v);
    up(rt);
}
ll query(int rt,int l,int r,int x,int y)
{
    if(x>r||y<l) return 0;
    if(x<=l&&r<=y)
    {
        return maxx[rt];
    }
    if(x>mid) return query(rt<<1|1,mid+1,r,x,y);
    else if(y<=mid) return query(rt<<1,l,mid,x,y);
    else return max(query(rt<<1,l,mid,x,y),query(rt<<1|1,mid+1,r,x,y));
}
int main() {
    int n;
    ll ans = 0;
    scanf("%d", &n);
    for(int i = 1;i<=n;++i) scanf("%d",&arr[i].h);
    for(int i = 1;i<=n;++i) scanf("%lld",&arr[i].s),arr[i].id = i;
    for(int i = 1;i<=n;++i)
    {
        ll tmp = 0;
        if(arr[i].h>1)  tmp = query(1,1,n,1,arr[i].h-1);
        update(1,1,n,arr[i].h,tmp+arr[i].s);
    }
    printf("%lld\n",maxx[1]);
    return 0;
}

Measured memory_bytes: 11044
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int i = 0;
		int count = 0;
		for(i = a; i <= b; i++) {
			String str = i + "";
			if(str.charAt(0) == str.charAt(4)) {
				if(str.charAt(1) == str.charAt(3)) {
					count++;
				}
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 33748
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 2000100;



int main(){
        _
        ll n,k; cin >> n >> k;
        map<ll,ll>atmost;
        vll a(n);
        for(int i = 0; i<n; i++){
            cin >> a[i];
            atmost[a[i]]++;
        }
        sort(all(a));
        for(auto v: atmost){
            ll mx = v.ss;
            if(mx>=k){
                cout<<0<<endl;
                return 0;
            }
        }
        ll ans = inf;
        for(int i = 0; i<n-k+1; i++){
          ans = min(ans, a[i+k-1]-a[i]);
        }
        cout<<ans<<endl;




return 0;
}




Measured memory_bytes: 7296
#include <bits/stdc++.h>
typedef long long int ll;
#define rep(i,n) for (int i = 0; i< (n); i++)
#define Rep(i,n,m) for (int i = (n); i< (m); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
const int INF = 1e9;
const ll MOD = 1000000007;
const ll LINF = 1e18;
using namespace std;



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


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

// #define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;

using P = pair<int, int>;


vector<int> to[100005];
int cost[100005];
signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) {
        int x;
        cin >> x;
        x--;
        a[x] = i+1;

    }
    rep(i,n) cout << a[i] <<" "<< flush;
    cout << "" << endl;


    return 0;
}



Measured memory_bytes: 3584
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <fstream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#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 ALL(s) begin(s),end(s)
#define ITE(c) typeof((c).begin())
#define VIEW(dat) for(auto v : dat){cout<<v<<endl;}
#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(a,b) make_pair((a),(b))
 
 
const int INF=1<<24;
 
using namespace std;
 
string valOf(int n){ stringstream ss;ss<<n;return ss.str();}
int    valOf(string s){return atoi(s.c_str());}
int    valOf(char s){return (unsigned int)(s - '0');}
 
int main(){
    int n, m, s;
    vector<int> a, b;
     
//  ifstream cin("in.txt");
     
    while(cin>>n>>m,n||m){
        int  A=0, B=0;
        a.clear();b.clear();
        rep(i,n){
            cin>>s;
            A+=s;
            a.pb(s);
        }
        rep(i,m){
            cin>>s;
            B+=s;
            b.pb(s);
        }
        sort(ALL(a));
        sort(ALL(b));
         
        int p,q;
        p=q=INF;
        rep(i,n){
            rep(j,m){
                if(A-a[i]+b[j]==B-b[j]+a[i]&&b[j]+a[i]<p+q){
                    p=a[i];
                    q=b[j];
                }
            }
        }
        if(p==INF){
            cout<<"-1"<<endl;
        }else{
            cout<<p<<" "<<q<<endl;
        }
    }
}

Measured memory_bytes: 1224
#include <cstdio>
int a[200005],n,ans;
bool dn(int x,int y,int z){return a[x]<=z&&a[y]<=z;}
bool up(int x,int y,int z){return a[x]>z&&a[y]>z;}
bool chk(int k)
{
	for(int i=0;i<n-1;i++)
	{
		if(up(n-i,n-i-1,k)||up(n+i,n+i+1,k)) return 0;
		if(dn(n-i,n-i-1,k)||dn(n+i,n+i+1,k)) return 1;
	}
	return dn(1,1,k);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n*2;i++) scanf("%d",&a[i]);
	for(int l=0,r=2*n-1,mid=(l+r)>>1;l<=r;mid=(l+r)>>1) if(chk(mid)) r=mid-1,ans=mid;else l=mid+1;
	printf("%d\n",ans);
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iterator>
#include <cstring>

using namespace std;
const int INF = (1<<30);
typedef pair<int, int> P;
typedef long long ll;
#define PB push_back
#define rep(i, a) for (int i = 0; i < a; i++)

int sx, sy;

int gx, gy;

int qqq;

//各座標までの最短距離
int d[100][100];


//移動方向のベクトル
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

//汎用
ll ans = 0;
pair<int, int> red[101], blue[101];
ll BIG = 10000000000;

//累乗
ll POW(ll a, ll b) {
ll c = 1;
for (int i = 0; i < b; ++i) {
c *= a;
}
return c;
}

//階乗
int Kaijou(int a) {
if (a < 2) return 1;
return a * Kaijou(a - 1);
}


int A[200000];
int kinds[200001];


int main() 
{
	int n;
	while(1){
		cin >> n;
		if (n == 0) break;

		vector<int> s(n);
		rep(i, n) cin >> s[i];
		sort(s.begin(), s.end());
		int sum = 0;
		for (int i = 1; i < n - 1; ++i)
			sum +=s[i];
		int ave = sum / (n - 2);
		cout << ave << endl;
	}
	cin >> qqq;
}



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

using namespace std;

int main() {
	string s[3];
	for (int i = 0; i < 3; ++i) {
		cin >> s[i];
	}
	for (int j = 0; j < 3; ++j) {
		cout << (char)(s[j][0] - ('a'-'A'));

		//cout << s[j] << endl;
		  //s[0] <- atcoder
		  //s[1] <- beginner
		  //s[2] <- contest

		//cout << s[j][3] << endl;
		  //s[0][0] <- a
		  //s[1][0] <- b
		  //s[2][0] <- c

		  //s[0][1] <- t
		  //s[1][1] <- e
		  //s[2][1] <- o

		  //s[0][2] <- c 
		  //s[1][2] <- g
		  //s[2][2] <- n
	}
	return 0;
}

Measured memory_bytes: 256
import numpy as np

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

score=0
tmp=-1
for i in A:
    score+=B[i-1]
    if i==tmp+1:
        score+=C[tmp-1]
    tmp=i
print(score)

Measured memory_bytes: 21288
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

alphasm=[chr(i) for i in range(97, 97+26)]
n=I()
lis=[list(SI()) for i in range(n)]
counter=[inf for i in range(26)]
for x in range(26):
    for i in range(n):
        counter[x]=min(counter[x],lis[i].count(alphasm[x]))
        #print(lis[i].count(al))
#print(counter)
for i in range(26):
    for j in range(counter[i]):
        print(alphasm[i],end="")
        

Measured memory_bytes: 3372
#include <stdio.h>
#define MAX 2000000
#define INFTY 30
void insert(int key,int A[]);
int extract(int A[]);
void heap(int i,int A[]);
void increase(int i,int key,int A[]);

int A[MAX+1];
int H;

int main(void){
	int key;
	char com[10];
	
	while(1){
		scanf("%s",com);
		if(com[0]== 'e' && com[1]=='n'){
			break;
		}
		if(com[0]=='i'){
			scanf("%d",&key);
			insert(key,A);
		}
		else{
			printf("%d\n",extract(A));
		}
	}
	
	return 0;
}


void insert(int key,int A[]){
	H++;
	A[H]=-INFTY;
	increase(H,key,A);
}

int extract(int A[]){
	int max;
	if(H<1){
		return -INFTY;
	}
	max=A[1];
	A[1]=A[H--];
	heap(1,A);
	return max;
}


void heap(int i,int A[]){
	int max;
	int a,b;
	int tmp;
	a=2*i;
	b=2*i+1;
	if(a<=H && A[a]>A[i]){
		max=a;
	}
	else {
		max=i;
	}
	
	if(b<=H && A[b]>A[max]){
		max=b;
	}
	if(max!=i){
		tmp=A[i];
		A[i]=A[max];
		A[max]=tmp;
		heap(max,A);
	}
}

void increase(int i,int key,int A[]){
	int tmp;
	if(key<A[i]){
		return;
	}
	A[i]=key;
	while(i>1 && A[i/2]<A[i]){
		tmp=A[i];
		A[i]=A[i/2];
		A[i/2]=tmp;
		i=i/2;
	}
}


Measured memory_bytes: 5608
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		double x1 = sc.nextDouble();
		double y1 = sc.nextDouble();
		double x2 = sc.nextDouble();
		double y2 = sc.nextDouble();
		double ans = Math.pow(x1-x2,2) + Math.pow(y1-y2,2);
		ans = Math.sqrt(ans);
		System.out.println(ans);
	}
}


Measured memory_bytes: 27920
import java.util.*;

public class Main {

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

        int H1 = sc.nextInt();
        int M1 = sc.nextInt();
        int H2 = sc.nextInt();
        int M2 = sc.nextInt();
        int K = sc.nextInt();
        sc.close();


        int H = (H2 - H1) * 60;
        int M = (M1 - M2);

        int result = H - M - K;

        System.out.println(result);

    }
}

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

#define ALL(a) (a).begin(), (a).end()
#define debug(x) cerr<<#x<<":"<< (x)<<endl

// dp[i] := i本使って作れる数値の最大値(stringで持つ)
// 遷移
// dp[i] = max(dp[i], dp[i-cost[a[j]]] + a[j])

string dp[101010];
int cost[9]={2,5,5,4,5,6,3,7,6};

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

	fill_n(dp,n,"0");
	dp[0]="";
	int sm=0;
	for(int i=0;i<=n;++i){
		for(auto &&ai: a){
			//cerr<<"fuge"<<endl;
			if (i-cost[ai-1]<0) continue;
			if (dp[i-cost[ai-1]]=="0") continue;
			//debug(i);
			//debug(ai);
			string tmp = to_string(ai) + dp[i-cost[ai-1]];
			//cerr<<"hoge"<<endl;
			//debug(cost[ai-1]);
			//cerr<<tmp<< endl<<endl;
			if(dp[i].size() > tmp.size()) continue;
			if(dp[i].size() == tmp.size()) {
				if(dp[i]>tmp) continue;
			}
			//cerr<<tmp<< endl;
			dp[i] = tmp;
			//cerr<<tmp<< endl;
		}
	}
	string ans = dp[n];
	sort(ALL(ans));
	reverse(ALL(ans));
	cout << ans << endl;
  return 0;
}



Measured memory_bytes: 33664
H, W = map(int, raw_input().split())
s = []
for i in xrange(H):
  s.append(list(raw_input()))

for y in xrange(H):
  for x in xrange(W):
    if s[y][x] == '#':
      continue
    count = 0
    for dy in [-1, 0, 1]:
      for dx in [-1, 0, 1]:
        ny = y + dy
        nx = x + dx
        if 0 <= ny < H and 0 <= nx < W:
          if s[ny][nx] == '#':
            count += 1
    s[y][x] = str(count)

for i in xrange(H):
  print ''.join(s[i])

Measured memory_bytes: 2692
/*
  #問題：
  


  #分析：
  #オブジェクト：
  
  #条件：
  

  #要求：
  

  #解法：
  
*/

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
#include <initializer_list>
#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define uLL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;


const unsigned int BIT_FLAG_0 = (1<<0);
const unsigned int BIT_FLAG_1 = (1<<1);
const unsigned int BIT_FLAG_2 = (1<<2);
const unsigned int BIT_FLAG_3 = (1<<3);
const unsigned int BIT_FLAG_4 = (1<<4);
const unsigned int BIT_FLAG_5 = (1<<5);
const unsigned int BIT_FLAG_6 = (1<<6);
const unsigned int BIT_FLAG_7 = (1<<7);


#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;

using Bint = mp::cpp_int;



int main(void){
  int a,b;
  cin>>a>>b;
  cout<<max({2*a-1,2*b-1,a+b})<<endl;
  return 0;
}



Measured memory_bytes: 256
n, m, q = map(int, input().split())
A, B, C, D = [], [], [], []
for i in range(q):
    a, b, c, d = map(int, input().split())
    A.append(a - 1)
    B.append(b - 1)
    C.append(c)
    D.append(d)

L = []

def f(l):
    if len(l) == n:
        L.append(l)
        return
    for i in range(l[-1], m + 1):
        f(l + [i])

for i in range(1, m + 1):
    f([i])

ans = 0

for l in L:
    ans = max(ans, sum(d for a, b, c, d in zip(A, B, C, D) if l[b] - l[a] == c))

print(ans)


Measured memory_bytes: 94728
w,h=map(int,input().split())
n=lambda :int(input())
pq=[]
for _ in range(w):
  pq.append((n(),0))
for _ in range(h):
  pq.append((n(),1))
pq.sort()
w,h=w+1,h+1
ans=0
for i,j in pq:
  if j:
    ans+=i*w
    h-=1
  else:
    ans+=i*h
    w-=1
print(ans)

Measured memory_bytes: 24540
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>

using namespace std;

int main(){
	int ans = 0;
	string N;
	cin>>N;
	for(int i=0;i<N.size();i++){
		if(N[i]=='2') ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
x0, y0, x1, y1 = map(int, input().split())

q = int(input())
for _ in range(q):
    x2, y2 = map(int, input().split())

    cross = (x1 - x0)*(y2 - y0) - (y1 - y0)*(x2 - x0)
    if cross > 0:
        print('COUNTER_CLOCKWISE')
        continue
    if cross < 0:
        print('CLOCKWISE')
        continue

    dot = (x1 - x0)*(x2 - x0) + (y1 - y0)*(y2 - y0)
    if dot < 0:
        print('ONLINE_BACK')
        continue
    if (x1 - x0)**2 + (y1 - y0)**2 < (x2 - x0)**2 + (y2 - y0)**2:
        print('ONLINE_FRONT')
    else:
        print('ON_SEGMENT')



Measured memory_bytes: 5604
/*    特徴    */

/*    教訓    */

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld  = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-9; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x) == 1) return x; }
long long il() { long long x; if (scanf("%lld", &x) == 1) return x; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

#define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
int lcm(int a, int b){return a / gcd(a, b) * b;}
#define begin_end(a) a.begin(),a.end() //sort(begin_end(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll) (n) ; i++ )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define p_b push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元vectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

// -------- template end - //


// - library ------------- //

// ゼロ除算エラーの対策をしていないので注意
// 関数の引数の評価順序が未規定のため、ceil_divide(ii(), ii())はNG
ll ceil_divide(ll a, ll b) {
  return (a + b - 1) / b;
}

// --------- library end - //



// - main() -------------- //

int main(){

ll N = il();

ll ans = 0;
if (N % 2 == 1){
  cout << 0 << endl;
  return (0);
}

N /= 2;

while(N >= 5){
  ans += N / 5;
  N /= 5;
}

cout << ans << endl;




// ---------- main() end - //
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF 1<<28
#define MAX 100005
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

typedef long long ll;

int n, a[100005];
int dp[MAX];

int main()
{
    FASTIO
    cin>>n;
    for(int i = 1; i <= n; i++)
        cin>>a[i];
    dp[1] = 0;
    for(int i = 2; i <= n; i++){
        dp[i] = dp[i-1] + abs (a[i] - a[i-1]);
        if(i > 2){
            dp[i] = min(dp[i], dp[i-2] + abs(a[i] - a[i-2]));
        }
    }
    cout << dp[n]<<endl;
   
    return 0;
} 

Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
    int n, x, i;

    while(1){
        scanf("%d %d", &n, &x);
        if(n == 0 && x == 0){
            break;
        }
        int narray[n];
        for(i = 1; i <= n; i++){
            narray[i - 1] = i;
        }

        int j, k, sum, count = 0;
        for(i = 0; i < n; i++){
            for(j = 0; j < n; j++){
                for(k = 0; k < n; k++){
                    sum = narray[i] + narray[j] + narray[k];
                    if(sum == x && narray[i] != narray[j] && narray[j] != narray[k] && narray[k] != narray[i]){
                        count++;
                    }
                }
            }
        }
        printf("%d\n", count / 6);
    }

    return 0;
}


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

#include <bits/stdc++.h>

static map<pair<ll, ll>, ll> mem;
ll combi(ll n, ll k) {
  if (n == k || k == 0) {
    return 1;
  } else {
    if (!mem.count({n, k})) { mem.insert({{n, k}, combi(n - 1, k - 1) + combi(n - 1, k)}); }
    return mem.at({n, k});
  }
}

int main() {
  int n, p;
  cin >> n >> p;
  vector<int> a(n);
  int c[2] = {0, 0};
  for (auto &e : a) {
    cin >> e;
    e %= 2;
    ++c[e];
  }

  //  combination combi(n);

  ll num[2] = {0, 0};
  // even
  {
    for (int i = 0; i <= c[0]; ++i) { num[0] += combi(c[0], i); }
  }
  // odd
  {
    for (int i = p; i <= c[1]; i += 2) { num[1] += combi(c[1], i); }
  }

  cout << num[0] * num[1] << endl;

}


Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] a1 = new int[n];
		int[] a2 = new int[n];
		
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			a1[i] = a2[i] = a;
		}
		
		Arrays.sort(a2);
		
		for (int i = 0; i < n; i++) {
			int max = a1[i] == a2[n - 1] ? a2[n - 2] : a2[n - 1];
			System.out.println(max);
		}
		
	}
}


Measured memory_bytes: 94680
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

ll mod(ll a){
  return (a % 1000000007);
}

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

ll nCr(ll n,ll r){
  if(r == 1) return n;
  else if(r == 0) return 1;
  else return nCr(n-1,r-1)*n/r;
}

int main(){
  ll n,x; cin >> n >> x; ll ans = n;
  vl powder(n);
  
  rep(i,n){
    cin >> powder[i];
    x -= powder[i];
  }
  
  sort(all(powder));
  
  while(x >= powder[0]){
    x -= powder[0];
    n++;
  }
  
  cout << n << endl;
  
}

Measured memory_bytes: 256
import sys

N = int(sys.stdin.readline())

d = []
for _ in range(N):
    d.append(list(map(int, sys.stdin.readline().split())))

grid_min_path = [[True for _ in range(N)] for _ in range(N)]

def warshall_floyd(d, n, grid_min_path):
    changed = False
    path_length = 0
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if d[i][j] > d[i][k] + d[k][j]:
                    changed = True
                if d[i][j] == d[i][k] + d[k][j] and i != k and k != j:
                    # print(i, j, k)
                    grid_min_path[i][j] = False
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d, changed, grid_min_path

d, changed, grid_min_path = warshall_floyd(d, N, grid_min_path)
# print(grid_min_path)
if changed:
    print(-1)
else:
    length = 0
    for i in range(N):
        for j in range(i+1, N):
            if grid_min_path[i][j]:
                length += d[i][j]
    print(length)

Measured memory_bytes: 75540