akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define ll long long

//#define TEST

signed main(){
    int n,k;
    cin >> n >> k;
    vector<pair<ll,ll>> sushi(n);
    for (int i = 0;i < n;++i)
        cin >> sushi[i].first >> sushi[i].second;

    /*
          s[i] : ネタi+1の寿司がおいしい順に並んだ配列
        とする.
    */
    vector<vector<ll>> s(n);
    for (auto si : sushi)
        s[si.first - 1].push_back(si.second);
    for (int i = 0;i < n;++i){
        sort(s[i].begin(),s[i].end(),greater<ll>());
        if (s[i].empty())
            s[i].push_back(-(ll)(1e13)); 
    }

#ifdef TEST
    cout << "--------s(not sorted)--------" << endl;
    for (auto si : s){
        for (auto sij : si)
            cout << sij << " ";
        cout << endl;
    }
#endif

    /*
          s[0],s[1],...,s[n]
        を、最大値について降順に並べ替える.
    */
    sort(
        s.begin(),
        s.end(),
        [](vector<ll> a,vector<ll> b){
            return a[0] > b[0];
        }
    );

#ifdef TEST
    cout << "----------s(sorted)----------" << endl;
    for (auto si : s){
        for (auto sij : si)
            cout << sij << " ";
        cout << endl;
    }
#endif

    /*
          s[0][0],s[1][0],...,s[k-1][0]
        をとる場合を考える.
        とらなかった寿司も保留しておく.
    */
    ll dpoi = 0; // おいしさポイント
    priority_queue<ll> q; // 取らなかった寿司を保留しておく
    for (int i = 0;i < k;++i){
        dpoi += s[i][0]; // s[i][0]をとる
        for (int j = 1;j < s[i].size();++j)
            q.push(s[i][j]); // 保留
    }
    ll ans = dpoi + (ll)k * k; // 暫定の答え
    for (int i = k;i < n;++i)
        for (int j = 0;j < s[i].size();++j)
            q.push(s[i][j]); // 保留


    /*
        とるネタの種類を減らしていき、答えを更新していく.
    */
    for (ll i = k - 1;i > 0;--i){
        ll new_sushi = q.top(); // 新たにとる候補の寿司
        if (s[i][0] < new_sushi){
            q.pop(); 
            dpoi += new_sushi;
            q.push(s[i][0]);
            dpoi -= s[i][0];
        }
        ans = max(ans,dpoi + i * i);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 10104
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main()
{
    int A, B;
    char op;
    cin >> A >> op >> B;
    if (op == '+') cout << A + B << endl;
    else cout << A - B << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    if (a>b)
    {
        cout << "a > b" << endl;
    }
    else if (a<b)
    {
        cout << "a < b" << endl;
    }
    else if (a==b)
    {
        cout << "a == b" << endl;
    }
    return 0;
}


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

int main() {
  int N; cin >> N;
  string S; cin >> S;
  int count =1;
  int sameColor =1;
  for (int i =0; i<N-1; i++) {
    if (S.at(i) != S.at(i+1)) {
      if (sameColor != 1) {
        count++;
        sameColor =1;
      } else {
        count++;
      }
    } else {
      sameColor++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3716
//
//  main.cpp
//  project for C++
//
//  Created by 伊藤博隆 on 2020/04/17.
//  Copyright © 2020 伊藤博隆. All rights reserved.
//

#include <iostream>
#include<set>
#include<string>
#include <sstream>

using namespace std;
int N,Y;

int a=-1,b=-1,c=-1;
int main(){
    cin>>N>>Y;
    for(int i = 0;i<=N;i++){
        for(int j=0;j<=N-i;j++){
            int num = 10000*i + 5000*j + 1000*(N-i-j);
            if (num == Y) {
                a = i;
                b = j;
                c = N-i-j;
               
            }
            
        }
    }
   cout << a << " " <<  b << " " << c <<endl;
    
    return 0;
}




Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define MOD 1000000007
#define PI 3.14159265358979

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

using namespace std;

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};

typedef vector< edge > edges;
typedef vector< edges > graph;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;

template < typename T >
bool chmin(T &x, const T &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T >
bool chmax(T &x, const T &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
int main() {
	int A, B;
	cin >> A >> B;
	int ans;
	if (A < 10 && B < 10)
		ans = A * B;
	else
		ans = -1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
A = []
b = []
for i in range(n):
    A.append([int(j) for j in input().split()])
for i in range(m):
    b.append(int(input()))
for i in range(n):
    sum = 0
    for j in range(m):
        sum += A[i][j]*b[j]
    print(sum)

Measured memory_bytes: 7976
#include<bits/stdc++.h>
using namespace std;
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);cout.tie(NULL);
        long int n;
        cin>>n;
        vector<long int> h(n),cost(n,0);
        for(long int i=0;i<n;i++){
                cin>>h[i];
        }
        cost[n-1]=0;
        cost[n-2]=abs(h[n-1]-h[n-2]);
        for(long int i=n-3;i>=0;i--){
                long int a,b;
                a=cost[i+1]+abs(h[i+1]-h[i]);
                b=cost[i+2]+abs(h[i+2]-h[i]);
                cost[i]=min(a,b);}
                cout<<cost[0];
        
return 0;
}
/*

        creation time:  15.09.2020 20:19:41

*/                      



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

int main(void) {
  int N;
  cin >> N;
  int p[N];
  int pi=-1, pj=-1;

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

  for (int i=1; i < N; i++) {
    if (p[i-1] > p[i]) {
      if (pi == -1) {
        pi = i-1;
      } else {
        pj = i;
      }
    }
  }

  if (pi != -1 && pj != -1) {
    int tmp = p[pi];
    p[pi] = p[pj];
    p[pj] = tmp;
  }

  for (int i=1; i<N; i++) {
    if (p[i-1] > p[i]) {
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 256
# coding:utf-8
n = int(input())
s = [input() for _ in range(n)]
# print(s)

print('AC x ' + str(s.count('AC')))
print('WA x ' + str(s.count('WA')))
print('TLE x ' + str(s.count('TLE')))
print('RE x ' + str(s.count('RE')))


Measured memory_bytes: 16192
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
using namespace std;


typedef long long ll;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)

const int mod = 1000000007;

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

  if(s == "Sunny")  cout << "Cloudy" << endl;
  if(s == "Cloudy") cout << "Rainy" << endl;
  if(s == "Rainy")  cout << "Sunny" << endl;

}

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

using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
// #define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#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 rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'



signed main() {
    fio();
    vector<string> s = {"AC", "WA", "TLE", "RE"};
    vi num(4);
    int n;
    cin >> n;
    rep (i, n) {
        string t;
        cin >> t;
        rep (j, 4) {
            if (s[j] == t) num[j]++;
        }
    }

    rep (j, 4) {
        cout << s[j] << " x " << num[j] << endl;
    }
}

Measured memory_bytes: 3656
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.B
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadText();
            var k = 0L;
            for (int i = 0; i < N.Length; i++)
            {
                k += int.Parse(N[i].ToString());
                k %= 9;
            }
            return k % 9 == 0 ? "Yes" : "No";
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


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

struct Trump{
	string suit;
	string num;
};

void print(Trump trump[], long N){
    for (long i = 0; i < N; i++){
        cout << trump[i].suit << trump[i].num;
        if (i < N - 1) cout << " ";
    }
    cout << endl;
}

void BubbleSort(Trump trump[], long N){
	for (long i = 0; i < N; i++){
		for (long j = N - 1; j >= i && j > 0; j--){
			if (trump[j].num < trump[j - 1].num){
				swap(trump[j], trump[j - 1]);
			}
		}
	}
}

void SelectionSort(Trump trump[], long N){
	for (long i = 0; i < N; i++){
		long minj;
		minj = i;
		for (long j = i; j < N; j++){
			if (trump[j].num < trump[minj].num){
				minj = j;
			}
		}
		swap(trump[i], trump[minj]);
	}
}

bool isStable(Trump card1[], Trump card2[], long N){
    BubbleSort(card1, N);
    SelectionSort(card2, N);
	for (long i = 0; i < N; i++){
        if (card1[i].num == card2[i].num){
            if (card1[i].suit != card2[i].suit){
                return false;
            }
        }
	}
	return true;
}

int main(){
	long N;
	cin >> N;
    string c;
	Trump card1[36];
	Trump card2[36];
	for (long i = 0; i < N; i++){
		cin >> c;
        card1[i].suit = c[0];
        card1[i].num = c[1];
	}
	for (long i = 0; i < N; i++){
		card2[i] = card1[i];
	}
	BubbleSort(card1, N);
	SelectionSort(card2, N);
    print(card1, N);
	cout << "Stable" << endl;
    print(card2, N);
	if (isStable(card1, card2, N)) cout << "Stable" << endl;
	else cout << "Not stable" << endl;
	return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
using namespace std;

const int MAXN = 13;

int N, M;
string S[MAXN];
int A[10], B[10];
map<char, char> cm;
set<int> notZero;
bool used[10];

char conv(char c) {
  if(!cm.count(c)) {
    cm[c] = (char)('a' + cm.size() - 1);
  }
  return cm[c];
}

void add(const string &a, int A[10]) {
  for(int i = a.size()-1, j = 1; i >= 0; --i, j *= 10) {
    A[a[i]-'a'] += j;
    if(i == 0 && a.size() != 1) notZero.insert(a[i]-'a');
  }
}

int rec(int k, int sum) {
  int res = 0;
  if(k == M) return sum == 0;
  for(int i = 0; i < 10; ++i) {
    if(used[i]) continue;
    if(i == 0 && notZero.count(k)) continue;
    used[i] = true;
    res += rec(k+1, sum + (A[k] - B[k]) * i);
    used[i] = false;
  }
  return res;
}

int main() {
  while(cin >> N && N) {
    cm.clear();
    notZero.clear();
    for(int i = 0; i < N; ++i) {
      cin >> S[i];
      for(int j = 0; j < S[i].size(); ++j) {
	S[i][j] = conv(S[i][j]);
      }
    }

    M = cm.size();
    fill(A, A+10, 0);
    fill(B, B+10, 0);
    for(int i = 0; i < N; ++i) {
      if(i+1 == N) {
	add(S[i], B);
      } else {
	add(S[i], A);
      }
    }
    /*
    cout << "B" << endl;
    for(int i = 0; i < M; ++i) {
      cout << (char)('a'+i) << ":" << A[i] << endl;
    }
    cout << endl;
    cout << "B" << endl;
    for(int i = 0; i < M; ++i) {
      cout << (char)('a'+i) << ":" << B[i] << endl;
    }
    cout << endl;
    */
    fill(used, used+10, 0);

    cout << rec(0,0) << endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define mem(x,y) for(int i=0;i<x.size()i++){ x[i]=y; }
#define fo(i, l, r)  for((i) = (l); (i) < (r); (i)++)
#define fok(i,r,k)  for((i) = 0; (i) < (r); (i)=i+(k))
#define prnt(a,n)  { for(int i=0;i<n;i++){ cout<<a[i]<<" "; } cout<<endl; } 
#define mp make_pair
#define pb push_back
#define pi pair<int,int> 
#define pll pair<long long,long long>
#define vi vector<int> 
#define vl vector<long long>
#define vpl vector<pair<long long,long long>> 
#define vpi vector<pair<int,int>> 
#define all(x) x.begin(),x.end()
#define f first
#define s second
#define br cout<<endl;
#define io { freopen("input.txt","r",stdin);  freopen("output.txt","w",stdout); }
ll modexpo(ll x,ll y,ll m){    x=x%m;if(y==0){return 1;}if(y%2==0){return modexpo(x*x,y/2,m); }else{    return  (x*modexpo(x*x,y/2,m))%m; }}
const int mod  = 1e9+7;
const int maxn = 1e5 + 10;

int n,k; 
int a[maxn]; 
int main()
{
fastio; 
/*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif */
int i,j,mn=0;
cin>>n>>k;
fo(i,0,n)
{ 
    cin>>a[i]; 
    if(a[i]<a[mn]){mn = i;}
}
i = 0; int ans = 0;
while(i<n-1)
{
i = i+(k-1);
ans++; 
}
cout<<ans;
return 0;
}
//g++ -g b.cpp -o b.exe

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define PI acos(-1)
typedef long long ll;

int max_digit(int x, int y) {
    return max(to_string(x).size(), to_string(y).size());
}

int main() {
    ll N;
    cin >> N;
    int ans = to_string(N).size();
    for (int i = 1; i <= sqrt(N); i++) {
        if (N % i == 0) ans = min(ans, max_digit(i, N / i));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3784
from collections import deque
n,m = map(int,input().split())
inf = 10**10

edge = [[] for i in range(n)]
x = [inf]*n
for i in range(m):
    l,r,d = map(int,input().split())
    edge[l-1].append((r-1,d))
    edge[r-1].append((l-1,-d))


for i in range(n):
    if x[i] == inf:
        x[i]=0
        q = deque([i])
        while len(q)!=0:
            now = q.popleft()
            for e in edge[now]:
                if x[e[0]] == inf:
                    x[e[0]] = x[now]+e[1]
                    q.append(e[0])
                elif x[e[0]]-x[now]!=e[1]:
                    print("No")
                    exit()

print("Yes")

Measured memory_bytes: 66252
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  string s1,s2="";
  int x=0;
  cin>>s1;
  for(int i = s1.length()-1;i>=0;i--)
  {
    s2=s2+s1.at(i);
  }
  for(int j=0;j<s1.length();j++)
  {
    if(s1[j] !=s2[j]){++x;}
  }
  if(x==0){cout << 0<<endl;}
  else{cout << x/2 << endl;}
  return 0;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
C = {}
for i in range(h):
    for c in input():
        C[c] = C.get(c, 0) + 1
if h == 1 or w == 1:
    odd = 0
    for c in C:
        if C[c] % 2 == 1:
            odd += 1
    if h % 2 == 1 and w % 2 == 1:
        if odd == 1:
            print('Yes')
        else:
            print('No')
    else:
        if odd == 0:
            print('Yes')
        else:
            print('No')
else:
    #print(C)
    four = 0
    odd = 0
    for c in C:
        if C[c] % 2 == 1:
            odd += 1
        if C[c] >= 4:
            four += C[c]//4
    needf = (h//2*2) * (w//2*2) // 4
    #print(needf)
    if h % 2 == 1 and w % 2 == 1:
        if four >= needf and odd == 1:
            print('Yes')
        else:
            print('No')
    else:
        if four >= needf and odd == 0:
            print('Yes')
        else:
            print('No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
vector<ll> V;
int pre[maxn];
const int mod=1e9+7;
int main() {
    int n,k;cin>>n>>k;
    ll sum=0,low=0,up=n;
    for(int i=1;i<=n+1;i++){
        if(i>=k) sum=(sum+up-low+1)%mod;
        low=(low+i)%mod;up=(up+n-i)%mod;
    }cout<<(sum+mod)%mod<<endl;
    return 0;
}

Measured memory_bytes: 3632
# include <iostream>
# include <algorithm>
# include <vector>
# include <functional>
# include <string>
using namespace std;

int main() {
	int N, memo;
	vector<int> a;

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

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

	cout << a[a.size()-1]-a[0] << endl;

	return 0;
}

Measured memory_bytes: 256
//2019.8.3 by ljz
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f
#define eps 5.6e-8
#define RG register
#define db double
#define pc(x) __builtin_popcount(x)
typedef pair<int,LL> Pair;
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pb push_back
#define gc getchar
//inline char gc() {
//    static char buf[100000],*p1,*p2;
//    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
//inline int read() {
//    res s=0,ch=gc();
//    while(ch<'0'||ch>'9')ch=gc();
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s;
//}
inline int read() {
    res s=0,ch=gc(),w=1;
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
    return s*w;
}
inline LL Read() {
    RG LL s=0;
    res ch=gc();
    while(ch<'0'||ch>'9')ch=gc();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
    return s;
}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
inline void swap(res &x,res &y) {
    x^=y^=x^=y;
}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//clock_t start=clock();
//inline void ck(){
//    if(1.0*(clock()-start)/CLOCKS_PER_SEC>0.1)exit(0);
//}
const int N=1e5+10;
namespace MAIN {
    int n;
    int h[N];
    inline void MAIN() {
        n=read();
        for(res i=1;i<=n;i++)h[i]=read();
        for(res i=1;i<n;i++){
            if(h[i]>h[i-1])h[i]--;
            if(h[i]>h[i+1]){puts("No");return;}
        }
        puts("Yes");
    }
}
int main() {
//    srand((unsigned)time(NULL));
//    freopen("nothard.in","r",stdin);
//    freopen("nothard.out","w",stdout);
    MAIN::MAIN();
    return 0;
}

Measured memory_bytes: 640
def main():
    n = int(input())
    num_list = list(map(int, input().split()))
    
    count = 0

    max = 0

    num_list.reverse()

    for i in range(n-1):
        if num_list[i] <= num_list[i+1]:
            count += 1
        else:
            count = 0
        if max < count:
            max = count

    print(max)

if __name__ == '__main__':
    main()

Measured memory_bytes: 63856
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(long long)>
using namespace std;
#define All(v) (v).begin(),(v).end()
const long long mod = 1000000007;
const long long inf = mod*mod;
const int AMAX = 100000;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
long long A[AMAX+1];
signed main(){
    int n;
    long long k;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        A[a]+=b;
    }
    for(int i=1;i<=AMAX;i++){
        if(k<=A[i]){
            cout<<i<<endl;
            break;
        }
        k-=A[i];
    }
}


Measured memory_bytes: 1024
//#include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll func(ll n){//
    ll x = floor(sqrt(n));
    //cout << "x" << x << endl;
    for(ll i=x; i>=1; i--){
        if(n%i==0){
            ll A = n/i;
            ll B = i;
            //cout << "A" << A << endl;
            //cout << "B" << B << endl;
            A--;
            B--;
            return A+B;
        }
    }
    return n-1;
}

int main(){
    ll N;
    cin >> N;
    ll ans = func(N);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )

#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

// eratosthenes の篩（素数かどうかの表が返る）
vector<bool> eratosthenes( int n )
{
	vector<bool> nums( n + 1, true );
	nums[0] = nums[1] = false;

	for ( int i = 0; i < nums.size(); ++i )
	{
		if ( !nums[i] )
		{
			continue;
		}

		for ( int j = 2; i * j < nums.size(); ++j )
		{
			nums[ i * j ] = false;
		}
	}

	return nums;
}

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

	VI primes;
	{
		vector<bool> isPrime( eratosthenes( 100000 ) );
		REP( i, 2, isPrime.size() )
		{
			if ( isPrime[i] )
			{
				primes.PB( i );
			}
		}
	}

	while ( true )
	{
		int m, a, b;
		cin >> m >> a >> b;

		if ( !( m | a | b ) )
		{
			break;
		}

		int p, q, maxmul = 0;
		REP( i, 0, primes.size() )
		{
			if ( m < primes[i] )
			{
				break;
			}

			REP( j, 0, primes.size() )
			{
				if ( m < primes[i] * primes[j] )
				{
					break;
				}
				if ( maxmul < primes[i] * primes[j] && 1. * a / b <= 1. * primes[i] / primes[j] && 1. * primes[i] / primes[j] <= 1 )
				{
					maxmul = primes[i] * primes[j];
					p = primes[i];
					q = primes[j];
				}
			}
		}

		cout << p << ' ' << q << endl;
	}

	return 0;
}

Measured memory_bytes: 1340
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define debug(var)  do{std::cerr << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cerr << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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 (b<a) { a=b; return 1; } return 0; }
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> v1;
typedef vector<v1> v2;
typedef vector<v2> v3;

typedef unordered_map<ll, unordered_map<ll, ll>> graph;

const ll INF = 1ll << 50;
const ll mod = 1000000007;

long n;
long u,v;
long a;

int main(){
    scanf("%ld", &n);
    a = n*(n+1)*(n+2)/6;
    for(ll i = 1;i < n;++i){
        scanf("%ld %ld", &u, &v);
        if(u < v) a -= u * (n-v+1);
        else a -= v * (n-u+1);
    }
    printf("%ld\n", a);
}


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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}
template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    int n, m; 
    cin >> n >> m;

    v_int input(n+5, 0);
    
    irep(i, m) {
        int l, r;
        cin >> l >> r;
        input[l] += 1;
        input[r+1] -= 1;
    }
    
    v_int card(n+5, 0);
    irep2(i, 1, n) {
        card[i] = card[i-1] + input[i];
    }

    int ans = 0;
    irep2(i, 1, n) {
        if(card[i] == m) { 
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
} /*atcoder*/


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

#define M 1046257
#define NIL (-1)
#define L 14

char H[M][L];

// 文字から数値に変換
int getChar(char ch) {
  if ( ch == 'A' ) return 1;
  else if ( ch == 'C' ) return 2;
  else if ( ch == 'G' ) return 3;
  else if ( ch == 'T' ) return 4;
  return 0;
}

// 文字列から数値へ変換して key を生成する
long long getKey(char str[]) {
  long long sum =0, p = 1, i;
  for(i=0;i<strlen(str);i++) {
    sum += p*(getChar(str[i]));
    p*= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]) {
  long long key, i, h;
  key = getKey(str); // 文字列を数値に変換
  for(i=0; ;i++) {
    h = (h1(key) + i*h2(key)) %M;
    if( strcmp(H[h],str) == 0) return 1;
    else if ( strlen(H[h]) == 0 ) return 0;
  }
  return 0;
}

int insert(char str[]) {
  long long key, i, h;
  key = getKey(str); // 文字列を数値に変換
  for(i=0; ; i++) {
    h = (h1(key) + i * h2(key)) %M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0) {
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(void) {
  int i, n;
  char str[L], com[9];
  for(i=0;i<M;i++) H[i][0] = '\0';
  scanf("%d",&n);
  for(i=0;i<n;i++) {
    scanf("%s %s",com,str); // より高速なscanfを使用
    if(com[0] == 'i') {
      insert(str);
    } else {
      if(find(str)){
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}


Measured memory_bytes: 16052
#include<stdio.h>
#include<math.h>
#include<string.h>
int main(void)
{
  int n;

  for(;scanf("%d",&n)!=EOF;){
    int a,b,c;
    int count=0;
    for(a=0;a<10;a++){
      for(b=0;b<10;b++){
	for(c=0;c<10;c++){
	  if((n-a-b-c)>=0 && (n-a-b-c)<10)
	    count+=1;
	}
      }
    }
    printf("%d\n",count);
  }

  return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;
import java.lang.Math;

public class Main {
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    while(true)
    {
      int x = scan.nextInt();
      int y = scan.nextInt();
      if (x==0 && y==0) break;
      System.out.println(Math.min(x,y) + " " + Math.max(x,y));
    }
    scan.close();
  }
}


Measured memory_bytes: 36868
#include <bits/stdc++.h>
using namespace std;
#define LL long long

int main () {
	int k, a, b; cin >> k >> a >> b;
	bool flg = false;
	for (int i = a; i <= b; i ++) {
		if (i % k == 0) 
			flg = true;
	}
	cout << (flg ? "OK" : "NG");
	return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N;
    cin >> N;
    vector<ll> a(N);
    REP(i, N) cin >> a[i];

    vector<ll> res(N, 0);
    set<ll> ans;
    for(ll i=N-1;i>=0;i--){
    	ll i_val = i+1;
    	ll sum = 0;
    	for(ll j_val=i_val;j_val<=N;j_val += i_val){
    		ll j = j_val-1;
    		sum += res[j];
    	}
    	//dump(i_val)
    	//dump(sum)
    	res[i] = (sum%2)^a[i];
    	if(res[i] == 1) ans.insert(i+1);
    }

    cout << ans.size() << endl;
    for(auto x: ans){
    	cout << x << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 9984
#include<stdio.h>
#include<string.h>
#define MAX 100000

typedef struct data{
  char name[11]; 
  int time;
}process;

static int head,tail;
process Q[MAX];

void enqueue(process p){
  Q[tail] = p;
  tail = (tail+1) % MAX;
}

process dequeue(){
  process p = Q[head];
  head = (head+1) % MAX;
  return p;
}

int main(){
  int n,q,t=0,count=0;
  process p;
  scanf("%d %d",&n,&q);
  head=0; tail=0;
  for(int i=0; i<n; i++){
    scanf("%s %d",p.name,&p.time);
    enqueue(p);
  }
  while(count!=n){
    p = dequeue();
    if(p.time-q > 0){
      p.time -= q;
      t += q;
      enqueue(p);
    }
    else{
      t += p.time;
      count++;    
      printf("%s %d\n",p.name,t);
    }
  }
  return 0;
}

Measured memory_bytes: 3240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int inf = 1000000000;
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};

int main(){
    int h,w;
    cin >> h >> w;
    int ch,dh,cw,dw;
    cin >> ch >> cw >> dh >> dw;
    vector<string> s(h);
    
    ch--; cw--; dh--; dw--;
    rep(i,h){
        cin >> s[i];
    }
    vector<vector<int>> dist(h,vector<int>(w,inf));
    deque<pair<int,int>> q;
    dist[ch][cw] = 0;
    q.emplace_back(ch,cw);
    while(!q.empty()){
        int i = q.front().first;
        int j = q.front().second;
        q.pop_front();
        int d = dist[i][j];
        rep(k,4){
            int ny = i+dx[k];
            int nx = j+dy[k];
            if(nx < 0 || nx>=w || ny<0 || ny>=h) continue;
            if(s[ny][nx] == '#') continue;
            if(dist[ny][nx]<=d) continue;
            dist[ny][nx] = d;
            q.emplace_front(ny,nx);
        }
        for(int ai=-2; ai<=2; ai++){
            for(int aj=-2; aj<=2; aj++){
            int ny = i+ai;
            int nx = j+aj;
            if(nx < 0 || nx>=w || ny<0 || ny>=h) continue;
            if(s[ny][nx] == '#') continue;
            if(dist[ny][nx]<=d+1) continue;
            dist[ny][nx] = d+1;
            q.emplace_back(ny,nx);
            }
        }
    }
    int ans = dist[dh][dw];
    if(ans == inf){
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9564
#include<cstdio>
#include<ctime>
#include<algorithm>
#define int long long 
#define re register
#define gc getchar
using namespace std;
inline int read(){
	re int t=0;re char v=gc();
	while(v<'0')v=gc();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=gc();
	return t;
}

int ans[200002],tot,num[200002],cnt;
inline long long msc(long long x,long long y,long long mod){
long long tmp=(x*y-(long long)((long double)x/mod*y+1.0e-8)*mod);
return tmp<0?tmp+mod:tmp;
}inline int ksm(re int x,re int y,re int M){
	re int ans=1;
	while(y){
		if(y&1)ans=msc(ans,x,M);
		x=msc(x,x,M);
		y>>=1;
	}
	return ans;
}
inline int random(re int x){
	return ((double)rand()/RAND_MAX*x+0.5);
}
inline bool mr(re int n){if(n<2)return 0;
srand((unsigned)time(NULL));	
if(n==2)return 1;
if(n==3)return 1;
if(n==5)return 1;
if(n==7)return 1;
if(n==11)return 1;
if(n==13)return 1;
	if(n&1)
	if(n%3)
	if(n%5)
	if(n%7)
	if(n%11)
	if(n%13){
		int m=n-1,k=0;
		while(!(m&1))m>>=1,++k;
		for(re int i=1;i<=3;++i){
			int a=random(n-2)+1,x=ksm(a,m,n),y=0;
			for(re int j=1;j<=k;++j){
				y=msc(x,x,n);
				if(y==1&&x!=1&&x!=n-1)return 0;
				x=y;
			}
			if(y!=1)return 0;
		}
		return 1;
	}
	return 0;
}
inline int gcd(re int x,re int y){
	return y?gcd(y,x%y):x;
}
inline int as(re int x){
	return x<0?-x:x;
}
#define ll long long
inline ll pr(ll x,ll c) {
	if(!c)c=rand();
	ll s=0,t=0;
	int stp=0,goal=1;
	ll val=1;
	for(goal=1;;goal<<=1,s=t,val=1) {
		for(stp=1; stp<=goal; ++stp) {
			t=(msc(t,t,x)+c)%x;
			val=msc(val,as(t-s),x);
			if((stp%127)==0) {
				ll d=gcd(val,x);
				if(d>1)return d;
			}
		}
		ll d=gcd(val,x);
		if(d>1)return d;
	}
}
int pp[40]= {9643,9649,9661,9677,9679,9689,9697,9719,9721,9733,9739,9743,9749,9767,9769,9781,9787,9791,9803,9811,9817,9829};
inline void ff(re int x){
	if(x==1)return;
	if(mr(x)){
		ans[++tot]=x;
		return;
	}
	int p=x,tmp=0;	
	
	while(p>=x)p=pr(x,pp[tmp++]);
	ff(p);
	ff(x/p);
}
int anss;
int t,n,m,M;
inline int H(re int x){
	return x&1?x:x/2;
}
inline void dfs(re int x,re int y,re int z){
	if(x>cnt){
		if(!(y&1)&&(n/y)&1)return;
		(anss+=ksm(m,(n/y+1)/2,M)*(H(n/y)%M)%M*(z%M)%M)%=M;
		return;
	}
	dfs(x+1,y,z);
	z*=(1-ans[x]);
	for(re int i=1;i<=num[x];++i){
		y*=ans[x];
		dfs(x+1,y,z);
	}
}
signed main(){
	srand((unsigned)time(NULL));
	n=read();m=read();M=1e9+7;tot=0;m%=M;
	ff(n);sort(ans+1,ans+tot+1);
	cnt=0;anss=0;
	for(re int i=1;i<=tot;++i)if(ans[i]!=ans[cnt])ans[++cnt]=ans[i],num[cnt]=1;else ++num[cnt];
	dfs(1,1,1);anss<0?anss+=M:anss;
	printf("%lld\n",anss);
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
 
int main(){
  int E,Y;
  cin >> E >> Y;
 
  switch(E){
    case 0:
      if(Y<=1911){
        cout << "M" << Y-1868+1 << endl;
        break;
      }else if(Y<=1925){
        cout << "T" << Y-1912+1 << endl;
        break;
      }else if(Y<=1988){
        cout << "S" << Y-1926+1 << endl;
        break;
      }else if(Y<=2016){
        cout << "H" << Y-1989+1 << endl;
        break;
      }
    case 1:
      cout << Y+1868-1 << endl;
      break;
    case 2:
    cout << Y+1912-1 << endl;
      break;
    case 3:
    cout << Y+1926-1 << endl;
      break;
    case 4:
    cout << Y+1989-1 << endl;
      break;
  }
  return 0;
}


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

int main() {
	string s;
	cin >> s;
	if (s[0]=='7'|| s[1] == '7'|| s[2] == '7') {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  string s;
  while(cin>>n,n){
    cin>>s;
    int c=1;
    while(n--){
      string ss;
      r(i,s.size()){
        if(s[i]!=s[i+1]){
          char w[100];
          sprintf(w,"%d",c);
          r(df,strlen(w))ss+=w[df];
          ss+=s[i];
          c=1;
        }
        else c++;
      }
      s=ss;
    }
    cout<<s<<endl;
  }
}

Measured memory_bytes: 3388
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
#from scipy.misc import comb

number = [0,2,5,5,4,5,6,3,7,6]

N,M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

dp = [-1]*(N+1)
dp[0] = 0
for i in range(N+1):
    for a in A:
        if i-number[a] >= 0:
            if dp[i-number[a]] >= 0:
                dp[i] = max(dp[i], dp[i-number[a]]*10+a)

print(dp[N])

Measured memory_bytes: 23688
#include<bits/stdc++.h>
#define ll long long
#define P pair<ll, ll>
using namespace std;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i=0;i<n;i++) cin >> a[i];

    ll ans = 0;
    for(int i=1;i<n;i++){
        if(a[i] < a[i-1]){
            ans += (a[i-1]-a[i]);
            a[i] = a[i-1];
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 4780
#include "bits/stdc++.h"
using namespace std;

#define ASC(a) a.begin(), a.end()		// 昇順ソート 例：sort(ASC(a));
#define DESC(a) a.rbegin(), a.rend()	// 降順ソート 例:sort(DESC(a));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(a) rep(i, n) cin>>a[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;
#define only_unique(vec) vec.erase(std::unique(vec.begin(), vec.end()), vec.end());

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vii;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };


// ────────────────────────────────────────────────────

int main() {
	int n; cin >> n;
	vi p(n); rep(i, n) cin >> p[i];

	sort(ASC(p));

	int ans = n;
	rep(i, n) {
		if (p[i] >= ans) break;
		ans--;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3168
import sys

while True:
	n, x = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
	if 0 == n and 0 == x:
		break
		
	cnt = 0
	goto = False
	for i in range( 1, n-1 ):
		if  x < 3*(i+1):
			break
		for j in range( i+1, n ):
			if  x <= ( i+j ):
				break
			for k in range( j+1, n+1 ):
				s = ( i + j + k )
				if x == s:
					cnt += 1
					break
				elif   x < s:
					goto = True
					break
			goto = False
	
	print( cnt )

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

namespace ITP1_10_B
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();

            double rad = input[2] / 180.0 * Math.PI;

            double[] a = new double[] { input[0], 0 };
            double[] b = new double[] { Math.Cos(rad) * input[1], Math.Sin(rad) * input[1] };

            double S = (a[0] * b[1] + a[1] * b[0]) * 0.5;
            double distance = Math.Sqrt(Math.Pow((b[0] - a[0]), 2) + Math.Pow((b[1] - a[1]), 2));
            double L = input[0] + input[1] + distance;
            double h = input[1] * Math.Sin(rad);
    
            Console.WriteLine(S);
            Console.WriteLine(L);
            Console.WriteLine(h);
        }
    }
}

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

int main(){
  int h1, h2, k1, k2, a, b, c, d, H, K;

  cin >> h1 >> h2 >> k1 >> k2 >> a >> b >> c >> d;
  H = h1*a + (h1/10)*c + h2*b + (h2/20)*d;
  K = k1*a + (k1/10)*c + k2*b + (k2/20)*d;

  if ( H > K ) cout << "hiroshi" << endl;
  else if ( H < K ) cout << "kenjiro" << endl;
  else cout << "even" << endl;

  return 0;
}


Measured memory_bytes: 3100
r, c, a1, a2, b1, b2 = gets.split.map(&:to_i)

m = [(a1-b1).abs, a1+r-b1, b1+r-a1].min
n = [(a2-b2).abs, a2+c-b2, b2+c-a2].min

x = (1..m+n).inject(1, :*) / (1..m).inject(1, :*) / (1..n).inject(1, :*)
x *= 2 if (a1-b1).abs * 2 == r
x *= 2 if (a2-b2).abs * 2 == c
p x % 100000007

Measured memory_bytes: 6668
#include<cstdio>
char s[100001];
int main(){
    scanf("%s",s);
    int n=0;
    while(s[n]!='\0')n++;
    if(s[n-1]=='1' || s[0]=='0'){
        printf("-1");
        return 0;
    }
    for(int i=0;2*i<n;i++){
        if(s[i]!=s[n-2-i]){
            printf("-1");
            return 0;
        }
    }
    int d=1;
    for(int i=2;i<=n;i++){
        printf("%d %d\n",d,i);
        if(s[i-2]=='1')d=i;
    }
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <iomanip>
#include <math.h>
#include <algorithm>
#define hmm "\n"
#define test() int t; cin>>t; while(t--)
#define ll long long int
#define ull unsigned long long
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
void solve()
{
    ll ar[20],ans;
    for(int i=0; i<5; i++){
        cin>>ar[i];
    }
    for(int i=0; i<5; i++){
        if(ar[i]==0){
            ans=i+1;
        }
    }
    cout<<ans<<hmm;
}
int main()
{
    fastIO
    //test()
    solve();
}


Measured memory_bytes: 3648
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {

    char[] ch;

    private void solve() {
        ch = next().toCharArray();

        if (ch.length < 26) {

            int[] cnt = new int[26];
            for(char c : ch) {
                cnt[c-'a']++;
            }

            int index = -1;
            for (int i = 0; i < 26; i++) {
                if (cnt[i] == 0) {
                    index = i;
                    break;
                }
            }

            StringBuilder sb = new StringBuilder();
            sb.append(ch);
            sb.append((char) ('a' + index));
            out.println(sb);
            return;
        } else {

            int[][] cnt = new int[ch.length + 1][26];
            for (int i = 0; i < ch.length; i++) {
                for (int j = 0; j < 26; j++) {
                    cnt[i + 1][j] += cnt[i][j];
                }
                cnt[i + 1][ch[i] - 'a']++;
            }

            for (int i = ch.length - 1; i >= 0; i--) {
                int c = ch[i] - 'a';
                int index = -1;
                for (int j = 25; j > c; j--) {
                    if (cnt[i][j] == 0) {
                        index = j;
                    }
                }

                if (index != -1) {
                    ch[i] = (char) ('a' + index);
                    out.println(String.valueOf(ch, 0, i + 1));
                    return;
                }
            }
        }
        out.println(-1);
    }
    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

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

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 22484