akhauriyash/Code-Regression huggingface dataset:
M, D = map(int, input().split())
cnt = 0
if(M < 4 or D < 22) :
    print(0)
else :
    for i in range(4, M + 1) :
        for j in range(22, D + 1) :
            d1 = j % 10
            d10 = j // 10
            if(d10 * d1 == i and d1 >= 2 and d10 >= 2) :
                cnt += 1
            else :
                pass
    print(cnt)

Measured memory_bytes: 3060
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int b=sc.nextInt();
		int n=b%10;
		if(n==2||n==4||n==5||n==7||n==9)System.out.println("hon");
		else if(n==1||n==6||n==8||n==0)System.out.println("pon");
		else System.out.println("bon");
	}

}


Measured memory_bytes: 27020
N = int(input())
A = map(int, input().split())
modified_A = []
for i, a in enumerate(A):
    modified_A.append(a - i - 1)

modified_A = sorted(modified_A)

min_sorrow = 1000000000000000
passed_A = 0
sum_A = sum(modified_A)
for i, a in enumerate(modified_A):
    passed_A += a
    sorrow = (2 * (i+1) - N) * a + sum_A - 2 * passed_A
    # print(i, a, sorrow)
    if sorrow < min_sorrow:
        min_sorrow = sorrow
print(min_sorrow)

Measured memory_bytes: 26128
a = input().split(" ")
ar = input().split(" ")
count = 0
k = 0
n = int(a[0])-1
while count != 1:
    n += 1
    for b in ar:
        if b in str(n):
            k += 1
    if k == 0:
        count += 1
    k = 0
print(n)
    

Measured memory_bytes: 3060
#include <stdio.h>
int W,H,x,y,r;

main(){
 scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);

 if(x+r>W||x-r<0){
 printf("No\n");
 }
 else if(y+r>H||y-r<0){
 printf("No\n");
 }
 
 
 
 
 
 else{printf("Yes\n");}


return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll K = 0;
ll H, W;
ll t;
ll ret = 0;
string s;
ll mat[20][20];
ll adj[400][400];

void input() {
  IN(H);
  IN(W);
  char c;
  REP(i, H) {
    IN(s);
    REP(j, W) {
      mat[i][j] = (s[j]=='.')?1:0;
      // DEBUG(mat[i][j]);
    }
  }
}

void solve() {
  REP(k, H*W) {
    REP(l, H*W) {
      adj[k][l] = INF;
    }
  }
  REP(i, H) {
    REP(j, W) {
      if (i != 0) { //上のマス
        adj[i * W + j][(i-1) * W + j] = (mat[i][j] * mat[i-1][j])?1:INF;
      }
      if (j != 0) { //左のマス
        adj[i * W + j][i * W + j-1] = (mat[i][j] * mat[i][j-1])?1:INF;
      }
      if (i != H-1) { //下のマス
        adj[i * W + j][(i+1) * W + j] = (mat[i][j] * mat[i+1][j])?1:INF;
      }
      if (j != W-1) { //右のマス
        adj[i * W + j][i * W + j+1] = (mat[i][j] * mat[i][j+1])?1:INF;
      }
      adj[i * W + j][i * W + j] = 0;
    }
  }
  // REP(k, H*W) {
  //   REP(l, H*W) {
  //     DEBUG((adj[k][l] >= INF)?-1:adj[k][l]);
  //   }
  //   LN();
  // }
  // LN();

  REP(k, H*W) {
    REP(i, H*W) {
      REP(j, H*W) {
        adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);
      }
    }
  }
  REP(i, H*W) {
    FOR(j, i+1, H*W) {
      if (adj[i][j] < INF) CHMAX(ret, adj[i][j]);
    }
  }
  PRINT(ret);
  // REP(k, H*W) {
  //   REP(l, H*W) {
  //     DEBUG((adj[k][l] >= INF)?-1:adj[k][l]);
  //   }
  //   LN();
  // }
}

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


Measured memory_bytes: 1536
<?php
$s = trim(fgets(STDIN));

if ($s === 'zyxwvutsrqponmlkjihgfedcba') {
    echo '-1' . PHP_EOL;
    exit;
}

$sss = 'abcdefghijklmnopqrstuvwxyz';
$arr = [];
for ($i = 0; $i < strlen($sss); $i++) {
    $arr[$sss[$i]] = 0;
}

if (strlen($s) !== 26) {
    for ($i = 0; $i < strlen($s); $i++) {
        $arr[$s[$i]]++;
    }

    for ($i = 0; $i < strlen($sss); $i++) {
        if ($arr[$sss[$i]] === 0) {
            echo $s . $sss[$i] . PHP_EOL;
            exit;
        }
    }
} else {
    $pos = 0;

    for ($i = 0; $i < strlen($s) - 1; $i++) {
        if ($s[$i] < $s[$i + 1]) {
            $pos = $i;

            for ($j = 0; $j <= $i; $j++) {
                $arr[$s[$j]]++;
            }
        }
    }

    for ($i = 0; $i < strlen($sss); $i++) {
        if ($arr[$sss[$i]] === 0 && $sss[$i] > $s[$pos]) {
            echo substr($s, 0, $pos) . $sss[$i] . PHP_EOL;
            exit;
        }
    }
}

Measured memory_bytes: 4728
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define cyes cout << "YES" << endl
#define cno cout << "NO" << endl
#define f(i, a, n) for(int i = a; i < n; i++)
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mod 1000000007
int gcd(int a, int b) { if (!b) return a; return gcd(b, a % b); }  
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
using namespace std;



int32_t main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  
  int a,b;
  cin >> a >> b;

  cout << 6 -(a+b);


  return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define  mp make_pair

ll int dp[105][100005];
ll int data[105][2];
ll int max(ll int a, ll int b)
{
    if (a > b) return a;
    return b;
}
ll int knap(ll int n, ll int w)
{
    if (n == 0 or w == 0) return 0;

    if (dp[n][w] != -1) return dp[n][w];

    if (data[n - 1][0] <= w)
    {
        dp[n][w] = max(data[n - 1][1] + knap(n - 1, w - data[n - 1][0]), knap(n - 1, w));

    }
    else
        dp[n][w] = knap(n - 1, w);

    //cout << dp[n][w] << " ";
    return dp[n][w];

}
void findAns()
{
    int n, w;
    cin >> n >> w;
    memset(dp, -1, sizeof(dp));
    for (int i = 0; i < n; i++) cin >> data[i][0] >> data[i][1];

    ll int ans = knap(n, w);
    cout << ans;
    return;



}
int main()
{

    fastio;
    // ll int t;
    // cin >> t;

    // while (t--)
    findAns();

    return 0;
}

Measured memory_bytes: 82304
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<hash_map>
#include<bitset>

using namespace std;

const int MAXN=100005;

struct Node{
	int x;
	int y;
	friend bool operator<(const Node &x,const Node &y){
		if(x.x!=y.x){
			return x.x<y.x;
		}
		return x.y<y.y;
	}
};

int H;
int W;
int N;
vector<Node>var(MAXN);
vector<long long>ans(10,0);

set<Node>myMap;

void Check(int x,int y){
	for(int i=0;i<3;++i){
		for(int j=0;j<3;++j){
			int sx=x-i;
			int sy=y-j;
			int ex=sx+2;
			int ey=sy+2;
			int sum=0;
			if(sx>0&&sx<=H-2&&sy>0&&sy<=W-2){
				for(int ii=sx;ii<=ex;++ii){
					for(int jj=sy;jj<=ey;++jj){
						Node tempNode;
						tempNode.x=ii;
						tempNode.y=jj;
						if(myMap.find(tempNode)!=myMap.end()){
							sum++;
						}
					}
				}
				ans[sum]+=1;
			}
		}
	}
}

void GetAns(){
	for(int i=0;i<N;++i){
		Check(var[i].x,var[i].y);
	}
	long long tempAns=(long long)(H-2)*(W-2);
	for(int i=1;i<10;++i){
		ans[i]/=i;
		tempAns-=ans[i];
	}
	ans[0]=tempAns;
}

int main(){		
	cin>>H>>W>>N;
	//cout<<(long long)(H-2)*(W-2)<<endl;
	for(int i=0;i<N;++i){
		scanf("%d%d",&var[i].x,&var[i].y);
		myMap.insert(var[i]);
	}
	GetAns();
	for(int i=0;i<10;++i){
		cout<<ans[i]<<endl;
	}
	return 0; 
}

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

#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define RREP(i, a, b) for (int i = (a); i >= (b); --i)

using namespace std;
using ll = long long;

static const ll MAX = 1e9;

void input (vector<ll> & v, int N) {
  REP(i, 0, N) {
    ll x;
    scanf("%lld", &x);
    v[i] = x;
  }
  sort(v.begin(), v.end());
}

/**
 * print an array in a row
 */
template <typename T>
void print_array (T arr[], size_t n) {
  for (int i = 0; i < n; i++) printf("%d%c", arr[i], (i == n - 1) ? '\n' : ' ');
}

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

  vector<ll> A(N);
  vector<ll> B(N);
  vector<ll> C(N);

  input(A, N);
  input(B, N);
  input(C, N);

  vector<ll> nb(N + 1);
  ll acc = 0;

  nb[N] = 0;

  RREP(i_b, N - 1, 0) {
    ll b = B[i_b];

    auto it = lower_bound(C.begin(), C.end(), b + 1);
    int i_c = distance(C.begin(), it);
    // printf("b=%d b+1=%d i_c=%d delta=%d\n",b, b+1, i_c, N - i_c);
    acc += N - i_c;
    nb[i_b] = acc;
  }

  // print_array(nb.data(), N);

  ll cnt = 0;

  RREP(i_a, N - 1, 0) {
    ll a = A[i_a];

    auto it = lower_bound(B.begin(), B.end(), a + 1);
    int i_b = distance(B.begin(), it);

    // printf("i_a=%d, i_b=%d\n", i_a, i_b);

    cnt += nb[i_b];
  }

  cout << cnt << '\n';
}


Measured memory_bytes: 3328
N = int(input())
a = list(map(int, input().split()))

color = [0] * 8
free = 0
for i in a:
    if i < 3200:
        color[i//400] += 1
    else:
        free += 1

# free = min(free, 8)

ans = 0
for i in color:
    if i > 0:
        ans += 1

if ans == 0:
    ans1 = 1
else:
    ans1 = ans
ans2 = ans + free

print(ans1, ans2)

Measured memory_bytes: 3064
n,m=map(int,input().split())
ab=[]
for i in range(n):
	lst=list(map(int,input().split()))
	ab.append(lst)
ab.sort()
cost=0
now=0
while m!=0:
	cost+=ab[now][0]
	ab[now][1]-=1
	m-=1
	if ab[now][1]==0:
		now+=1
print(cost)

Measured memory_bytes: 27760
import sys

R, G, B, N = list(map(int, sys.stdin.readline().strip().split(" ")))

count = 0

for r in range(int(N/R) + 1):
    N1 = N - R*r
    for g in range(int(N1/G) + 1):
        N2 = N1 - G*g
        if N2 % B == 0:
            count += 1
        #for b in range(int(N2/B) + 1):
        #if r*R + g*G + b*B == N:
        #count += 1
print(count)


Measured memory_bytes: 3060
// #define _GLIBCXX_DEBUG

#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <string>
#include <vector>
#include <chrono>
#include <cmath>

#define int long long

using namespace std;


signed main() {
  string s, t;
  cin >> s >> t;

  for (int i = 0; i < s.size(); i++) {
    if (s[i] != t[i]) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}


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

int main()
{
	int n,sum,minn=0x7fffffff;
	cin>>n;
	int a[n+1];
	
	for(int i=1;i<=n;i++)
		cin>>a[i];
	
	for(int i=1;i<=100;i++)
	{
		sum=0;
		for(int j=1;j<=n;j++)
			sum+=(a[j]-i)*(a[j]-i);
		minn=min(minn,sum);
	}
	cout<<minn<<endl;
	return 0;
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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


const string YES = "YES";
const string NO = "NO";

map<lli,lli> cnts;

void func(long long N, std::vector<long long> D, long long M, std::vector<long long> T){

    REP(i,0,N){
        cnts[D[i]]++;
    }

    REP(i,0,M){
        if(cnts[T[i]]==0){
            cout<<NO<<endl;
            return;
        }
        cnts[T[i]]--;
    }

    cout<<YES<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    std::vector<long long> D(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&D[i]);
    }
    long long M;
    scanf("%lld",&M);
    std::vector<long long> T(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&T[i]);
    }
    func(N, std::move(D), M, std::move(T));
    return 0;
}


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

const int E_MAX = 100010;
struct edge {int u, v, cost;};

bool comp(const edge& e1, const edge& e2){
    return e1.cost < e2.cost;
}

int V, E;
edge G[E_MAX];

struct UnionFind{
    vector<int> par;
    UnionFind(int N) : par(N){
        for(int i = 0; i < N; i++){
            par[i] = -1;
        }
    }
    int root(int x){
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        else{
            if(par[rx] > par[ry]) swap(rx, ry);
            par[rx] += par[ry];
            par[ry] = rx;
       }
    }
    bool same(int x, int y){
        return root(x) == root(y);
    }
    void check(){
        for(auto x : par){
            cout << x << " ";
        }
        cout << endl;
    }
};

int kruskal() {
    sort(G, G + E, comp);
    UnionFind uf(V);
    int res = 0;
    for(int i = 0; i < E; i++){
        edge e = G[i];
        if(uf.same(e.u, e.v)) continue;
        else{
            uf.unite(e.u, e.v);
            res += e.cost;
        }
    }
    return res;
}

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

    while(cin >> V){
        if(V == 0) break;
        cin >> E;
        for(int i = 0; i < E; i++){
            int a, b, d;
            char c;
            cin >> a >> c >> b >> c >> d;
            G[i].u = a;
            G[i].v = b;
            G[i].cost = d;
        }
        cout << kruskal() / 100 - (V - 1) << endl;
    }

    return 0;
}


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

def exec(a, n):
    if len([x for x in a if x%2 == 0]) == n:
        return [int(x/2) for x in a]
    return []

i = 0
while True:
    t = exec(a, n)
    if len(t):
        i += 1
        a = t
    else:
        break

print(i)

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

int main() {
  int a,c=0;
  cin>>a;
  vector<int> b(a);
  for(int i=0;i<a;i++){
    cin>>b.at(i);
  }
  for(int i=0;i<a;i+=2){
    if(b.at(i)%2==1)c++;
  }
  cout<<c<<endl;
}

Measured memory_bytes: 3636
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> W >> H;
	long long int v, t;
	cin >> v >> t;
	long long int sx, sy, gx, gy;
	cin >> sx >> sy >> gx >> gy;
	int dif = v * t / min(H,W) + 10;
	long long int ans = 0;
	for (int i = -dif; i <= dif; i++) {
		long long int x = sx, y = sy;
		if (i % 2)y = H - y;
		y += i * H;
		if ((y - gy)*(y - gy) + (x - gx)*(x - gx) <= v * v*t*t)ans++;
		L = 0, R = dif;
		while (R - L > 1) {
			int mid = (R + L) / 2;
			x = sx;
			if (mid % 2)x = W - x;
			x += mid * W;
			if ((y - gy)*(y - gy) + (x - gx)*(x - gx) <= v * v*t*t)L = mid;
			else R = mid;
		}
		ans += L;
		L = 0, R =dif;
		while (R - L > 1) {
			int mid = (R + L) / 2;
			x = sx;
			if (mid % 2)x = W - x;
			x -= mid * W;
			if ((y - gy)*(y - gy) + (x - gx)*(x - gx) <= v * v*t*t)L = mid;
			else R = mid;
		}
		ans += L;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3164
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <list>
#include <math.h>
using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007


bool isint(double f){
	if (fabs(f - (int)(f + 0.1)) <= 0.0000000001)
		return true;
	else
		return false;
}

signed main(){

	int N, a, b, c;
	cin >> N;
	for (a = N / 4 + 1; a <= N * 3 / 4; a++){
		for (b = a*N / (4 * a - N) + 1; b <= a*N / (4 * a - N) * 2; b++){
			if (isint(1.0 / (4.0 / N - 1.0 / a - 1.0 / b))){
				cout << a << " " << b << " " << (int)(1.0 / (4.0 / N - 1.0 / a - 1.0 / b )+0.1) << endl;
				return 0;
			}
		}
	}

	return 0;
}


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

using namespace std;
int v[NMAX];
int main()
{
    int k,n,dmax=0;
    cin>>k>>n;
    for(int i=0;i<n;i++){
        cin>>v[i];
        if(i) dmax=max(dmax,v[i]-v[i-1]);
    }
    dmax=max(dmax,k-v[n-1]+v[0]);
    cout<<k-dmax;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int N,A,B;
    cin>>N;
    cin>>A;
    cin>>B;
    int p[N];
    for(int i=0;i<=N-1;i++){
        cin>>p[i];
        }
    int count1=0,count2=0,count3=0;
    for(auto x:p){
        if(x<=A){
            count1++;
            }
        if(A+1<=x&&x<=B){
            count2++;
        }
        if(x>=B+1){
            count3++;
            
        }
    }
    cout<<min({count1,count2,count3})<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define llu unsigned long long
const llu base=131;
map<llu,int>mp;
int main()
{
    int n;scanf("%d",&n);
    long long ans=0;
    for(int i=1;i<=n;i++)
    {
        char t[22];
        scanf("%s",t+1);
        llu has=0;
        sort(t+1,t+10+1);
        for(int j=1;j<=10;j++)
            has=has*base+t[j];
        ans+=mp[has];
        mp[has]++;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 6528
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip	;
const double PI=acos(-1);
const double EPS=1e-8;
const ll inf=1e17;
vp in;
vvi dp;
int f(int a,int b){
	if(dp[a][b]!=inf)return dp[a][b];
	if(b==2){
		return dp[a][b]=in[a].first*in[a].second*in[a+b-1].first*in[a+b-1].second;
	}
	ll mi=f(a,b-1)+in[a].first*in[a+b-2].second*in[a+b-1].first*in[a+b-1].second;
	mi=min<ll>(mi,f(a+1,b-1)+in[a].first*in[a].second*in[a+1].first*in[a+b-1].second);
	rep(i,b-3)mi=min<ll>(mi,f(a,i+2)+f(a+i+2,b-i-2)+in[a].first*in[a+i+1].second*in[a+i+2].first*in[a+b-1].second);
	return dp[a][b]=mi;
}
int main(){
	int n;
	cin>>n;
	in=vp(n);
	dp=vvi(n,vi(n+1,inf));
	rep(i,n)cin>>in[i].first>>in[i].second;
	if(n==1)cout<<0<<endl;
	else cout<<f(0,n)<<endl;
}

Measured memory_bytes: 1320
import heapq

n = int(input())
maxim = 100010
adj = [[] for _ in range(n)]

for _ in range(n):
    u, k, *v = map(int, input().split())
    if k == 0:
        adj[u].append((0,0))
    for i in range(k):
        adj[u].append((v[i*2+1], v[i*2]))

def dijkstra():
    global adj
    PQ = []
    heapq.heapify(PQ)
    color = ['W']*n
    d = [maxim]*n
    d[0] = 0
    heapq.heappush(PQ, (0, 0))
    color[0] = 'G'

    while PQ:
        f = heapq.heappop(PQ)
        u = f[1]
        color[u] = 'B'
        if d[u] < f[0]*-1:
            continue
        for j in range(len(adj[u])):
            v = adj[u][j][1]
            if color[v] == 'B':
                continue
            if d[v] > d[u]+adj[u][j][0]:
                d[v] = d[u]+adj[u][j][0]
                heapq.heappush(PQ, (d[v], v))
                color[v] = 'G'
    return d

D = dijkstra()
for i, x in enumerate(D):
    print(i, x)


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

using namespace std;

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

  int cnt[26];
  for(int i = 0; i < 26; i++) {
    cnt[i] = count(begin(s), end(s), i + 'a');
  }
  int ret = 0;
  bool one = false;
  for(int i = 0; i < 26; i++) {
    ret += cnt[i] % 2;
  }

  cout << ret / 2 << endl;
}

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

const int Nmax = 100001;
int Q;
bool isPrime[Nmax];
int cnt[Nmax];

int main() {
	fill(isPrime, isPrime +Nmax,1);
	isPrime[1] = false;
	for (int i = 2; i*i < Nmax; i++) {
		for (int j = 2; j*i < Nmax; j++) {
			isPrime[i*j] = false;
		}
	}

	/*for (int i = 0; i <= Nmax; i++) {
		if (isPrime[i]) cout << i << " " << endl;
	}*/

	int buf = 0;
	for (int i = 0; i <= Nmax; i++) {
		if (isPrime[i]) {
			if (isPrime[(i + 1) / 2]) {
				buf++;
			}
		}
		cnt[i] = buf;
	}

	cin >> Q;
	for (int i = 0; i < Q; i++) {
		int l, r;
		cin >> l >> r;
		cout << cnt[r] - cnt[l - 1] << endl;
	}

	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int N; cin >> N;
  vector<int> a(N);
  REP(i, N) cin >> a[i];

  int ans = 0;
  REP(i, N) if (i+1 == a[a[i]-1]) ans++;
  cout << ans/2 << endl;
}

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

using namespace std;


int main() {
    int n;

    cin >> n;

    vector<int> d(n);

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

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

    int now = 0;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (d[i] > now) {
            cnt++;
            now = d[i];
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  int a,b,c;
  cin>>a>>b>>c;
  int e,f=0,g;
  int d[b];
  rep(i,b)cin>>d[i];
  rep(i,a){
    e=0;
    rep(o,b){
      cin>>g;
      e+=g*d[o];
    }
    e=e+c;
    if(e>0){
      f++;
    }
  }
  cout<<f;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)
	prevt, prevx, prevy := 0, 0, 0
	// そこまでの距離と時間差の比較, 偶数と奇数の比較
	for i := 0; i < n; i++ {
		var t, x, y int
		fmt.Scan(&t, &x, &y)

		if t-prevt < int(math.Abs(float64(x-prevx))+math.Abs(float64(y-prevy))) {
			fmt.Println("No")
			return
		}
		if (t-prevt)%2 != int(math.Abs(float64(x-prevx))+math.Abs(float64(y-prevy)))%2 {
			fmt.Println("No")
			return
		}
		prevt = t
		prevx = x
		prevy = y
	}
	fmt.Println("Yes")
	return
}


Measured memory_bytes: 6336
def main():
    count = 0

    # 引数を受け取る
    args = input().split(' ')

    # リストの中身をint型に変換
    args = [int(i) for i in args]

    for i in range(args[0], args[1]+1, 1):
        if args[2]%i == 0:
            count += 1

    print(count)

if __name__ == "__main__":
    main()


Measured memory_bytes: 5604
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <bits/stdc++.h>
#include <iomanip>
#include <numeric>
#include <map>
#include <algorithm>
using namespace std;

int main(void)
{
    int h, a;
    cin >> h >> a;
    int ans = (h + a - 1) / a;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <math.h>
#include <queue>
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

const int M = 1000005;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> cnt(M);
    for (int x : a) {
        if (cnt[x]!=0) {
            cnt[x]=2;
            continue;
        }
        for (int i=x; i<M; i+=x) cnt[i]++;
    }
    int ans=0;
    for (int x : a) {
        if (cnt[x]==1) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

int N, M;
vector<int> G[100];
int order[100], low[100];

int dfs(int v, int pr, int& k){
    order[v] = k;
    low[v] = k;
    ++k;
    
    for(int w : G[v]){
        if(w == pr){continue;}
        
        if(order[w] == -1){
            low[v] = min(low[v], dfs(w, v, k));
        }else{
            low[v] = min(low[v], order[w]);
        }
    }

    return low[v];
}
    
int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> N >> M;

    for(int i=0;i<M;++i){
        int a, b;
        std::cin >> a >> b;

        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }

    memset(order, -1, sizeof(order));
    int k = 1;
    dfs(1, -1, k);

    // for(int i=1;i<=N;++i){
    //     std::cout << order[i] << ", " << low[i] << std::endl;
    // }
    
    int res = 0;
    for(int i=1;i<=N;++i){
        for(int j : G[i]){
            int v = i, w = j;
            if(order[v] > order[w]){swap(v, w);}
            if(order[v] < low[w]){++res;}
        }
    }

    std::cout << (res / 2) << std::endl;
}


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


int main() {
    int n, lb, rb, l, r;
    cin >> n >> n;
    for(int i = 0; i < n; ++i) {
        cin >> l >> r;
        if(i)
            lb = max(lb, l), rb = min(rb, r);
        else
            lb = l, rb = r;
    }


    cout << max(rb-lb+1, 0) << endl;
    return 0;
}

Measured memory_bytes: 256
struct Scanner {
    private var elements = [String]()
    private var index = 0

    mutating func peek() -> String {
        while elements.count == index {
            elements = readLine()!.split(separator: " ").map(String.init)
            index = 0
        }
        return elements[index]
    }

    mutating func next() -> String {
        let value = peek()
        index += 1
        return value
    }

    mutating func nextInt() -> Int {
        return Int(next())!
    }

    mutating func nextDouble() -> Double {
        return Double(next())!
    }
}

var scanner = Scanner()
let R = scanner.nextInt()
let C = scanner.nextInt()
let K = scanner.nextInt()

struct Array2D<Element> {
    let n1: Int
    let n2: Int
    private var elements: [Element]

    init(repeating: Element, _ n1: Int, _ n2: Int) {
        self.n1 = n1
        self.n2 = n2
        self.elements = [Element](repeating: repeating, count: n1 * n2)
    }

    subscript(i: Int, j: Int) -> Element {
        get {
            elements[i * n2 + j]
        }
        set {
            elements[i * n2 + j] = newValue
        }
    }
}

struct Array3D<Element> {
    let n1: Int
    let n2: Int
    let n3: Int
    private var elements: [Element]

    init(repeating: Element, _ n1: Int, _ n2: Int, _ n3: Int) {
        self.n1 = n1
        self.n2 = n2
        self.n3 = n3
        self.elements = [Element](repeating: repeating, count: n1 * n2 * n3)
    }

    subscript(i: Int, j: Int, k: Int) -> Element {
        get {
            elements[(i * n2 + j) * n3 + k]
        }
        set {
            elements[(i * n2 + j) * n3 + k] = newValue
        }
    }
}

infix operator ++=: AssignmentPrecedence

extension Int {
    static func ++= (lhs: inout Int, rhs: Int) {
        if lhs < rhs {
            lhs = rhs
        }
    }
}



var V = Array2D(repeating: 0, R, C)
for _ in 0 ..< K {
    let r = scanner.nextInt() - 1
    let c = scanner.nextInt() - 1
    V[r, c] = scanner.nextInt()
}

var dp = Array3D<Int>(repeating: Int.min, R, C, 5)
dp[0, 0, 0] = 0
dp[0, 0, 1] = V[0, 0]

for i in 0 ..< R {
    for j in 0 ..< C {
        for k in 0 ... 3 {
            if i + 1 < R {
                dp[i + 1, j, 0] ++= dp[i, j, k]
                dp[i + 1, j, 1] ++= dp[i, j, k] + V[i + 1, j]
            }

            if j + 1 < C {
                dp[i, j + 1, k] ++= dp[i, j, k]
                dp[i, j + 1, k + 1] ++= dp[i, j, k] + V[i, j + 1]
            }
        }
    }
}

let answer = (0 ... 3).map { dp[R - 1, C - 1, $0] }.max()!
print(answer)




Measured memory_bytes: 429412
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;cin >> s;
    string t;cin >> t;
    string u;cin >> u;
    string ans = {s[0], t[1], u[2]};
    cout << ans << "\n";
}

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

using namespace std;

int n,a[100]={0},b[100]={0},c[100]={0};

int main(){
	cin>>n;
	for(int i=0;i<n;++i)
		cin>>a[i];
	for(int i=0;i<n;++i)
		if(i==0)
			b[i]=a[i];
		else
			b[i]=b[i-1]+a[i];
	for(int i=n-1;i>=0;i--)
		if(i==n-1)
			c[i]=a[i];
		else
			c[i]=c[i+1]+a[i];
	int minDiff=INT_MAX;
	for(int i=0;i<n-1;++i)
		minDiff=min(minDiff,abs(b[i]-c[i+1]));
	cout<<minDiff<<endl;				
	return 0;
}

Measured memory_bytes: 256
nk = list(map(int, list(input().split())))
n = nk[0]
k = nk[1]
s = list(map(int, list(input())))

count = 1
if s[0] == 0:
    count_list = [0]
elif s[0] == 1:
    count_list = []

for i in range(n - 1):
    if s[i] == s[i + 1]:
        count = count + 1
    else:
        count_list.append(count)
        count = 1
count_list.append(count)

count_list2 = [0]
count2 = 0
for i in range(len(count_list)):
    count2 = count2 + count_list[i]
    count_list2.append(count2)

maximum = []
i = 0
while 2 * i < len(count_list2):
    l = count_list2[2 * i]
    if 2 * i + 2 * k + 1 > len(count_list2) - 1:
        r = count_list2[len(count_list2) - 1]
    else:
        r = count_list2[2 * i + 2 * k + 1]
    maximum.append(r - l)
    i = i + 1

print(max(maximum))

Measured memory_bytes: 10480
import java.util.Scanner;

public class Main {

	static int w, h, count=100;
	static int[] v1 = {1, 0, -1, 0};
	static int[] v2 = {0, 1, 0, -1};
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			count=100;
			w = cin.nextInt();
			h = cin.nextInt();
			if(w+h==0){
				break;
			}
			Field f = new Field();
			f.field = new int[h+2][w+2];
			f.flr = 1;
			for(int i = 0; i<= h+1; i++){
				f.field[i][0] = -1;
				f.field[i][w+1] = -1;
			}
			for(int i = 0; i<= w+1; i++){
				f.field[0][i] = -1;
				f.field[h+1][i] = -1;
			}
			for(int i = 1; i<= h; i++){
				for(int j = 1; j <= w; j++){
					String str = cin.next();
					f.field[i][j] = Integer.parseInt(str);
					if(f.field[i][j] == 2){
						f.x = i;
						f.y = j;
					}
				}
			}
			recursive(f);
			if(count==100){
				System.out.println(-1);
			}
			else{
				System.out.println(count);
			}
		}
	}
	static void recursive(Field f){
		if(f.flr > 10 || f.flr >= count)
			return;
		for(int i = 0; i < 4; i++){
			int nowX = f.x;
			int nowY = f.y;
			boolean first = true;	
			while(true){
				nowX += v1[i];
				nowY += v2[i];
				if(f.field[nowX][nowY] == -1){
					break;
				}
				if(f.field[nowX][nowY] == 3){
					count = Math.min(count, f.flr);
					break;
				}
				if(first){
					if(f.field[nowX][nowY] == 1){
						break;
					}
					first = false;
				}
				else{
					if(f.field[nowX][nowY] == 1){
						Field a = new Field();
						//a.field = f.field.clone();
						/*
						a.field = new int[h+2][w+2];
						for(int k = 0; k < h+2; k++){
							for(int j = 0; j < w+2; j++){
								a.field[k][j] = f.field[k][j];
							}
						}
						*/
						a.field = new int[h+2][];
						
						for(int j = 0; j < h+2; j++){
							a.field[j] = f.field[j].clone();
						}
						//output(a);
						a.field[f.x][f.y] = 0;
						a.field[nowX][nowY] = 0;
						a.field[nowX-v1[i]][nowY-v2[i]] = 2;
						a.x = nowX-v1[i];
						a.y = nowY-v2[i];
						a.flr = f.flr+1;
						//output(f);
						recursive(a);
						break;
					}
				}
			}
		}
	}
	static void output(Field f){
		for(int i = 0; i<= h+1; i++){
			for(int j = 0; j <= w+1; j++){
				System.out.print(f.field[i][j] + " ");
			}
			System.out.println();
		}
	}
}
class Field{
	int[][] field;
	int x, y;
	int flr;
}

Measured memory_bytes: 13000
#include <stdio.h>

int main ()
{
  int n;
  scanf("%d",&n);
  if(n/100==1)
  {
    if(n%100/10==1)
    {
      if(n%10==1)
      {
        printf("%d\n",999);
      }
      else
      {
          printf("%d\n",991);
      }
    }
    else
    {
      if(n%10==1)
      {
        printf("%d\n",919);
      }
      else
      {
          printf("%d\n",911);
      }
    }
  }
  else
  {
    if(n%100/10==1)
    {
      if(n%10==1)
      {
        printf("%d\n",199);
      }
      else
      {
          printf("%d\n",191);
      }
    }
    else
    {
      if(n%10==1)
      {
        printf("%d\n",119);
      }
      else
      {
          printf("%d\n",111);
      }
    }
  }
}


Measured memory_bytes: 128
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
ll gcd(ll a, ll b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}

// const ll MAX_N = 1e5;
// ll N;
// ll h[MAX_N];
// ll dp[MAX_N+1]; // メモ化テーブル
 
// // i番目以降の品物から重さの総和がj以下になるように選ぶ
// void rec(ll i){
// 	if (i==0) dp[i] = 0;
// 	else if (i==1) dp[i] = abs(h[1]-h[0]);
// 	else dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
// 	return;
// }
 
 
int main() {
	// 入力
	ll N,Q;
	string S;
	cin >> N>>Q>>S;
	ll l[Q],r[Q];
	for (ll i = 0; i < Q; ++i) cin >> l[i]>>r[i];
 
	// 解法
	ll acm[N] = {0};
	REP(i,N-1){
		if (S[i]=='A' & S[i+1]=='C'){
			acm[i+1] = acm[i]+1;
		}
		else{
			acm[i+1] = acm[i];
		}
	}
	// REP(i,N){
	// 	printf("%lld ", acm[i]);
	// }
	// printf("\n");
	
	REP(i,Q){
		printf("%lld\n", acm[r[i]-1]-acm[l[i]-1]);
	}
}


Measured memory_bytes: 3456
n,k = map(int,raw_input().split())
boats = [map(int,raw_input().split()) for i in range(k)]
r = input()
hate = [map(int,raw_input().split()) for i in range(r)]
blue = [0]*51
for i,j in hate:
	for boat in boats:
		if i in boat[1:] and j in boat[1:]:
			blue[i] = 1
			blue[j] = 1
print sum(blue)

Measured memory_bytes: 4336
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> ans(n+1);
  for(int i = 0; i < n-1; i++){
      cin >> a.at(i);
      ans[a[i]]++;
  }
  for(int i = 1; i < n+1; i++){
      cout << ans[i]<< endl;
  }
}

Measured memory_bytes: 6428
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];

  int ans = 0;
  while(!all_of(all(a), [&](auto x){return x == 0;})){
    rep(i,n) if(a[i]>0){
      ans++;
      while(i<n && a[i]>0){
        a[i]--;
        i++;
      }
      dbg(a);
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



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


	int N; cin >> N;

	int l = 2;
	VI so, shi;
	while (l*l <= N) {
		int cnt = 0;
		while (N%l == 0) {
			cnt++;
			N /= l;
		}
		if (cnt > 0) {
			shi.push_back(cnt);
			so.push_back(l);
		}
		l++;
	}
	if (N != 1) {
		shi.push_back(1);
		so.push_back(N);
	}


	int ans = 0;
	REP(i, so.size()) {
		int k = 1;
		while (shi[i] - k >= 0) {
			ans++;
			shi[i] -= k;
			k++;
		}
	}
	cout << ans << endl;

	return 0;
}



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

int main() {
  long n;
  cin >> n;
  
  long long ans = 0;
  for (int i=1; i <= n; ++i) {
    for (int j=i; j<=n; j+=i) {
      if (j%i==0) ans += j;
    }
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool cmp(string a,string b){
    string s = a+b;
    string t = b+a;
    return s<t;
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,l;cin>>n>>l;
    string a[n];for(ll i=0;i<n;i++)cin>>a[i];
    sort(a,a+n,cmp);
    for(ll i=0;i<n;i++)cout<<a[i];
}

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

int main() {

    int n;
    cin >> n;

    int each_digit_sum = 0;

    int tmp = n;

    while(tmp!=0){
        each_digit_sum += tmp%10;
        tmp /= 10;
    }

    string ans = "Yes";

    if(n % each_digit_sum != 0){
        ans = "No";
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/13
import itertools


def check(Queens, L):
    # row
    for i in range(L):
        cnt = 0
        for j in range(L):
            if (i, j) in Queens:
                cnt += 1
        if cnt != 1:
            return False

    # colmn
    for j in range(L):
        cnt = 0
        for i in range(L):
            if (i, j) in Queens:
                cnt += 1
        if cnt != 1:
            return False

    # diagonally
    for i in range(L):
        cnt = 0
        for i in range(L):
            if (i, j) in Queens:
                cnt += 1
        if cnt != 1:
            return False

    for queen in Queens:
        i = queen[0] - 1
        j = queen[1] - 1
        while 0 <= i and 0 <= j:
            if (i, j) in Queens:
                return False
            i -= 1
            j -= 1
        i = queen[0] - 1
        j = queen[1] + 1
        while 0 <= i and j < 8:
            if (i, j) in Queens:
                return False
            i -= 1
            j += 1
        i = queen[0] + 1
        j = queen[1] - 1
        while i < 8 and 0 <= j:
            if (i, j) in Queens:
                return False
            i += 1
            j -= 1
        i = queen[0] + 1
        j = queen[1] + 1
        while i < 8 and j < 8:
            if (i, j) in Queens:
                return False
            i += 1
            j += 1

    return True


def print_result(Queens, L):
    for i in range(L):
        for j in range(L):
            if (i, j) in Queens:
                print('Q', end='')
            else:
                print('.', end='')
        print()


if __name__ == "__main__":

    num_of_queen = 8
    L = 8
    k = int(input())

    GivenQueens = set()
    for i in range(k):
        r, c = map(int, input().split())
        GivenQueens.add((r, c))

    A = [i for i in range(L)]
    for pernutated in itertools.permutations(A, L-k):
        Queens = set(GivenQueens)
        row = 0
        i = 0
        while len(Queens) < num_of_queen:
            if row not in list(map(lambda queen: queen[0], Queens)):
                Queens.add((row, pernutated[i]))
                i += 1
            row += 1

        if check(Queens, L):
            print_result(Queens, L)
            break



Measured memory_bytes: 5676
#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;

int main() {
    string s;
    cin >> s;
    int counter = 1;
    vector<int> ans(sz(s), 0);
    bool b;

    rep(i, sz(s)-1){
        if(!b&&'R'==s[i]&&'L'==s[i+1]){

            int rnum = (counter + 1) / 2;
            int lnum = counter / 2;
            ans[i]+=rnum;
            ans[i+1]+=lnum;
            counter=1;
            b=true;

            continue;
        }
        if(b&&'L'==s[i]&&'R'==s[i+1]){
            int lnum = (counter + 1) / 2;
            int rnum = counter / 2;
            ans[i-counter+1]+=lnum;
            ans[i-counter]+=rnum;
            counter=1;
            b=false;

            continue;
        }

        counter++;
    }

    if(b){
        int lnum = (counter + 1) / 2;
        int rnum = counter / 2;
        ans[sz(s)-counter]+=lnum;
        ans[sz(s)-counter-1]+=rnum;
    }else{
        ans[sz(s)-1]++;
        ans[sz(s)-2]++;
    }

    rep(i, sz(s)){
        cout << ans[i] << " ";
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;

int main() {
    int n,u,k,v;
    cin >> n;
    vector<vector<int>>M(n,vector<int>(n));
    rep(i,n) {
        rep(j,n) {
            M[i][j] = 0;
        }
    }
    rep(i,n) {
        cin >> u >> k;
        u--;
        rep(j,k) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    rep(i,n) {
        rep(j,n) {
            cout << M[i][j];
            if(j != n-1) cout <<" ";
        }
        cout << endl;
    }
    return 0;
}


    



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

int main() {
  int n; cin >>n;
  vector<int>a(n);
  for(long long i=0;i<n;i++)cin>>a[i];
  int count4=0;
  int count2=0;
  int count=0;
  for(int i=0;i<n;i++){
    if(a[i]%2==0)count++;
    count2=0;
    while(a[i]%2==0){
      count2++;
      if(count2>=2){
        count4++;
        break;
      }
      a[i]/=2;
    }
  }
  if(n%2==1){
    if(count4>=n/2){
      cout<<"Yes"<<endl;
    }else{
      if(count-count4 >=n-count4*2-1){
        cout<<"Yes"<<endl;
      }else{
        cout<<"No"<<endl;
      }
    }
  }else{
    //cout<<count<<" "<<count4<<" "<<count2<<endl;
     if(count4>=n/2){
      cout<<"Yes"<<endl;
    }else{
      if(count-count4 >=max(0,n-count4*2)){
        cout<<"Yes"<<endl;
      }else{
        cout<<"No"<<endl;
      }
    }
  }
  return 0;
}
   

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

int main() {
	int n; cin >> n;
	vector<int> p(n);
	vector<int> q(n);

	for (auto& x : p)
		cin >> x;

	for (auto& x : q)
		cin >> x;

	if (p > q) swap(p, q);

	int ans = 0;
	while (p < q) {
		next_permutation(p.begin(), p.end());
		ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256