jiahuimbzuai/CoQuIR huggingface dataset:
//  [java]
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.foodsLovedByEveryone();
    }

    private void foodsLovedByEveryone() {
        try (Scanner scan = new Scanner(System.in)) {
            int n = Integer.parseInt(scan.next());
            int m = Integer.parseInt(scan.next());
            List<List<Integer>> lovedFoods = IntStream.range(0, n).boxed().map(
                    i -> {
                        int j = Integer.parseInt(scan.next());
                        return IntStream.range(0, j).map(l -> Integer.parseInt(scan.next())).boxed().collect(Collectors.toList());
                    })
                    .collect(Collectors.toList());

            System.out.println(
                    IntStream.rangeClosed(1, m)
                            .mapToObj(i -> lovedFoods.stream().filter(j -> j.contains(i)).count()).filter(i -> i >= n).count());
        }
    }

    private void bPlusMinusA() {
        try (Scanner scan = new Scanner(System.in)) {
            int a = Integer.parseInt(scan.next());
            int b = Integer.parseInt(scan.next());
            if (b % a == 0) {
                System.out.println(a + b);
            } else {
                System.out.println(b - a);
            }
        }
    }
}
//  [java]
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[] m = new int[sc.nextInt()];

		for (int i = 0; i < n; i++) {
			int k = sc.nextInt();
			for (int j = 0; j < k; j++) {
				int a = sc.nextInt();
				m[a - 1]++;
			}
		}
		System.out.println(Arrays.stream(m).filter(x -> x == n).count());
		sc.close();
	}
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;
#define ll long long

ll ar[100000005],br[100000005]={0};
int main()
{
    ll a,b,c,i,j,cnt=0;


    cin>>a>>b;

    for(i=0;i<a;i++)
    {
        cin>>c;
        for(j=0;j<c;j++)
        {
            cin>>ar[j];
            br[ar[j]]++;
        }
    }
    for(i=0;i<=100000005;i++)
    {
        if(br[i]>=a)cnt++;
    }

    cout<<cnt<<endl;






    return 0;
}
//  [cpp]

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;
const ll 	N 		= 	2*1e6;

vll adj[N];ll visit[N]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

// <------------- Declare Variables Here ------------> //

ll T=1;
ll n,x,y,m,k;
string s,t;
vll a,b,p,ans;
// <------------- Implement Functions Here ----------> //


// <------------- Start of main() -------------------> //

void MAIN() {
	cin >>n>>m;
	vll cnt(m+1);
	for(ll i=0;i<n;i++) {
		cin>>x;
		for(ll j=0;j<x;j++) {
			cin >> y;
			cnt[y]++;
		}
 	}
 	ll cou = 0;
 	for(ll i=0;i<=m;i++) cou+=(cnt[i]==n);
	cout<<cou;
}

int main() {
	fastio;randomINT;
	//cin>>T;
	while(T--) {
		MAIN();
	}
	return 0;
}
//  [c]
#include "stdio.h"

int main(){
    int N,M,K,i,j,F[31],t;
    scanf("%d%d",&N,&M);
  	for(i=0;i<=30;i++) F[i]=0;
    for(i=0;i<N;i++){
        scanf("%d",&K);
        for(j=0;j<K;j++){
            scanf("%d",&t);
            F[t]++;
        }
    }
    t=0;
    for(i=1;i<=M;i++){
        if(F[i]==N){
            t++;
        }
    }
    printf("%d",t);
    return 0;
}
//  [c]
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
typedef struct{
    int a,b;
}data;

//昇順
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
//構造体降順
int comp( const void *c1, const void *c2 )
{
  data test1 = *(data *)c1;
  data test2 = *(data *)c2;
  int tmp1 = test1.b;   /* b を基準とする */
  int tmp2 = test2.b;
  return tmp2 - tmp1;
}


int kai(int n){
    if(n==0){
        return 1;
    }
    int sum=1;
    for(int i=1;i<=n;i++){
        sum*=i;
    }
    return sum;
}

int main(){
    int N,M;
    scanf("%d%d",&N,&M);
    int kind[M];
    rep(i,M){
        kind[i]=0;
    }
    rep(i,N){
        int K;
        scanf("%d",&K);
        rep(j,K){
            int temp;
            scanf("%d",&temp);
            kind[temp-1]++;
        }
    }
    int sum=0;
    rep(i,M){
        if(kind[i]==N){
            sum++;
        }
    }
    printf("%d",sum);
}
//  [c]
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef long long ll;
typedef int keytype;

int gcd(int a, int b){ return (a % b) ? gcd(b, a % b) : b;}
int lcm(int a, int b){ return (a / gcd(a, b)) * b;}

/* a[0], ..., a[n-1] の数の最大公約数 */
int ngcd(int n, int a[])
{
    int i, d;

    d = a[0];
    for (i = 1; i < n && d != 1; i++)
        d = gcd(a[i], d);
    return d;
}

void quicksort(keytype a[], int first, int last)
{
    int i, j;
    keytype x, t;

    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

int is_prime(int x){
    if(x <= 1) return 0;
    for(int i = 2; i * i <= x; i++){
        if(x % i == 0) return 0;
    }
    return 1;
}

int is_substr(char s[], char t[], int i){
    int flag = 1;

    if(s[i] == '\0') flag = 0;

    for(int j = 0; j < strlen(t); ++j, ++i){
        if(s[i] != t[j]){
            flag = 0;
            break;
        }
    }
    return flag;
}

// factor list, number of factors, natural number
void factorize(int ftr[], int *num, int n){
    int a = 2, cnt = 0;

    while(n >= a){
        if(n % a == 0){
            n = n / a;
            ftr[cnt++] = a;
        }else{
            a++;
        }
    }
    *num = cnt;
}

//#define N 5
//int p[N + 1];
int nextperm(int p[], int N)  /* 辞書式順序で次の順列 */
{
    int i, j, t;

    i = N - 1;
    p[0] = 0;  /* 番人 */
    while (p[i] >= p[i + 1]) i--;
    if (i == 0) return 0;  /* 完了 */
    j = N;
    while (p[i] >= p[j]) j--;
    t = p[i];  p[i] = p[j];  p[j] = t;
    i++;  j = N;
    while (i < j) {
        t = p[i];  p[i] = p[j];  p[j] = t;  i++;  j--;
    }
    return 1;  /* 未了 */
}

void comb(int size1, int size2, int v[size1][size2]){
  for(int i = 0; i < size1; i++){
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for(int k = 1; k < size1; k++){
    for(int j = 1; j < k; j++){
      v[k][j] = (v[k-1][j-1] + v[k-1][j]);
    }
  }
}

int abs_val(int a, int b){
    if(a > b) return a - b;
    else return b - a;
}

const int inf = 1012345678;
int main(){
    int n, m;
    int k[35];
    int a[35][35];
    int memo[35][35] = {0};
    int ans[35];

    for(int i = 0; i < 35; ++i){
        ans[i] = 1;
    }
    //printf("%d\n", ans[4]);

    scanf("%d %d", &n, &m);
    for(int i = 0; i < n; ++i){
        scanf("%d", &k[i]);
        for(int j = 0; j < k[i]; ++j){
            scanf("%d", &a[i][j]);
            memo[i][a[i][j]] = 1;
        }
    }

    for(int i = 0; i < n; ++i){
        for(int j = 1; j <= m; ++j){
            //printf("%d\n", ans[j]);
            ans[j] = (memo[i][j] & ans[j]);
        }
    }

    int cnt = 0;
    for(int i = 1; i <= m; ++i){
        //printf("%d\n", ans[i]);
        if(ans[i] == 1) cnt++;
    }

    printf("%d\n", cnt);

    return 0;
}
//  [javascript]
'use strict'

function main(input) {
  input = input
    .trim()
    .split('\n')
    .map(v => v.split(' ').map(Number))

  const N = input[0][0]
  const M = input[0][1]

  const enq = input.slice(1)
  const votebox = [...Array(M + 1)].map(v => 0)
  enq.forEach(item => {
    for (let i = 1; i < item.length; i++) {
      votebox[item[i]]++
    }
  })
  const ans = votebox.filter(num => {
    return num === N
  })
  console.log(ans.length)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))
//  [javascript]
'use strict'
function Main(input){
  input=input.split('\n');
  input[0]=input[0].split(' ');
  var N=parseInt(input[0].shift());
  var M=parseInt(input[0].shift());
  input.shift();
  var K=[];
  var ninzu=[];
  for(let i=0;i<M;i++){
    ninzu[i]=0;
  }
  for(let i=0;i<N;i++){
    input[i]=input[i].split(' ');
    K[i]=parseInt(input[i].shift());
    for(let j=0;j<K[i];j++){
      ninzu[parseInt(input[i][j])-1]++;
    }
  }
  var counter=0;
  for(let i=0;i<M;i++){
    if(ninzu[i]===N)counter++;
  }
  console.log(counter);
} 

Main(require('fs').readFileSync('/dev/stdin','utf8'));
//  [javascript]
"use strict";

// read lines from stdin
const input = require("fs")
  .readFileSync("/dev/stdin", "utf8")
  .split("\n");

const firstLine = input[0].split(" ");
const N = parseInt(firstLine[0], 10);
const M = parseInt(firstLine[1], 10);

const survay = [];

for (let i = 1; i <= N; i++) {
  const line = input[i].split(" ");
  const K = parseInt(line[0], 10);

  for (let j = 1; j <= K; j++) {
    const voted = parseInt(line[j], 10);
    survay[voted] = survay[voted] ? survay[voted]+1 : 1;
  }
}

let ans = 0;

for (let i = 1; i <= M; i++) {
  if (survay[i] === N) { ans++; }
}

console.log(ans);
//  [go]
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	sc.Split(bufio.ScanWords)
	var n, m, ans int
	var k [30]int
	var a [30][30]int
	fmt.Scanf("%d %d", &n, &m)
	for i := 0; i < n; i++ {
		k[i] = nextInt()
		for j := 0; j < k[i]; j++ {
			a[i][j] = nextInt()
		}
	}

	f := map[int]int{}
	for i := 0; i < m; i++ {
		f[i+1] = 0
	}

	for i := 0; i < n; i++ {
		for j := 0; j < k[i]; j++ {
			b := f[a[i][j]]
			f[a[i][j]] = b + 1
		}
	}

	for i := 0; i < m; i++ {
		if f[i+1] == n {
			ans++
		}
	}

	fmt.Println(ans)

}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"math/bits"
	"os"
)

func main() {
	N, M := ReadInt(), ReadInt()
	s := 1<<M - 1
	for i := 0; i < N; i++ {
		K := ReadInt()
		v := 0
		for j := 0; j < K; j++ {
			v |= 1 << (ReadInt() - 1)
		}
		s &= v
	}
	fmt.Println(bits.OnesCount(uint(s)))
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }
//  [go]
package main

import "fmt"

func main() {
	// Code for B - Foods Loved by Everyone
	var N, M int
	fmt.Scanf("%d %d", &N, &M)

	flag := make(map[int]int, M)
	var K, A int
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &K)
		for j := 0; j < K; j++ {
			fmt.Scanf("%d", &A)
			flag[A]++
		}
	}

	var count int = 0
	for i := 1; i <= M; i++ {
		if flag[i] == N {
			count++
		}
	}
	fmt.Println(count)
}
//  [ruby]
people_count = gets.chomp.split()[0].to_i
favs_count = {}
people_count.times do |c|
  gets.chop.split()[1..-1].each do |fav|
      favs_count[fav] = (favs_count[fav]||0) + 1
  end
end

p favs_count.values.count(people_count)
//  [ruby]
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N, M = get_ints
K = []
A = Array.new(N) { [] }
m = Array.new(M+1) { Set.new }

N.times do |i|
  test = get_ints
  K[i] = test[0]
  A[i] = test[1..]
  A[i].each do |a|
    m[a].add(i)
  end
end

puts m.count { |set| set.length == N }
//  [ruby]
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]
M = lines[0][1]

num_like = []
for i in 1..M do
  num_like[i-1] = 0
end

for i in 1..N do
  k = lines[i][0]
  for j in 1..k do
    food = lines[i][j]
    num_like[food-1] += 1
  end
end

ans = 0
for i in 1..M do
  if num_like[i-1] == N then
    ans += 1
  end
end
puts ans
//  [rust]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize
    };

    let mut s = vec![];
    for i in 1..=m {
        s.push(i);
    }

    for _ in 0..n {
        input! {
            k: usize,
            a: [usize; k]
        }
        let mut b = vec![];
        for ai in a.iter() {
            if s.contains(ai) {
                b.push(*ai);
            }
        }

        s = b;
    }

    println!("{}", s.iter().count())
}
//  [rust]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
    n: usize,
    m: usize,
    }
    let mut a_list = vec![];
    for _ in 0..n {
        input! {
        k: usize,
        a: [Usize1; k]
        }
        a_list.push(a);
    }
    let mut is_like = vec![1; m];
    for i in 0..n {
        for j in 0..m {
            if !a_list[i].contains(&j) {
                is_like[j] = 0;
            }
        }
    }
    let ans = is_like.iter().filter(|&&x| x == 1).count();
    println!("{}", ans);
}
//  [rust]
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    let mut n:usize=read!();
    let mut m:usize=read!();
    let mut v=[0;33];
    for i in 0..n {
        let mut k:usize=read!();
        for j in 0..k {
            let mut a:usize=read!();
            v[a]+=1;
        }
    }
    let mut ans=0;
    for i in 0..33 {
        if v[i]==n {ans+=1; }
    }
    println!("{}",ans);
}
//  [typescript]
let  lines: any = [];
const reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
reader.on('line', function (line: string) {
  lines.push(line.split(/\s/).map(i => parseInt(i)));
});
reader.on('close', function() {
  let [n, m]: number[] = lines.shift();
  let k: number[][] = lines;
  let array: number[] = new Array(m + 1);
  array.fill(0);
  for (let i = 0; i < n; i++) {
    let idx: number = k[i].shift();
    for (let j = 0; j < idx; j++) {
      const element: number = k[i][j];
      array[element] += 1;
    }
  }
  
  console.log(array.filter(item => item === n).length);
});
//  [typescript]
import * as fs from 'fs';

namespace AtCoder.abc118 {

    class ProgramB {
        inp: string[];

        // in
        // 3 4
        // 2 1 3
        // 3 1 2 3
        // 2 3 2
        // out
        // 1
        constructor(inp: string) {
            this.inp = inp.split('\n');
        }

        main() {
            const [n, m]: number[] = this.inp[0].split(' ').map(Number);
            this.inp.shift();

            let cnt: number = 0;
            for (let i: number = 1; i <= m; i++) { // 食べ物
                let flg = true;
                for (let j: number = 0; j < n; j++) { // 人
                    if (!this.inp[j].split(' ').map(Number).slice(1).some((x: number) => x == i)) {
                        flg = false;
                    }
                }
                if (flg) cnt++;
            }
            console.log(cnt);
        }
    }

    const args: string = fs.readFileSync('/dev/stdin', 'utf8').trim();
    const func = new ProgramB(args);
    func.main();
}
//  [typescript]
namespace Coder {
  class Scanner {
    private buffer: string = '';
    private stdinQueue: any = [];

    constructor() {
      process.stdin.resume();
      process.stdin.setEncoding('utf8');
      process.stdin.on(
        'data',
        (chunk): void => {
          this.buffer += chunk;
          while (this.stdinQueue.length > 0) {
            const i = this.buffer.indexOf('\n');
            if (i < 0) {
              break;
            }
            let line = this.buffer.substr(0, i);
            if (line.endsWith('\r')) {
              line = line.slice(0, -1);
            }
            this.buffer = this.buffer.substr(i + 1);
            this.stdinQueue.shift()(line);
          }
        },
      );
    }
    public getLine(): Promise<string> {
      return new Promise((resolve, reject) => {
        const i = this.buffer.indexOf('\n');
        if (i >= 0 && this.stdinQueue.length == 0) {
          let line = this.buffer.substr(0, i);
          if (line.endsWith('\r')) {
            line = line.slice(0, -1);
          }
          this.buffer = this.buffer.substr(i + 1);
          resolve(line);
        } else {
          this.stdinQueue.push(resolve);
        }
      });
    }

    public close(): void {
      process.stdin.pause();
    }
  }

  async function slove() {
    const sc = new Scanner();
    const [n, m] = (await sc.getLine()).split(' ').map((x) => +x);
    const list = [];
    const cnt = Array(m).fill(0);
    for (let i = 0; i < n; i++) {
      const t = (await sc.getLine()).split(' ').map((x) => +x);
      t.shift();
      for (let v of t) {
        cnt[v - 1]++;
      }
    }
    console.log(cnt.filter((x) => x === n).length);
    sc.close();
  }

  slove();
}
//  [python]
N = map(int, input().split())
l = list(map(int, input().split()))
from collections import deque


l = deque(l)

count=0
for i in range(len(l)-1):
    if l[i] >l[i+1]:
        c=l[i] -l[i+1]
        l[i+1]+=c
        count+=c

print(count)
//  [python]
import sys
import numpy as np
from numba import vectorize

readline = sys.stdin.readline
read = sys.stdin.read

n = int(input())
a = np.array(readline().split(), dtype=np.int64)

@vectorize("i8(i8,i8)")
def larger (a,b):
    return max(a,b)

b = larger.accumulate(a)
ans = sum(b-a)
print(ans)
//  [python]
import numpy as np
from numba import jit
N = int(input(''))
A1 = np.array(list(map(int, input('').split(' '))))

@jit(nopython=True)
def func(A):
    step = 0
    for k in range(0,N-1):
        if A[k] > A[k+1]:
            add = A[k] - A[k+1]
            step += add
            A[k+1] += add
    return step
        
print(func(A1))
//  [java]
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        BigInteger[] nums = new BigInteger[N];


        for (int i = 0; i < N; i++) {
            nums[i] = sc.nextBigInteger();
        }

        BigInteger sum = BigInteger.ZERO;
        for (int i = 1; i < N; i++) {
            if (nums[i-1].compareTo(nums[i]) > 0) {
                BigInteger b = nums[i - 1].subtract(nums[i]);

                sum = sum.add(b);
                nums[i] =nums[i].add(b);
            }
        }

        System.out.println(sum);

    }
}
//  [java]
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long former = 0;
        long latter = 0;
        long formerStep = 0;
        List<Long> actualList = new ArrayList<>();
        List<Long> stepList = new ArrayList<>();
        stepList.add(0l);

        for(int i = 0; i < n; i++){
            actualList.add(sc.nextLong());
        }
        sc.close();

        for(int i = 1; i < n ; i++){
            former = actualList.get(i - 1);
            latter = actualList.get(i);
            formerStep = stepList.get(i - 1);

            if((former + formerStep) <= latter){
                stepList.add(0l);
            }
            else{
                stepList.add(former + formerStep - latter);
            }
        }

        System.out.println(stepList.stream().mapToLong(e -> e).sum());
        
    }
}
//  [java]
import java.util.*;
import java.math.BigInteger;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int noc=sc.nextInt(), i=0, n=noc;
		BigInteger t = BigInteger.ZERO;
		int[] a = new int[noc];
		while (noc-->0) a[i++] = sc.nextInt();
		for (i=0; i<n-1; i++) {
			if (a[i]>a[i+1]) {
				t = t.add(new BigInteger(""+(a[i]-a[i+1])));
				a[i+1]=a[i];
			}
		}
		System.out.println(t);
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}
//  [cpp]
 #include "bits/stdc++.h"
 
using namespace std;
 
typedef long long ll;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
    
 #define sz(x) (int)(x).size()
 #define mp make_pair
 #define pb push_back
 #define all(x) x.begin(), x.end()
 
 #define PI 3.14159265358979323846264338327950L
const int MOD = 1000000007;
 
int main() 
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    
    int n;cin>>n;

    map<int,int> v;
    vi vec(n);
    for(int i=0;i<n;++i)
    {
        cin>>vec[i];
        v[vec[i]]=0;
    }
    
    ll count=0;
    
    vi temp(vec);
    sort(all(temp));
    
    if(!is_sorted(vec.begin(),vec.end()))
    {
    int j=n-1;
    for(int i=n-1;i>=0;--i)
    {
        if(v[temp[i]]==0)
        {
            while(vec[j]!=temp[i])
            {
                count+=(temp[i] - vec[j]);
                v[vec[j]]=1;
                vec[j]=temp[i];
                --j;
            }
            --j;
            
        }
    }
    }
    cout<<count;
}
//  [cpp]
#include <iostream>
#include <cstdio>
#include <string.h>
#include <vector>
#include <limits>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <assert.h>
#include <sstream>
#include <type_traits>
#define SET(x,y) x |= (1 << y)
#define CLEAR(x,y) x &= ~(1<< y)
#define READ(x,y) ((0u == (x & (1<<y)))?0u:1u)
#define TOGGLE(x,y) (x ^= (1<<y))
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pb push_back
#define mp make_pair
#define si(n) scanf("%d",&n)
#define sf(n) scanf("%f",&n)
#define sl(n) scanf("%lld",&n)
#define slu(n) scanf("%llu",&n)
#define sd(n) scanf("%lf",&n)
#define ss(n) scanf("%s",n)
#define pnl printf("\n")
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pF first
#define pS second
#define CL(a,b) memset(a,b,sizeof(a))
#define sqr(x) ((x)*(x))
#define intLIMIT numeric_limits<int>
#define longLIMIT numeric_limits<long long>
#define GCD(a,b) __gcd((a),(b))
#define dbl(x) (double)(x)
#define vi vector <int>
#define vii vector < pair <int, int> >
#define vll vector <long long>
#define allof(x) (x).begin(), (x).end()
#define fastCin cin.sync_with_stdio(0);cin.tie(0)
#define scanUnsigned(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
#define printArr(a,l) cout<<#a<<": ";for(int i=0;i<(l);i++){cout<<a[i]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(int i=0;i<(r);i++){for(int j=0;j<(c);j++){cout<<a[i][j]<<" ";}cout<<endl;}
char _;
using namespace std;
void PRINT (int x, int y) { for (int i = y-1; i >= 0; i--) { cout << READ(x,i); } cout << endl; }

vector<string>vec_splitter(string s){s+=',';vector<string>res;while(!s.empty()){res.push_back(s.substr(0,s.find(',')));s=s.substr(s.find(',')+1);}
return res;}
void debug_out(vector<string>__attribute__((unused))args,__attribute__((unused))int idx,__attribute__((unused))int LINE_NUM){cerr<<endl;}
template<typename Head,typename...Tail>void debug_out(vector<string>args,int idx,int LINE_NUM,Head H,Tail...T){if(idx>0)cerr<<", ";else cerr<<"Line("<<LINE_NUM<<") ";stringstream ss;ss<<H;cerr<<args[idx]<<" = "<<ss.str();debug_out(args,idx+1,LINE_NUM,T...);}
#ifdef LOCAL_DBG
#define dbg(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define dbg(...) 42
#endif

int main () {
	fastCin;
	int n;
	cin >> n;
	vi a(n);
	ll ans = 0;
	for (int x = 0; x < n; x++) {
		cin >> a[x];
		if (x > 0) {
			if (a[x] < a[x-1]) {
				ans += a[x-1]-a[x];
				a[x] = a[x-1];
			}
		}
	}
	cout << ans << "\n";
	return 0;
}
//  [cpp]
#include <iostream>
using namespace std;
int main(void){
    int N;
    
    cin >> N;
    int A[N];
    
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    
    long dai = 0;
    int max = A[0];
    
    for(int i = 1; i < N; i++){
        if(A[i] < max){
            dai += max - A[i];
        }else{
            max = A[i];
        }
    }
    
    cout << dai << endl;
    
}
//  [c]
#include <stdio.h>
int main(void){
	long int i=0,a[1000000]={0},j[1000000]={0},tya=0,t=0,b=0;
	scanf("%ld",&b);
	for(i=0;i<b;i++){
		scanf("%ld",&a[i]);
	}
	j[0]=0;
	i=0;
	t=1;
	while(i!=b){
	if(a[i]<=a[i+1]){
		j[t]=0;
		i++;
		t++;
	}
	else if(a[i]>a[i+1]){
		j[t]=a[i]-a[i+1];
		a[i+1]=a[i+1]+j[t];
		i++;
		t++;
	}
	}
	t=0;
	while(t!=b){
	tya=tya+j[t];
	t++;
	}
	printf("%ld\n",tya);
	return 0;
}
//  [c]
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void) {
	long long int n, a, b = 0, i, ans = 0;

	scanf("%lld", &n);

	for (i = 0; i < n; i++) {
		scanf("%d", &a);
		if (i == 0) {
			b = a;
		}
		if (b > a) {
			ans += b - a;
		}
		else {
			b = a;
		}
	}
	printf("%lld", ans);
}
//  [c]
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	long long int a[200005];
	for (i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	long long int ans = 0;
	for (i = 1; i < n; i++)
	{
		if (a[i - 1] > a[i])
		{
			ans += a[i - 1] - a[i];
			a[i] = a[i - 1];
		}
	}
	printf("%lld\n", ans);
	return 0;
}
//  [javascript]
'use strict'
 
function main(A) {
  A = A.replace(/\r?\n/g,' ');
  A = A.split(' ');
  let N = A.shift(); //sortNum | A.length
  var s = A.map(Number);
  let humidai = 0;
  
  for(let i = 1; i < N; i++){
    if(s[i - 1] > s[i]){
      humidai += s[i - 1] - s[i];
      s[i] = s[i - 1];
    }else if(s[i - 1] == s[i]){
	  humidai += 0;
    }
  }
  
  console.log(humidai);
  
}
 
main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]

function main(input = "") {
    let lines = input.split("\n");
    let N = 0 | lines[0];
    let arr = lines[1].split(" ").map((v) => (Number(v)));

    let res = 0;
    for (let i = 1; i < N; i++) {
        let diff = arr[i - 1] - arr[i];
        if (diff > 0) {
            res += diff
            arr[i] += diff;
        }
    }
    return res;
}

//******************************
exports.main = main;

function Main(input) {
    console.log(main(input.trim()));
}

if (process.argv[2] !== "test") {
    Main(require("fs").readFileSync("/dev/stdin", "utf8"));
}
//  [javascript]
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");

  	var N = parseInt(input[0], 10);
	var tmp = input[1].split(" ");
	
  	var dif = 0;
  	var sum = 0;
  	var pre = 0;
  	var cur = 0;
  
  	for (var i = 0; i < N; i++) {
		cur = parseInt(tmp[i], 10);

      	if (pre !== 0) {
          	if (pre + dif > cur) {
              	
              	dif = pre + dif - cur;
              	sum = sum + dif;
            } else {
              dif = 0;
            }
        }
      	pre = cur;      	
	}
  
	//出力
	console.log('%d',sum);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [go]
package main

import (
	"fmt"
)

func main() {
	var n, d int
	fmt.Scanf("%d", &n)
	slice := []int{}
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &d)
		slice = append(slice, d)
	}

	total := 0
	fm := 0
	l := len(slice) - 1
	for i := 0; i < l; i++ {
		t1 := slice[i] + fm
		t2 := slice[i+1]
		if t1 > t2 {
			fm = t1 - t2
			total = total + fm
		} else {
			fm = 0
		}
	}
	fmt.Println(total)

}
//  [go]
package main

import (
	"fmt"
)

func main() {
	//reader := []byte("1000 1 1000")
	var n int
	fmt.Scanf("%d", &n)

	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &arr[i])
	}

	total := 0
	min := arr[0]
	for _, v := range arr {
		//fmt.Println(i, v)
		if v >= min {
			min = v
			continue
		} else {
			//fmt.Printf("[%d]=%d (%d)\t%d\n", i, v, (min - v), min)
			total += (min - v)
		}

	}

	fmt.Println(total)

}
//  [go]
package main

import "fmt"

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

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}

	fmt.Println(solve(n, a))
}

func solve(n int, a []int) int {
	sum := 0
	max := a[0]

	for i := 0; i < n; i++ {
		max = maxInt(max, a[i])
		sum += (max - a[i])
	}

	return sum
}

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

	return b
}
//  [ruby]
N = gets.chomp.to_i

results = []

gets.chomp.split.map(&:to_i).each_with_index do |shincho, i|
  if i == 0
    results << { shincho: shincho, dai: 0 }
  else
    maenohitotonosa = (results[i-1][:shincho] + results[i-1][:dai]) - shincho
    if maenohitotonosa > 0
      results << { shincho: shincho, dai: maenohitotonosa }
    else
      results << { shincho: shincho, dai: 0 }
    end
  end
end

puts results.sum { |r| r[:dai] }
//  [ruby]
def run
  gets
  aa = gets.chomp.split(/\s+/).map(&:to_i)
  tc, _ = aa.reduce([0, 0]){|h, a| if h[1] <= a then [h[0], a] else [h[0] + h[1] - a, h[1]] end}
  puts tc
end

run
//  [ruby]
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)

max = 0
ans = 0
a.each do |h|
  if h < max
    ans += max - h
    h = max
  elsif h > max
    max = h
  end
end

puts ans
//  [rust]
use proconio::input;
// use proconio::marker::{Bytes, Chars};

fn main() {
    input! {
        n: i128,
        a: [i128; n],
    }

    let mut height = a[0];
    let mut sum = 0;

    for person in a {
        if height > person {
            sum += height - person;
        } else {
            height = person;
        }
    }
    println!("{}", sum);
}
//  [rust]
use std::io;
use std::cmp::max;
//use std::vec;
// fn sum_of_string(s: &String) -> u32 {
//     s.chars().fold(0, |acc, c| c.to_digit(10).unwrap_or(0) + acc)
//   }

fn main(){

    let mut n:String = String::new();

    io::stdin().read_line(&mut n).expect("Required Input");

    let _n: i128 = n.trim().parse().unwrap();

    let mut stol_height: i128 = 0;
    let mut input: String = String::new();
    let mut prev_height: i128 = 0;

    io::stdin().read_line(&mut input).expect("Input required");

    let values: Vec<i128> = input
            .split_whitespace()
            .map(|x| x.parse::<i128>())
            .collect::<Result<Vec<i128>, _>>()
            .unwrap();

    for i in values.iter(){

        if prev_height <= *i{
            prev_height = max(prev_height, *i);
            continue;
        }

        stol_height += prev_height-*i;

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

}
//  [rust]
use text_io::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;

fn main() {
    let mut n:usize = read!();
    let mut a:usize = 0;
    let mut max:usize = 0;
    for i in 0..n {
        let ai:usize = read!();
        if max<ai {
            max=ai;
        }
        else {
            a+=max-ai;
        }
    }
    println!("{}",a);
}
//  [swift]
import Foundation

let input1 = readLine()!
let input2 = readLine()!
let n = Int(input1)!
let a = input2.components(separatedBy: " ").map { Int($0)! }
var current = a[0]
var res = 0
for i in (1..<n) {
  if (a[i] < current) {
    res += (current - a[i])
  } else {
    current = a[i]
  }
}
print(res)
//  [swift]
import Foundation

let n = Int(readLine()!)!
let a = readLine()!.components(separatedBy: " ")

var acc = 0
var sub = 0
var mem = 0

for str in a {
  let tmp = Int(str)!
  sub = mem + sub - tmp
  sub = sub > 0 ? sub : 0
  acc = acc + sub
  mem = tmp
}

print(acc)
//  [swift]
import Foundation

func readInt() -> Int {
    return Int(readLine()!)!
}

func readString() -> String {
    return readLine()!
}

func readLines(times: Int) -> [String] {
    var array = [String]()
    for _ in 0..<times {
        array.append(readLine()!)
    }
    return array
}

func readSeparatedStrings() -> [String] {
    return readLine()!.split(separator: " ").map {String($0)}
}

func readStringToStrings() -> [String] {
    return readLine()!.map{String($0)}
}

func readSeparatedInts() -> [Int] {
    return readLine()!.split(separator: " ").map {Int($0)!}
}
func readSeparatedDouble() -> [Double] {
    return readLine()!.split(separator: " ").map {Double($0)!}
}

// 二進数に変換
func convertIntToRadix2(n: Int, radix: Int = 2) -> String {
    return String(n, radix: radix)
}

//配列を逆順にする reverced ソートする　sorted
//最初数文字取得 prefix


let N = readInt()
let students = readSeparatedInts()

var top = 0
var result = 0


for i in 0..<N {
    let h = students[i]
    
    if i == 0 {
        top = h
    } else {
        if top > h {
            result += top - h
        } else if top == h {
            
        } else {
            top = h
        }
    }
}
print(result)
//  [typescript]
import * as fs from 'fs';

const input = fs.readFileSync('/dev/stdin', 'utf8');
// const input = fs.readFileSync('./input.txt', 'utf8');

_c(input);

function _c(input: string) {
  const A = input
    .split('\n')[1]
    .split(' ')
    .map((s) => parseInt(s));
  let sum = 0n;
  let front = 0;
  for (const a of A) {
    if (front <= a) {
      front = a;
    } else {
      sum += BigInt(front - a);
    }
  }
  console.log(sum.toString());
}
//  [typescript]
"use strict";

const main = (arg) => {
  const heights = arg
    .trim()
    .split("\n")[1]
    .split(" ")
    .map((item) => Number(item));

  let currentMax = heights[0];
  let stepSum = 0;

  const after = heights.map((height) => {
    if (height < currentMax) {
      const stepSize = currentMax - height;
      stepSum += stepSize;
      currentMax = height + stepSize;
      return stepSize;
    }
    currentMax = height;
    return 0;
  });
  console.log(stepSum);
  // console.log(heights);
  // console.log(after);
};

main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [python]
n=int(input())
h=list(map(int,input().split()))
li=[0]
while len(h)>1:
  for i in range(len(h)):
    if i==len(h)-1:
      li += [len(h)-1]
      del h[1:]
    elif h[i]<h[i+1]:
      li += [len(h[0:i+1])-1]
      del h[0:i+1]
      break
print(max(li))
//  [python]
n = int(input())
H = list(map(int,input().split()))
ans = 0
num = 0
for i in range(n-1):
    if H[0] >= H[1]:
      num += 1
      H.pop(0)
      if num > ans:
        ans = num
    else:
      num = 0
      H.pop(0)
print(ans)
//  [python]
import numpy as np
n=int(input())
h=list(map(int,input().split()))
cnt=0
ans=0
for i in range(n-1):
    if h[i]>=h[i+1]:
        cnt+=1
    else:
        ans=np.max((ans,cnt))
        cnt=0
ans=np.max((ans,cnt))
print(ans)
//  [java]

import java.util.Scanner;

/**
 * @author author
 *
 */
public class Main {


  /**
   * @param args
   */
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = Integer.parseInt(sc.next());
    int[] h = new int[n];
    for (int i = 0; i < n; i++) {
      h[i] = Integer.parseInt(sc.next());
    }

    int returnMax = 0;
    int count = 0;
    for (int i = 0; i < n - 1; i++) {
      int leftPoint = i;
      count = 0;
      for (int j = i + 1; j < n; j++) {
        if (h[leftPoint] >= h[j]) {
          leftPoint = j;
          count++;
          if (returnMax < count) {
            returnMax = count;
            if (returnMax >= (n - i)) {
              break;
            }
          }
        } else {
          break;
        }
      }
      if (returnMax >= (n - i)) {
        break;
      }
    }
    System.out.println(returnMax);
  }
}
//  [java]
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i=0;i<n;i++)h[i]=sc.nextInt();
        int ans = 0;
        for (int i=0;i<n;i++){
            int count = i;
            while (count<n-1&&h[count]>=h[count+1])count++;
            ans=Math.max(ans,count-i);
        }
        System.out.println(ans);
    }
}
//  [java]
import java.util.Scanner;

public class Main {

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] H = new int[N];
        for (int i = 0; i < N; i++) {
            H[i] = sc.nextInt();
        }
        int max = 0;
        for (int i = 0; i < N; i++) {
            if (max >= ((N - 1) - i)) {
                break;
            }
            int moveCount = 0;
            for (int j = i; j <= N - 2; j++) {
                if (H[j] >= H[j + 1]) {
                    moveCount++;
                }
                else {
                    break;
                }
            }
            max = Math.max(max, moveCount);
        }
        System.out.print(max);
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;

#define ENDL '\n'
#define sayy cout<<"YES"<<ENDL;
#define sayn cout<<"NO"<<ENDL;

int main(){

    int n;
    cin >> n;

    vector<int> v(n);
    for(int i(0); i<n; i++){
        cin >> v.at(i);
    }

    int max(0);
    for(int i(v.size()-1); i>=1; i--){
        int temp(0),j(i);
        while(v[j] <= v[j-1]){
            temp++;
            j--;
        }
        if(temp > max) max = temp;
    }
    cout << max << ENDL;

    return 0;
}
//  [cpp]

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
const int MOD = 1e9+7,mxN = 50,INF = 1e9;
int n;
void fastscan(int &number);

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    fastscan(n);
    int a[n];
    for(int i=0;i<n;i++)
        fastscan(a[i]);
    int best = 1;
    for(int i=0;i<n-1;i++)
    {
        int j=i+1;
        while(j<n&&a[j]<=a[j-1])
            j++;
        if(j-i>best)
            best = j-i;
    }
    cout << best-1;
    
}

void fastscan(int &number) 
{ 
    bool negative = false; 
    register int c; 
    number = 0; 
    c = getchar_unlocked(); 
    if (c=='-') 
    { 
        negative = true; 
        c = getchar_unlocked(); 
    } 
    for (; (c>47 && c<58); c=getchar_unlocked()) 
        number = number *10 + c - 48; 
    if (negative) 
        number *= -1; 
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

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

    int n; cin >> n;
    vint a(n);
    rep(i,n) cin >> a[i];

    int res=0;
    rep(i,n){
        int tmp=0;
        for(int j=i; j<n-1; j++){
            if(a[j]>=a[j+1]) tmp++;
            else break;
        }
        chmax(res,tmp);
    }
    cout<<res<<endl;
}
//  [c]
#include <stdio.h>

//Compiler version gcc  6.3.0

int main()
{
  long long int n;
  long long int count=0,max=0,i,k,j;
  scanf("%lld",&n);
  long long int a[n];
  for(i=0;i<n;i++)
    scanf("%lld",&a[i]);
  for(i=0;i<n-1;i++)
  {
    k=i;
    j=i+1;
      while(a[k]>=a[j])
      {
        k++;
        count++;
        j++;
      }
    if(count>max)
      max=count;
    count=0;
  }
  printf("%lld",max);
  return 0;
}
//  [c]
#include <stdio.h>

int main (void) {
  int N, H[100000], i, j;
  int a = 0;

  scanf ("%d", &N);

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

  for (i = 0; i < N-1; i++) {
    j = 0;
    while (H[i+j] >= H[i+j+1] && i+j != N-1) {
      j++;
    }
    if (a < j) {
      a = j;
    }
    if (a >= N - i - 1) {
     break;
    }
  }

  printf ("%d", a);
}
//  [c]
#include<stdio.h>

int main(){
    int n,count=0,tmp,j;
    scanf("%d",&n);
    int h[n];
    for(int i=0;i<n;i++){
        scanf("%d ",&h[i]);
    }
    for(int i=0;i<n-1;i++){
        if(count>n-i)break;
        tmp=0;
        j=0;
        while(h[i+j]>=h[i+j+1]){
            tmp++;
            j++;
            if(i+j+1>=n)break;
        }
        if(tmp>count)count=tmp;
    }
    printf("%d",count);
    return 0;
}
//  [javascript]
'use strict'
function main(inp) {
  inp = inp.trim().split('\n')
  const N = Number(inp.shift())
  inp = inp[0].split(' ').map(n => Number(n));
  let temp = 0
  let max = 0

  for (let i = 1; i < N; i++) {
    if (inp[i] > inp[i - 1]) {
      if (temp > max) max = temp
      temp = 0
    } else {
      temp++
    }
  }
  if (temp > max) max = temp

  console.log(max)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
process.stdin.resume();
process.stdin.setEncoding('utf8'); 
var lines = [];
var reader = require('readline').createInterface({
	input: process.stdin,
	output: process.stdout
});
 
reader.on('line', (line) => {
	lines.push(line);
});

reader.on('close', () => {
	"use strict"
	const N=+lines[0];
	const H=lines[1].split(" ").map(Number);
	
	var temp=0;
	var ans=0;
	
	for(var i=1;i<N;i++){
		if(H[i]<=H[i-1]){
			temp++;
			temp>ans && (ans=temp);
		} else {
			temp=0;
		}
	}
	console.log(ans);
});
//  [go]
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	Hz := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&Hz[i])
	}

	maxJump := 0
	tmpJump := 0

	for i := 0; i < N-1; i++ {
		if Hz[i] >= Hz[i+1] {
			tmpJump++
		} else {
			tmpJump = 0
		}

		if tmpJump > maxJump {
			maxJump = tmpJump
		}
	}
	fmt.Println(maxJump)
}
//  [go]
package main

import (
	"fmt"
)

func main() {

	var N int
	fmt.Scanf("%d", &N)

	var max int = 0
	var count int
	var H, Hbefore int
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &H)
		if Hbefore >= H {
			count++
		} else {
			if max <= count {
				max = count
			}
			count = 0
		}

		Hbefore = H
	}

	if count > 0 {
		if max <= count {
			max = count
		}
	}

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

import "fmt"

func main() {
	var N, t, h, cnt, r int
	fmt.Scan(&N)
	fmt.Scan(&t)
	for i := 1; i < N; i++ {
		fmt.Scan(&h)
		if t >= h {
			cnt++
		} else {
			r = Max(r, cnt)
			cnt = 0
		}
		t = h
	}
	r = Max(r, cnt)
	fmt.Println(r)

}
func Max(a, b int) int {
	if b > a {
		return b
	}
	return a
}
//  [ruby]
$debug = false
flag = ARGV.shift
if flag == "-d"
  $debug = true
end

def dputs str
  p str if $debug
end

def max(n, m)
  if n > m
    return n
  else
    return m
  end
end

def min(n, m)
  if n < m
    return n
  else
    return m
  end
end

def gets_all_int
  return gets.chomp.split.map{|v| v.to_i}
end

## start

N = gets_all_int[0]
Hs = gets_all_int

dputs N
dputs Hs

cnt = 0
max = 0
1.upto(N-1) do |n|
  dputs "#{Hs[n] <= Hs[n-1]} max =#{max}"
  if Hs[n] <= Hs[n-1]
    cnt += 1
    dputs "move #{cnt}"
    if max < cnt
      max = cnt
    end
  else
    dputs "cant move #{cnt}"
    if max < cnt
      max = cnt
    end
    cnt = 0
  end
end

puts max
//  [ruby]
    n = gets.chomp.to_i
    h = gets.chomp.split(/\s/).map{|x| x.to_i}

    if n == 1
        puts 0
        exit
    end

    o = []
    s = 0
    ms = 0
    for i in 0..(n-2)
        o[i] = h[i]-h[i+1]
        if o[i] >= 0
            s += 1
            ms = [s, ms].max
        else
            s = 0
        end
    end

    if o.max < 0
        puts 0
        exit
    end

    puts ms
//  [ruby]
a = gets().to_i
b = gets().split(" ")

for i in 0..a-1
  b[i] = b[i].to_i
end

c = []

for i in 0..a-1
  if b[i+1]!=nil
    if b[i]>=b[i+1]
      c.push(1)
    else
      c.push(0)
    end
  end
end

t = []

c.chunk { |u|
 u==1 
}.each{ |r, w|
  if r==true
    t.push(w.length)
  end
}

f = t.max
if f==nil
  f = 0
end

p f
//  [rust]
fn read<T: std::str::FromStr>() -> T {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let n: usize = read();
  let hs: Vec<u32> = read_vec();

  let mut max = 0;

  for i in 0..n as usize {
    let mut j = i;
    let mut cnt = 0;

    if max > n - j { break; };

    loop {
      if j == n - 1 { break; };
      if hs[j as usize] >= hs[j + 1 as usize] {
        cnt += 1;
        j += 1;
      } else {
        break;
      }
    }

    if max < cnt { max = cnt; };
  }

  println!("{}", max);
}
//  [rust]
use text_io::*;
use std::collections::*;
use std::process::exit;

fn main() {
    let mut n:usize = read!();
    let mut v:Vec<usize> = Vec::new();
    let mut ans:usize = 0;
    let mut sum:usize = 0;
    for i in 0..n {
        let a:usize = read!();
        v.push(a);
    }
    for i in 0..n-1 {
        if v[i]>=v[i+1] {
            sum+=1;
        }
        else {
            sum=0;
        }
        if ans<sum {
            ans=sum;
        }
    }
    println!("{}",ans);
}