akhauriyash/Code-Regression huggingface dataset:
w,h,n=map(int,input().split())
bx=by=0
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1 and bx<x:
    bx=x
  elif a==2 and w>x:
    w=x    
  elif a==3 and by<y:
    by=y
  elif a==4 and h>y:
    h=y
if w-bx<=0 or h-by<=0:
  print(0)
else:
  print((w-bx)*(h-by))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

int n, W, w[100], v[100];
ll dp[100][100001];

ll f(int k, int r)
{
    if (r < 0) return -1e9;
    if (k == n) return 0;
    if (dp[k][r] != -1) return dp[k][r];
    return dp[k][r] = max(v[k] + f(k + 1, r - w[k]), f(k + 1, r));
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> W;
    for (int i = 0; i < n; ++i)
        cin >> w[i] >> v[i];
    memset(dp, -1, sizeof dp);
    cout << f(0, W);
}


Measured memory_bytes: 78336
allmoney = $stdin.read.split("\n")
allmoney.shift
print(allmoney.reduce(0.0){|sum, onemoney| sum+(onemoney[-3,3]=="BTC" ? onemoney.gsub(/ BTC/,"").to_f*380000.0 : onemoney.gsub(/ JPY/,"").to_i)})

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

using int64 = long long;

int main() {
  int n, m;
  cin >> n >> m;
  map<int,int> count;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    count[a] = count[a] + 1;
  }
  for (int i = 0; i < m; ++i) {
    int b, c;
    cin >> b >> c;
    while (b) {
      auto it = count.begin();
      int cc = it->first;
      int bb = it->second;
      if (cc >= c)
        break;
      int k = min(bb, b);
      b -= k;
      if (k == bb)
        count.erase(it);
      count[c] = count[c] + k;
      if (k != bb)
        count[cc] = bb - k;
    }
  }
  int64 sum = 0;
  for (auto& p : count) {
    sum += static_cast<int64>(p.first) * p.second;
  }
  cout << sum << "\n";
  return 0;
}


Measured memory_bytes: 4992
H,W=map(int,input().split())
a=[""]*H
for i in range(H):
  a[i]=input()
row=[False]*H
col=[False]*W
for i in range(H):
  for j in range(W):
    if a[i][j]=="#" :
      row[i]=True
      col[j]=True
for i in range(H):
  if row[i]:
    for j in range(W):
      if col[j]:
        print(a[i][j],end="")
    print()

Measured memory_bytes: 9068
# D - Wizard in Maze

h,  w  = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
s = []
for i in range(h):
    s.append([c for c in input()])

queue = [[(ch - 1, cw - 1)], []]

dist = 0
while len(queue[0]) > 0:
    while len(queue[0]) > 0:
        y, x = queue[0].pop()
        if s[y][x] != '.':
            continue
        s[y][x] = dist
        for vy in range(-2, 3):
            for vx in range(-2, 3):
                if 0 <= y + vy < h and 0 <= x + vx < w and \
                   s[y + vy][x + vx] == '.':
                    cost = 0 if abs(vx) + abs(vy) <= 1 else 1
                    queue[cost].append((y + vy, x + vx))
    dist += 1
    queue = [queue[1], queue[0]]

dist = s[dh - 1][dw - 1]
print(dist if dist != '.' else -1)


Measured memory_bytes: 188356
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

using pi = pair<int,int>;
using edge = pair<int,pi>;

struct UF{
    int n;
    //??£?????£????????????????????????,????????£???????????§??£?????????????????°
    vector<int> d;
    UF() {}
    UF(int N):n(N), d(N,-1){}
    int root(int v){
        if(d[v]<0) return v;
        return d[v]=root(d[v]);
    }
    bool unite(int X,int Y){
        X=root(X); Y=root(Y);
        if(X==Y) return false;
        if(size(X) < size(Y)) swap(X,Y);
        d[X]+=d[Y];
        d[Y]=X;
        return true;
    }
    int size(int v){ return -d[root(v)]; }
    bool same(int X,int Y){ return root(X)==root(Y); }
};

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

        vector<edge> e(m);
        rep(i,m)
        {
            int a,b,d;
            scanf(" %d,%d,%d", &a, &b, &d);
            e[i] = edge(d,pi(a,b));
        }
        sort(all(e));

        UF uf(n);
        ll ans = 0;
        rep(i,m)
        {
            int a=e[i].se.fi, b=e[i].se.se, cost=e[i].fi;
            if(!uf.same(a,b))
            {
                uf.unite(a,b);
                ans += cost/100 - 1;
            }
        }

        printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 3188
#include <cstdio>

int main() {
	int n, s;
	for(int i = 0; i < 5; i++) {
		scanf("%d", &n);
		if(n < 40)
			n = 40;
		s += n;
	}
	printf("%d\n", s/5);
	return 0;
}

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

int main()
{
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> l(q), r(q);
    rep(i, q) cin >> l.at(i) >> r.at(i);

    int cnt = 0;
    vector<int> c(n, 0);
    for (int i = 1; i < n; i++)
    {
        if ((s.at(i - 1) == 'A') && (s.at(i) == 'C'))
        {
            cnt += 1;
        }
        c.at(i) = cnt;
    }

    rep(i, q)
    {
        cout << c.at(r.at(i) - 1) - c.at(l.at(i) - 1) << endl;
    }
}

Measured memory_bytes: 2176
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>

#define isNum(a) (a >= '0' && a <= '9')
#define SP putchar(' ')
#define EL putchar('\n')
#define File(a) freopen(a ".in", "r", stdin), freopen(a ".out", "w", stdout)

template<class T>
void read(T&);
template<class T>
void write(const T&);

typedef long long ll;
typedef const long long & cll;
typedef const int & ci;
typedef std::pair<int, int> pii;
const int iinf = 2147483647;
const ll llinf = 9223372036854775807ll;
using std::min;
using std::max;
using std::abs;
using std::sort;
const int N = 200005;

bool check(ll);

int n;
ll k;
ll a[N], b[N];

int main () {
  read(n), read(k);
  for (int i = 1; i <= n; ++i) {
    read(a[i]);
  }
  for (int i = 1; i <= n; ++i) {
    read(b[i]);
  }
  sort(a + 1, a + n + 1, std::greater<ll>());
  sort(b + 1, b + n + 1);
  ll l = 0, r = ll(1e12) + 1;
  ll ans = 0;
  while (l <= r) {
    ll mid = (l + r) >> 1;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  write(ans), EL;
  return 0;
}

template<class T>
inline void read(T &Re) {
  T k = 0;
  char ch = getchar();
  int flag = 1;
  while (!isNum(ch)) {
    if (ch == '-') {
      flag = -1;
    }
    ch = getchar();
  }
  while (isNum(ch)) {
    k = (k << 1) + (k << 3) + ch - '0';
    ch = getchar();
  }
  Re = flag * k;
}
template<class T>
inline void write(const T &Wr) {
  if (Wr < 0) {
    putchar('-');
    write(-Wr);
  } else {
    if (Wr < 10) {
      putchar(Wr + '0');
    } else {
      write(Wr / 10);
      putchar((Wr % 10) + '0');
    }
  }
}

bool check(ll x) {
  ll now = 0;
  for (int i = 1; i <= n; ++i) {
    now += max(0ll, a[i] - x / b[i]);
  }
  return now <= k;
}


Measured memory_bytes: 3328
import java.util.*;
import java.lang.*;

import static java.lang.StrictMath.abs;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        int L = sc.nextInt();
        int[] ans = new int[d];
        int sum =0;
        for(int i =1; i <= d; i++){
            ans[i-1] = L + i -1;
        }
        //もとのアップルパイの味
        for(int j =0; j < d; j++){
            sum += ans[j];
        }
        //食べたあとのアップルパイの味
        
        if(ans[0] > 0){
            System.out.println(sum - ans[0]);
        }
        //０に近いものを食べる
        else if(ans[d-1] < 0){
            System.out.println(sum - ans[d-1]);
        }
        //０に近いものを食べる
        else{
            System.out.println(sum);

        }

    }
} 

Measured memory_bytes: 21844
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <algorithm>
#include <vector>
  
using namespace std;
  
class Node {
public:
    int location;
    int l, r;
};
  
class Point {
public:
    int id, x, y;
    Point() {}
    Point(int id, int x, int y) :id(id), x(x), y(y) {}
    bool operator<(const Point&p) const {
        return id < p.id;
    }
  
    void print() {
        printf("%d\n", id);
    }
};
  
static const int MAX = 500000;
static const int NIL = -1;
  
int N;
Point P[MAX];
Node T[MAX];
int np;
Point ans[MAX];
int NANS;
  
bool lessX(const Point &p1, const Point &p2) {
    return p1.x < p2.x;
}
  
bool lessY(const Point &p1, const Point &p2) {
    return p1.y < p2.y;
}
  
int makeKDTree(int l, int r, int depth) {
    if (l == r) {
        return NIL;
    }
    int mid = (l + r) / 2;
    int t = np++;
    if (depth % 2 == 0) {
        sort(P + l, P + r, lessX);
    }
    else {
        sort(P + l, P + r, lessY);
    }
    T[t].location = mid;
    T[t].l = makeKDTree(l, mid, depth + 1);
    T[t].r = makeKDTree(mid + 1, r, depth + 1);
  
    return t;
}
  
void find(int v, int sx, int tx, int sy, int ty, int depth) {
    int x = P[T[v].location].x;
    int y = P[T[v].location].y;
  
    if (sx <= x && x <= tx && sy <= y && y <= ty) {
        ans[NANS++] = P[T[v].location];
    }
  
    if (depth % 2 == 0) {
        if (T[v].l != NIL) {
            if (sx <= x) find(T[v].l, sx, tx, sy, ty, depth + 1);
        }
        if (T[v].r != NIL) {
            if (x <= tx) find(T[v].r, sx, tx, sy, ty, depth + 1);
        }
    }
    else {
        if (T[v].l != NIL) {
            if (sy <= y) find(T[v].l, sx, tx, sy, ty, depth + 1);
        }
        if (T[v].r != NIL) {
            if (y <= ty) find(T[v].r, sx, tx, sy, ty, depth + 1);
        }
    }
}
  
int main() {
    int x, y;
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d %d", &x, &y);
        P[i] = Point(i, x, y);
        T[i].l = T[i].r = NIL;
    }
  
    np = 0;
  
    int root = makeKDTree(0, N, 0);
  
    int q;
    scanf("%d", &q);
    int sx, tx, sy, ty;
    for (int i = 0; i < q; i++) {
        scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
        NANS = 0;
        find(root, sx, tx, sy, ty, 0);
        sort(ans, ans + NANS);
        for (int j = 0; j < NANS; j++) {
            ans[j].print();
        }
        printf("\n");
    }
  
    return 0;
}


Measured memory_bytes: 13948
#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
    long double n;
    std :: cin >> n;

    std :: vector < long double > v , vv;

    while(n--)
    {
        long double x;
        std :: cin >> x;

        v.push_back(x);
    }

    std :: sort(v.begin() , v.end());

    vv.push_back((v.at(0) + v.at(1)) / 2);

    for(int i = 0 ; i < v.size() - 2 ; i++)
    {
        vv.push_back((vv.at(i) + v.at(i + 2)) / 2);
    }

   /* for(auto i : vv)
        std :: cout << i << ' ';*/

    std :: cout << vv.at(vv.size() - 1) << '\n';
}


Measured memory_bytes: 256
void main(){
	int n = _scan();
	int[] a = _scanln();
	int ans;
	for(int i=1; i<=a.length; i+=2){
		if(a[i-1]&1)ans++;
	}
	ans.writeln();
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2680
package main

import (
	"fmt"
)

func main() {
	var n, m int

	fmt.Scan(&n)

	A := make([]int, n)
	B := make([]int, n)
	C := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Scan(&A[i])
	}

	for i := 0; i < n; i++ {
		fmt.Scan(&B[i])
	}

	for i := 0; i < n-1; i++ {
		fmt.Scan(&C[i])
	}

	for i:=0;i<len(A);i++ {
		m += B[A[i]-1]
		if i<len(A)-1 && A[i+1]-A[i] == 1 {
			m += C[A[i]-1]
		}
	}
	fmt.Println(m)
}


Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
int main(){
  int a,b;
  char s[11], t[11], u[11];
  scanf("%s%s%d%d%s",s,t,&a,&b,u);
  printf("%d %d\n",a-!strcmp(s,u),b-!strcmp(t,u));
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define test(a) cout << "*" << a << endl
#define rep0(i,n) for(i=0;i<n;i++)
#define ll long long
int main(){
  int n;
  ll i,j;
  ll a[100000];
  ll sum=0;
 
  cin >> n;
  rep0(i,n)
    cin >> a[i];
  /*test(n);
  rep0(i,n)
    test(a[i]);*/
  
  rep0(i,n){
    sum += a[i]-1;
  }
  cout << sum << endl;
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
int main(){
    ll n, b, a[10000], ans=0, x=0;
    cin>>n>>b;
    for(int i=0; i<n; ++i){
        cin>>a[i];
    }
    sort(a, a+n);
    for(int i=n-1; i>=0; --i){
        ans+=a[i];
        ++x;
        if(x==b){
            break;
        }
    }
    cout<<ans;
return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder.AISing
{
    class B
    {
        public static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            var ans = Console.ReadLine().Split(' ').Select((x, i) => (num: i + 1, value: int.Parse(x))).Count(x => x.num % 2 == 1 && x.value % 2 == 1);
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 27608
N = int(input())
S = input()
flag = True
n = int(N/2)

if(N % 2) == 1:
    print('No')
else:
    for a in range(n):
        if not S[a] == S[n + a]:
            print('No')
            flag = False
            break
    if flag == True:
        print('Yes')

Measured memory_bytes: 3060
package main

import "fmt"

func f(n, x int64) int64 {
	if n == -1 {
		return 0
	}
	return n/x + 1
}

func main() {
	var a, b, x int64
	fmt.Scan(&a, &b, &x)
	fmt.Println(f(b, x) - f(a-1, x))
}


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

using namespace std;

int main(){
    int N;
    int tmp;
    int min, max;
    int dist;
    vector<int> a;

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

    min = *std::min_element(a.begin(), a.end());
    max = *std::max_element(a.begin(), a.end());

    dist = max - min;

    cout << dist << endl;

    return 0;
}


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

#define ll long long
#define pii pair<int, int>
using namespace std;
const ll mod = 1e9 + 9;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b + c >= 22) {
        cout << "bust";
    } else cout << "win";

}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int main(){
	long long a,b;scanf("%lld%lld",&a,&b);
	long long ret=mod*2;
	if(a<=b)ret=min(ret,b-a);
	if(-a<=b)ret=min(ret,b+a+1);
	if(a<=-b)ret=min(ret,-b-a+1);
	if(-a<=-b)ret=min(ret,-b+a+2);
	printf("%lld\n",ret);
}

Measured memory_bytes: 128
#include <cstdio>
#include <cctype>

int main(){
	char ch;
	
	while(1){
		scanf("%c", &ch);
		
		if(islower(ch)) printf("%c", toupper(ch));
		else if(isupper(ch)) printf("%c", tolower(ch));
		else printf("%c", ch);
		
		if(ch=='\n') break;
	}

	return 0;
}

Measured memory_bytes: 940
#include <iostream>
#include <map>
#include <queue>
#include <vector>

using namespace std;

typedef pair<int, int> Edge;
 
int main(void){
  int N;
  cin >> N;
  vector<vector<int>> G(N);
  vector<Edge> edges(N - 1);
  for(int i = 1;i < N; i++){
    int a,b;
    cin >> a >> b;
    G[a-1].push_back(b-1);
    G[b-1].push_back(a-1);
    edges[i-1] = Edge(a-1,b-1);
  }
 
  int K=0;
  map<Edge,int> color_table;
  
  vector<int> parent_color(N,0); 
 
  vector<bool> visited(N,false);
  queue<int> que;
  
  visited[0]=true;
  que.push(0);
  
  while(!que.empty()){
    int v = que.front(); que.pop();

    if(K < G[v].size())
      K = G[v].size();
    
    int color = 1;
    
    for(int u : G[v]){
      if(visited[u])
	continue;

      // avoid using same color
      if(color == parent_color[v])
	color++;

      color_table[Edge(v, u)] = color;
      color_table[Edge(u, v)] = color;
      parent_color[u] = color;
      
      color++;

      visited[u] = true;
      que.push(u);
    }
  }
 
  cout << K <<endl;
  for(Edge e : edges)
    cout << color_table[e] <<endl;
  
  return 0;
}


Measured memory_bytes: 19712
a = gets.chomp.to_i
lst = []
4.times do |i|
  lst[i] = gets.chomp.to_i
end

def leng(a)
  ((10 - a % 10) % 10)
end

ans = 0

for e in lst do
  ka = leng(a)
  ke = leng(e)
  if ke > ka
    ans += ka + a
    a = e
  else
    ans += ke + e
  end
end

ans += a
puts ans


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep2(i, s, n) for (long long i = (s); i < (long long)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<string> vs;
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
const long long MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    vvll a(N), b(N);
    rep(i, N) {
        ll j;
        cin >> j;
        rep(k, j) {
            ll x, y;
            cin >> x >> y;
            if (y) a[i].push_back(x - 1);
            else b[i].push_back(x - 1);
        }
    }
    ll ans = 0;
    for (ll bit = 0; bit < (1 << N); bit++) { 
        vll c(N, 0), d(N, -1);
        bool flag = true;
        rep(i, N) {
            if (bit & (1 << i)) {
                c[i] = 1;
                for (auto x : a[i]) {
                    if (d[x] == 0) flag = false;
                    else d[x] = 1;
                }
                 for (auto x : b[i]) {
                     if (d[x] == 1) flag = false;
                     else d[x] = 0;
                }
            }
        }
        rep(i, N){
            if (d[i] != -1 && c[i] != d[i]) flag = false;
        }
        if (flag) {
            ans = max(ans, (ll)count(all(c), 1));
        }
        }
    cout << ans << endl;
}


Measured memory_bytes: 3568
#include <iostream>
#include <algorithm>
#include <vector>

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

using namespace std;


int main()
{
	int dp[5001] = {0};
	
	
	rep(i,5001) dp[i] = 1000000;
	
	int p[6] = {200,300,500,1000,1200,1500};
	int v[6] = {380,550,850,380*5*0.8,550*4*0.85,850*3*0.88};

	dp[0] = 0;
	
	rep(i,6)
	{
		rep(j,5001)
		{
			int x = p[i] + j;
			if(x > 5001) break;

			dp[x] = min(dp[x],dp[j]+v[i]);
		}
	}
	

	int n;
	while(cin >> n && n)
	{
		cout << dp[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 1184
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>

using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

int hist[200000+5];

int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n-1) {
    int v;
    scanf("%d", &v);
    --v;
    hist[v]++;
  }
  REP(i, n) {
    printf("%d\n", hist[i]);
  }
  return 0;
}


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

int main(void){
    string s;
    int cnt = 0;
    cin >> s;
    for(int i=0; i<s.length(); i++) cnt += s[i] == 'A';
    cout << ((cnt != 0 && cnt != 3) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 380
from math import floor, ceil
a, b, x = list(map(int, input().split()))

if a == 0 and b == 0:
    print(1)
elif a%x == 0 and b%x == 0:
    print((b-a)//x+1)
elif a%x == 0:
    b_ = (b//x)*x
    print((b_-a)//x+1)
elif b%x == 0:
    a_ = ((a//x)+1)*x
    print((b-a_)//x+1)
else:
    a_ = ((a//x)+1)*x
    b_ = (b//x)*x
    print((b_-a_)//x+1)


Measured memory_bytes: 3064
import java.util.*;
//import java.lang.Math;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int A[];
        A=new int[N];
        for(int i=0;i<N;i++) A[i]=sc.nextInt();
        int cnt=0;
        for(int i=0;i<N;i++){
            int mi=i;
            for(int j=i;j<N;j++) if(A[j]<A[mi]) mi=j;
            if(mi!=i) cnt++;
            int tmp=A[i];
            A[i]=A[mi];
            A[mi]=tmp;
        }
        for(int i=0;i<N;i++){
            System.out.print(A[i]);
            System.out.print(i==N-1?"\n":" ");
        }
        System.out.println(cnt);
        sc.close();
    }
}


Measured memory_bytes: 26436
#include<bits/stdc++.h>
using namespace std;
int a[100005][4];
int dp[100005][4];
int n;

int funcc(int index, int flag) {

	if (index == n) return 0;

	if (dp[index][flag] != -1) return dp[index][flag];

	int maxi = 0;
	if (flag == 0) {
		maxi = max(maxi, a[index][1] + funcc(index + 1, 1));
		maxi = max(maxi, a[index][2] + funcc(index + 1, 2));
		maxi = max(maxi, a[index][3] + funcc(index + 1, 3));
	}
	else if (flag == 1) {
		maxi = max(maxi, a[index][2] + funcc(index + 1, 2));
		maxi = max(maxi, a[index][3] + funcc(index + 1, 3));
	}
	else if (flag == 2) {
		maxi = max(maxi, a[index][1] + funcc(index + 1, 1));
		maxi = max(maxi, a[index][3] + funcc(index + 1, 3));
	}
	else {
		maxi = max(maxi, a[index][1] + funcc(index + 1, 1));
		maxi = max(maxi, a[index][2] + funcc(index + 1, 2));
	}

	return dp[index][flag] = maxi;
}

int main() {

	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= 3; j++) {
			cin >> a[i][j];
		}
	}

	memset(dp, -1, sizeof dp);

	cout << funcc(0, 0);

	return 0;
}


Measured memory_bytes: 14472
#include <iostream>
#include <utility>
#include <queue>
#include <vector>

#define MAX 1000
#define MAXCHEESE 10

char map[MAX][MAX];
int d[MAX][MAX];
int W,H,N;
typedef std::pair<int, int> P;
std::vector<P> cheese(MAXCHEESE); // 0番目はスタート
int sx, sy;
int gx, gy;
int dx[4] = {0,-1,1,0};
int dy[4] = {-1,0,0,1};

int bfs(int goal){
    sx = cheese[goal-1].first;
    sy = cheese[goal-1].second;
    gx = cheese[goal].first;
    gy = cheese[goal].second;
    std::queue<P> que;
    for(int j=0; j<H; j++){
        for(int i=0; i<W; i++){
            d[i][j] = -1;
        }
    }
    que.push(P(sx,sy));
    d[sx][sy] = 0;

    while(que.size() != 0){
        P p = que.front();
        que.pop();

        for(int i = 0; i<4; i++){
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];
            if(0 <= nx && nx < W && 0 <= ny && ny <= H && map[nx][ny] != 'X' && d[nx][ny] == -1){
                que.push(P(nx,ny));
                d[nx][ny] = d[p.first][p.second] + 1;
                if(nx == gx && ny == gy) return d[nx][ny];
            }
        }
    }
    return -1;
}

int main(){
    std::cin >> H >> W >> N;

    std::string tmp;
    for(int j=0; j<H; j++){
        std::cin >> tmp;
        for(int i=0; i<W; i++){
            map[i][j] = tmp[i];
            if (map[i][j] == 'S') cheese[0] = P(i,j);
            if ('0' <= map[i][j] && map[i][j] <= '9'){
                int x = map[i][j] - '0';
                cheese[x] = P(i,j);
            }
        }
    }

    int ans = 0;

    for(int i = 1; i<=N; i++){
        if(bfs(i) == -1){
            ans = -1;
            break;
        }
        ans += bfs(i);
    }

    std::cout << ans << "\n";

    return 0;
}



Measured memory_bytes: 8048
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>

using namespace std;
int main() {
	string s;
	cin >> s;
	string a, b, c, d, e;
	int n = s.size();
	a = s.substr(0, n/2);
	b = a;
	c = s.substr(n/2+1);
	d = c;
	e = s;

	reverse(b.begin(), b.end());
	reverse(d.begin(), d.end());
	reverse(e.begin(), e.end());

	if (a == b && c == d && e == s) cout << "Yes" << endl;
	else cout << "No" << endl;

}


Measured memory_bytes: 256
n,m = map(int,input().split())
c=[list(map(int,input().split())) for i in range (n)]
c=sorted(c)
ans=0
d=0
for a,b in c:
  if b+d>=m:
    ans+=a*(m-d)
    break
  else:
    ans+=a*b
    d+=b
print(ans)

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

int main() {
  int A, B, C ,D;
  cin >> A >> B >> C >> D;
  if (A+B > C+D) {
    cout << "Left" << endl;
  }
  else if (A+B < C+D) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}


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

int main(){
int a;
  cin>>a;
  vector<int> b(a);
  for(int i=0;i<a;i++)
    cin>>b.at(i);
  sort(b.begin(),b.end());
  cout<<b.at(a-1)-b.at(0)<<endl;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;

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

	void solve(int V, int E, int[][] cap, int[][] flow, int s, int t) {
		int tot = 0;
		while (true) {
			int[] pre = new int[V];
			Arrays.fill(pre, -1);
			ArrayDeque<Integer> que = new ArrayDeque<>();
			que.add(s);
			out: while (!que.isEmpty()) {
				int cur = que.poll();
				for (int dst = 0; dst < V; ++dst) {
					if (cap[cur][dst] - flow[cur][dst] <= 0)
						continue;
					if (pre[dst] != -1 && dst != s)
						continue;
					pre[dst] = cur;
					if (dst == t)
						break out;
					que.add(dst);
				}
			}
			if (pre[t] == -1)
				break;
			int inc = Integer.MAX_VALUE / 16;
			for (int i = t; i != s; i = pre[i]) {
				inc = Math.min(inc, cap[pre[i]][i] - flow[pre[i]][i]);
			}
			for (int i = t; i != s; i = pre[i]) {
				flow[pre[i]][i] += inc;
				flow[i][pre[i]] -= inc;
			}
			tot += inc;
		}
		System.out.println(tot);

	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int V = sc.nextInt();
		int E = sc.nextInt();
		int[][] cap = new int[V][V];
		int[][] flow = new int[V][V];
		for (int i = 0; i < E; ++i) {
			int u = sc.nextInt();
			int v = sc.nextInt();
			int c = sc.nextInt();
			cap[u][v] = c;
		}
		int s = 0;
		int t = V - 1;

		solve(V, E, cap, flow, s, t);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 34792
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <utility>
#include <algorithm>
using namespace std;

int main(void){
    
    int n, m;
    cin>>n;
    vector<string> s(n);
    for(int i=0; i<n; i++){
        cin>>s[i];
    }
    cin>>m;
    vector<string> t(m);
    for(int i=0; i<m; i++){
        cin>>t[i];
    }
    
    map<string, int> mp;
    
    for(int i=0; i<n; i++){
        auto itr=mp.find(s[i]);
        
        if(itr!=mp.end()){
            itr->second+=1;
        }else{
            mp[s[i]]=1;
        }
    }
    
    for(int i=0; i<m; i++){
        auto itr=mp.find(t[i]);
        
        if(itr!=mp.end()){
            itr->second-=1;
        }else{
            mp[t[i]]=-1;
        }
    }
    
    int vmax=0;
    
    for(auto itr=mp.begin(); itr!=mp.end(); itr++){
        vmax=max(vmax, itr->second);
    }
    
    cout<<vmax<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.begin(), c.end()
#define Cin(T, x) T x; cin >> x;
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i];
#define Cout(val) cout << (val) << "\n";
#define Sort(a) sort(Range(a));
#define DeSort(a) sort(RevRange(a));

using namespace std;
using ll = long long;

int main(void){
    Cin(int, a);
    Cin(int, b);
    Cin(int, c);
    Cin(int, d);
    Cout((a+b)%24);
    //Cout(() ? "Yes" : "No");
    //Cout(() ? "YES" : "NO");
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
using namespace std;
#define i64  long long
#define lint long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define MOD 1000000007

 #define int long long


int MIN = I64_MAX;



const int MAX = 1000000;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


void solve()
{

  int X,Y;
  cin>>X>>Y;
  int P,Q;
  P = 2*Y - X;
  Q = 2*X - Y;

  if((P<0)||(Q<0))
  {
    cout<<0<<endl;
    return;
  }
  
  if(P % 3 == 0)
  {
    P /= 3;
  }
  else
  {
    cout<<0<<endl;
    return;
  }
  
  if(Q % 3 == 0)
  {
    Q /= 3;
  }
  else
  {
    cout<<0<<endl;
    return;
  }
  
  int A = P + Q;
  int B = min(P,Q);
  COMinit();
  
  cout<<COM(A,B)%MOD<<endl;
  
  return;  
}
 
int32_t main(int32_t argc, const char *argv[])
{
 
  solve();
 
  return 0;
}

Measured memory_bytes: 23680
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  bool dp[30010][4][1000] = {};
  dp[0][0][0] = 1;
  rep(i,n){
    rep(j,4){
      rep(k,1000){
        if(dp[i][j][k]){
          dp[i+1][j][k] = 1;
          dp[i+1][j+1][10*k+s[i]-'0'] = (j < 3);
        }
      }
    }
  }
  int ans = 0;
  rep(i,1000) if(dp[n][3][i]) ans ++;
  cout << ans << endl;
}


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

#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)

#define INF (int)1e9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef map<int, int> mii;



int main()
{
#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll a,b;
    cin>>a>>b;
    cout<<a*b;
    return 0;
}


Measured memory_bytes: 3616
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderBeginnerContest
{
    public class Program
    {
        public static void Main(string[] args)
        {
            // B
            var A = Console.ReadLine();
            var B = Console.ReadLine();

            if (A == B)
            {
                Console.WriteLine("EQUAL");
                return;
            }
            if (A.Count() > B.Count())
            {
                Console.WriteLine("GREATER");
                return;
            }
            if (A.Count() < B.Count())
            {
                Console.WriteLine("LESS");
                return;
            }

            // 長さが同じ場合
            for (int i = 0; i < A.Count(); i++)
            {
                if (Convert.ToInt16(A[i]) > Convert.ToInt16(B[i]))
                {
                    Console.WriteLine("GREATER");
                    return;
                }
                if (Convert.ToInt16(A[i]) < Convert.ToInt16(B[i]))
                {
                    Console.WriteLine("LESS");
                    return;
                }
            }

        }
    }
}

Measured memory_bytes: 13268
n = int(input())
a = list(map(int,input().split()))
print(' '.join(map(str,a)))
for i in range(n-1):
    cur = sorted(a[:i+2])
    if i != n-2:
        print(' '.join(map(str,cur))+' '+' '.join(map(str,a[i+2:])))
    else:
        print(' '.join(map(str,cur)))


Measured memory_bytes: 5600
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        final int N = scan.nextInt();
        int A[] = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextInt() - 1;
        }
        int B[] = new int[N];
        for (int i = 0; i < N; i++) {
            B[i] = scan.nextInt();
        }
        int C[] = new int[N];
        for (int i = 0; i < N - 1; i++) {
            C[i] = scan.nextInt();
        }
        scan.close();

        int score = 0;
        for (int i = 0; i < N; i++) {
            score += B[A[i]];
            if (i > 0) {
                if (A[i] - A[i - 1] == 1) {
                    score += C[A[i - 1]];
                }
            }
        }
        System.out.println(score);
    }    
}

Measured memory_bytes: 23892
import sys

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

#print(A)
#print(B)
#print(C)
#print(K)

sum = 0
if K > A:
  sum = A
  K = K - A
else:
  print(K)
  sys.exit()
  
if K > B:
  K = K - B
else:
  print(sum)
  sys.exit()

if K > C:
  sum += (-C)
else:
  sum += (-K)
  print(sum)
  sys.exit()

print(sum)

Measured memory_bytes: 9180
N = int(input())
res = [x for x in range(1, N + 1)]
result = {}
for i in res:
    result[i] = 0
    tmp = i
    while True:
        if tmp % 2 == 0:
            tmp = tmp / 2
            result[i] += 1
        else:
            break
print(sorted(result.items(), key=lambda x: -x[1])[0][0])


Measured memory_bytes: 3060
D = int(input())
C = [int(i) for i in input().split()]
L = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
P = []
for d in range(D):
    s = [int(i) for i in input().split()]
    ans = 0
    ma = 0
    P.append(0)
    for j in range(26):
        tmp = s[j]
        for k in range(26):
            if k != j:
                tmp -= C[k] * (d + 1 - L[k])
        if tmp > ma:
            ma = tmp
            ans = j
    L[ans] = d + 1
    print(ans + 1) 


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

st = sorted(p)
x = list(itertools.permutations(st, n))
num1 = x.index(p)
num2 = x.index(q)
print(abs(num1 - num2))

Measured memory_bytes: 8052
using System;
using System.Linq;

namespace ABC135
{
    class A
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(' ');

            int[] array = new int[N];
            for (int i = 0; i < N; i++)
            {
                array[i] = int.Parse(input[i]);
            }

            int conut = 0;
            for (int i = 0; i < N; i++)
            {
                if (array[i] != i + 1) conut++;
            }

            if (conut == 0 || conut == 2)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}


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

int main()
{
    long int a,b;
    cin>>a>>b;
    
    
    vector<long int>v(a);
    
    for(int i=0;i<a;i++)
    {
        cin>>v[i];
    }
    
    sort(v.rbegin(),v.rend());
    int l=0;
    if(b>=a)
    {cout<<"0";l=1;}
    
    long long int x=0;
    
    for(int i=b;i<a;i++)
    {x+=v[i];}
    
    if(l==0)
    cout<<x;
    
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

const int M = 107;

void read() {
  int a, b;
  cin >> a >> b;
  if (a <= 0 && 0 <= b)
    cout << "Zero\n";
  else if (a < 0 && b < 0 && (b - a + 1) % 2 == 1)
    cout << "Negative\n";
  else
    cout << "Positive\n";
}


void kill() {

}

int main() {
  cout.precision(20);
  cout << fixed;
  ios_base::sync_with_stdio(false);
  read();
  kill();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007 //S.size() 配列名.Length()
using namespace std;
typedef unsigned long long ll;

int main(void){
	int n, m;
	cin >> n >> m;
	vector<int> l(m),r(m);
	rep(i, m) cin >> l[i] >> r[i];

	SORT(l);
	SORT(r);

	int	ans = r[0] - l[m - 1] + 1;

	cout << (ans >= 0 ? ans : 0) << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using llong = long long;
using vi    = vector<int>;
using vvi   = vector<vi >;
using vvvi  = vector<vvi >;
using pii   = pair<int,int>;
constexpr int    INF=1e9;
constexpr double EPS=1e-9;
constexpr int    MOD=1e9+7;
template<class Type>
void line(const Type &a){int cnt=0;for(const auto &elem:a){cerr<<(cnt++?' ':'>');cerr<<elem;}cerr<<endl;}

template<typename T>
class SegmentTree{
	using F=function<T(T,T)>;
	int n,offset;	//n:=(葉の数（2の階乗数）),offset:=(n-1).
	const T e;		//e:=(単位元).
	vector<T> node;
	const F f;		//f:=(二項演算処理).
	
	int bufsize(int n_){//木に必要なノード数を返す.
		n=1;
		while(n<n_) n<<=1;
		offset=n-1;
		return 2*n-1;
	}
	void build(int l=0,int r=-1){//木を構築する. O(N).
		if(r<0) r=n;
		l+=offset, r+=offset;
		do{
			l=(l-1)/2, r=(r-1)/2;
			for(int i=l;i<r;++i) node[i]=f(node[2*i+1],node[2*i+2]);
		}while(l>0);
	}
	
public:
	/*constructor.*/
	SegmentTree(int n_,T e_,F f_):node(bufsize(n_),e_),e(e_),f(f_){}
	SegmentTree(const vector<T> &v_,T e_,F f_):node(bufsize(v_.size()),e_),e(e_),f(f_){
		copy(ALL(v_),node.begin()+offset);//<algorithm>.
		build();
	}
		
	void init(){fill(ALL(node),e);}//初期化する.
	void update(int k,T a){//k番目の要素をaに更新する. O(log N).
		k+=offset;
		node[k]=a;
		while(k>0){
			k=(k-1)/2;//parent.
			node[k]=f(node[2*k+1],node[2*k+2]);
		}
	}
	void add(int k,T a){update(k,node[k+offset]+a);}//k番目の要素にaを加算する.
	/*[a,b)間のクエリ結果を返す. O(log N).
	（後ろの3つの引数は計算の簡単のための引数. kはノード番号,lとrはそのノードが[l,r)に対応づいているかを表す. 外からはquery(a,b,0,0,n)と呼ぶ.）*/
	T query(int a,int b,int k=0,int l=0,int r=-1){
		if(r<0) r=n;
		if(b<=l or r<=a) return e;			//[a,b)と[l,r)が交差しなければe.
		if(a<=l and r<=b) return node[k];	//[a,b)が[l,r)を完全に含んでいれば,この節点の値.
		T vl=query(a,b,2*k+1,l,(l+r)/2);
		T vr=query(a,b,2*k+2,(l+r)/2,r);
		return f(vl,vr);					//交差する場合,2つの子をクエリ処理して比較.
	}
	
	typename vector<T>::reference operator[](int i){return node[i+offset];}
};

int main(){
	int n,k;
	cin>>n>>k;
	
	vector<pii > vp(k);
	REP(i,k){
		int l,r;
		cin>>l>>r;
		vp[i]=pii(l,r);
	}
	
	using Type=llong;
	auto f=[](Type a,Type b)->Type{return (a+b)%998244353LL;};
	SegmentTree<Type> tree(n+1,0LL,f);
	tree.update(1,1LL);
	//REP(i,n+1) cout<<tree[i]<<endl;
	
	for(int i=2;i<=n;++i){
		REP(j,k){
			int l,r;
			tie(l,r)=vp[j];
			
			if(i-l<1){}
			else{
				l=max(i-l,1);
				r=max(i-r,1);
				//if(i==4) printf(">%d %d\n",l,r);
				tree.add(i,tree.query(r,l+1));
			}
		}
	}
	//REP(i,n+1) cout<<tree[i]<<endl;
	
	cout<<tree.query(n,n+1)<<endl;
}

Measured memory_bytes: 7428
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

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

    int n;
    cin >> n;
    vl h(n);
    rep(i,n) cin >> h[i];
    int ans = 0;
    int tmp = 0;
    rep(i,n-1){
        if(h[i]>=h[i+1]) tmp++;
        else{ ans = max(ans,tmp);tmp=0;}    
    }
    cout << max(ans,tmp) << endl;
    return 0;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
using namespace std;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*(b/gcd(a, b)); }
template<typename T> T keta(T num){ T k=0; while(num>0){ num/=10; k++; } return k; }
template<typename T> void vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], ll n){ reps(i, 0, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    int w, h;
    char a[10][10];

    rep(y, 10){
        rep(x, 10){
            a[x][y] = '.';
        }
    }

    ll cnt = 0;

    cin >> h >> w;
    rep(y, h){
        rep(x, w){
            cin >> a[x][y];
            if(a[x][y] == '#') cnt++;
        }
    }

    int px=0, py=0;
    bool res = false;
    ll rescnt = 1;
    while(true){
        if(px == w-1 && py == h-1){
            res = true;
            break;
        }
        if(px >= w || py >= h) break;
        if(a[px+1][py] == a[px][py+1]) break;
        else{
            if(a[px+1][py] == '#'){
                px++;
            }else if(a[px][py+1] == '#'){
                py++;
            }
            rescnt++;
        }
    }

    auto solve = [](bool res){
        if(res) cout << "Possible" << endl;
        else cout << "Impossible" << endl;
    };

    if(rescnt != cnt) res = false;

    //cout << rescnt sp cnt << endl;

    solve(res);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;int main() {
  int A, B, Sum;
  cin >> A >> B;
  for(int i = A; i < B + 1; i++){
    if(i / 1000 == ((i % 100) / 10) + ((i % 10) * 10)){
      Sum += 1;
    }
  }
  cout << Sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
    using namespace std;
 
    typedef long long ll;
    typedef long double ld;
 
    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 FOR(i, a, b) for (int i=a; i<(b); i++)
    
    #define sz(x) (int)(x).size()
    #define mp make_pair
    #define pb push_back
    #define f first
    #define s second
    #define lb lower_bound
    #define ub upper_bound
    #define all(x) x.begin(), x.end()
 
    template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
    template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
    
    #define trav(container, it) for(typeof(container.begin()) it=container.begin(); it!=container.end(); it++)
 
    const int MOD = 1000000007;
    const char nl = '\n';
 
    int main() 
    {
        ios_base::sync_with_stdio(0); cin.tie(0);
        ll x;cin>>x;

        ll p=100;

        int count=0;

        while(x>p)
        {
            p = (p/100 + p);
            count++;
        }

        cout<<count;
    }


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

int main(){
    int H, W;
    
    while(1){
        cin >> H >> W;
        
        if(H == 0 && W == 0) break;
        
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                cout << "#";
            }
            cout << endl;
        }
        
        cout << endl;
    }
    
    return 0;
}


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

int main(){
    vector<int> o(5),v(5);
    for(int i=0;i<5;i++){
        cin>>o[i];
        v[i]=i;
    }

    int ans=1e9;
    do{
        int cnt=0;
        for(int i=0;i<5;i++){
            if(i==4) cnt+=o[v[i]];
            else{
                cnt+=(o[v[i]]+10-1)/10*10;
            }
        }
        ans=min(cnt,ans);
    }while(prev_permutation(v.rbegin(),v.rend()));
    cout<<ans<<endl;
}

Measured memory_bytes: 256
S = int(input())

def memo(func):
  D = {}
  def ret(*args):
    if args not in D:
      D[args] = func(*args)
    return D[args]
  return ret

@memo
def func(x):
  if x<3:
    return 0
  ret = 1
  for i in range(3, x-3+1):
    ret = (ret + func(i)) % 1000000007
  return ret

print(func(S))


Measured memory_bytes: 9300
#include<iostream>
using namespace std;
main() {
	string c,s,u="++++++++++";
	int p=0,t[10]={},i,j,k,a,b,d;
	c=">+++++[<++++++>-]>+++++[<++++++++>-]>+++++[<"+u+">-]>++++++[<"+u+">-]>+++++++[<"+u+">-]>++++++++[<"+u+">-]>+++++++++[<"+u+">-]>"+u+"[<"+u+">-]>+++++++++++[<"+u+">-]>++++++++++++[<"+u+">-]<<<<<<<<<<";
	for(cin>>s,i=0;i<s.length();++i){
		a=(s[i]/10)-3,b=a-p,p=a,d=s[i]-(a+3)*10;
		for(j=b>0?b:-b;j--;)c+=(b>=0?">":"<");
		for(k=d;k--;)c+="+";
		c+=".";
		for(k=d;k--;)c+="-";
	}
	cout<<c<<endl;
}

Measured memory_bytes: 1248
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef int64_t Int;
typedef uint64_t uInt;
const double pi = M_PI;

int main() {
    while (true) {
        Int n, x, ans = 0;
        cin >> n >> x;
        if (n == 0 && x == 0) {
            break;
        }

        for (Int i = 1; i < n - 1; i++) {
            for (Int j = i + 1; j < n; j++) {
                for (Int k = j + 1; k < n + 1; k++) {
                    if (i == j || i == k || j == k) {
                        continue;
                    }

                    if ((i + j + k) == x) {
                        ans++;
                    }
                }
            }
        }

        cout << ans << endl;
    }
}



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

long long k,i=0,n;
int main(){
	ios::sync_with_stdio(0);
    cin>>k;
    
    if(k%2==0||k%5==0){
	   cout<<"-1";
       return 0;
    }
    while(i<=1000000){
    	i++;
    	n=(n*10+7)%k;
    	
    	if(n==0){
		   cout<<i;
    	   return 0;
    	}
    }
	
	cout<<"-1";
	
	return 0;
}


Measured memory_bytes: 3596
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    let v: Vec<i64> = buf.split_whitespace().map(|x| x.parse().unwrap()).collect();
    let (x, y) = (v[0], v[1]);

    let ans: i64 = if x * y < 0 || x * y == 0 && x > y {
        (x + y).abs() + 1
    } else if x <= y {
        y - x
    } else {
        x - y + 2
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352