jiahuimbzuai/CoQuIR huggingface dataset:
//  [rust]
use std::fmt::Debug;
use std::str::FromStr;

pub struct TokenReader {
    reader: std::io::Stdin,
    tokens: Vec<String>,
    index: usize,
}

impl TokenReader {
    pub fn new() -> Self {
        Self {
            reader: std::io::stdin(),
            tokens: Vec::new(),
            index: 0,
        }
    }

    pub fn next<T>(&mut self) -> T
    where
        T: FromStr,
        T::Err: Debug,
    {
        if self.index >= self.tokens.len() {
            self.load_next_line();
        }
        self.index += 1;
        self.tokens[self.index - 1].parse().unwrap()
    }

    pub fn vector<T>(&mut self) -> Vec<T>
    where
        T: FromStr,
        T::Err: Debug,
    {
        if self.index >= self.tokens.len() {
            self.load_next_line();
        }
        self.index = self.tokens.len();
        self.tokens.iter().map(|tok| tok.parse().unwrap()).collect()
    }

    pub fn load_next_line(&mut self) {
        let mut line = String::new();
        self.reader.read_line(&mut line).unwrap();

        self.tokens = line
            .split_whitespace()
            .map(String::from)
            .collect();
        self.index = 0;
    }
}

fn divisors(mut n: i64) -> i64 {
    let mut div = 1;
    let mut fac = 2;

    while fac * fac <= n {
        let mut pow = 0;
        while n % fac == 0 {
            n /= fac;
            pow += 1;
        }

        div *= pow + 1;
        fac += 1;
    }
    if n > 1 {
        div *= 2;
    }

    div
}

fn solve(n: i64) -> i64 {
    let mut res = 0;
    for i in 1..n {
        res += divisors(n - i);
    }
    res
}

fn main() {
    let mut reader = TokenReader::new();
    let n = reader.next();

    let res = solve(n);
    println!("{}", res);
}
//  [rust]
use std::{io::{self, prelude::*}, *};

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    let mut scan = Scanner::new(stdin.lock());
    let mut w = io::BufWriter::new(stdout.lock());
    
    let mut p = Vec::<i64>::new();
    const N:usize =1e6 as usize + 1;
    let mut isp = vec![false; N];
    
    for i in 2..(N as i64) {
        if !isp[i as usize] {
            p.push(i as i64);
        }
        for x in &p {
            if x * i >= N as i64 {
                break;
            }
            isp[(x * i) as usize] = true;
            if i % x == 0 {
                break;
            }
        }
    }
    // writeln!(w, "ok");
    let mut ans = 0;
    let n = scan.next();
    for i in 1..n {
        let mut t = i;
        let mut s = 1;
        for x in &p {
            if x * x > i {
                break;
            }
            let mut c = 0;
            while t % x == 0 {
                c += 1;
                t /= x;
            }
            s *= c + 1;
        }
        if t > 1 {
            s *= 2;
        }
        ans += s;
    }
    writeln!(w, "{}", ans);
}
 
 
pub struct Scanner<B> {
    reader: B,
    buf_str: Vec<u8>,
    buf_iter: std::str::SplitWhitespace<'static>,
}
impl<B: BufRead> Scanner<B> {
    pub fn new(reader: B) -> Self {
        Self {
            reader,
            buf_str: Vec::new(),
            buf_iter: "".split_whitespace()
        }
    }
    pub fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse");
            }
            self.buf_str.clear();
            self.reader.read_until(b'\n', &mut self.buf_str).expect("Failed read");
            self.buf_iter = unsafe {
                let slice = std::str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_whitespace()) }
        }
    }
}
//  [swift]
let n = Int(readLine()!)!
var dpTable = [Int](repeating: 0, count: 1000000+1) // dpTable
var cutter = [Int](repeating: 0, count: 1000000+1) // divisor count
dpTable[2] = 1 

for it in 1...1000000 {
  var k = 1
  while k * it <= 1000000 {
    cutter[k*it] += 1
    k += 1
  }
}

if n > 2 {
  for it in 3...n {
   dpTable[it] = dpTable[it-1] + cutter[it-1]
  }
}

print(dpTable[n])
//  [swift]
import Foundation

let n = Int(readLine()!)! - 1
var c = 0
for i in 1...n{
  c += n / i
}
print(c)
//  [swift]
let n = Int(readLine()!)!
var count = 0
for i in 1..<n {
    count += (n-1) / i
}
print(count)
//  [python]
n, m, x = map(int, input().split())
a = list(map(int, input().split()))

c1 = 0
for i in a:
    if i < x:
        c1 += 1

c2 = 0
for i in a:
    if i > x:
        c2 += 1

print(min(c1, c2))
//  [python]
N, M, X = map(int, input().split())
A = [int(a) for a in input().split()]
left, right = 0, 0
for a in A:
  if a < X: left += 1
  else: right += 1
print(min(left, right))
//  [python]
N,M,X = list(map(int, input().split()))
A = list(map(int, input().split()))

len_left = len([i for i in A if i < X])
len_right = len([i for i in A if i > X])

ans = min(len_left,len_right)
print(ans)
//  [python]
l = list(map(int, input().split()))
N, M, X = l[0], l[1], l[2]

fee = list(map(int, input().split()))

import numpy as np
fee = np.array(fee)
left = np.sum(fee < X)
right = np.sum(fee > X)

if left > right:
    print(right)
else:
    print(left)
//  [python]
# coding : utf-8

import numpy as np

X = [int(i) for i in input().split()]
C = np.array([int(i) for i in input().split()])

high = np.sum(C > X[2])
low  = np.sum(C < X[2])

print(min(high,low))
//  [python]
import numpy as np
N,M,X=map(int,input().split())
A=list(map(int,input().split()))

A=np.array(A)

print(min(np.count_nonzero(A<X),np.count_nonzero(A>X)))
//  [java]
import java.util.*;
import java.io.*;

public class Main {
	static final int like = 753;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		for(int i = 0; i < m; i ++)
			list.add(sc.nextInt());
		
		int a = 0, b = 0;
		for(int i = x; i > 0; i--) {
			if (list.contains(i))
				a++;
		}
		for(int i = x; i < n; i++) {
			if (list.contains(i))
				b++;		
		}
		out.println(Math.min(a, b));
		
		out.close();
	}
	


static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}
//  [java]
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int m = saori.saori_hayami();
		int x = saori.saori_hayami();
		int count = 0;
		int num = 0;
		for(int i = 0;i < m;i++){
			num = saori.saori_hayami();
			if(num < x){
				count++;
			} 
		}
		if(m - count >= count){
			System.out.println(count);
		} else {
			System.out.println(m-count);
		}

		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}
//  [java]
import java.util.*;
import java.io.*;

public class Main {
   
	public static void main(String[] args) throws IOException {
		InputReader in = new InputReader(System.in);
		int n = in.readInt();
		int m = in.readInt();
		int arr[] = new int[n];
		int k = in.readInt();
		for(int i = 0; i<m; i++) {
		  int x = in.readInt();
		  arr[x-1] = 1; 
		}
		int m1 = 0; 
		for(int i = 0; i<k; i++){
			m1 += arr[i]; 
		}
		int m2 = 0; 
		for(int i = k-1; i<n; i++) {
			m2 += arr[i]; 
		}
		System.out.println(Math.min(m1, m2)); 
	}
}
class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	
	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}
//  [java]
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        int m = cin.nextInt();
        int x = cin.nextInt();
        int [] a = new int[m];
        for (int i = 0; i < m; i++) {
            a[i] = cin.nextInt();
        }
        if (x == n) {
            System.out.println(0);
            return;
        }

        long left = Arrays.stream(a).filter(ai -> { return (ai < x); }).count();
        long right = Arrays.stream(a).filter(ai -> { return (ai > x); }).count();

        System.out.println(Math.min(left, right));
    }
}
//  [java]
import java.util.Arrays;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int X = sc.nextInt();
        int[] A = new int[M];
        for (int i = 0; i < A.length; ++i) {
            A[i] = sc.nextInt();
        }

        System.out.println(solve(N, A, X));

        sc.close();
    }

    static int solve(int N, int[] A, int X) {
        Set<Integer> gates = Arrays.stream(A).boxed().collect(Collectors.toSet());

        return Math.min((int) IntStream.range(1, X).filter(gates::contains).count(),
                (int) IntStream.range(X + 1, N).filter(gates::contains).count());
    }
}
//  [cpp]
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<type_traits>
#include<numeric>
#include<limits>
#include<iomanip>
#include<set>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;

//define
#define INF 100000000
#define NUM 1000000007


int main() {
	int n, m, x;
	cin >> n >> m >> x;
	VI a(m);
	int cnt_a = 0,cnt_b=0;
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}

	sort(a.begin(), a.end());
	
	for (int i = 0; i < m; i++) {
		if (a[i] < x) {
			cnt_a++;
		}
		else {
			cnt_b++;
		}
	}

	int ans = min(cnt_a, cnt_b);
	cout << ans << endl;
	return 0;
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;
int n, m, x;
int main(){
  cin >> n >> m >> x;
  int a(m);
  int many = 0;
  int litt = 0;
  for(int i = 0; i < m; ++i){
    cin >> a;
    if(x > a) ++many;
    if(x < a) ++litt;
  }
  if(many < litt) cout << many << endl;
  else cout << litt << endl;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int N, M, X;

int main(void){
    
    scanf("%d %d %d", &N, &M, &X);
    int a = 0, b = 0;
    for(int i = 0; i < M; ++i){
        int A; scanf("%d", &A);
        if(A < X) ++a;
        if(A > X) ++b;
    }
    printf("%d\n", min(a, b));
    
    return 0;
}
//  [cpp]
#include <iostream>


int main(void){

	int n, m, x;
	std::cin >> n >> m >> x;

	bool* pass = new bool[n];
	for(int i = 0; i < n; i++){
		pass[i] = true;
	}

	int tmp;
	for(int i = 0; i < m; i++){
		std::cin >> tmp;
		pass[tmp] = false;
	}
	int costL = 0;
	int costR = 0;
	for(int i = x; i < n; i++){
		costR += pass[i] ? 0 : 1;
	}
	for(int i = x; i > 0; i--){
		costL += pass[i] ? 0 : 1;
	}
	
	std::cout << ((costL > costR) ? costR : costL) << std::endl;

	delete[] pass;

	return 0;
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,x,s1=0,s2=0,i,a;
	scanf("%d %d %d",&n,&m,&x);
	for(i=0;i<m;i++)
	{
		scanf("%d",&a);
		if(a<x)
		{
			s1++;
		}
		else
		{
			s2++;
		}
	}
	printf("%d",min(s1,s2));
	return 0;
}
//  [c]
#include <stdio.h>

int main(){
  int i,N,M,X;
  scanf("%d%d%d",&N,&M,&X);
  int A[M+1];
  for(i=1;i<=M;i++){
    scanf("%d",&A[i]);
  }
  int k=0;
  for(i=1;i<M;i++){
    if(A[i]<X && X<A[i+1]){
      k=i;
    }
  }

  if(k<M-k){
    printf("%d",k);
  }else{
    printf("%d",M-k);
  }
  return 0;
}
//  [c]
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a,b) ((a)>(0)?(a):-(a))

int main(void){
    int N,M,X,B,C;
    B =0 ;
    C =0 ;
    scanf("%d %d %d",&N,&M,&X);
    for(int i =0; i<M;i++){
        int A[i];
        scanf("%d",&A[i]);
        if(A[i]>X){
            B++;
        }else{C ++;
        }}
        printf("%d",MIN(B,C));
    
    
    return 0;
}
//  [c]
#include <stdio.h>

int main()
{
	int i, N, M, X, A[101];
	scanf("%d %d %d", &N, &M, &X);
	for (i = 1; i <= M; i++) scanf("%d", &(A[i]));

	int B[101] = {};
	for (i = 1; i <= M; i++) B[A[i]] += 1;

	int neg = 0, pos = 0;
	for (i = X; i >= 0; i--) neg += B[i];
	for (i = X; i <= N; i++) pos += B[i];
	
	if (neg < pos) printf("%d\n", neg);
	else printf("%d\n", pos);
	fflush(stdout);
	return 0;
}
//  [c]
#include<stdio.h>
int main()
{

    int a,b,k,i,j,z=0,c,count1=0,count2=0;
    scanf("%d%d%d",&a,&b,&c);
    int ara[b],ara2[a+1];

    for(i=0;i<b;i++)
    {
        scanf("%d",&ara[i]);

    }
    for(j=0;j<=a;j++)
    {
        ara2[j]=j;
        
    }

    for(j=1;j<c;j++)
    {
        for(i=0;i<b;i++)
        {
        if(ara2[j]==ara[i])
        {
            count1++;
        }
    }
}
      for(k=c+1;k<a;k++)
      {
          for(i=0;i<b;i++)
        {
        if(ara2[k]==ara[i])
        {
            count2++;
        }
    }
      }


     if(count1>=count2)
     {
         printf("%d\n",count2);
     }
     else
    {
        printf("%d\n",count1);
        }
}
//  [c]
#include <stdio.h>
#define MIN(x,y)	((x)<(y)?(x):(y))

int main(){
    int n, m, x, a[101]={0}, b;
    scanf("%d%d%d", &n, &m, &x);

    for(int i=0; i<m; i++){
        scanf("%d", &b);
        a[b]++;
    }

    int cnt1=0, cnt2=0;
    for(int i=x; i<n; i++){
        if( a[i] ){ cnt1++; }
    }
    for(int i=x; i>0; i--){
        if( a[i] ){ cnt2++; }
    }

    printf("%d\n", MIN( cnt1, cnt2 ));
    return 0;
}
//  [c]
#include<stdio.h>

int main( )
{
    int N , Mu[200] , X , lcount=0 , rcount=0 , i , j , M  ;
    
    scanf("%d%d%d" , &N , &M, &X);

    for( i = 1 ; i <= M ; i++)
        scanf("%d" , &Mu[i] );
    
    for( i = X-1 ; i > 0 ; i--)
    {
        for( j = 1 ; j <= M ; j++)
        {
            if( i == Mu[j] )
            {
                 lcount++ ;
                 break ;
            }
        }
    }
    
    
    for( i = X+1 ; i < N ; i++)
    {
        for( j = 1 ; j <= M ; j++)
        {
            if( i == Mu[j] )
            {
                 rcount++ ;
                 break ;
            }
               
        }
    }
    
    if( lcount >= rcount)
        printf("%d\n" , rcount);
    else 
        printf("%d\n" , lcount);
    
    return 0; 
}
//  [javascript]
function main(input) {
    var n = input[0].split(" ")[0]-0;
    var m = input[0].split(" ")[1]-0;
    var x = input[0].split(" ")[2]-0;
    var list = input[1].split(" ").map(v=>v-0);
    var a = 0, b=0;
    list.forEach(v=>{
        if(v<x) a++;
        else b++;
    });
    console.log(Math.min(a,b));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))
//  [javascript]
function Main(input){
    input = input.split("\n");
    var mem = input[0].split(" ").map(Number);
    var arr = input[1].split(" ").map(Number);
    var x= mem[2];
    var a = 0,b=0;
    for(var i=0;i<arr.length;i++){
        if(arr[i]<x)a++;
        else b++;
    }
    console.log(Math.min(a,b))
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
//  [javascript]
"use strict";

const main = arg => {
    const N = parseInt(arg.split("\n")[0].split(" ")[0]);
    const M = parseInt(arg.split("\n")[0].split(" ")[1]);
    const X = parseInt(arg.split("\n")[0].split(" ")[2]);
    const m = arg.split("\n")[1].split(" ").map(n=>parseInt(n));
    
    let rightCost = 0;
    let leftCost  = 0;
    
    for(let i=X; i<=N; i++) {
        if(m.indexOf(i) != -1) rightCost++;
    }
    
    for(let i=X; i>0; i--) {
        if(m.indexOf(i) != -1) leftCost++;
    }
    
    console.log(Math.min(rightCost, leftCost));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
function main(input){
  var line1 = parse(input[0]);
  var n = line1[0];
  var m = line1[1];
  var x = line1[2];
  var line2 = parse(input[1]);
  
  var costN = line2.filter((a) => a>x).length;
  console.log(Math.min(costN, m-costN));
}

function parse(line){
  var ret = [];
  var arr = line.split(' ');
  for (var i = 0; i < arr.length; i++) {
    ret.push(parseInt(arr[i]));
  }
  return ret;
}

var
input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main(input);
});
//  [javascript]
function Main(s) {
  s = s.split("\n");
  var a = s[1].split(" ").map(a => +a);
  s = s[0].split(" ").map(a => +a);
  var l = 0, r = 0, k = 0;
  for(var i = 1; i < s[0]; i++){
    if(i === a[k]){
      k++;
      if(i < s[2])l++;
      else r++;
    }
  }
  console.log(l < r ? l : r);
}

Main(require("fs").readFileSync("/dev/stdin","utf8"));
//  [javascript]
function Main(input) {
    input = input.split("\n");
    params = input[0].split(" ");
    n = parseInt(params[0]);
    m = parseInt(params[1]);
    x = parseInt(params[2]);
    fee_stations = input[1].split(" ");

    sum = 0;
    for(var i=0; i < m; i++){
        pos = parseInt(fee_stations[i]);
        if( pos > x){
            break;
        }
        else{
            sum += 1;
        }
    }
    if( sum < m/2 ){
        console.log(sum);
    }
    else{
        console.log(m - sum);
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [go]
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

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

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var N, M, X int

func main() {
	sc.Split(bufio.ScanWords)
	//X: 最初のマス
	N, M, X = nextInt(), nextInt(), nextInt()

	ans := make([]int, 2)
	for i := 0; i < M; i++ {
		tmp := nextInt()
		if X < tmp {
			ans[1]++
		} else {
			ans[0]++
		}
	}

	fmt.Println(minInt(ans[0], ans[1]))
}
//  [go]
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

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

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

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	n, m, x := nextInt(), nextInt(), nextInt()
	a := map[int]bool{}

	for i := 0; i < m; i++ {
		a[nextInt()] = true
	}

	l, r := 0, 0
	for i := x + 1; i < n+1; i++ {
		if a[i] {
			r++
		}
	}
	for i := 0; i < x+1; i++ {
		if a[i] {
			l++
		}
	}

	fmt.Println(min(l, r))
}
//  [go]
package main

import (
	"fmt"
)

func main() {
	var n, m, x int
	fmt.Scanf("%d %d %d", &n, &m, &x)

	left, right := 0, 0
	for i := 0; i < m; i++ {
		var a int
		fmt.Scanf("%d", &a)
		if a < x {
			left += 1
		} else {
			right += 1
		}
	}

	res := left
	if left > right {
		res = right
	}
	fmt.Println(res)
}
//  [go]
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N, M, X int
	fmt.Scan(&N, &M, &X)

	A := make([]int, M)
	for i := 0; i < M; i++ {
		fmt.Scan(&A[i])
	}
	sort.Ints(A)

	// 経路2つ分のコスト合計
	var a, b int

	for _, v := range A {
		if v < X {
			// 0-Xまでコスト
			a++
		} else {
			// X-Nまでコスト
			b++
		}
	}

	if a < b {
		fmt.Println(a)
	} else {
		fmt.Println(b)
	}
}
//  [go]
package main

import "fmt"

func main() {
        var n, m, x int
        fmt.Scan(&n, &m, &x)

        var lcost, rcost int
        for i := 0; i < m; i++ {
                var a int
                fmt.Scan(&a)
                if a < x {
                        lcost++
                        continue
                }
                rcost++
        }

        if lcost < rcost {
                fmt.Println(lcost)
                return
        }
        fmt.Println(rcost)
}
//  [go]
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	m := iScan()
	x := iScan()
	a := make(map[int]int)
	for i := 0; i < m; i++ {
		a[iScan()-1] = 1
	}
	p, q := 0, 0
	for i := 0; i < x; i++ {
		p += a[i]
	}
	for i := x; i < n; i++ {
		q += a[i]
	}
	fmt.Println(smaller(p, q))
}
//  [ruby]
n,m,x = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
i = a.bsearch_index {|n| n > x}
puts [a[0...i].size, a[i..-1].size].min
//  [ruby]
N,M,X = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
now = X
left = 0
right = 0
loop do
    now -= 1
    left += 1 if A.include?(now)
    break if now == 0
end

now = X
loop do
    now += 1
    right += 1 if A.include?(now)
    break if now == N+1
end
puts [left, right].min
//  [ruby]
n, m, x = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
l, r = 0, 0
(1..x).each do |i|
  if a.include?(i)
    l += 1
  end
end
(x..n).each do |i|
  if a.include?(i)
    r += 1
  end
end
puts [l,r].min
//  [ruby]
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

n,w,x=gi
a=gi
l=a.find_all{|ta| ta < x}.size
r=a.find_all{|ta| ta > x}.size
puts min l,r
1
//  [ruby]
N, M, X = gets.split.map &:to_i
A = gets.split.map &:to_i

cnt = 0
A.each do |e|
  cnt += 1 if e < X
end

if cnt < A.size - cnt
  puts cnt
else
  puts A.size - cnt
end
//  [rust]
use std::io;
use std::cmp::min;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let n = v[0];
	let m = v[1];
	let x = v[2];
	let mut a = vec![0; (n+1) as usize];
	/*for i in &a {
		println!("{}", i);
	}*/
	let v:Vec<i32> = procon_read();
	for i in v {
		a[i as usize] = 1;
	}
	let mut left = 0;
	let mut right = 0;
	for i in 0..x {
		left += a[i as usize];
	}
	for i in (x+1)..(n+1) {
		right += a[i as usize];
	}
	println!("{}", min(left, right));
}
//  [rust]
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::cmp::min;

fn main() {
    let n: usize = read();
    let m: usize = read();
    let x: usize = read();
    let mut a: Vec<usize> = vec![0; n + 1];

    for _ in 0..m {
        let ai: usize = read();
        a[ai] = 1;
    }

    let mut ans = 0;
    let mut ans2 = 0;

    for i in 0..x {
        ans += a[i];
    }

    for i in x..n + 1 {
        ans2 += a[i];
    }

    println!("{}", min(ans, ans2))
}
//  [rust]
use std::io::stdin;
use std::cmp::min;

fn main() {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let mut n_m_x: Vec<i32> = Vec::with_capacity(3);
    for iter in buf.split_whitespace(){
        n_m_x.push(iter.parse::<i32>().unwrap());
    }

    buf.clear();
    stdin().read_line(&mut buf).unwrap();
    let mut cost_array: Vec<i32> = Vec::new();
    for iter in buf.split_whitespace(){
        cost_array.push(iter.parse::<i32>().unwrap());
    }

    println!("{}", solve(n_m_x, cost_array));
}

fn solve(n_m_x: Vec<i32>, cost_array: Vec<i32>) -> i32 {
    let n = n_m_x[0];
    let x = n_m_x[2] as usize;

    let mut cost = vec![0; n as usize];
    for index in cost_array {
        cost[index as usize] = 1;
    }
    cost[x] = 0;

    let (left, right) = cost.split_at(x);
    min(left.iter().sum(), right.iter().sum())
}
//  [rust]
use proconio::fastout;
use whiteread::parse_line;

#[fastout]
fn main() {
    let (n, _, x): (usize, usize, usize) = parse_line().unwrap();
    let a: Vec<usize> = parse_line().unwrap();

    let mut cost: Vec<usize> = vec![0; n + 1];
    for pos in a {
        cost[pos] += 1;
    }

    let mut to_0 = 0;
    for i in 0..x {
        to_0 += cost[i];
    }
    let mut to_n = 0;
    for i in (x + 1)..(n + 1) {
        to_n += cost[i];
    }
    println!("{}", std::cmp::min(to_0, to_n));
}
//  [rust]
#[allow(unused_imports)]
use std::{cmp::Reverse, collections::*};

#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Chars, Usize1},
};

#[allow(unused_imports)]
use itertools::Itertools;

#[allow(unused_imports)]
use num::Integer;

#[fastout]
pub fn main() {
    input! {
        _n: usize, m: usize, x: usize,
        a: [usize; m],
    }

    let mut left = std::usize::MAX;
    let mut right = std::usize::MAX;
    for i in 0..=m {
        if a[i] < x {
            left = i;
        } else {
            right = i;
            break;
        }
    }

    let cost_l: usize = if left == std::usize::MAX {
        0
    } else {
        a[..=left].iter().count()
    };
    let cost_r: usize = if right == std::usize::MAX {
        0
    } else {
        a[right..].iter().count()
    };

    println!("{}", cost_l.min(cost_r));
}
//  [swift]
import Foundation
func toTuple<T>(_ args: [T]) -> (T, T, T) { (args[0], args[1], args[2]) }
func readInts() -> [Int] { readLine()!.split(separator: " ").map { Int($0)! } }

let (n, _, x) = toTuple(readInts())
let ai = readInts()
print(min(ai.filter { $0 > 0 && $0 < x }.count, ai.filter { $0 > x && $0 < n}.count))
//  [swift]
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element {
        return self.maxElement()!
    }
    func min() -> Element {
        return self.minElement()!
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}

/*************** テストスペース ***************/



/*************** メインプログラム ***************/

let X = readIntSplit(by: " ")[2]
let A = readIntSplit(by: " ")
print(min(A.filter{$0<X}.count, A.filter{$0>X}.count))
//  [typescript]
function Main(input: string) {
  const lines: string[] = input.split('\n');
  const params1 = lines[0].split(' ');
  const params2 = lines[1].split(' ');

  const n = parseInt(params1[0]);
  const m = parseInt(params1[1]);
  const x = parseInt(params1[2]);

  const a = params2.map(x => parseInt(x));

  const costL = a.filter(n => n < x).length;
  const costR = a.filter(n => n > x).length;

  const min = Math.min(costL, costR);

  console.log(min);
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [typescript]
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);const tn=():number=>{const a=input[0];input.shift();return Number(a)};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{const a=input[0];input.shift();return String(a)};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const tc=():string=>{let a=input[0].split('');const b=a[0];a.shift();if(a.length>0){input[0]=a.join('')}else{input.shift()}return String(b)};const tcc=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(tc())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1];}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};
const main=()=>{
  let [n,m,x]=tnn(3)
  let l=0,r=0
  for(let i=0;i<m;i++){
    if(tn()>x)r++
    else l++
  }
  to(min(r,l))
}
main()
//  [typescript]
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const [n, m, x] = stdin
  .split('\n')[0]
  .split(' ')
  .map(Number)

const a = stdin
  .split('\n')[1]
  .split(' ')
  .map(Number)

const ans = () => {
  const left = a.filter(v => v < x).length
  const right = a.filter(v => v > x).length

  return Math.min(left, right)
}

console.log(ans())
//  [typescript]
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [, , X] = input[0].map(Number);
  const A = input[1].map(Number);

  const right = A.findIndex((num) => num > X);

  if (right === -1) {
    return 0;
  }

  return Math.min(right, A.length - right);
};

console.log(main(read()));
//  [typescript]
var lines: string[] = [];
var reader: any = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on("line", function(line: string) {
  lines.push(line);
});
reader.on("close", function() {
  var valueN: number = Number(lines[0].split(" ")[0]);
  var valueM: number = Number(lines[0].split(" ")[1]);
  var valueX: number = Number(lines[0].split(" ")[2]);
  var listA: number[] = lines[1]
    .split(" ")
    .map(function(value: string): number {
      return Number(value);
    });

  var counterA: number = 0;
  var costList: number[] = new Array<number>(valueN + 1).fill(0);
  for (var idx in listA) {
    costList[listA[idx]] = 1;
  }

  var sumPrime = costList
    .slice(0, valueX)
    .reduce(function(accumulator, currentValue): number {
      return accumulator + currentValue;
    }, 0);
  var sumSecond = costList
    .slice(valueX, valueN + 1)
    .reduce(function(accumulator, currentValue): number {
      return accumulator + currentValue;
    }, 0);
  if (sumPrime > sumSecond) {
    console.log(sumSecond);
  } else {
    console.log(sumPrime);
  }
});
//  [python]
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
 
## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
 
N=int(input())

# 1 2 3 4 5
# 2 3 4 5 1

ans = 0

for i in range(N-1):
    ans += i+1

print(ans)
//  [python]
def main():
    n = int(input())

    print(sum(range(1,n)))

if __name__ == '__main__':
    main()
//  [python]
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    count = 0
    for nn in range(1, N):
        count += nn
    print(count)

if __name__ == '__main__':
    main()
//  [java]
import java.util.*;
public class Main implements Runnable {
    public static void main(String[] args) {
      new Thread(null, new Main(), "", 16 * 1024 * 1024).start(); //16MBスタックを確保して実行
    }
    public void run() {
      //ここに処理を書く
      
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
        long ans = 0;
        for(int i = 1; i <= n; i++) {
          if (i == 1) {
            continue;
          } 
          ans += i - 1;
        }
    
		// 出力
		System.out.println(ans);
    }
}
//  [java]
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long ans = 0;
        for(int i = 1; i <= n; i++){
            ans += i-1;
        }
        System.out.println(ans);
    }
}
//  [java]
import java.io.*;
import java.util.*;
import static java.lang.System.in;

public class Main {
    PrintWriter out = new PrintWriter(System.out);
    // no self-loop or multiple edges
    public static void main(String[] args) throws Exception {
        Main main = new Main();
//        main.solve();
        System.out.println(main.solve());
    }
    long solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long ans = 0;
        for(int i=1;i<=n;i++){
            ans += i-1;
        }
        return ans;
    }
}
//  [cpp]
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const int MOD = 1e9+7;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;


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

    cin >> n;
    ll c=0;
    for(int i = 1; i < n;i++){
        c+= i%MOD;
    }
    cout << c << endl;
    

    return 0;
}
//  [cpp]
#include<iostream>

using namespace std;

int N;

int main() {
    cin >> N;
    long ans = 0;
    if(N > 1) {
        for (int i = 1; i < N+1; i++) {
            if (i == 1) {
                ans += 1;
            } else if (i == N) {
                ans += 0;
            } else {
                ans += (long)(i);
            }
        }
    }
    cout << ans << endl;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n, ans=0, i;
    cin >> n;
    for(i=0;i<n-1;i++){
        ans=ans+i+1;
    }
    cout << ans <<endl;
    return 0;

}
//  [c]
#include<stdio.h>
int n,i;
long r=0;
int main(){
    scanf("%d",&n);
    for(i=n;i--;)r+=i;
    printf("%ld",r);
    return 0;
}
//  [c]
#include <stdio.h>

long long ModSum(int N){
  int i;
  long long S;
  S = 0;
  for(i = N - 1;i >= 0;i--) S += i;
  return S;
}

int main(void){
  int N;
  scanf("%d", &N);
  printf("%lld\n", ModSum(N));
  return 0;
}
//  [c]
#include <stdio.h>

long long int ans(int num) {
	if (num == 0) return 0;
	if (num == 1) return 1;
	return num + ans(num - 1);
}

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

	printf("%lld", ans(N - 1));

	return 0;
}
//  [go]
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	sum := 0
	for i := 0; i < n - 1; i++ {
		sum = sum + i + 1
	}

	fmt.Println(sum)
}
//  [go]
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	total := 0
	for i := 0; i < n-1; i++ {
		total += i + 1
	}

	fmt.Println(total)
}
//  [ruby]
n=gets.to_i

puts n*(n-1)/2
//  [ruby]
n = gets.chomp.to_i
puts (n * (n-1) / 2)
//  [ruby]
N=gets.to_i
p N*(N-1)/2
//  [python]
import numpy as np

n, m = map(int,input().split())

ss = np.zeros((n,m),int)

for i in range(n):
    s = list(map(int, input().split()))
    
    if s[0]>0:
        for k in s[1:]:
            ss[i,k-1]=1

c = ss.sum(0)

ans = np.sum(c==n)

print(ans)
//  [python]
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions

def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())


#n = ip()                              #入力整数1つ
a,b= (int(i) for i in input().split())      #入力整数横2つ
#n,x,y = (int(i) for i in input().split())    #入力整数横3つ
#n,m,x,y= (int(i) for i in input().split())  #入力整数横4つ
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
c = []
for i in range(a):
    d = [int(i) for i in input().split()]
    d.pop(0)
    c.append(d)
s = set(c[0])
for i in range(1,a):
    s = s.intersection(set(c[i]))
print(len(s))
//  [python]
import numpy as np
n, m = map(int, input().split())

cnt = np.array([0 for x in range(m + 1)])

for i in range(n):
    a = list(map(int, input().split()))[1:]
    cnt[a] += 1
print(np.sum(cnt >= n))