akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <string>
#include <algorithm>

using namespace std;

bool testcase_ends() {
    char buf[128];
    if (scanf("%s", buf) == EOF)
        return 1;

    string s(buf);
    scanf("%s", buf);
    string t(buf);

    if (s.length() > 80 || t.length() > 80)
        return !printf("overflow\n");

    reverse(s.begin(), s.end());
    reverse(t.begin(), t.end());

    if (s.length() > t.length()) {
        t += string(s.length()-t.length(), '0');
    } else if (s.length() < t.length()) {
        s += string(t.length()-s.length(), '0');
    }

    string u;
    int carry=0;
    for (size_t i=0; i<s.length(); ++i) {
        u.push_back(s[i]+t[i]+carry-'0');
        if (u.back() > '9') {
            carry = 1;
            u.back() -= 10;
        } else {
            carry = 0;
        }
    }
    if (carry)
        u.push_back('1');

    if (u.length() > 80)
        return !printf("overflow\n");

    reverse(u.begin(), u.end());
    printf("%s\n", u.c_str());
    return 0;
}

int main() {
    size_t n;
    scanf("%zu", &n);

    for (size_t i=0; i<n; ++i)
        if (testcase_ends())
            return 1;

    return 0;
}

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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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;
}

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag,
              long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll n, k;
    cin >> n >> k;
    vec<ll> a(n);
    REP(i, n) {
        cin >> a[i];
    }
    ll all = 1LL << n;
    ll ans = INF;
    REP(bit, all) {
        ll ma = 0;
        ll con = 0;
        ll cost = 0;
        REP(i, n) {
            if((bit >> i) & 1) {
                //見えるようにする
                con++;
                ma = max(a[i], ma + 1);
                cost += ma - a[i];
            } else {
                if(ma < a[i]) {
                    con++;
                    ma = a[i];
                }
            }
        }
        if(con >= k) {
            chmin(ans, cost);
        }
    }
    cout << ans << en;
}

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

    solve();

    /*
    ll t;
    cin >> t;
    REP(i, t) { solve();}
    */

    return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
// -----------------<fast IO>------------------
#define IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FLSH             fflush(stdout)
#define fileIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);
#define PRECISION(x)     cout << fixed << setprecision(x);
// -----------------<TypeDef Start>------------------
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
// -----------------<Constants>------------------
const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI=acos(-1);

const int INF=1e9;

int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
/*ll gcd(ll a,ll b)
{
    if(a==0)
    return(b);
    return(gcd(b%a,a));
}*/
// --------------------------------------------------</TEMPLATE>--------------------------------------------------

void solve()
{
    string s;
    cin>>s;
    ll cnt=0;
    ll ans=0;
    for(ll i=0;i<3;)
    {
        ll cnt=0;
        while(s[i]=='R')
            {
                cnt++;
                i++;
            }
        i++;
        ans=max(ans,cnt);
    }
    cout<<ans<<endl;
}

int main()
{
    IOS
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return(0);
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    int r, d, x;
    cin >> r >> d >> x;
    for (int i = 0; i < 10; i++) {
        x = r * x - d;
        cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    V v; //0:none 1:A 2:BC

    string s;
    cin >> s;

    int i = 0;

    v.push_back(0);

    while (i < s.size())
    {
        if (s[i] == 'A')
        {
            v.push_back(1);
            i++;
        }
        else if (i < s.size() - 1 && s[i] == 'B' && s[i + 1] == 'C')
        {
            v.push_back(2);
            i += 2;
        }
        else
        {
            if (v[v.size() - 1] != 0)
                v.push_back(0);
            i++;
        }
    }

    ll res = 0;
    int an = 0;

    for (int i : v)
    {
        if (i == 0)
            an = 0;
        if (i == 1)
            an++;
        if (i == 2)
            res += an;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1680
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef map<char,int> M;
const ll mod=1000000000+7;

int main(){
    ll N;
    cin>>N;
    ll cnt=0;
    map<string,ll> jud;
    vector<string> s(N);
    for(ll i=0;i<N;i++)cin>>s.at(i);
    for(ll i=0;i<N;i++){
        sort(s.at(i).begin(),s.at(i).end());
    }
    for(ll i=0;i<N;i++){
        if(jud.count(s.at(i))){
            cnt+=jud[s.at(i)];
            jud[s.at(i)]++;
        }
        else{
            jud[s.at(i)]=1;
        }
    }
    cout<<cnt<<endl;
}

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

const int INF=100000000;
int N;
int A[230];

int main(){
 	cin>>N;
  	for(int i=0;i<N;++i)cin>>A[i];
  
  	int res=INF;
  	for(int i=0;i<N;++i){
		int count=0;
      	while(A[i]%2==0){
          A[i]/=2;
          ++count;
        }
     
      if(res>count)res=count;
    }
  
      cout<<res;
  
}


Measured memory_bytes: 3192
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static void Main(string[] args)
        {
            int[] V = ReadInts();
            Console.WriteLine(V[0] * 500 >= V[1] ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define ll long long int
#define N 1000
#define M 1000000007
#define f(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define po pop_back
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mp make_pair
#define bs binary_search
#define debug(x) cout << #x << " = " << x << endl
#define ub upper_bound
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define all(x) x.begin(), x.end()
#define PI 3.14159265
#define cot cout.tie(0)
using namespace std;
/**
  * @author :: Rishabh
  *
  */
int main()
{
	ibs;
	cti;
	string s,t;
	cin>>s>>t;
	if(t.size()>s.size())
	{
		cout<<"0\n";
		return 0;
	}
	int n=t.size();
	string x="";
	for(int i=0;i<n;i++)
	{
		x=x+s[i];
	}
	int c=0;
	int ans=0;
	for(int i=0;i<n;i++)
	{
		if(t[i]==x[i])
		c++;
	}
	c=n-c;
	ans=c;
	c=0;
	for(int i=n;i<s.size();i++)
	{
		x=x+s[i];
		x.erase(0,1);
		for(int j=0;j<x.size();j++)
		{
			if(t[j]==x[j])
			c++;
		}
		c=n-c;
		ans=min(ans,c);
		c=0;
	}
	cout<<ans<<"\n";
	return 0;
}

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 100;
const long long LLINF = 2e18 + 129;
const long long MOD = 1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    string a, b;
    cin >> a >> b;

    int n = (int)a.size() - (int)b.size() + 1;
    bool ans = false;
    rep(i, n){
        bool flag = true;
        rep(j, b.size()){
            flag &= (a[i + j] == b[j] || b[j] == '_');
        }
        ans |= flag;
    }

    if(ans){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
long long arr[100005],bas[65];
bool b[65];
int main()
{
	int n;
	scanf("%d",&n);
	for (int i=0;i<n;i++)
	{
		scanf("%lld",&arr[i]);
		for (int j=60;j>=0;j--)
		{
			if (arr[i]&(1LL<<j))
			b[j]^=1;
		}
	}
	long long ans=0;
	for (int i=0;i<=60;i++)
	{
		if (b[i])
		{
			ans+=(1LL<<i);
			for (int j=0;j<n;j++)
			{
				if (arr[j]&(1LL<<i))
				arr[j]^=(1LL<<i);
			}
		}
	}
	for (int i=0;i<n;i++)
	{
		for (int j=60;j>=0;j--)
		{
			if (arr[i]&(1LL<<j))
			arr[i]^=bas[j];
		}
		for (int j=60;j>=0;j--)
		{
			if (arr[i]&(1LL<<j))
			{
				bas[j]=arr[i];
				break;
			}
		}
	}
	long long mx=0;
	for (int i=60;i>=0;i--)
	{
		if (!(mx&(1LL<<i)))
		mx^=bas[i];
	}
	printf("%lld ",ans+2*mx);
}

Measured memory_bytes: 1024
n = gets.to_i
card_array = gets.split(' ')

def bubble_sort(card_array, n)
  cards = card_array.dup
  (0..(n - 1)).each do |sorted_i|
    ((sorted_i + 1)..(n - 1)).reverse_each do |i|
      value = cards[i]
      if value[1] < cards[i - 1][1]
        cards[i] = cards[i - 1]
        cards[i - 1] = value
      end
    end
  end
  cards
end

def selection_sort(card_array, n)
  cards = card_array.dup
  (0..(n - 1)).each do |sorted_i|
    min_i = sorted_i
    ((sorted_i)..(n - 1)).each do |i|
      if cards[i][1] < cards[min_i][1]
        min_i = i
      end
    end
    value = cards[sorted_i]
    cards[sorted_i] = cards[min_i]
    cards[min_i] = value
  end
  cards
end

def is_stable(stable_res, item)
  return true if stable_res == item
  false
end

b_sort_res = bubble_sort(card_array, n)
puts b_sort_res.join(' ')
puts 'Stable'
s_sort_res = selection_sort(card_array, n)
puts s_sort_res.join(' ')
puts is_stable(b_sort_res, s_sort_res) ? 'Stable' : 'Not stable'



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

int main(){
	ll h, w;
	cin >> h >> w;
    ll ans = 0;
    ll ans0 = (w+1)/2;
    ll ans1 = (h+1)/2;
    ans += ans0*ans1;
    ans0 = w/2;
    ans1 = h/2;
    ans += ans0*ans1;
    if(h == 1 || w == 1){
      cout << 1 << endl;
    }else{
      cout << ans << endl;
    }
    return 0;
}


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

using namespace std;
int main()
{

int a,b,flag=0;
int ans;
cin>>a>>b;
for (int i=0; i<=998244353; ++i)
{
  if(abs(a-i)==abs(b-i))
  {
    ans=i;
    flag=1;
    break;
  }
  
  
}

if(flag==1){
cout<<ans;  
}
else
{
  cout<<"IMPOSSIBLE";
}


}



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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define rep(idx, N) for (u64 idx = 0; idx < N; idx++)

int main() {
  u64 n, k;
  cin >> n >> k;

  vector<u64> a(n);
  u64 max = 0;
  rep(i, n) {
    cin >> a[i];
    if (a[i] > max)
      max = a[i];
  }

  u64 r = 0;
  u64 l = max;
  u64 cnt = 0;

  while (r + 1 != l && cnt < 100000000) {
    u64 m = (r + l) / 2;
    u64 ki = 0;
    rep(i, n) {
      if (a[i] > m) {
        ki += (a[i] - 1) / m;
      }
    }

    if (ki <= k) {
      l = m;
    } else {
      r = m;
    }
    // cout << "l:" << l << "\tr:" << r << endl;
    cnt++;
  }

  cout << r + 1;

  return 0;
}


Measured memory_bytes: 4832
def selectionSort(A, N): 
    m = 0
    for i in range(N):
        minj = i
        for j in range(i,N):
            if A[j] < A[minj]:
                minj = j
        A[i],A[minj] = A[minj],A[i]
        if i != minj:
            m += 1
    print ' '.join(map(str,A))
    print m

N = int(raw_input())
A = map(int,raw_input().split())
selectionSort(A,N)

Measured memory_bytes: 4224
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>


using namespace std;

// vector<vector<int>> mat(N, vector<int>(M, 0));

int main(int argc, const char *argv[])
{
    //ABC139 C

    int N;
    cin>>N;
    vector<int> vec(N,0);
    for (int i = 0; i < N; i++)
    {
        cin>>vec[i];
    }
    
    int count = 0;
    int max = 0;
    for (int i = 0; i < N-1; i++)
    {
        /* code */
        if(vec[i] >= vec[i+1])
        {
            count++;
        }
        else
        {   
        if(count >= max)
        {
            max = count;
        }
            count = 0;
        }
        
    }
        if(count >= max)
        {
            max = count;
        }  
    cout<<max;
}


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

using namespace std;

typedef long long ll;

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

int main() {
  int a[3][3];
  map <int, int> mp;
  for(int i = 0; i < 3; i++) {
    for(int j = 0; j < 3; j++) {
      cin >> a[i][j];
    }
  }
  int n; cin >> n;
  for(int i = 0; i < n; i++) {
    int x; cin >> x;
    mp[x] = 1;
  }
  for(int i = 0; i < 3; i++) {
    if(mp[a[i][0]] + mp[a[i][1]] + mp[a[i][2]] == 3) {
      puts("Yes");
      return 0;
    }
    if(mp[a[0][i]] + mp[a[1][i]] + mp[a[2][i]] == 3) {
      puts("Yes");
      return 0;
    }
  }
  if(mp[a[0][0]] + mp[a[1][1]] + mp[a[2][2]] == 3) {
    puts("Yes");
    return 0;
  }
  if(mp[a[0][1]] + mp[a[1][1]] + mp[a[2][0]] == 3) {
    puts("Yes");
    return 0;
  }
  puts("No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pr(a) cout << (a) << endl
#define PR(a,b) cout << (a) << " " << (b) << endl;
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000001;
const ll MAXL=1000000000000000001LL;
const ll mod=1000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main() {
  int n,m;
  while(cin >> n >> m && (n||m)) {
    m++;
    int dp[m][m],dp2[m][m];
    fill(dp[0],dp[m],MAX);
    fill(dp2[0],dp2[m],MAX);
    rep(i,m) {
      dp[i][i]=0;
      dp2[i][i]=0;
    }
    rep(i,n) {
      int x,y,a,b;
      cin >> x >> y >> a >> b;
      dp[x][y]=min(dp[x][y],a);
      dp[y][x]=min(dp[y][x],a);
      dp2[x][y]=min(dp2[x][y],b);
      dp2[y][x]=min(dp2[y][x],b);
    }
    rep(k,m) {
      rep(i,m) {
	rep(j,m) {
	  dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
	  dp2[i][j]=min(dp2[i][j],dp2[i][k]+dp2[k][j]);
	}
      }
    }
    int k;
    cin >> k;
    rep(i,k) {
      int x,y,z;
      cin >> x >> y >> z;
      if(z) pr(dp2[x][y]);
      else pr(dp[x][y]);
    }
  }
  return 0;
}


Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define ALL(v) v.begin(),v.end()
typedef long long ll;
int main() {
  int n; 
  string s;
  cin >> n >> s;
  int count=0;
  rep(i,n-1){
    if(s.at(i)!=s.at(i+1)){
      count++;
    }
  }
  cout << count+1 << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = pow(10, 9) + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divCeil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << endl; exit(0);}

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

  vector<ll> A = {0};
  for (ll i = 1; ; i++)
  {
    if (A.back() >= N)
      break;
    A.push_back(A.back() + i);
  }

  ll x = distance(A.begin(), lower_bound(A.begin(), A.end(), N));
  cout << x << " " << endl;
  ll y = x * (x + 1) / 2 - N;
  //cerr << y << endl;
  for (ll i = x - 1; i >= 1; i--)
  {
    if (i != y)
      cout << i << endl;
  }
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class CHonestOrUnkind2 {
public:
	void solve(istream& in, ostream& out) {
	    int x[20][20],y[20][20],a[20],ans = 0;
	    int n; in >> n;
	    for(int i = 0;i < n;i++){
	        in >> a[i];
	        for(int j = 0;j < a[i];j++){
	            in >> x[i][j] >> y[i][j];
	            x[i][j]--;
	        }
	    }

	    for(int tmp = 0;tmp < (1 << n);tmp++){
	        bool ok = true;
	        bitset<15> bit(tmp);
	        for(int i = 0;i < n;i++){
	            if(bit.test(i)){
	                for(int j = 0;j < a[i];j++){
	                    if(y[i][j]){
	                        if(bit.test(x[i][j])) continue;
	                        else ok = false;
	                    }else{
	                        if(bit.test(x[i][j])) ok = false;
	                        else continue;
	                    }
	                }
	            }
	        }
	        if(ok) ans = max(ans,__builtin_popcount(tmp));
	    }
        out << ans << endl;

	}
};

int main() {
	CHonestOrUnkind2 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

 string s;cin>>s;
 ll ans = 0;
 ll count = 0;
 REP(i,s.length()){
  if(s[i]=='B'){
    count++;
  }else{
    ans += count;
  }
 }
cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void){
    int H,W,i,j;
    scanf("%d %d",&H,&W);
    while(H || W){
        for(i = 0;i<H;i++){
            for(j = 0;j<W;j++){
                if((i + j) % 2 == 0){
                    printf("#");
                } else {
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
        scanf("%d %d",&H,&W);
    }
    return 0;
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i,s,e) for(int i=s;i<e;i++)
#define endl '\n'
int main(){
    int a,b;cin>>a>>b;
    if((a*b)%2==1)cout<<"Odd"<<endl;
    else cout<<"Even"<<endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

int main() {
  int X;
  std::cin >> X;
  std::cout << 1000 * (X / 500) + 5 * (X % 500 / 5) << '\n';
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//ルートの数　ループ回数になる
		int N = sc.nextInt();

    // 基準となる時間
    int firstT = sc.nextInt();

    int printCost = 1001;

    for(int i =0; i < N; i++){
      //コスト
  		int c = sc.nextInt();
      // そのルートの時間
      int t = sc.nextInt();
      if( firstT >= t ){
        if(printCost > c ){
          printCost = c;
        }
      }
    }
    if(printCost == 1001){
      System.out.println("TLE");
    }
    else {
  		System.out.println(printCost);
    }
	}
}

Measured memory_bytes: 23124
#include<stdio.h>
#include<ctype.h>
int main(void) {
	char c;
	int stack[100],flag=0,top = 0;

	while ((c=getchar()) != '\n') {
		if (c >= '0'&&c <= '9') {
			if (flag) {
				stack[top] = stack[top] * 10 + (c - '0');
			}else {
				stack[top] = (c - '0');
				flag++;
			}
		}
		if (c == ' ') {
			if (flag) {
				top++;
				flag = 0;
			}
		}
		if (c == '+') {
			if (top > 1) {
				top--;
			}
			stack[top - 1] += stack[top];
			stack[top] = 0;
		}
		if (c == '-') {
			if (top > 1) {
				top--;
			}
			stack[top - 1] -= stack[top];
			stack[top] = 0;
		}
		if (c == '*') {
			if (top > 1) {
				top--;
			}
			stack[top - 1] *= stack[top];
			stack[top] = 0;
		}
	}

	printf("%d\n", stack[0]);

	return 0;
}


Measured memory_bytes: 2108
#include <iostream>
using namespace std;
int main(){
    int a,b;
    cin >> a >>b;
    if (a>b){
        cout << "a > b" << endl;
    }
    if (a==b){
        cout << "a == b" << endl;
    }
    if (a<b){
        cout << "a < b" << endl;
    }
}

Measured memory_bytes: 1156
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int N, MA, MB;
	cin >> N >> MA >> MB;
	vector<int> a(N);
	vector<int> b(N);
	vector<int> c(N);
	for (auto i = 0; i < N; ++i)
	{
		cin >> a[i] >> b[i] >> c[i];
	}

	auto width = 10 * N * 10 * N + 1;
	vector<vector<ll>> dp(N + 1, vector<ll>(width, INT_MAX));
	dp[0][0] = 0;
	for (auto i = 0; i < N; ++i)
	{
		for (auto j = 0; j < width; ++j)
		{
			dp[i + 1][j] = dp[i][j];
			auto offset = a[i] * 10 * N + b[i];
			if (j >= offset)
			{
				dp[i + 1][j] = min(dp[i][j], dp[i][j - offset] + c[i]);
			}
		}
	}

	ll ans = INT_MAX;
	for (auto i = MA * 10 * N + MB; i < width; i += MA * 10 * N + MB)
	{
		ans = min(ans, dp[N][i]);
	}

	if (ans >= INT_MAX)
	{
		ans = -1;
	}
	cout << ans << endl;

	return 0;
}

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

using namespace std;

int main(){
   long long N;
   cin >> N;
   int A[N];
   for(int i = 0 ; i <N; i++) cin >> A[i];
   long long cnt[N+1];
   for(int i = 0; i< N+1; i++) cnt[i]=0;
   for(int i = 0 ; i <N ; i++) cnt[A[i]]+=1;
   long long baseAns = 0;
   for(int i = 0 ; i <= N ; i++){
      baseAns += cnt[i]*(cnt[i]-1)/2;
   }
   for(int i = 0 ; i < N ; i++){
      cout << baseAns-cnt[A[i]]+1 << endl;
   }
   return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
#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 PI 3.141592653589793
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){ 
    ll H,N;
    cin >> H >> N;
    vector<ll> A(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }

    ll sum =0;
    for(int i = 0; i < N; i++){
        sum += A[i];
    }
    if( sum>=H){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    

}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

var sc = bufio.NewScanner(os.Stdin)

func ri() int {
	sc.Scan()
	b := sc.Bytes()
	if b[0] == 45 {
		return -b2i(b[1:])
	} else {
		return b2i(b)
	}
}

func b2i(a []byte) (n int) {
	for _, v := range a {
		n = n*10 + int(v-48)
	}
	return
}

func main() {
	sc.Split(bufio.ScanWords)
	n, m := ri(), ri()
	cakes := make([][]int, n)
	for i := 0; i < n; i++ {
		cakes[i] = []int{ri(), ri(), ri()}
	}
	ans := 0
	for i := 0; i < 8; i++ {
		sli := make([]int, 0, n)
		for j := 0; j < n; j++ {
			temp := 0
			for k := 0; k < 3; k++ {
				if i&(1<<uint(k)) == 0 {
					temp += cakes[j][k]
				} else {
					temp -= cakes[j][k]
				}
			}
			sli = append(sli, temp)
		}
		sort.Sort(sort.Reverse(sort.IntSlice(sli)))
		sum := 0
		for i := 0; i < m; i++ {
			sum += sli[i]
		}
		if sum > ans {
			ans = sum
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+5,mod=998244353;
vector<int>v[N];
int n,a[N];
ll sum[N],f[N],inv[N];
int main()
{
    inv[1]=1;
    for(int i=2;i<=1000000;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
    int tot=0;
    for(int i=1;i<=1000000;i++)
        for(int j=i;j<=1000000;j+=i)
            v[j].push_back(i),tot++;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        for(int j=0;j<v[a[i]].size();j++)
            sum[v[a[i]][j]]=(sum[v[a[i]][j]]+a[i])%mod;
    }
    sort(a+1,a+1+n);
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<v[a[i]].size();j++)
        {
            int x=v[a[i]][j];
            sum[x]=(sum[x]-a[i])%mod,f[x]=sum[x];
        }
        for(int j=v[a[i]].size()-1;j>=0;j--)
        {
            int x=v[a[i]][j];
            ans=(ans+f[x]*a[i]%mod*inv[x])%mod;
            for(int k=0;k<v[x].size()-1;k++)
                f[v[x][k]]=(f[v[x][k]]-f[x])%mod;
        }
    }
    ans=(ans+mod)%mod;
    printf("%lld\n",ans);
}


Measured memory_bytes: 140032
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


void solve() {
  int a; string s; cin >> a >> s;
  if (a >= 3200) cout << s << endl;
  else cout << "red" << endl;
}


Measured memory_bytes: 3492
#include<iostream>
#include<stdio.h>
using namespace std;
int a[103];
int main(){
	int n,m,p,x;
	int sum=0;
	scanf("%d",&n);
	for(int i=0;i<n;++i){
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	scanf("%d",&m);
	for(int i=0;i<m;++i){
		scanf("%d %d",&p,&x);
		if(x<a[p-1])
			printf("%d\n",sum-(a[p-1]-x));
		else
			printf("%d\n",sum+(x-a[p-1]));
		}
	
	
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int l,m,n;
    int i,j;
    int sum;
    int tuki,flg;
    while(1){
        sum = tuki = 0;
        flg = 0;
        scanf("%d",&l);
        if(l == 0) break;
        for(i = 1; i <= 12; i++){
            scanf("%d%d",&n,&m);
            sum = sum + n - m;
            if(sum >= l){
                if(flg == 1) continue;
                tuki = i;
                flg = 1;
            }
        }
        if(tuki != 0) printf("%d\n",tuki);
        else printf("NA\n");

    }

    return 0;
}

Measured memory_bytes: 612
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;


int main(){
    ll n;
    cin>>n;
    vector<ll>h(n);
    rep(i,n)cin>>h[i];
    vector<ll>dp(n,0);
    dp[0]=0;dp[1]=abs(h[1]-h[0]);
    rep(i,n-2){
      dp[i+2]=min(dp[i+1]+abs(h[i+1]-h[i+2]),dp[i]+abs(h[i]-h[i+2]));
    }
    cout<<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <list>
#include <cmath>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define mp make_pair
#define pb push_back
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9+7;

int x[10], y[10];

double dist(int i, int j) {
	double dx = x[i] - x[j];
	double dy = y[i] - y[j];
	return pow(dx*dx + dy*dy, 0.5);
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> x[i] >> y[i];

	vector<int> v;
	int factorial = 1;
	for (int i = 1; i <= n; i++) {
		v.pb(i);
		factorial *= i;
	}

	double ans = 0;
	do {
		double d = 0;
		for (int i = 0; i < n-1; i++) {
			d += dist(v[i], v[i+1]);
		}
		d /= factorial;
		ans += d;
	} while (next_permutation(ALL(v)));

	printf("%8lf", ans);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
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;
}
int main(){
ll x;
cin >> x;
cout << (2199 - x) / 200 << endl;
}

Measured memory_bytes: 3628
n = int(input())

biggest = 0
biggest_i = 0
next_biggest = 0
for i in range(n):
    x = int(input())
    if x >= biggest:
        next_biggest = biggest
        biggest = x
        biggest_i = i
    elif x >= next_biggest:
        next_biggest = x

for i in range(n):
    if i == biggest_i:
        print(next_biggest)
    else:
        print(biggest)


Measured memory_bytes: 4540
#include <bits/stdc++.h>
using namespace std;
#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 ALL(v) v.begin(), v.end()
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
const int MOD = 1e9+7;



int main(){
 int h,w; cin>>h>>w;
 string s[h+2];
 s[0].append(w+2, '.');
 s[h+1].append(w+2, '.');
 
 FOR(i,1,h+1){
     cin>>s[i];
 s[i].push_back('.');
 s[i]='.'+s[i];
 }

 
 FOR(i,1,h+1){
     FOR(j,1,w+1){
         int count=0;
         if(s[i][j]!='#'){
         for(int l=i-1;l<=i+1;l++){
             for(int m=j-1;m<=j+1;m++)
             if(!(l==i&&m==j)&&s[l][m]=='#')count++;
         }
         cout<<count;
         }else cout<<'#';
     }
     cout<<endl;
 }
 
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))

Acum = [0]
for i in range(N):
  Acum.append(Acum[-1] + A[i])

B = []
for i in range(1, len(Acum)):
  for j in range(i):
    B.append(Acum[i] - Acum[j])
#print("B:", B)

tmp = []
for i in range(41, -1, -1):
  C = []
  for j in range(len(B)):
    if (B[j] >> i) & 1:
      C.append(B[j])
  lenC = len(C)
  if lenC >= K:
    B = C
    tmp.append(i)

answer = 0
for t in tmp:
  answer += 2 ** t
print(answer)

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

typedef long long intt;

int main()
{
        int n,k;
        cin>>n>>k;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        //cout << 0;
        vector<int> dp (n+k+10,1e9+7);
        dp[0]=0;
        //dp[1]=abs(a[0]-a[1]);
        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<=i+k && j<n ;j++)
            {
                dp[j]=min(dp[j],min(dp[i]+abs(a[i]-a[j]),dp[j-1]+abs(a[j-1]-a[j])));
            }

        }
        cout<<dp[n-1]<<" ";

	return 0;
}
/**
2
aaa
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
abab
1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
*/


Measured memory_bytes: 4036
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

const int limit = 8;
vector<vbool> graph(limit,vbool(limit,false));
vbool visited(limit,false);

int dfs(int v,int n);

int main(){
  int n,m;
  cin >> n >> m;
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--,b--;
    graph[a][b] = graph[b][a] = true;
  }
  cout << dfs(0,n) << endl;
}

int dfs(int v, int n){
  bool all_visited = true;
  ll ans = 0;
  visited[v] = true;
  //rep(i,limit) cout << visited[i];
  //cout << endl;
  //cout << "v" << v << endl;
  rep(i,n){
    if(!(visited[i])) all_visited = false;
  }
  if(all_visited){
    visited[v] = false;
    return 1;
  }
  rep(v2,n){
    //cout << v <<" "<< v2 << "  " << graph[v][v2] << endl; 
    if(graph[v][v2] == false) continue;
    if(visited[v2]) continue;
    ans += dfs(v2,n);
  }
  visited[v] = false;
  return ans;
}

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

int main(){
	string s;
	cin >> s;
	int count = 0;
	if (s[0] == 'o') count++;
	if (s[1] == 'o') count++;
	if (s[2] == 'o') count++;
	cout << 700 + 100 * count << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXIST2(s,e) (find(ALL(s),(e))!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);


int main(){
	vi a(10);
	REP(i,10){
		cin>>a[i];
	}
	sort(RALL(a));
	cout<<a[0]<<endl;
	cout<<a[1]<<endl;
	cout<<a[2]<<endl;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
#include <vector>
#include <iostream>
#include <cmath>
#include <math.h>

using namespace std;

int main(){
    double n;
    cin>>n;
    if (n==0)
    cout<<1<<endl;
    if (n==1)
    cout<<0<<endl;


}

Measured memory_bytes: 3768
// vim: shiftwidth=2 expandtab foldmethod=marker

// include {{{
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <utility>
#include <cstdlib>
// }}}

// debug(...) {{{
#ifdef LOCAL_DEBUG
#include "./debug.h"
#else
#define debug(...)
#endif
// }}}

// misc {{{
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

template<class T>
void sort(T& arr) {
  std::sort(arr.begin(), arr.end());
}
template<class T, class By>
void sort_by(T& arr, By by) {
  std::sort(arr.begin(), arr.end(), [by](auto l, auto r){return  by(l) < by(r); });
}

template<class T>
void reverse(T& arr) {
  std::reverse(arr.begin(), arr.end());
}

// }}}

// main {{{
void solve();
int main() {
  solve();
}
// }}}

void solve() {
  int N;
  cin >> N;
  vector<int> H(N);
  rep(i, N) {
    cin >> H[i];
  }

  int sum = 0;
  while(true) {
    int i = 0;
    while(i < N && H[i] == 0) i++;
    if(i == N) break;
    while(i < N && H[i] > 0) {
      H[i]--;
      i++;
    }
    sum++;
  }
  cout << sum << endl;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll H, W;
    cin >> H >> W;

    REP(i, H+2){
        if(i==0 || i==H+1){
            REP(j, W+2){
                cout << '#';
            }
            cout << endl;
            continue;
        }
        cout << '#';
        string s;
        cin >> s;
        cout << s;
        cout << '#' << endl;;
    }
    return 0;
}

Measured memory_bytes: 3624
def main():
  n,m=map(int,input().split())
  ab=[list(map(int,input().split())) for _ in range(n)]
  grp=[[]for _ in range(m+1)]
  for a,b in ab:
    if a>m:
      continue
    grp[a].append(b)
  for i,grpi in enumerate(grp):
    grpi.sort()
  import heapq
  maxs=[]
  heapq.heapify(maxs)
  ans=0
  for i in range(1,m+1):
    if len(grp[i])>0:
      heapq.heappush(maxs,[-grp[i].pop(),i])
    if len(maxs)>0:
      v,j=heapq.heappop(maxs)
      ans-=v
      if len(grp[j])>0:
        heapq.heappush(maxs,[-grp[j].pop(),j])

  print(ans)
if __name__=='__main__':
  main()

Measured memory_bytes: 35664
# include <bits/stdc++.h>
# define rep(i, n) for(ll i = 0; i < (n); ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define ll long long
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define P pair<int, int>
using namespace std;
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; }
ll lmax(ll a, ll b){if(a>= b) return a;return b;}
ll lmin(ll a, ll b){if(a>= b) return b;return a;}
static const ll INF = 1e18;

int main() {
  int h, w; cin >> h >> w;
  int k; cin >> k;
  vector<vector<char>> v(h, vector<char>(w));
  rep(i, h)rep(j, w) cin >> v[i][j];

  int ans = 0;
  rep(s, (1<<h)){
    rep(t, (1<<w)){
      int black = 0;
      rep(i, h){
        rep(j, w){
          if(!((s>>i)&1) && !((t>>j)&1)){
            if(v[i][j]=='#')++black;
          }
        }
      }

      if(black==k) ++ans;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3620
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a += b;
	if(a>MOD){
		a -= MOD;
	}
}

struct edge{
	int a;
	int b;
	ll w;
};

int c[100100],ufp[100100],ufr[100100],p[100100];
vector<edge> g;
bool used[100100];

void ufinit(int n){
	int i;
	for(i=0; i<n; ++i){
		ufp[i] = i;
		ufr[i] = 1;
	}
}

int ufind(int x){
	if(ufp[x] == x){
		return x;
	}else{
		ufp[x] = ufind(ufp[x]);
		return ufp[x];
	}
}

void unionf(int x, int y){
	x = ufind(x);
	y = ufind(y);
	if(x==y){
		return;
	}
	if(ufr[x]>ufr[y]){
		ufp[y] = x;
		ufr[x] += ufr[y];
	}else{
		ufp[x] = y;
		ufr[y] += ufr[x];
	}
}


bool comp(edge a, edge b){
	return a.w < b.w;
}

int main(void){
	int n,m,k,i;
	edge e;
	ll ans=0ll;
	fill(p,p+100100,-1);
	cin >> n >> m >> k;
	ufinit(n);
	for(i=0; i<n; ++i){
		cin >> c[i]; --c[i];
		if(c[i]<0){
			continue;
		}
		if(p[c[i]]<0){
			p[c[i]] = i;
		}else{
			unionf(p[c[i]],i);
		}
	}
	for(i=0; i<m; ++i){
		cin >> e.a >> e.b >> e.w;
		--e.a; --e.b;
		g.push_back(e);
	}
	sort(g.begin(),g.end(),comp);
	for(i=0; i<m; ++i){
		if(k==1){
			break;
		}
		e = g[i];
		if(ufind(e.a)==ufind(e.b)){
			continue;
		}
		unionf(e.a,e.b);
		ans += e.w;
		--k;
	}
	cout << ((k==1)?ans:(-1)) << endl;
	return 0;
}


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

int main() {
	string S; cin >> S;
	char small[26];
	for(int i=0; i<26; ++i) small[i]='a'+i;
	bool ans=true;
	int C=-1;
	for(int i=0; i<S.size(); ++i){
	    if(i==0){
	        if(S[i]!='A'){
	        ans=false;
	        break;
	        }
	    }
	    else if(S[i]=='C'){
	        if(C==-1) C=i;
	        else{
	            ans=false;
	            break;
	        }
	    }
	    else{
	        bool large=true;
	        for(int j=0; j<26; ++j){
	            if(small[j]==S[i]){
	                large=false;
	                break;
	            }
	        }
	        if(large){
	            ans=false;
	            break;
	        }
	    }
	}
	if(ans && abs(C)!=1 && C+1<S.size()) cout << "AC" << endl;
	else cout << "WA" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
ll N,A[5];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N;
	REP(i,5)cin>>A[i];
	ll mn=*min_element(A,A+5);
	cout<<5+(N-1)/mn<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
    
    public class Main{
    public static void main(String args[]){
    String sS;
    	Scanner scan = new Scanner(System.in);
    sS=scan.nextLine();
    int j=0;
    boolean first=true;
    
    char[] cS = sS.toCharArray();
    
    for(int i=0;i<sS.length();i++){
    	while(cS[i]=='B' && first==true){
    		i++;
    	}
    	first=false;
    		
    	if(cS[i]=='B' && cS[i-1]=='B' && cS[i-2]=='B' && cS[i-3]=='B' && i-7>=0)cS[i-7]='a';
    	if(cS[i]=='B' && cS[i-1]=='B' && cS[i-2]=='B' && i-5>=0)cS[i-5]='a';
    	if(cS[i]=='B' && i!=0 && cS[i-1]!='B')cS[i-1]='a';
    	if(cS[i]=='B' && cS[i-1]=='B' && i-3>=0)cS[i-3]='a';
    }
    for(int i=0;i<sS.length();i++){
    	if(cS[i]!='a' && cS[i]!='B')System.out.print(cS[i]);
    }
    }
}

Measured memory_bytes: 9556
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;

int main()
{
	int n,m;
	cin >> n >> m;
	cout<<(n+m)%24<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define inf 10000000
#define mod 30000000
#define omarshagar                    \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
using namespace std;
ll ncr(int n,int r)
{
    ll res=1;
    int v=1;
    for(int i=n;i>n-2;i--)
    {
        res*=i;
    }
    return res/2;
}
int main()
{
   int n,m;
   cin>>n>>m;
   cout<<ncr(n,2)+ncr(m,2)<<endl;
    return 0;
}
/*












 */

Measured memory_bytes: 256
A=list(map(int,input().split()))
print(A[1]+(A[0]//2+A[3]//2+A[4]//2)*2 if 0 in (A[0],A[3],A[4]) or A[0]%2+A[3]%2+A[4]%2<2 else A[1]+((A[0]-1)//2+(A[3]-1)//2+(A[4]-1)//2)*2+3)

Measured memory_bytes: 9148
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  ll a,b,ans;
  char op;
  cin >> a >> op >> b;
  if(op=='+') ans = a+b;
  else ans = a-b;
  cout << ans << endl;
}


Measured memory_bytes: 256