akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

using ll = long long;
using P = pair<int, int>;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

const double PI = acos(-1.0);

int main() {
    int n, m;
    cin >> n >> m;
    ll sum = 0;
    rep(i, m) {
        ll a;
        cin >> a;
        sum += a;
    }
    cout << max<ll>(-1, n - sum) << endl;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int M = sc.nextInt();
    sc.nextLine();

    int[] list = new int[M];

    for(int i = 0; i < M; i++) {
      list[i] = sc.nextInt();
    }

    for(int i : list) {
      N -= i;
    }

    if(N <= -1) {
      N = -1;
    }

    System.out.println(N);
    sc.close();
  }
}

Measured memory_bytes: 46252
#include<bits/stdc++.h>
using namespace std;
int a[10005];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int n,cnt=0;
	cin >> n;
	for(int i=1;i<=150;i++){
		for(int j=1;j<=150;j++){
			for(int k=1;k<=150;k++){
				int x = (i+j)*(i+j)+(k+j)*(k+j)+(i+k)*(i+k);
				if(!(x&1)&&x/2<=10000) a[x/2]++;
			}
		}
	}
	for(int i=1;i<=n;i++){
		printf("%d\n",a[i]);
	}
	return 0;
} 

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

int main(void){
	int n, m;
	int tmp;
	int sum_tarou, sum_hanako;
	bool frag;

	while(1){
		cin >> n >> m;
		if(n == 0 && m == 0){
			break;
		}

		int t_change = 101, h_change = 101;
		frag = true;
		vector<int> tarou;
		vector<int> hanako;

		for(int i = 0; i < n; i++){
			cin >> tmp;
			tarou.push_back(tmp);
		}
		for(int i = 0; i < m; i++){
			cin >> tmp;
			hanako.push_back(tmp);
		}
		sum_tarou = accumulate(tarou.begin(), tarou.end(), 0);
		sum_hanako = accumulate(hanako.begin(), hanako.end(), 0);

		int diff = sum_tarou - sum_hanako;
		if(diff % 2 != 0){
			cout << "-1" <<endl;
			continue;
		}

		for(auto itr = tarou.begin(); itr != tarou.end(); ++itr){
			vector<int>::iterator citer = find(hanako.begin(), hanako.end(), *itr - diff/2);
			if(citer != hanako.end()){
				frag = false;
				if(*itr + *citer < t_change + h_change){
					t_change = *itr;
					h_change = *citer;
				}
			}
		}
		if(frag){
			cout << "-1" << endl;
		}else{
			cout << t_change << " " << h_change << endl;
		}
	}
	return 0;
}

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

sub=[1,6,9,36,81,216,729,1296,6561,7776,46656,59049]
cost=[0]*(n+1)
for i in range(n+1):
    cost[i]=i
for i in range(n+1):
    for j in range(len(sub)):
        if sub[j]<=i:
            cost[i]=min(cost[i], cost[i-sub[j]]+1)
        else:
            break
print(cost[n])


Measured memory_bytes: 12480
#include<bits/stdc++.h>
using namespace std;
int weight[100+5];
long long int value[100+5];
long long int dp[100000+5]; 


int main(int argc, char const *argv[])
{
	int N, W;
	while(cin >> N >> W) {
		memset(weight, 0, sizeof(weight));
		memset(value, 0, sizeof(value));
		memset(dp, 0, sizeof(dp));
		for(int i=1; i<=N; i++){
			cin >> weight[i] >> value[i];
		}
		for(int i=1; i<=N; i++) {
			for(int j=W; j>=weight[i]; j--){
				dp[j] = max(dp[j], dp[j - weight[i]] + value[i]);
			}
		}
		cout << dp[W] << endl;
	}
	return 0;
}

Measured memory_bytes: 4372
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main(){
        int N;
        map<int,int> counter;
        vector<int> save;
        map<int,bool> dp;
        cin >> N;
        for(int i=0 ; i<N ; i++ ){
                int x;
                cin >> x;
                counter[x]++;
                save.push_back(x);
        }
        vector<int>::iterator itr;
        int count=0;
        for(itr=save.begin() ; itr!=save.end() ; ++itr ){
                if(dp[*itr])continue;
                if(*itr>counter[*itr])
                        count+=counter[*itr];
                else if(*itr<counter[*itr])
                        count+=(counter[*itr]-*itr);
                dp[*itr]=true;
        }
        cout << count << endl;
}

Measured memory_bytes: 9592
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define ull       unsigned long long
#define si(x)     scanf("%d", &x)
#define sll(x)    scanf("%lld", &x)
#define sd(x)     scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100000
#define maxn 	  200002
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000
#define MOD		  1000000007
#define vi(a)	  vector<ll>a
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


int main ()
{
		ios::sync_with_stdio(0);
		cin.tie(0);
		//CODE TONOY
        ll n;
        sll(n);
        map<ll,ll>  m;
        for (int i=0 ; i<n ; i++)
        {
			ll x;
			sll(x);
			m[x]++;
			//cerr << imie(m[x]);
		}
		ll ans = 0;
		/*for (int i=0 ; i<(int)m.size() ; i++)
		//cout << m[i] << " ";
		{
			if(m[i]==0) continue;
			if(m[i]>i)
			ans+=abs(m[i]-i);
			else if (m[i]<i)
			ans+=m[i];
			else
			ans+=0;
			//cerr << imie(m[i]) << imie(i) << imie(ans);
			//cerr << endl;
		}
		cout << ans << endl;*/
		for (auto i : m)
		{
			if(i.second > i.first)
			{
				ans+=(i.second - i.first);
			}
			else if (i.second < i.first)
			{
				ans+=i.second;
			}
		}
		cout << ans << endl;
		return 0;
}


Measured memory_bytes: 9584
#include<iostream>
#include<list>
#include<queue>
using namespace std;
int n,k,v[100];
long long memm[101][3][100][100];
void chmax(long long & a,const long long & b){if(a<b)a=b;}  
long long req(int n, list<int> l, int u, int rm, int lm){
  if(memm[n][u][rm][lm] != -(1.0e+9))return memm[n][u][rm][lm];
  if(u == 1){
    l.pop_back();    
  }
  if(u == 2){
    l.pop_front();
  }
  if(n == 0 || l.empty())return 0;
  long long ret=0;
  if(n >= 2){
    chmax(ret, req(n - 2, l, 2,rm,lm-1));
    chmax(ret, req(n - 2, l, 1,rm-1,lm));
  }
  chmax(ret, req(n - 1, l, 2,rm,lm-1) + l.front());
  chmax(ret, req(n - 1, l, 1,rm-1,lm) + l.back());
  memm[n][u][rm][lm] = ret;
  return ret;
}


int main(){
  cin>>n>>k;
  list<int> l;
  for(int i = 0; i < n; ++i){
    cin>>v[i];
    l.push_back(v[i]);
  }
  for(int i = 0; i < 101; ++i){
    for(int j = 0; j < 3; ++j){
      for(int k = 0; k < 100; ++k){
	for(int l = 0; l < 100; ++l){
	  memm[i][j][k][l] = -(1.0e+9);
	}
      }
    }
  }

  cout << req(k,l,0,0,0) << endl;
  return 0;
}


Measured memory_bytes: 23936
#include <stdio.h>

#define Mod 1000000007

int main()
{
	char S[100001];
	scanf("%s", S);
	
	int i, j, k, l, tmp;
	long long dp[2][13] = {};
	for (l = 0; S[l] != 0; l++);
	for (i = l - 1, tmp = 1, dp[1-i%2][0] = 1; i >= 0; i--, tmp = tmp * 10 % 13) {
		if (S[i] != '?') {
			k = S[i] - '0';
			for (j = 0; j < 13; j++) dp[i%2][(j+tmp*k)%13] = dp[1-i%2][j];
		} else {
			for (j = 0; j < 13; j++) dp[i%2][j] = 0;
			for (j = 0; j < 13; j++) {
				for (k = 0; k <= 9; k++) dp[i%2][(j+tmp*k)%13] += dp[1-i%2][j];
			}
			for (j = 0; j < 13; j++) dp[i%2][j] %= Mod;
		}
	}
	
	printf("%lld\n", dp[0][5]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1776
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}


int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

      bool flag=false;

      string str;
    cin>>str;


    n=str.size();

    a=0;
    b=1;
    for(i=0; i<n; i++)
    {
        if( (str[i]-'0')!=a)ans++;

        if( (str[i]-'0')!=b)sum++;

        if(a==0)a=1;

        else a=0;

        if(b)b=0;
        else b=1;
    }

    cout<<min(ans,sum)<<endl;

}



Measured memory_bytes: 3776
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a: i16 = read();
    let s: String = read();
    if a < 3200 {
        println!("red");
    } else {
        println!("{}", s);
    }
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   
    double n,x,y;
    cin>>n;
    x = 1.0 * ceil(n/1.08);
    y = 1.0 * floor(n/1.08);
    if(int(1.08 * x) == int(n))
        {
            cout<<x;
            return 0;
        }

        if(int(1.08 * y) == int(n))
        {
            cout<<y;
            return 0;
        }

        cout<<":(";
}

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

int main() {
  int A , B , C , D;
  cin >> A >> B >> C >> D;

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



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int keta(long long q){
	long long s=1;
	int ret=0;
	while(q>=s)ret++,s*=10;
	return ret;
}
int main(){
	long long n;
	int ans=810;
	cin>>n;
	for(long long i=1;i*i<=n;i++){
		if(n%i==0){
			ans=min(ans,keta(n/i));
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
alp_list = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
s = input()
ans = ""
for i in s:
    ind = alp_list.index(i)
    upd_ind = ind + n
    if upd_ind >= 26 and n != 0:
        upd_ind -= 26
    ans += alp_list[upd_ind]

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

//-------------------------------------

string alp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

char transform(char c, int back)
{
    int index = 0;
    for (int i = 0; i < (int)alp.size(); i++)
    {
        if (c == alp[i])
        {
            index = i;
        }
    }
    int ans_index = index - back;
    if (ans_index < 0)
    {
        ans_index += (int)alp.size();
    }
    return alp[ans_index];
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (true)
    {
        int n;
        cin >> n;
        if(n == 0){
            return 0;
        }
        vector<int> key(n);
        string s;
        for (int i = 0; i < n; i++)
        {
            cin >> key[i];
        }
        cin >> s;

        for (int i = 0; i < (int)s.size(); i++)
        {
            int back = key[i % n]; // 戻すべき文字数
            s[i] = transform(s[i], back);
        }
        cout << s << endl;
    }
}


Measured memory_bytes: 3240
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

#define MAXN 40
long long n, a, b, i, j, k, ans, MOD = 1000000007, aa, bb, x, ca, cb;
vector<long long> p(MAXN);

long long mul_inv(long long a, long long b)
{
	long long b0 = b, t, q;
	long long x0 = 0, x1 = 1;
	if (b == 1) return 1;
	while (a > 1) {
		q = a / b;
		t = b, b = a % b, a = t;
		t = x0, x0 = x1 - q * x0, x1 = t;
	}
	if (x1 < 0) x1 += b0;
	return x1;
}

long long division(long long a, long long b, long long p) {		// (a / b) mod p = ((a mod p) * (b^(-1) mod p)) mod p
	long long ans, inv;
	inv = mul_inv(b, p);
	ans = ((a % p) * inv) % p;
	return ans;
}

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

	p[0] = 2;
	for (i = 1; i < MAXN; i++) p[i] = (p[i - 1] * p[i - 1]) % MOD;

	cin >> n >> a >> b;

	// calculate 2^n - 1
	ans = 1;
	for (i = 0; i < MAXN; i++) {
		x = 1LL << i;
		if (x & n) ans = (ans * p[i]) % MOD;
	}
	ans = (ans + MOD - 1) % MOD;

	// calculate C(N, a) and C(N, b)
	aa = 1; ca = 1;
	for (i = 1; i <= a; i++) {
		ca = (ca * i) % MOD;
		aa = (aa * (n + 1 - i)) % MOD;
	}
	aa = division(aa, ca, MOD);
	
	bb = 1; cb = 1;
	for (i = 1; i <= b; i++) {
		cb = (cb * i) % MOD;
		bb = (bb * (n + 1 - i)) % MOD;
	}
	bb = division(bb, cb, MOD);

	ans = (ans + MOD + MOD - aa - bb) % MOD;

	cout << ans << "\n";



	return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll find(ll s){
	ll l=0,r=1000000000LL;
	while(l+1LL<r){
		ll mid=(l+r)/2LL;
		if(mid*mid>=s){
			r=mid;
		}else{
			l=mid;
		}
	}
	return r;
}

int main(void){
	ll s;
	scanf("%lld",&s);
	ll pos=find(s);
	ll pos2=pos;
	while(pos*(pos2-1LL)>=s){
		pos2--;
	}
	ll dif=pos*pos2-s;
	ll ed=1;
	if(dif==0LL)ed=0;
	printf("%lld %lld %lld %lld %lld %lld\n",0LL,0LL,pos,ed,dif,pos2);	
	return 0;
}


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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) Sort(x);reverse(ALL(x))

template<typename V,typename T>
T find_num(V v, T num) {
    if ( find(ALL(v), num) == v.end() ) {
        return false;
    } else {
        return true;
    }
}

// π M_PI
// deg = rad*180/M_PI

int main() {
    ll n;
    cin >> n;
    ll ans = 0;
    ll num = 100;
    while ( num < n ) {
        num *= 1.01;
        // cout << "a " << num << endl;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
#define int long long
const int N = 100;
string mp[N];
signed main(){
	int h,w,k;
	cin>>h>>w>>k;
	int ans=0;
	for(int i=0;i<h;i++)
		cin>>mp[i];
	for(int i=0;i<(1<<h);i++){
		for(int j=0;j<(1<<w);j++){
			int sum=0;
			for(int a=0;a<h;a++){
				for(int b=0;b<w;b++){
					if(i&(1<<a)||j&(1<<b)) continue;
					if(mp[a][b]=='#') sum++;

				}
			}
			if(sum==k) ans++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3604
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <list>
#include <string>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;

int main()
{
    int P, Q, R;
    cin >> P >> Q >> R;

    vector<int> sum;
    sum.push_back(P + Q);
    sum.push_back(Q + R);
    sum.push_back(P + R);
    sum.push_back(Q + R);
    sum.push_back(R + P);
    sum.push_back(Q + P);

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

    cout << sum[0] << endl;
}

struct data_t
{
    int i;
    string s;
    int p;

    // 最後のconstを忘れると"instantiated from here"というエラーが出てコンパイルできないので注意
    bool operator<(const data_t &right) const
    {
        return s != right.s ? s < right.s : p > right.p;
    }
};

void cheatsheet()
{
    /*data_t sp[N];
    REP(i, N)
    {
        string s;
        int p;
        cin >> s >> p;
        sp[i].i = i + 1;
        sp[i].s = s;
        sp[i].p = p;
    }

    sort(sp, sp + N);
*/
    // loop
    // vector<int> vec(10);
    vector<int> vecloop;
    REP(i, 10)
    {
        vecloop.push_back(i);
    }

    // swap
    int a = 1;
    int b = 5;
    swap(a, b); // -> a = 5, b = 1

    // sort
    int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    sort(arr, arr + 9, greater<int>()); // 9 8 7 6 5 4 3 2 1

    // lower
    vector<int> vec(arr, end(arr));
    sort(vec.begin(), vec.end());
    cout << lower_bound(vec.begin(), vec.end(), 2)[0]; // 2

    // map
    map<Pll, ll> m;
    m[Pll(10, 100)] = 100;
}


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

int powi(int a,int n){
    int b = 1;

    for(int i=0; i<n; i++){
        b *= a;
    }

    return b;
}


int main(){
    int a,n,m; 
    cin >> a >> n >> m;
    int sum(0); 

    for(int i=a+1; powi(i,n)<m; i++){
        int x = powi(i,n);
        int y = i-a;

        int z = 0;
        while(x>0){
            z +=(x%10);
            x/=10;
        }

        if(y==z){
            sum++;
        }
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3108
#include<iostream>
using namespace std;
int main()
{
  int k,n,i;
  cin>>n>>k;
  char a[n];
  cin>>a;
  for(i=0;i<n;i++)
  {
    if(k==(i+1))
      a[i]=a[i]+32;
  }
  for(i=0;i<n;i++)
    cout<<a[i];
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        
        // 上下左右
        int[] dx = new int[]{1, 0, -1, 0, 1, -1, 1, -1};
        int[] dy = new int[]{0, 1, 0, -1, 1, -1, -1, 1};
        
        char[][] board = new char[h][w];
        for (int i = 0; i < h; i++) {
            String str = sc.next();
            for (int j = 0; j < w; j++) {
                board[i][j] = str.charAt(j);
            }
        }
        
        int[][] ans = new int[h][w];
        // スタート地点の全探索(BFS)
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (board[i][j] == '#') {
                    ans[i][j] = -1;
                    continue;
                }
                
                // 移動可能なら現在地までの距離+1を代入
                for (int k = 0; k < 8; k++) {
                    int nx = i + dx[k];
                    int ny = j + dy[k];
                    
                    if (0 <= nx && nx < h && 0 <= ny && ny < w &&
                        board[nx][ny] == '#') {
                        ans[i][j]++;
                    }
                }
                
            }
        }
        
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (ans[i][j] == -1) {
                    System.out.print("#");
                } else {
                    System.out.print(ans[i][j]);
                }
                
                if (j == w - 1) {
                    System.out.println();
                }
            }
        }
    }
}

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

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

Measured memory_bytes: 3600
N = int(input())
xzero = 3
yzero = 5
y = N+1

biggest = 8*(int(N/4)+1)*(int(N/4)+1)+4
a = [[0 for i in range(N+4)] for j in range(N+4)]
fours = [4*i for i in range((int(N/4)+1))]
odds = [2*i for i in range(int((N+1)/2))]
evens = [2*i+1 for i in range(int(N/2))]

if N==2:
    print("4 7")
    print("23 10")
else:
    x = xzero
    for i in fours:
        for j in fours:
            a[i][j] = x
            a[i+1][j+1] = 2*x
            a[i][j+2]=biggest-x
            a[i+1][j+3] = 2*(biggest-x)
            a[i+2][j] = biggest-x-(int(N/4)+1)*2
            a[i+3][j+1] = 2*(biggest-x-(int(N/4)+1)*2)
            a[i+2][j+2] = x+(int(N/4)+1)*2
            a[i+3][j+3] = 2*(x+(int(N/4)+1)*2)
            x += 2
        x+=(int(N/4)+1)*2

    for i in odds:
        for j in evens:
            ans = 1
            ans *= a[i][j - 1]
            ans *= a[i][j + 1]
            if i > 0:
                ans *= a[i - 1][j]
            else:
                ans *= 2
            ans += 1
            a[i][j] = ans

    for i in evens:
        for j in odds:
            ans = 1
            ans *= a[i - 1][j]
            ans *= a[i + 1][j]
            if j > 0:
                ans *= a[i][j - 1]
            else:
                ans *= 2
            ans += 1
            a[i][j] = ans
    a = [i[0:N] for i in a[0:N]]

    for i in range(N):
        print(" ".join(str(j) for j in a[i]))

Measured memory_bytes: 18836
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int size = sc.nextInt();
			int[] array = new int[size];
			for (int i = 0; i < size; i++) {
				array[i] = sc.nextInt();
			}
			Arrays.sort(array);
			BigDecimal ans = BigDecimal.ZERO;
			for (int i = 1; i <= size; i++) {
				BigDecimal div;
				if (i == size) {
					div = new BigDecimal(Math.pow(2, i - 1));
				} else {
					div = new BigDecimal(Math.pow(2, i));
				}
				ans = ans.add(new BigDecimal(array[size - i]).divide(div).setScale(10, BigDecimal.ROUND_HALF_UP));
			}
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) \
  SORT(var);       \
  REVERSE(var)
#define OPTIMIZE_STDIO         \
  ios::sync_with_stdio(false); \
  cin.tie(0);                  \
  cout.precision(10);          \
  cout << fixed
#define endl '\n'

const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
struct mint {
  ll x;
  mint() : x(0) {
  }
  mint(ll x) : x((x % MOD + MOD) % MOD) {
  }
  mint& operator+=(const mint& r) {
    if ((x += r.x) >= MOD) {
      x -= MOD;
    }
    return *this;
  }
  mint& operator-=(const mint& r) {
    if ((x -= r.x) < 0) {
      x += MOD;
    }
    return *this;
  }
  mint& operator*=(const mint& r) {
    if ((x *= r.x) > MOD) {
      x %= MOD;
    }
    return *this;
  }
  mint& operator++() {
    if ((++x) >= MOD) {
      x -= MOD;
    }
    return *this;
  }
  mint operator++(int) {
    mint ret = x;
    if ((++x) >= MOD) {
      x -= MOD;
    }
    return ret;
  }
  mint& operator--() {
    if ((--x) < 0) {
      x += MOD;
    }
    return *this;
  }
  mint operator--(int) {
    mint ret = x;
    if ((--x) < 0) {
      x += MOD;
    }
    return ret;
  }
  mint operator+(const mint& r) {
    mint ret;
    return ret = x + r.x;
  }
  mint operator-(const mint& r) {
    mint ret;
    return ret = x - r.x;
  }
  mint operator*(const mint& r) {
    mint ret;
    return ret = x * r.x;
  }
  mint operator-() {
    return mint() - *this;
  }
  bool operator<(const mint& a) {
    return x < a.x;
  }
  bool operator>(const mint& a) {
    return x > a.x;
  }
  bool operator<=(const mint& a) {
    return x <= a.x;
  }
  bool operator>=(const mint& a) {
    return x >= a.x;
  }
  bool operator==(const mint& a) {
    return x == a.x;
  }
  bool operator!=(const mint& a) {
    return x != a.x;
  }
};
ostream& operator<<(ostream& os, const mint& r) {
  os << r.x;
  return os;
}
ostream& operator>>(ostream& os, const mint& r) {
  os >> r.x;
  return os;
}

void solve(istream& cin, ostream& cout) {
  int n;
  string s, t;
  cin >> n;
  cin >> s >> t;
  string ans = "";
  REP(i, n) {
    ans += s[i];
    ans += t[i];
  }
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
typedef long long ll;
using namespace std;

const ll MAXN = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll X, Y, ans=0, tmp=0;
vector<ll> A;

signed main(){
    cin >> X >> Y;
    if(abs(X-Y)>=2) cout << "Alice" << endl;
    else cout << "Brown" << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
using namespace std;
int main()
{
    char s[3];
    int add=0;
    cin>>s;

    for(int i=0; i<3; i++)
    {
        if(s[i]=='7')
            add++;
    }
    if(add==0)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
    return 0;
}


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

class E
{
	static void Main()
	{
		Func<int[]> read = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
		var h = read();
		int n = h[0];
		var rs = new int[h[1]].Select(_ => read()).ToArray();
		var qs = new int[int.Parse(Console.ReadLine())].Select(_ => read()).ToArray();

		var d = new long[n + 1, n + 1];
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
				d[i, j] = long.MaxValue;
		for (int i = 1; i <= n; i++)
			d[i, i] = 0;
		foreach (var r in rs)
		{
			d[r[0], r[1]] = r[2];
			d[r[1], r[0]] = r[2];
		}

		for (int k = 1; k <= n; k++)
			for (int i = 1; i <= n; i++)
				for (int j = 1; j <= n; j++)
					if (d[i, k] < long.MaxValue && d[k, j] < long.MaxValue)
						d[i, j] = Math.Min(d[i, j], d[i, k] + d[k, j]);

		var map = new int[n + 1].Select(_ => new List<int>()).ToArray();
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
				if (d[i, j] != 0 && d[i, j] <= h[2]) map[i].Add(j);

		var g = new int[n + 1, n + 1];
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
				g[i, j] = -1;
		var q = new Queue<int>();
		for (int i = 1; i <= n; i++)
		{
			g[i, i] = 0;
			q.Enqueue(i);

			while (q.Any())
			{
				var p = q.Dequeue();
				foreach (var np in map[p])
				{
					if (g[i, np] >= 0) continue;
					g[i, np] = g[i, p] + 1;
					q.Enqueue(np);
				}
			}
		}
		Console.WriteLine(string.Join("\n", qs.Select(x => g[x[0], x[1]]).Select(x => x > 0 ? x - 1 : x)));
	}
}


Measured memory_bytes: 30636
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll,ll>;
vector<pair<ll, ll>> factrize(ll n)
{
    vector<pair<ll, ll>> res;
    for (ll i = 2; i <= sqrtl(n); i++)
    {
        ll k = i;
        ll cnt = 0;
        while (n % k == 0)
        {
            n /= k;
            cnt++;
        }
        res.emplace_back(k, cnt);
    }
    if (n != 1)
    {
        res.emplace_back(n, 1);
    }
    return res;
}
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n;
cin >> n;
map<ll,ll> mp;
for(int i = 2; i <= n; i++){
    int k = i;
    vector<P> res = factrize(i);
    for(auto v : res){
        mp[v.first] += v.second;
    }
}
ll ans = 1;
for(auto v : mp){
    ans = (ans * (v.second + 1)) % ll(1e9 + 7);
}
cout << ans << endl;
}

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

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

    int a,b,c;cin>>a>>b>>c;
    cout<<min(b/a,c)<<endl;
    
}

Measured memory_bytes: 3584
while True:
    n, r = map(int, raw_input().split())
    if n == 0 and r == 0:
        break

    l = range(n, 0, -1)

    for i in range(r):
        tmp = []
        p, c = map(int, raw_input().split())
        for j in range(c):
            tmp.append(l.pop(p - 1))
        l = tmp + l
    print l[0]

Measured memory_bytes: 6348
#include <iostream>
using namespace std;
#define brk system("pause");

const int N = 1e5 + 1;
int dp[N][4], a[N][4];
main()
{
	int n; cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i][1] >> a[i][2] >> a[i][3];
	
	dp[1][1] = a[1][1];
	dp[1][2] = a[1][2];
	dp[1][3] = a[1][3];
	
	for(int i = 2; i <= n; i++)
	{
		dp[i][1] = max(dp[i - 1][2], dp[i - 1][3]) + a[i][1];
		dp[i][2] = max(dp[i - 1][1], dp[i - 1][3]) + a[i][2];
		dp[i][3] = max(dp[i - 1][2], dp[i - 1][1]) + a[i][3];
	}
	
	cout << max(dp[n][1], max(dp[n][2], dp[n][3])) << endl;
}


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

int main(){
  int N;
  cin >> N;
  int A;
  A = N;
  int S;
  S = 0;
  while(N != 0){
    S += N % 10;
    N = N / 10;
  }
  
  if(A % S == 0){
    cout << "Yes" << endl;
  } 
  else{
    cout << "No"  << endl;
  }
}

Measured memory_bytes: 256
#include <cstring>
#include <algorithm>
#include <cstdio>

using std::max_element;
const int N = 100010;
const int M = 30;
int _w;

namespace Tree {
	int head[N], nxt[N*2], to[N*2], eid;
	void init() {
		eid = 0;
		memset(head, -1, sizeof head);
	}
	void link( int u, int v ) {
		to[eid] = v, nxt[eid] = head[u], head[u] = eid++;
		to[eid] = u, nxt[eid] = head[v], head[v] = eid++;
	}
}

int n, f[N][M], g[N];

void dfs( int u, int fa ) {
	using namespace Tree;
	for( int i = head[u]; ~i; i = nxt[i] ) {
		int v = to[i];
		if( v == fa ) continue;
		dfs(v, u);
		for( int j = 0; j < M; ++j )
			f[u][j] += f[v][j];
	}
	int i;
	for( i = M-1; i; --i )
		if( f[u][i] >= 2 )
			break;
	while( f[u][i] ) ++i;
	g[u] = i, f[u][i] = 1;
	for( int j = 0; j < i; ++j )
		f[u][j] = 0;
}

int main() {
	_w = scanf( "%d", &n );
	Tree::init();
	for( int i = 1; i < n; ++i ) {
		int u, v;
		_w = scanf( "%d%d", &u, &v );
		Tree::link(u, v);
	}
	dfs(1, 0);
	printf( "%d\n", *max_element(g+1, g+n+1) );
	return 0;
}


Measured memory_bytes: 19968
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
  int N;
  cin >> N;
  float temp, sum;
  sum = 0;
  for (int i = 0; i < N; i++){
    cin >> temp;
    sum += 1 / temp;
  }
  cout << 1 / sum;
 return 0; 
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
using namespace std;
#define mod 1000000007
typedef long long ll;
int n,X,Y,Z;
ll f[45][(1<<17)+50];
inline void upd(ll &x,ll y) {
	x=x+y; if(x>=mod) x-=mod;
}
int main() {
	scanf("%d%d%d%d",&n,&X,&Y,&Z);
	int mask=(1<<(X+Y+Z))-1,tt=(1<<(X+Y+Z-1))|(1<<(Y+Z-1))|(1<<(Z-1));
	f[0][0]=1;
	int i,s,j;
	ll ans=1;
	for(i=1;i<=n;i++) ans=ans*10%mod;
	for(i=0;i<n;i++) {
		for(s=0;s<=mask;s++) if(f[i][s]) {
			for(j=1;j<=10;j++) {
				int now=((s<<j)|(1<<(j-1)))&mask;
				if((now&tt)==tt) continue;
				upd(f[i+1][now],f[i][s]);
			}
		}
	}
	for(s=0;s<=mask;s++) upd(ans,mod-f[n][s]);
	printf("%lld\n",ans);
}


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

signed main() {
  int k;
  cin >> k;
  string s = "ACL";
  rep(i,k) {
    cout << s;
  }
  cout << endl;
}




Measured memory_bytes: 3536
#include<bits/stdc++.h>
#define inf 0x7fffffff;
using namespace std;
int l,r,a[2021],ans=inf;
int main()
{
    scanf("%d%d",&l,&r);
    for(int i=l;i<=min(l+2018,r);i++)a[i%2019]=1;
    for(int i=0;i<2018;i++)
        if(a[i])for(int j=i+1;j<=2018;j++)
            if(a[j])ans=min(ans,i*j%2019);
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256
N = int(input())
balls = []
for i in range(N):
    x, y = map(int, input().split(' '))
    balls.append((x, y))

if N == 1:
    print("1")
    exit()
#(p,q)に対応するグラフの辺の数
dic = {}

#すべての点について検討
for i in range(N):
    for j in range(i+1,N):
        #dx,dy == p,qの候補
        dx = balls[j][0] - balls[i][0]
        dy = balls[j][1] - balls[i][1]

        if (dx,dy) not in dic:
            dic[(dx,dy)] = 1
        else:
            dic[(dx,dy)] += 1
        
        dx *= -1
        dy *= -1
        if (dx,dy) not in dic:
            dic[(dx,dy)] = 1
        else:
            dic[(dx,dy)] +=1 
d_max = max(dic.values())
print(N-d_max)        


        



Measured memory_bytes: 3444
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 2000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define dum(x) cout<<#x<<'='<<x<<endl
#define dum2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define dum3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl

//ifstream in("Text.txt");cin.rdbuf(in.rdbuf());

ll A[100010];

int main() {
    int N;
    cin >> N;
    rep(i, N)cin >> A[i];

    sort(A, A + N);

    ll h, w, cou = 0;
    for (int i = N - 1; i > 0; i--) {
        if (A[i] == A[i - 1]) {
            cou++;
            if (cou == 1)h = A[i];
            if (cou == 2) {
                w = A[i];
                break;
            }
            i--;
        }
    }
    cout << h*w << endl;
}

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

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

int main()
{
    char inp[10], ans[10];
    scanf("%s %s", inp, ans);

    int cnt = 0;
    for (int i = 0; i < 3; i++)
        if (inp[i] == ans[i])
            cnt++;

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

    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = input()
B = input()
C = input()

ans = 0
for a, b, c in zip(A, B, C):
    xs = set([a, b, c])
    if len(xs) == 1:
        ans += 0
    elif len(xs) == 2:
        ans += 1
    else:
        ans += 2

print(ans)


Measured memory_bytes: 3060
/**************** Geometrical Library ****************/

#include<cmath>
#include<vector>
#include<algorithm>

#define	EPS	1e-9

enum {CCW=1,CW=-1,ON=0};

#define	mp	make_pair
#define	pb	push_back

using namespace std;

class Point{
public:
	double x,y;
	Point(){}
	Point(double xx,double yy):x(xx),y(yy){}
};

class Line:public vector<Point>{
public:
	Line(const Point &a,const Point &b){
		pb(a),pb(b);
	}
};

class Segment:public Line{
public:
	Segment(const Point &a,const Point &b):Line(a,b){}
};

class Polygon:public vector<Point>{};

class Circle{
public:
	Point c;
	double r;
	Circle(const Point &cc,double rr) : c(cc),r(rr){}
};

Point &operator +=(Point &a,const Point &b){
	a.x+=b.x,a.y+=b.y;
	return a;
}

Point &operator -=(Point &a,const Point &b){
	a.x-=b.x,a.y-=b.y;
	return a;
}

Point &operator *=(Point &a,double c){
	a.x*=c,a.y*=c;
	return a;
}

Point &operator /=(Point &a,double c){
	a.x/=c,a.y/=c;
	return a;
}

Point operator +(const Point &a,const Point &b){
	Point c=a;
	return c+=b;
}

Point operator -(const Point &a,const Point &b){
	Point c=a;
	return c-=b;
}

Point operator *(double c,const Point &a){
	Point b=a;
	return b*=c;
}

Point operator /(const Point &a,double c){
	Point b=a;
	return b/=c;
}

bool operator <(const Point &a,const Point &b){
	return (a.x==b.x)?(a.y<b.y):(a.x<b.x);
}

bool operator >(const Point &a,const Point &b){
	return b<a;
}

double cross(const Point &a,const Point &b){
	return a.x*b.y-a.y*b.x;
}

int ccw(const Point &a,Point b,Point c){
	b-=a,c-=a;
	double rotdir=cross(b,c);
	if(rotdir>EPS)		return CCW;
	if(rotdir<-EPS)		return CW;
	return ON;
}

/**************** Library END ****************/

#include<cstdio>

int main(){
	int n;	scanf("%d",&n);
	while(n--){
		Point a,b,c,star[2];
		scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",
			&a.x,&a.y,&b.x,&b.y,&c.x,&c.y,&star[0].x,&star[0].y,&star[1].x,&star[1].y);
		bool in[2];
		for(int i=0;i<2;i++){
			int cnt=0;
			cnt+=ccw(a,b,star[i]);
			cnt+=ccw(b,c,star[i]);
			cnt+=ccw(c,a,star[i]);
			in[i]=(cnt==3*CCW || cnt==3*CW);
		}
		puts(in[0]==in[1]?"NG":"OK");
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main(void){
    int n;
    int h[105];
    int ans = 0;
    cin >> n;
    for(int i=0;i<n;i++) cin >> h[i];
    
    for(int i=0;i<n;i++){
        while(h[i]>0){
            for(int j=i;j<n;j++){
                if(h[j]==0) break;
                h[j]--;
            }
            ans++;
        }
    }
    
    cout << ans << endl;
    
}


Measured memory_bytes: 256
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 3*1e5 +5 ;
const long long MOD = 1e9 + 7;
const long long inf = 1e18;
 
using namespace std;
 

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll modFact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result;  
} 
 
bool isPrime(int x)
{
    if(x%2==0)
        return 0;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
 
ll binomialCoeff(ll n, ll k) 
{ 
	ll C[n + 1][k + 1]; 
	ll i, j; 


	for (i = 0; i <= n; i++) 
	{ 
		for (j = 0; j <= min(i, k); j++) 
		{ 
			
			if (j == 0 || j == i) 
				C[i][j] = 1; 

			else
				C[i][j] = (C[i - 1][j - 1] + 
										C[i - 1][j])%MOD; 
		} 
	} 

	return C[n][k]; 
}
bool compare(const string &a , const string&b){
	
}
 
void solve()
{
    int n;
    cin>>n;
    if(n%1000){
    	cout<<1000-n%1000<<endl;return ;
    }
    cout<<0<<endl;
}
 
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;

int32_t main(){
   fast;
   int a,b;
   cin >>  a >> b;
   cout << a*b;
}

Measured memory_bytes: 3656
/*
	Copyright: razouq (c)
	Author: Anass BENDARSI
	Date: 20-Apr-20 4:01:42 AM
	flamers will **** you
*/
//#include<flamers.h>

#include "bits/stdc++.h"
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define PB push_back
#define POB pop_back

using namespace std;

int main(){
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie();
	int n;
	cin>>n;
	int a[n];
	for(int i = 0; i < n; i++) a[i] = 0;
	for(int i = 0; i < n-1; i++) {
		int x;
		cin>>x;
		a[x-1]++;
	}
	for(int i = 0; i < n; i++) cout<<a[i]<<endl;
	return 0;
}


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

template <typename T>
vector<vector<T>> warshall_floyd(int n, vector<vector<T>> d) {

  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) 
      for (int j = 0; j < n; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  }
  return d;
}

int main(){
  int n;
  cin >> n;
  vector<vector<int>> a(n,vector<int>(n));
  ll res = 0;
  rep(i,n) rep(j,n) cin >> a[i][j], res += a[i][j];
  res /= 2;
  auto dist = warshall_floyd(n,a);
  vector<vector<bool>> memo(n,vector<bool>(n,false));
  for (int k = 0; k < n ; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = i+1; j < n; j++) {
        if (a[i][j] != dist[i][j]) {
          puts("-1");
          return 0;
        }
        if (i == j || j == k || k == i) continue;
        if (dist[i][j] == dist[i][k] + dist[k][j] && !memo[i][j]) {
          memo[i][j] = true;
          res -= dist[i][j];
        }
      }
    }
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 1024
n,m = map(int, input().split())
nlst = [[int(i) for i in input().split()] for _ in range(n)]
mlst = [[int(i) for i in input().split()] for _ in range(m)]

for i in nlst:
    tmp = [abs(i[0] - j[0]) + abs(i[1] - j[1]) for j in mlst]
    print(tmp.index(min(tmp)) + 1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define REP(i, n) for (int i=0; i<n; ++i)
#define print(x) cout << x << endl;

using namespace std;

void solve() {
    int a, b, c, d, e, k;
    vector<int> vec(5);
    REP(i, 5) {
        cin >> vec[i];
    }
    cin >> k;
    bool ok = true;
    bool finish = false;
    for (int i=0; i<5; ++i) {
        for (int j=i+1; j<5; ++j) {
            int d = abs(vec[i] - vec[j]);
            if (d > k) {
                ok = false;
                finish = true;
                break;
            }
        }
        if (finish) {
            break;
        }
    }
    if (ok) {
        print("Yay!");
    } else {
        print(":(");
    }
    
}

int main() {

    solve();
    return 0;
}

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

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

    switch(n%10){
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            cout << "hon" << endl;
            break;

        case 0:
        case 1:
        case 6:
        case 8:
            cout << "pon" << endl;
            break;

        default:
            cout << "bon" << endl;
    }

    return 0;
}

Measured memory_bytes: 3060
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var n=Arr.shift()-0;
   if(n==0)break;
   var s=[];
   var sum=0;
   for(var i=0;i<n;i++){
      var arr=(Arr.shift()).split(" ").map(Number);
      s.push(arr);
      sum+=arr[0];
   }
   s.sort(function(a,b){
      a=a[1];
      b=b[1];
      return b-a;
   });
   var result="Yes"
   for(var i=0;i<s.length;i++){
      var v=s[i];
      if(sum>v[1]){
         result="No";
         break;
      }
      sum-=v[0];
   }
   console.log(result);
}

Measured memory_bytes: 10092
#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 vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000000000009
#define int long long
using P = pair<int,int>;

signed main(){
  cout << fixed << setprecision(10);
  double n;
  cin >> n;
  vdouble x(n);
  vdouble y(n);
  rep(i,n) cin >> x[i] >> y[i];
  vint order(n);
  rep(i,n) order[i] = i;
  double ans = 0;
  do{
    int nowx = x[order[0]];
    int nowy = y[order[0]];
    rep1(i,n){
      ans += sqrt(pow(x[order[i]]-nowx,2) + pow(y[order[i]] - nowy,2));
      nowx = x[order[i]];
      nowy = y[order[i]];
    }
  }while(next_permutation(order.begin(),order.end()));
  double nnn = 1;
  erep1(i,n){
    nnn *= i;
  }
  cout << ans / nnn << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int par[100005];
int find(int x){return x==par[x]?x:par[x]=find(par[x]);}
int n,m;
int main(){
	for(int i=1;i<=100000;i++)par[i]=i;
	cin>>n>>m;
	while(m--){
		int x,y,z;cin>>x>>y>>z;
		par[find(x)]=find(y);
	}
	set<int>S;
	for(int i=1;i<=n;i++)S.insert(find(i));
	cout<<S.size()<<endl;
	return 0;
}

Measured memory_bytes: 5376