akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include<algorithm>
#include <stdio.h>
using namespace std;

int main() {
	long long n, sr=0,kr=0,ans;
	string s;
	bool f = true, si = false;
	cin >> n >> s;
	for (int i = 0; i < n; i++) {
	
		if (s[i] == '.') {
			kr++;
		}
		

	}
	ans = kr;
	for (int i = 0; i < n; i++) {
		if (s[i] == '.') {
			kr--;
		}
		else if (s[i] == '#') {
			sr++;
		}
		if (ans > kr + sr) {
			ans = kr + sr;
		}
		
	}
	
	cout << ans << endl;
	
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }
#define D1(a) cerr<<#a<<":"<<a<<endl
#define D2(a,b) cerr<<#a<<":"<<a<<","<<#b<<":"<<b<<endl
#define D3(a,b,c) cerr<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cerr<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl
#define DH(c) do{rep(__i, c.size())cerr<<c[__i]<<(__i==c.size()-1?'\n':' ');}while(0)

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

    int N; cin >>N;
    string s; cin >> s;
    vector<int> a(N);
    vector<int> c(3, 0);
    rep(i, N) {
        a[i] = s[i] - '1';
        c[a[i]]++;
    }
    if (c[1]) {
        int x = 0;
        rep(i, N) {
            if ((a[i] & 1) && ((N-1) & i) == i) {
                x ^= a[i];
            }
        }
        cout << ((x & 1) ? 1 : 0) << endl;
        return 0;
    }
    {
        int x = 0;
        rep(i, N) {
            if ((a[i] & 2) && ((N-1) & i) == i) {
                x ^= a[i];
            }
        }
        cout << ((x & 2) ? 2 : 0) << endl;
        return 0;
    }

}


Measured memory_bytes: 5276
N = int(input())
A = list(map(int, input().split()))
B = [0]
B.extend(A)
B.append(0)

plan = 0
for i in range(N+1):
    plan += abs(B[i]-B[i+1])

    
for i in range(N):
    act = plan
    if not ((B[i] <= B[i+1] <= B[i+2]) or (B[i] >= B[i+1] >= B[i+2])):
        act -= 2*min(abs(B[i+1]-B[i]), abs(B[i+1]-B[i+2]))
    print(act)

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

using namespace std;

#define int long long
#define MOD 1000000007

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}

//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

string s, t;

signed main()
{

    cin >> s >> t;
    int ans = 0;

    rep(i, 3)
    {
        if (s[i] == t[i])
        {
            ans++;
        }
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long;

template <typename T, typename F = std::plus<T>>
class fenwick_tree {
public:
	using value_type = T;
private:
	std::vector<T> m_data;
	F m_func;
public:
	fenwick_tree()
		: m_data(1)
		, m_func()
	{ }
	explicit fenwick_tree(
		size_t n,
		const value_type& x = value_type(),
		const F& f = F())
		: m_data(n + 1)
		, m_func(f)
	{
		m_data[0] = value_type();
		for(size_t i = 1; i <= n; ++i){
			m_data[i] = x;
			for(size_t j = i; (j & 1) == 0u; j >>= 1){
				m_data[i] = m_func(m_data[j], m_data[i]);
			}
		}
	}
	size_t size() const {
		return m_data.size() - 1;
	}
	value_type query(size_t i) const {
		value_type s = m_data[i];
		for(i -= i & -i; i > 0; i -= i & -i){
			s = m_func(m_data[i], s);
		}
		return s;
	}
	void modify(size_t i, const value_type& x){
		const auto n = m_data.size();
		for(++i; i < n; i += i & -i){
			m_data[i] = m_func(m_data[i], x);
		}
	}
};

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	ll k;
	cin >> n >> k;
	vector<ll> a(n);
	for(int i = 0; i < n; ++i){ cin >> a[i]; }
	vector<ll> b(n + 1);
	for(int i = 0; i < n; ++i){ b[i + 1] = b[i] + a[i]; }
	vector<ll> c(n + 1);
	for(int i = 0; i <= n; ++i){ c[i] = b[i] - i * k; }
	vector<ll> comp(c);
	sort(comp.begin(), comp.end());
	comp.erase(unique(comp.begin(), comp.end()), comp.end());
	const int m = comp.size();
	vector<int> d(n + 1);
	for(int i = 0; i <= n; ++i){
		d[i] = lower_bound(comp.begin(), comp.end(), c[i]) - comp.begin();
	}
	fenwick_tree<int> ft(m);
	for(int i = 0; i <= n; ++i){ ft.modify(d[i], 1); }
	ll answer = 0;
	for(int i = 0; i < n; ++i){
		ft.modify(d[i], -1);
		const int t = lower_bound(comp.begin(), comp.end(), c[i]) - comp.begin();
		answer += (n - i) - ft.query(t);
	}
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 8064
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ii> vii;
typedef map<int,int> mii;
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 7;


int main(){
	int n, m;  cin>>n>>m;
	int ans = 0;
	for(int i = 0; i < n; i++){
		int t; cin>>t;
		if(t>=m) ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

template<class T>
bool UpdateMax(T &a, const T &b){
  if(a<b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template<class T>
bool UpdateMin(T &a, const T &b){
  if(a>b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int a;
  cin>>a;
  cout<<a+a*a+a*a*a<<endl;



  return 0;
}




Measured memory_bytes: 3648
H,W,K = map(int,input().split())
c = [list(input()) for _ in range(H)]
ans = 0

for I in range(2**H):
  for J in range(2**W):
    black = 0
    for i in range(H):
      for j in range(W):
        if (I>>i)&1 == 0 and (J>>j)&1 == 0 and c[i][j] == "#":
          black += 1
    if black == K:
      ans += 1
print(ans)

Measured memory_bytes: 9048
n,k = map(int,input().split())
ret = 0
if k == 0:
  ret = n*n
else:
  for b in range(k+1,n+1):
    r = n%b
    q = int((n-r)/b)
    ret += q*(b-k) + max(r-k+1,0)
    
print(ret)

Measured memory_bytes: 3060
/**
 *    author:  FromDihPout
 *    created: 2020-07-29
**/

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


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    string s;
    cin >> n >> s;
    
    int begin = 0, bal = 0;
    for (int i = 0; i < n; i++) {
        if (bal <= 0 && s[i] == ')') {
            begin++;
        }
        else if (s[i] == ')') {
            bal--;
        }
        else {
            bal++;
        }
    }
    
    while (begin > 0) {
        cout << '(';
        begin--;
    }
    cout << s;
    while (bal > 0) {
        cout << ')';
        bal--;
    }
    cout << '\n';
    
    return 0;
}

Measured memory_bytes: 3604
n = int(input())
a = list(map(int,input().split()))

for i in range(n):
    v = a[i]
    j = i -1
    while j >= 0 and a[j] > v:
        a[j+1] = a[j]
        j -= 1
    a[j+1] = v
    print(" ".join(map(str,a)))

Measured memory_bytes: 7508
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
typedef long long LL;

LL n,m,k = 0,mi;
LL a[500005];

int main(){
	ios::sync_with_stdio(false);
	cin >> n; mi = n + 1;
	for(LL i = 1;i <= n;i ++){
		cin >> a[i];
		if(a[i] < mi){
			mi = a[i];
			k ++;
		}
	}
	cout << k << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1e+9 + 7;

//マクロ
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main()
{
  ll n;
  cin >> n;
  vector<ll> buka(n, 0);
  rep(i, n - 1)
  {
    ll in;
    cin >> in;
    in--;
    buka[in]++;
  }
  rep(i, n)
  {
    cout << buka[i] << endl;
  }
  return 0;
}

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

using namespace std;

int main()
{

    //int t;

    unsigned long long a,b,x,res;

    //cin>>t;

    //while(true){

        cin>>a>>b>>x;

        res = (b-a+1)/x;

        //cout<<"\nres f = "<<res<<" ";

        //if(a!=b){
            a+=res*x;
            //cout<<"a = "<<a<<"\n";
        //}

        if(a<=b){
            if(a==b && a%x==0)
                res++;

            else if( a%x > b%x || a%x==0 )
                res++;
        }

        cout<<res<<endl;
   //}

    return 0;
}

Measured memory_bytes: 3608
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#define FOR(n) for(int i = 0;i < n;i++)
#define PRN(n) printf("%d\n",n)

 int main(void){
   int a, b, c;
   int i=scanf("%d%d%d",&a,&b,&c);
   a = a* 100;
   b = b* 10;
   if((a+b+c)%4 == 0 )
     printf("YES");
   else
     printf("NO");
   return 0;
}

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

using namespace std;

int n, x;
set<int> s;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	while (n--) {
		cin >> x;
		if (s.find(x) == s.end())
			s.insert(x);
		else
			s.erase(x);
	}
	cout<<s.size()<<"\n";
}

Measured memory_bytes: 4992
#include<stdio.h>

int main()
{
    int n,count1=0,count2=0,j;
    scanf("%d",&n);
    int arr[n];
    for(int i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    for(int i=0;i<n;i++)
    {
        if((arr[i]==(i+1)))
        {
            count1++;
        }
        if(arr[i]!=(i+1))
        {
            count2++;
        }
    }
    if((count1==n))
    {
        printf("YES\n");
    }
    else if(count2<=2)
    {
        printf("YES\n");
    }
    else
    {
        printf("NO\n");
    }


    return 0;
}


Measured memory_bytes: 1656
#include<stdio.h>
int main()
{
    int n,tr,tx,tt;
    scanf("%d %d %d",&n,&tr,&tx);
    tt=tr*n;
    if(tt>tx)
    {
        printf("%d",tx);
    }
    else if(tt<tx)
    {
        printf("%d",tt);
    }
    else
    {
        printf("%d",tt);
    }
    return 0;












}


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

int main(){
  int l,r,d;
  cin >> l >> r >> d;
  int cnt = 0;
  for(int i = l; i <= r; i++){
    if(i%d == 0){
      cnt++;
    }
  }
  cout << cnt << endl;
}

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


//配列に格納した要素について、ある要素番号の要素はその番号より１だけ大きい。
int main(){
    int N; cin >> N;
    int A[N]={};
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    int cnt=0;
    for(int i=0;i<N;i++){
        if(A[i]!=i+1){
            cnt++;
        }
    }
    if(cnt<=2){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  int input[n];

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

  int ct = 0;
  for (int i = 1; i < n - 1; i++) {
    if ((input[i - 1] < input[i] && input[i] < input[i + 1]) ||
        (input[i - 1] > input[i] && input[i] > input[i + 1])) {
      ct++;
    }
  }
  cout << ct << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int n=1,a[8][6]={0},b,c,b1,c1;
  for(b=1;b<9;b++)for(c=1;c<6;c++)a[b][c]=n++;
  cin>>n;
  while(n--){
    cin>>b1>>c1;
    b=b1/100;
    c=c1/30+1;
    if(b1%100==0){
      if(c1%30==0)cout<<a[c][b]<<endl;
      else cout<<a[c][b]<<' '<<a[c+1][b]<<endl;
    }
    else {
      if(c1%30==0)cout<<a[c][b]<<' '<<a[c][b+1]<<endl;
      else cout<<a[c][b]<<' '<<a[c][b+1]<<' '<<a[c+1][b]<<' '<<a[c+1][b+1]<<endl;
    }
  }
}

Measured memory_bytes: 3060
$a, $b, $n = gets.split(" ").map(&:to_i)
def f x
  return ($a.to_r * x / $b).floor - $a * (x / $b.to_r).floor
end
ans = [f(1), f($n)].max
ans = [ans, f($b-1)].max if ($b-1).between?(1, $n)
puts ans

Measured memory_bytes: 14376
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int a[6];
int main(){
	scanf("%d%d%d%d%d",a,a+1,a+2,a+3,a+4);
	for(int i=0;i<5;i++)a[i]||(printf("%d\n",i+1),exit(0),0);
	return 0;
}

Measured memory_bytes: 3808
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

int main(void)
{
	int h, a;
	while(scanf("%d%d", &h, &a)==2)
	{
		int ans=(h+a-1)/a;

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


Measured memory_bytes: 128
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

A, B = getNM()
A -= 1
B -= 1

maze = [['#'] * 100 for i in range(100)]

# 右半分を黒で塗る
for i in range(100):
    for j in range(50, 100):
        maze[i][j] = "."

for i in range((A + 25 - 1) // 25):
    for j in range(25):
        maze[2 * i][2 * j] = '.'
        if i == ((A + 25 - 1) // 25) - 1 and j == (A % 25) - 1:
            break

for i in range((B + 25 - 1) // 25):
    for j in range(25):
        maze[2 * i][2 * j + 51] = '#'
        if i == ((B + 25 - 1) // 25) - 1 and j == (B % 25) - 1:
            break

print(len(maze), len(maze[0]))
for i in maze:
    print(''.join(i))

Measured memory_bytes: 83776
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

long calc(long n, long[] a) {
    long cap = a.reduce!min;

    // N 人を k 個のグループに分ける
    long k = (n + cap - 1) / cap;
    // k - 1 個のグループを進ませて、最後の 1 グループが 5 マス進む
    return (k - 1) + 5;
}

void main() {
    long n = read!long;
    long[] a;
    for (int i = 0; i < 5; i++) a ~= read!long;

    writeln(calc(n, a));
}


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

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

int main()
{
    long long x;
    cin >> x;

    long long p = x;
    while (!is_prime(p))
    {
        p++;
    }
    cout << p << endl;
}


Measured memory_bytes: 256
s = list(input())
# print(''.join(s[0:3]))
A = []
for i in range(0, len(s) - 2):
    A.append(abs(int(''.join(s[i:i+3])) - 753))
# for i in range(0, len(s) - 4):
#     A.append(abs(int(''.join(s[i:i+4])) - 753))
print(min(A))


Measured memory_bytes: 2940
local times = io.read("*l")
local paths = {}
for i = 1,times do
	local tmp = {}
	for j = 1,3 do
		tmp[j] = io.read("*n")
	end
	paths[i] = tmp
end
local pos = {0,0,0}
for k,v in ipairs(paths) do
	local step = v[1] - pos[1]
	local x = v[2]
	local y = v[3]
	local dis = math.abs(x - pos[2]) + math.abs(y - pos[3])
	if dis > step  or (dis-step)%2 == 1 then
		print("No")
		return
	end
	pos = v
end
print("Yes")

Measured memory_bytes: 16376
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int N;
  cin >> N;
  VEC<LL> H(N);
  REP(i, 0, N) cin >> H[i];
  for (int i = N - 1; i >= 1; i--) {
    if (H[i] - H[i - 1] == -1) H[i - 1]--;
  }
  REP(i, 0, N - 1) {
    if (H[i] > H[i + 1]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 1024
import sys
import itertools
input = sys.stdin.readline
n=int(input())
p=list(input().split())
q=list(input().split())
a=0

for i in range(1,n+1):
    a=a*10+i
b=list(itertools.permutations(str(a),n))
d=b.index(tuple(q))
e=b.index(tuple(p))
c=abs(d-e)
print(c)


Measured memory_bytes: 44656
#include <stdio.h>
#include <string.h>

char map[1000][31];
int page[1000];
int main(void){
    char mozi[31];
    int page1,i,q=0;
    for(;scanf("%s %d",mozi,&page1)!= EOF;q++){
        for(i=q;i>0 && (strcmp(map[i-1],mozi)>0 || (strcmp(map[i-1],mozi)==0 && page[i-1]>page1));i--){
            strcpy(map[i],map[i-1]);
            page[i]=page[i-1];
        }
        strcpy(map[i],mozi);
        page[i]=page1;
    }
    for(i=0;i<q;i++){
        if(i==0 || strcmp(map[i],map[i-1]) != 0)
            printf("%s\n%d%s",map[i],page[i],strcmp(map[i],map[i+1])==0?" ":"\n");
        else
            printf("%d%s",page[i],strcmp(map[i],map[i+1])==0?" ":"\n");
    }
    return 0;
}

Measured memory_bytes: 628
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;
int deco[1000];

int c[30];
ll dp[52][2510];
ll a[101];
void Solve() {
	int n;
	cin >> n;
	ll res = INF;
	for (size_t i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	sort(a, a + n);
	

	for (int i = a[0]; i <= a[n - 1]; i++)
	{
		ll val = 0;
		for (size_t j = 0; j < n; j++)
		{
			val += (a[j] - i) * (a[j] - i);
		}
		res = min(res, val);
	}

	cout << (a[0] == a[n-1] ? 0 : res) << endl;
}
int main() {
	Solve();
	return 0;
}



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

using namespace std;

int main(){
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  if(k <= a){
    cout << k << "\n";
    return 0;
  }
  if(k <= a + b){
    cout << a << "\n";
    return 0;
  }
  cout << (a - (k - a - b)) << "\n";
}

Measured memory_bytes: 3592
List = list(map(int, input().split()))
List.sort()
res = List[2]-List[1]
List[1] = List[2]
List[0] += res
mid = List[2] - List[0]
if mid % 2 == 1:
  res += mid // 2 +2
else:
  res += mid //2
print(res)

Measured memory_bytes: 9168
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    string t;
    cin>>t;
    for(int i=0;i<t.length();i++){
        if(t[i]=='?'){
            t[i]='D';
        }
    }
    cout<<t<<endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; i++){
    int tmp;
    cin >> tmp;
    A[tmp-1] = i+1;
  }
  for(int i = 0; i< N; i++) cout << A[i] << " ";
  return 0;
}

Measured memory_bytes: 1152
#s = input()
#a, b, c = map(int, input().split())

n = int(input())

list = []
for i in range(n):
    list.append(int(input()))

m = max(list)

#print(list)

list.pop(list.index(m))

#print(list)

sum = 0
for l in list:
    sum += l

sum += m / 2

print(int(sum))
#print(dict[n])


Measured memory_bytes: 2940
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {_a:String, _b:String}
    let num: i32 = (_a + &_b).parse().unwrap();
    let mut index: i32 = 1;
    let mut flag: bool = true;
    while index * index <= num {
        if index * index == num {
            println!("Yes");
            flag = false;
        }
        index += 1;
    }
    if flag {
        println!("No");
    }
}


Measured memory_bytes: 4352
#!/usr/bin/env python3
#
# FILE: 2138-AtCoDeer_and_Paint_Cans.py
#
# @author: Arafat Hasan Jenin <opendoor.arafat[at]gmail[dot]com>
#
# LINK: https://abc046.contest.atcoder.jp/tasks/abc046_a?lang=en
#
# DATE CREATED: 17-06-18 00:09:52 (+06)
# LAST MODIFIED: 17-06-18 00:19:32 (+06)
#
# VERDICT: Accepted
#
# DEVELOPMENT HISTORY:
# Date         Version     Description
# --------------------------------------------------------------------
# 17-06-18     1.0         Deleted code is debugged code.
#
#               _/  _/_/_/_/  _/      _/  _/_/_/  _/      _/
#              _/  _/        _/_/    _/    _/    _/_/    _/
#             _/  _/_/_/    _/  _/  _/    _/    _/  _/  _/
#      _/    _/  _/        _/    _/_/    _/    _/    _/_/
#       _/_/    _/_/_/_/  _/      _/  _/_/_/  _/      _/
#
##############################################################################

print(len(set(map(int, input().split()))))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define FOR0(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<int,int>
#define pb push_back
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e18
ll power(ll num,ll g,ll mod){
  if(g==0)return 1;
  if(g%2==1)return (num*power((num*num)%mod,g/2,mod))%mod;
  return power( (num*num)%mod,g/2,mod);
}


int main(){
	int n, x;
	cin >> n;
	vector<int> v[200001];
	FOR1(i, n-1){
		cin >> x;
		v[x].pb(i);
	}
	FOR1(i, n) cout << v[i].size() << endl;
}

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

namespace _174_b
{
    internal class Distance
    {
        private static void Main(string[] args)
        {
            var nd = Console.ReadLine()?.Split(" ").Select(int.Parse).ToArray();
            if (nd == null) return;
            var n = nd[0];
            var d = nd[1];

            var count = 0;
            for (var i = 0; i < n; i++)
            {
                var xy = Console.ReadLine()?.Split(" ").Select(int.Parse).ToArray();
                if (xy == null) return;
                var x = xy[0];
                var y = xy[1];

                var distance = Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2));
                if (distance <= d)
                {
                    count++;
                }
            }

            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 47040
#include<stdio.h>
int main(void)
{
  int i,j;
  char str[4];
  scanf("%s",str);
  if (str[0]==str[1]&&str[0]==str[2])
    printf("Yes\n");
  else if (str[1]==str[2]&&str[1]==str[3])
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}

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

int main(void){
    int N,K;
    cin>>N>>K;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    double ans=ceil((double)(N-1)/(double)(K-1));
    cout<<ans<<endl;
    return 0;
}



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

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define f first
#define s second
#define EPS (1e-10)

using namespace std;

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

double adjust(double a, double b, double c){
  return max(b, min(a, c));
}

typedef pair<double, double> P;

int main(){
  while(true){
    int w = getInt();
    int h = getInt();
    int n = getInt() * 2;

    if(w + h + n == 0) break;

    vector<P> pos(n + 2);

    REP(i, n){
      pos[i].f = getInt();
      pos[i].s = getInt();

      if(pos[i].f == 0.0) pos[i].f = EPS;
    }

    pos[n].f = w; pos[n].s = 0;
    pos[n + 1].f = w; pos[n + 1].s = h;

    vector<double> y;
    y.push_back(0.0);
    y.push_back(h);
    y.push_back(EPS);
    y.push_back(h - EPS);

    REP(i, n + 2) for(int j = i + 1; j < n + 2; j++){
      P pos1 = pos[i];
      P pos2 = pos[j];

      if(pos1.f == pos2.f) continue;

      double k  = (double)(pos2.s - pos1.s) / (pos2.f - pos1.f);
      double yy = (double)pos1.s - k * pos1.f;

      if(yy > 0.0 && yy < h){
        y.push_back(yy - EPS);
        y.push_back(yy + EPS);
      }
    }

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

    double prevw = 0.0;
    double ans   = 0.0;

    REP(i, y.size()){
      vector<double> tmp(n);

      REP(j, n){
        const double k = (pos[j].s - y[i]) / pos[j].f;
        tmp[j] = k;
      }

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

      const double y1 = adjust(y[i] + tmp[n / 2 - 1] * w, 0.0, h);
      const double y2 = adjust(y[i] + tmp[n / 2] * w, 0.0, h);
      const double w  = y2 - y1;

      //printf("%.3f: (%.3f, %.3f)\n", y[i], y1, y2);

      if(i != 0){
        ans += (y[i] - y[i-1]) * (prevw + w) / 2;
      }

      prevw = w;
    }

    printf("%.10f\n", ans / (h * h));
  }

  return 0;
}

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

int main() {
	string s1, s2, s3, s4;
	cin >> s1 >> s2 >> s3;
  	s4 = s1[0];
  	s4.append(1, s2[0]);
  	s4.append(1, s3[0]);
	transform(s4.begin(), s4.end(), s4.begin(), ::toupper);
	cout << s4;
	return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i, k, n) for(auto i = k; i != n; i++)
#define rrep(i, n) RREP(i, n, 0)
#define RREP(i, n, k) for(auto i = n; i != k; i--)
#define ALL(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " " << x << endl;

typedef long long ll;

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

    int N; cin >> N;
    map<ll, int> m;
    rep(i,N) {
        ll A; cin >> A;
        if(m.find(A) != m.end()) m[A] += 1;
        else m[A] = 1;
    }
    int ans = 0;
    REP(itr,m.begin(),m.end()) {
        ans += itr->second % 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); 
	
	vector<int> cnt(26, 1234567);
	int n;
	cin >> n;
	while(n--) {
		string s;
		cin >> s;
		vector<int> tmp(26);
		for(int i = 0; i < s.size(); i++) {
			tmp[s[i] - 'a']++;
		}
		for(int i = 0; i < 26; i++) {
			cnt[i] = min(cnt[i], tmp[i]);
		}
	}
	string ans;
		for(int i = 0; i < 26; i++) {
			cerr << cnt[i] << endl;
		}
	for(int i = 0; i < 26; i++) {
		for(int j = 0; j < cnt[i]; j++) {
			ans += 'a' + i;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n,k = list(map(int,input().split(' ')))
h = list(map(int, input().split(' ')))

dp = [0]*n 

for i in range(1,n):
    dp[i] = dp[i-1]+abs(h[i]-h[i-1])
    for j in range(2,k+1):
        if i-j>=0:
            dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]), dp[i])
    
print(dp[-1])

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


int main(){
  string s, t;
  cin >> s >> t;
  int l_s, l_t;
  l_s = s.size();
  l_t = t.size();
  for(int i=0;i<l_s;i++){
    if(s[i]!=t[i]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 3624
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(); sc.nextLine();
		for(int i=0;i<n;i++) System.out.println(sc.nextLine().replace("Hoshino", "Hoshina"));
	}
}

Measured memory_bytes: 17412
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define endl "\n"
#define fo for(int i=0;i<n;i++)
#define clear cin.clear();cin.ignore(numeric_limits<streamsize>::max(), '\n');
#define loopSolve int t; cin>>t; while(t--){solve();}
//INT_MAX         2,147,483,647                       <10^10
//U_INT_MAX       4,294,967,295                       <10^10
//LONG_LONG_MAX   9,223,372,036,854,775,807           <10^18
//U_LONG_LONG_MAX 18,446,744,073,709,551,615          <10^18
/*ll power(int a, int b){
    return (ll)(pow(a,b)+0.5);
}*/

int getBits(ll num){
	return (int)log2(num) + 1;
}

vector<int> gV(int n){
    vector<int> v;
    int input;
    fo { cin>>input; v.pb(input); }
    return v;
}

int* gA(int n){
    int* arr = new int[n];
    fo cin>>arr[i];
    return arr;
}


//https://atcoder.jp/contests/abc174/tasks/abc174_d
void solve(){
    int n; cin>>n;
    string s; cin>>s;
    vector<int> whiteIndices, redIndices;
    for(int i=0;i<s.length();i++){
        if(s[i]=='W') whiteIndices.push_back(i);
        else redIndices.push_back(i);
    }
    if(whiteIndices.size()==0 || redIndices.size()==0){
        cout<<0<<endl; return;
    }

    int whiteBegin=0,redEnd=redIndices.size()-1;
    int count=0;
    while(whiteBegin<whiteIndices.size() && redEnd>=0 && whiteIndices[whiteBegin]<redIndices[redEnd]){
        count++;
        whiteBegin++;
        redEnd--;
    }

    cout<<count<<endl;


}


int main() {
	ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);

    solve();
    //loopSolve;

	return 0;
}


Measured memory_bytes: 4704
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
#define _name3(_1,_2,_3,name,...) name
#define _rep1(n) for(ll i=0;i<(n);++i)
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _name3(__VA_ARGS__,_rep3,_rep2,_rep1)(__VA_ARGS__)
#define rrep(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define each(i,a) for(auto &i:a)
#define sum(a) accumulate(range(a),0LL)
#define range(i) (i).begin(),(i).end()
template<class T> inline constexpr bool chmin(T &mn,const T &cnt){if(mn>cnt){mn=cnt;return 1;}else return 0;}
template<class T> inline constexpr bool chmax(T &mx,const T &cnt){if(mx<cnt){mx=cnt;return 1;}else return 0;}

struct Bipartite_Matching
{
  vector< vector< int > > graph;
  vector< int > match, alive, used;
  int timestamp;
 
  Bipartite_Matching(int n)
  {
    timestamp = 0;
    graph.resize(n);
    alive.assign(n, 1);
    used.assign(n, 0);
    match.assign(n, -1);
  }
 
  void add_edge(int u, int v)
  {
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
 
  bool dfs(int v)
  {
    used[v] = timestamp;
    for(int i = 0; i < graph[v].size(); i++) {
      int u = graph[v][i], w = match[u];
      if(alive[u] == 0) continue;
      if(w == -1 || (used[w] != timestamp && dfs(w))) {
        match[v] = u;
        match[u] = v;
        return (true);
      }
    }
    return (false);
  }
 
  int bipartite_matching()
  {
    int ret = 0;
    for(int i = 0; i < graph.size(); i++) {
      if(alive[i] == 0) continue;
      if(match[i] == -1) {
        ++timestamp;
        ret += dfs(i);
      }
    }
    return (ret);
  } 
};
struct Lexicographically_Matching : Bipartite_Matching
{
  Lexicographically_Matching(int n) : Bipartite_Matching(n) {}

  int back(int k)   // 押し戻す
  {
    match[match[k]] = -1;
    match[k] = -1;
    ++timestamp;
    dfs(k);
    return (match[k]);
  }

  void decide(int k) // 決める
  {
    alive[match[k]] = 0;
    alive[k] = 0;
  }
};
int main() {
    int n;
    cin>>n;
    n--;
    vector<vector<int>>a(n,vector<int>(n));
    each(i,a)each(j,i)cin>>j;
    Lexicographically_Matching match(n*2);
    rep(n)rep(j,n)if(a[i][j])match.add_edge(j,i+n);
    each(i,match.graph)sort(i.begin(),i.end());
    match.bipartite_matching();
    rep(n)if(match.match[i]==-1)return puts("no")&0;
    rep(n){
        match.back(i);
        match.decide(i);
    }
    puts("yes");
    rep(n)cout<<match.match[i]+1-n<<endl;
}



Measured memory_bytes: 4064
/*input
1000000
*/
/*
       _==/          i     i          \==_
     /XX/            |\___/|            \XX\
   /XXXX\            |XXXXX|            /XXXX\
  |XXXXXX\_         _XXXXXXX_         _/XXXXXX|
 XXXXXXXXXXXxxxxxxxXXXXXXXXXXXxxxxxxxXXXXXXXXXXX
|XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX|
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX|
 XXXXXX/^^^^"\XXXXXXXXXXXXXXXXXXXXX/^^^^^\XXXXXX
  |XXX|       \XXX/^^\XXXXX/^^\XXX/       |XXX|
    \XX\       \X/    \XXX/    \X/       /XX/
       "\       "      \X/      "      /"

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
//loops
#define f(i,s,n) for(ll i=(ll)s;i<(ll)n;i++)
#define rf(i,n,s) for(ll i=(ll)(n-1);i>=(ll)s;i--)
//reset
#define ms0(X) memset((X), 0, sizeof((X)))
#define ms1(X) memset((X), -1, sizeof((X)))
//IO
#define bio ios_base::sync_with_stdio;cin.tie(NULL)
//STL
#define pb push_back
#define pii pair<ll,ll>
#define vll vector<ll>
#define vpii vector<pii >
#define mll map<ll, ll>
#define mpii map<pii,ll> 
#define msll map<string, ll> 
#define sortv(v) sort(v.begin(),v.end())
#define F first
#define S second
//standard values
#define mod (ll)(1e9+7)
#define INF (ll)1e16
#define MAXN (ll)(1e5+5)
//comparator
bool cmp(pii a, pii b)
{
    return a.F < b.F;
}
ll exp(ll a,ll b){ll ans=1;while(b!=0){if(b%2==1)ans=ans*a;a=a*a;b/=2;}return ans;}
/********************************************************************************************************/
int main() 
{
  bio;
  ll n;
  cin>>n;
  ll sum = 0;
  f(i,1,n+1) {
    sum += (i%3 != 0 && i%5 != 0) ? i:0;
  }
  cout<<sum<<endl;

}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int n,k;cin >> n>> k;
    vector<int> v(n);
    REP(i,n) cin >> v[i];

    int mn = 1<<30;
    int md = 0;
    int cnt = 0;
    REP(i,n-1) {
        mn = min(v[i],mn);
        int d = v[i+1] - mn;
        if (d > md) {
            md = d;
            cnt = 1;
        } else if (d == md) {
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N,L;
  cin >> N >> L;
  vector<int> a(N),b(N);
  rep(i,N) 
  {
    cin >> a[i];
  }
  rep(i,N-1)
  {
    b[i] = a[i] + a[i+1];
  }
  sort(RALL(b));
  if(b[0]<L)
  {
    cout << "Impossible" << endl;
    return 0;
  }
  else
  {
    cout << "Possible" << endl;
    int k = 0;
    rep(i,N-1)
    {
      if(a[i]+a[i+1]==b[0])
      {
        k = i+1;
        break;
      }
      else
      {
        cout << i + 1 << endl;
      }
    }
    for(int i = N-1;i>=k;i--)
    {
      cout << i << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3996
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Abhas Jain
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AColorfulSubsequence solver = new AColorfulSubsequence();
        solver.solve(1, in, out);
        out.close();
    }

    static class AColorfulSubsequence {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.ni();
            long mod = (long) 1e9 + 7L;
            String s = in.next();
            int[] ar = new int[26];
            for (int i = 0; i < n; ++i) ar[s.charAt(i) - 'a']++;
            long ans = 1;
            for (int i = 0; i < 26; ++i) {
                ans = (ans % mod * (ar[i] + 1L) % mod) % mod;
            }
            ans--;
            if (ans < 0) ans += mod;
            out.print(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ni() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 22996
N, M, X = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]

ans = 10**9 + 10

for i in range(1, 2**N):
    money = 0
    L = [0] * M
    for j in range(N):
        if (i >> j) & 1:
            money += A[j][0]
            for k in range(M):
                L[k] += A[j][k+1]
    if min(L) >= X and money < ans:
        ans = money

if ans == 10**9+10:
    ans = -1

print(ans)

Measured memory_bytes: 9220
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n, dist[MAXN];
vector <int> a[MAXN];
void dfs(int pos, int fa) {
	for (auto x : a[pos])
		if (x != fa) {
			dist[x] = dist[pos] + 1;
			dfs(x, pos);
		}
}
int main() {
	int n; read(n);
	for (int i = 1; i <= n - 1; i++) {
		int x, y; read(x), read(y);
		a[x].push_back(y);
		a[y].push_back(x);
	}
	dist[1] = 0, dfs(1, 0);
	int pos = 1;
	for (int i = 1; i <= n; i++)
		if (dist[i] > dist[pos]) pos = i;
	dist[pos] = 0, dfs(pos, 0);
	int Max = 0;
	for (int i = 1; i <= n; i++)
		chkmax(Max, dist[i]);
	if (Max % 3 == 1) puts("Second");
	else puts("First");
	return 0;
}

Measured memory_bytes: 21376
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
	bool ok=false;
	double eps=1e-7;
	int t;scanf("%d",&t);
	double val=0;
	while(t--){
		int a,b;scanf("%d%d",&a,&b);
		double p=0;
		double ex=0;
		for(int i=0;i<b;i++){
			int q;double r;scanf("%d%lf",&q,&r);
			p+=r;ex+=r*q;
		}
		ex/=p;
		val=max(val,ex);
	}
	int a,b;scanf("%d%d",&a,&b);
	double p=0;double ex=0;
	for(int i=0;i<b;i++){
		int q;double r;scanf("%d%lf",&q,&r);
		p+=r;ex+=r*q;
	}
	ex/=p;
	if(ex+eps<val)printf("YES\n");else printf("NO\n");
}

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

template<typename type>
struct union_find{
	vector<type>par; vector<size_t>rank,len;
	explicit union_find(size_t n)
		:par(n,-1),rank(n),len(n,1){}
	type find(type val){
		if(par.at(val)<0)return val;
		return par.at(val)=find(par.at(val));
	}
	bool same(type a,type b){
		return find(a)==find(b);
	}
	void unite(type a,type b){
		a=find(a),b=find(b);
		if(a==b)return;
		if(rank.at(a)<rank.at(b)){
			par.at(a)=b;
			len.at(b)+=len.at(a);
		}
		else{
			if(rank.at(a)==rank.at(b))++rank.at(a);
			par.at(b)=a;
			len.at(a)+=len.at(b);
		}
	}
	size_t size(size_t i){return len.at(find(i));}
};

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,m; cin>>n>>m;
	union_find<int>uf(n);
	for(int i=0;i<m;++i){
		int a,b; cin>>a>>b; --a,--b;
		uf.unite(a,b);
	}
	int ans=0;
	for(int i=0;i<n;++i)ans=max(ans,(int)uf.size(i));
	cout<<ans<<"\n"s;
}


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

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

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

    int max=0;
    for(int i=0; i<N; i++){
        for(int j=i; j<N; j++) {
            int cur = abs(a[i] - a[j]);
            if(cur > max){
                max = cur;
            }
        }
    }
    cout << max << endl;
}

int abs(int i){
    if(i<0){
        return i*-1;
    }
    return i;
}

Measured memory_bytes: 256
/*

 */
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;
struct UnionFind {
  int *data;
  UnionFind(int *_data, int size) : data(_data) {
    for(int i = 0; i < size; i++) data[i] = -1;
  }
  bool unionSet(int x, int y) {
    x = find(x); y = find(y);
    if (x != y) {
      if (data[y] < data[x]) std::swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  int find(int x) {
    return data[x] < 0 ? x : data[x] = find(data[x]);
  }
  int size(int x) {
    return -data[find(x)];
  }
};
int main(int argc, char *argv[])
{
  // kruskal with x being unused.
  // assumption: es is sorted
  auto kruskal = [](int n, const vector<pair<int,pair<int,int>>> &es, int x, vector<bool> &used) {
    vector<int> ufdata(n);
    UnionFind uf(&(ufdata[0]), n);
    int sum = 0;
    for(int i = 0; i < es.size(); i++) {
      if(i == x) continue;
      const int u = es[i].second.first;
      const int v = es[i].second.second;
      if(uf.find(u) != uf.find(v)) {
        used[i] = true;
        uf.unionSet(u, v);
        sum += es[i].first;
      }
    }
    return sum;
  };
  int n, m;
  vector<pair<int,pair<int,int>>> es;
  cin >> n >> m;
  for(int i = 0; i < m; i++) {
    int s, d, c;
    cin >> s >> d >> c;
    es.push_back(make_pair(c, make_pair(s-1, d-1)));
  }
  sort(es.begin(), es.end());
  vector<bool> used(m, false);
  int mn = kruskal(n, es, -1, used);
  int sum = 0;
  int cnt = 0;
  vector<bool> used2(m, false);
  for(int i = 0; i < m; i++) {
    if(!used[i]) continue;
    int mni = kruskal(n, es, i, used2);
    if(mni != mn) {
      cnt ++;
      sum += es[i].first;
    }
  }
  cout << cnt << " " << sum << endl;
  return 0;
}




Measured memory_bytes: 3816