akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<" ";}
#define dumpl(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

class Rectangle {
public:
	int w, d;
	Rectangle(int w, int d) :w(w), d(d) {};
	bool operator<(const Rectangle &R) { return area() == R.area() ? w < R.w : area() < R.area(); }
	bool operator==(const Rectangle &R) { return area() == R.area(); }
	int area() const { return w*d; }
};
pair<Rectangle, Rectangle> cut(const Rectangle &R, int s) {
	dump(R.w)dumpl(R.d);
	int ss = s % (R.w + R.d);
	dumpl(ss);
	if (R.w > ss) {
		return make_pair(Rectangle(R.w - ss, R.d), Rectangle(ss, R.d));
	}
	else {
		ss -= R.w;
		return make_pair(Rectangle(R.w, R.d - ss), Rectangle(R.w, ss));
	}
}

signed main() {
	for (int n, w, d; cin >> n >> w >> d && (n || w || d);) {
		vector<Rectangle> v = { Rectangle(w,d) };
		rep(i, 0, n) {
			dumpl(i);
			dumpl(v.size());
			int p, s; cin >> p >> s; p--;
			dump(p)dumpl(s);
			auto res = cut(v[p], s);
			Rectangle R1 = res.first, R2 = res.second;
			if (R2 < R1)swap(R1, R2);
			v.erase(v.begin() + p);
			v.emplace_back(R1);
			v.emplace_back(R2);
		}
		sort(all(v));
		cout << v[0].area(); rep(i, 1, v.size()) { cout << " " << v[i].area(); } cout << endl;
	}
	return 0;
}

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

const int MAX=2e5+5;
int n,T,cnt=0,In[MAX],Out[MAX],S[MAX];
vector<int> g[MAX];

void DFS(int u,int par)
{
	In[u]=++cnt;
	for(int v:g[u])
		if(v!=par)
			DFS(v,u);
	Out[u]=cnt;
}

int main() 
{
	ios_base::sync_with_stdio(false);
	//freopen(".inp","r",stdin);
	cin>>n>>T;
	int u,v;
	for(int i=1;i<n;i++)
	{
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	DFS(1,1);
	while(T--)
	{
		cin>>u>>v;
		S[In[u]]+=v;
		S[Out[u]+1]-=v;
	}
	for(int i=1;i<=n;i++)
		S[i]+=S[i-1];
	for(int i=1;i<=n;i++)
		cout<<S[In[i]]<<' ';
}

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

using namespace std;

long long a, b, c, d, e;

long long gcd(long long x, long long y)
{ return y == 0 ? x : gcd(y, x % y); }

long long calc(long long x)
{ return x / c + x / d - x / e; }

int main(void)
{
    scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
    e = c * d / gcd(c, d);
    printf("%lld\n", b - a + 1 - calc(b) + calc(a - 1));
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	static BufferedReader br;
	static StringTokenizer tokenizer;

	public static void main(String[] args) throws Exception {
		br = new BufferedReader(new InputStreamReader(System.in));
		int n = nextInt();
		int w = nextInt();
		int[] weight = new int[n];
		int[] val = new int[n];
		int max = 0;
		for(int i = 0; i < n; i++) {
			weight[i] = nextInt();
			val[i] = nextInt();
			max += val[i];
		}
		long[] dp = new long[max + 1];
		Arrays.fill(dp, Long.MAX_VALUE);
		dp[0] = 0;
		for(int i = 0; i < n; i++) {
			for(int k = max; k >= val[i]; k--) {
				if(dp[k - val[i]] == Long.MAX_VALUE || dp[k - val[i]] + weight[i] > w)
					continue;
				dp[k] = Math.min(dp[k], dp[k - val[i]] + weight[i]);
			}
		}
		for(int i = max; i >=0; i--) {
			if(dp[i] < Long.MAX_VALUE) {
				System.out.println(i);
				return;
			}
		}
	}

	public static String next() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			String line = br.readLine();
			if (line == null)
				throw new IOException();
			tokenizer = new StringTokenizer(line);
		}
		return tokenizer.nextToken();
	}

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


Measured memory_bytes: 23124
#define _USE_MATH_DEFINES
#pragma region include

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////

void solve() {
	LL N, K;
	cin >> N >> K;
	LL A, B;
	A = N % K;
	B = (K - A);
	LL ans = A;
	if (A > B) {
		ans = B;
	}
	cout << ans << endl;
}

#pragma region main
signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
if sum(A) ==0: #すべてゼロ
  print("Yes")
  exit()

if N%3 != 0:
  print("No")
else:
  dic = {}
  for x in A:
    if x in dic:
      dic[x] += 1
    else:
      dic[x] = 1
  V = list(dic.values())
  if len(V) == 2:
    K = list(dic.keys())
    if K[0] == 0 and dic[K[1]] == dic[0]*2:
      print("Yes")
    elif K[1] == 0 and dic[K[0]] == dic[0]*2:
      print("Yes")
    else:
      print("No")
    exit()  
  if len(V) != 3:
    print("No")
    exit()
  if V[0] == V[1] and V[1] == V[2]:
    K = list(dic.keys())
    if K[0]^K[1] == K[2] and K[1]^K[2] == K[0] and K[2]^K[0] == K[1]:
      print("Yes")
    else:
      print("No")
  else:
    print("No")

Measured memory_bytes: 20360
#author: raghav_0901
from math import *

mod = (10**9) + 7


def _in():
    return [int(x) for x in input().split(' ')]


if __name__ == "__main__":
    k = int(input())
    curr, cnt = 100, 0
    while(curr < k):
        curr = int(curr * (1.01))
        cnt = cnt + 1
    print(cnt)


Measured memory_bytes: 9172
function Main(input) {
  input = input.split("\n");
  var A = parseInt(input[0].split(" ")[0]);
  var B = parseInt(input[0].split(" ")[1]);
  var H = parseInt(input[0].split(" ")[2]);
  var M = parseInt(input[0].split(" ")[3]);
  var hrad = Math.PI*2/(12*60);
  var mrad = Math.PI*2/60;
  var ans = Math.sqrt(Math.pow(A,2)+Math.pow(B,2)-2*A*B*Math.cos((H*60+M)*hrad-M*mrad));


  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29656
w,h,n=map(int,input().split())
t=[list(map(int,input().split()))for i in range(n)]
x_left=0
x_right=w
y_low=0
y_hight=h
for i in range(n):
    if t[i][2]==1:
        if x_left<=t[i][0]:
            x_left=t[i][0]
    elif t[i][2]==2:
        if t[i][0]<=x_right:
            x_right=t[i][0]
    elif t[i][2]==3:
        if y_low<=t[i][1]:
            y_low=t[i][1]
    elif t[i][2]==4:
        if t[i][1]<=y_hight:
            y_hight=t[i][1]
if x_right<=x_left or y_hight<=y_low:
    print(0)
else:
    print((x_right-x_left)*(y_hight-y_low))
    


Measured memory_bytes: 3064
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        int N = sc.nextInt();
        int odd = 0;
        for (int i = 0; i < N; ++i) {
            int a = sc.nextInt();
            if (a % 2 != 0) {
                ++odd;
            }
        }
        if (odd % 2 == 1) {
            if (N == 1) {
                _out.println("YES");
            } else {
                _out.println("NO");
            }
        } else {
            _out.println("YES");
        }
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 48452
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
const int mod = MOD7;

void ERROR(int num) { cout << "ERROR" << num << endl; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};


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

    ll N, W;
    cin >> N >> W;
    vector<ll> v(N), w(N);
    rep(i,N) cin >> w[i] >> v[i];

    // vector<vector<int>> dp(N+5,vector<int>(W+5));
    vector<ll> dp(W+5);
    for(ll i = 0; i < N; i++){
        for(ll j = W; j >= w[i]; j--){
            dp[j] = max(dp[j], dp[j-w[i]]+v[i]);
        }
    }
    cout << dp[W] << endl;
}


Measured memory_bytes: 3984
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
cnt = [0]*n

for k in range(n):
    for i in range(m):
        for j in range(2):
            if(k+1 == a[i][j]):
                cnt[k] += 1
for l in range(len(cnt)):
    print(cnt[l])

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
	int a, b, s;
	cin>>s;
	for(a=1;a<=9;a++)
	    for(b=1;b<=9;b++){
	    	if(a*b==s){
	    		cout<<"Yes"<<endl; return 0;
			}
		}
	cout<<"No"<<endl;
	return 0;
} 

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

int main() {
  int N; cin >> N;
  vector<int> L(2*N);
  for (int i = 0; i < 2*N; i++) cin >> L.at(i);
  sort(L.begin(), L.end());
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += min(L.at(2*i), L.at(2*i+1));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
static const int MAX = 1000;
static const int di[4] = {0, -1, 0, 1};
static const int dj[4] = {1, 0, -1, 0};
bool T[MAX*MAX+1], P[MAX+1][MAX+1];
int G[MAX+1][MAX+1];
pair<int, int> C[MAX*MAX+1], dp[MAX+1][MAX+1];

void eratos( int n, bool prime[] ){
  for ( int i = 0; i <= n; i++ ) prime[i] = true;
  prime[0] = prime[1] = false;
  for ( int i = 2; i*i <= n; i++ ){
    if ( prime[i] )
      for ( int j = 2; i*j <= n; j++ ) prime[i*j] = false;
  }
}

void setp(int pi, int pj, int &p){
  P[pi][pj] = T[p];      
  C[p] = make_pair(pi, pj);
  G[pi][pj] = p++;
}

void init(){
  int pi = 500, pj = 500, p = 1;
  setp(pi, pj, p);
  for ( int r = 0;; r++ ){
    for ( int i = 0; i < r/2+1; i++ ){
      pi += di[r%4];
      pj += dj[r%4];
      setp(pi, pj, p);
      if ( p >= MAX*MAX ) return;
    }
  }
}

pair<int, int> solve(int pi, int pj, int m){
  if ( dp[pi][pj].first != -1 ) return dp[pi][pj];
  pair<int, int> v, res = make_pair(0, 0);

  for ( int j = -1; j <= 1; j++ ){
    int ni = pi + 1;
    int nj = pj + j;
    if ( ni > MAX || nj < 0 || nj > MAX ) continue;
    int np = G[ni][nj];
    if ( np > m ) continue;
    v = solve(ni, nj, m);
    res = max(res, v);
  }

  if ( 0 == res.second ){
    if ( P[pi][pj] ) return dp[pi][pj] = make_pair(1, G[pi][pj]);
    return dp[pi][pj] = res;
  } else {
    if ( P[pi][pj] ) res.first++;
    return dp[pi][pj] = res;
  }
}

main(){
  eratos(MAX*MAX+1, T);
  init();
  int m, n;
  while( cin >> m >> n ){
    if ( m == 0 && n == 0 ) break;
    for ( int i = 0; i < MAX+1; i++ )
      for ( int j = 0; j < MAX+1; j++ ) dp[i][j] = make_pair(-1, 0);
    pair<int, int> ans = solve(C[n].first, C[n].second, m);
    cout << ans.first << " " << ans.second << endl;
  }
}

Measured memory_bytes: 22780
#include<stdio.h>
#include<limits.h>
#define MAX 102
int d[MAX],color[MAX],pi[MAX],ar[MAX][MAX],sum=0;
void prim(int ,int);
int main(){
  int n,i,j;
scanf("%d",&n);
 
for(i=1;i<=n;i++){
  for(j=1;j<=n;j++){
    scanf("%d",&ar[i][j]);
    if(ar[i][j]==-1){
      ar[i][j]=INT_MAX;
    }
  }
 }
 prim(n,1);
 for(i=1;i<=n;i++){
   sum+=d[i];
 }
 printf("%d\n",sum);
}
void prim(int w,int r){
  int i,j,mincost,k;
  for(i=1;i<=w;i++){
    d[i]=INT_MAX;
    pi[i]=-1;
    color[i]=0;
  }
  d[r]=0;

  while(1){
    mincost=INT_MAX;
    for(j=1;j<=w;j++){
      if(color[j]!=1&&d[j]<mincost){
	mincost=d[j];
	i=j;
      }
    }
    if(mincost==INT_MAX){
      break;
    }
    color[i]=1;
    for(k=1;k<=w;k++){
      if(color[k]!=1&&ar[i][k]<d[k]){
	pi[k]=i;
	d[k]=ar[i][k];
      }
    }
  }
}



Measured memory_bytes: 2060
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#define rp(i,a,b) for(int (i)=(int)(a);i<(int)(b);++i)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll R=1000000000+7;
map<P, ll> M;
ll  rec(ll x,ll y){
    for(auto it = M.find(P(x,y)); it != M.end();) return it->second;
    if(x==0LL or y==0LL)  return 1LL;
    
    ll ans=0LL;
    if(x>=0LL and y>=0LL)ans+=rec(x/2LL,y/2LL);
    if(x>0LL and y>0LL) ans+=rec((x-1LL)/2LL,(y-1LL)/2LL);
    if(x>1LL and y>=0LL) ans+=rec((x-2LL)/2LL,(y)/2LL);
    ans%=R;
    return M[P(x,y)] = ans;
}
int main(){
    ll n;
    cin>>n;
    rec((ll)n,(ll)n);
    cout<<M[P((ll)n,(ll)n)]<<endl;    
        
};





Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;


int main() {
    int n, y;
    cin >> n >> y;
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= n - i; ++j) {
            int k = n - i - j;
            if (i * 10000 + j * 5000 + k * 1000 == y) {
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
//l={1,2,3,4}
//greater<int>()
//sort(l,l+N)

int main(void)
{
	char a, b, c, d;
	cin >> a >> b >> c >> d;
	
	if (b == c) {
		if (a == b || c == d)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <algorithm>
#include <queue>
#include <tuple>

using namespace std;

#define INT_MAX 2147483647
typedef long long ll;

ll gcd(ll m, ll n);
ll lcm(ll m, ll n);

int main(void) {

	int n;
	cin >> n;
	vector<tuple<string, int, int>> vt;

	for (int i = 1; i <= n; i++) {
		string str;
		int num;
		cin >> str >> num;
		num *= -1;
		auto t = tie(str, num, i);
		vt.push_back(t);
	}
	sort(vt.begin(), vt.end());

	for (auto i : vt) {
		cout << get<2>(i) << endl;
	}


	return 0;

}

// 2番目から3要素だけ抜き出した部分文字列を取得する
//std::string result = s.substr(2, 3);  
#if 1
//最大公倍数
ll gcd(ll m, ll n)
{
	ll temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

//最小公倍数
ll lcm(ll m, ll n)
{
	return m * n / gcd(m, n);
}
#endif

Measured memory_bytes: 256
package main

import (
    "fmt"
)

func main() {
    var n int
    fmt.Scanf("%d", &n)

    res := 0
    for i := 0; i < n; i++ {
        var l int
        var r int
        fmt.Scanf("%d %d", &l, &r)
        res += r-l+1
    }

    fmt.Printf("%d\n", res)
}


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

int main()
{
    int a,b;
    cin >> a >> b;
    if ((b%a)==0){
        cout << a+b;
    }else{
        cout << b-a;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Roc ios_base::sync_with_stdio(false), cin.tie(NULL)
#define ll long long
#define NMAX 3009
using namespace std;
double pd[NMAX][NMAX], v[NMAX], ans;
int n, cat;

int main()
{
    Roc;
    cin >> n;
    cat = (n + 1) / 2;
    for(int i = 1; i <= n; ++i)
        cin >> v[i];
    pd[0][0] = 1.00000;
    for(int i = 1; i <= n; ++i)
        for(int j = 0; j <= i; ++j)
        {
            if(j > 0)
                pd[i][j] += pd[i-1][j-1] * v[i];
            pd[i][j] += pd[i-1][j] * (1.0000 - v[i]);
        }
    for(int i = cat; i <= n; ++i)
        ans += pd[n][i];
    cout << setprecision(10) << ans << '\n';
    return 0;
}


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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

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


int n, m, q, l[200000], r[200000], num[501][501] = {0};
P p[100000];

int main(){
	cin >> n >> m >> q;
	for(int i = 0; i < m; i++){
		cin >> l[i] >> r[i];
		num[l[i]][r[i]]++;
	}
	for(int i = 0; i < q; i++){
		cin >> p[i].first >> p[i].second;
	}
	
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			num[i][j] += num[i][j-1];
		}
	}
	for(int i = 1; i <= n; i++){
		for(int j = n-1; j >= 0; j--){
			num[j][i] += num[j+1][i];
		}
	}
	
	for(int i= 0; i < q; i++){
		cout << num[p[i].first][p[i].second] << endl;
	}
	
	return 0;
}

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

int main(){
    ll n;
    cin >> n;
    vector <ll> a(n);
    vector <vector <ll>> a2(n,vector <ll> (2));

    rep(i,n){
        cin >> a[i];
        a2[i][0]=a[i];
        a2[i][1]=i+1;
    }

    sort(a2.rbegin(),a2.rend());

    vector <vector <ll>> dp(n+1,vector <ll>(n+1,0));
    dp[1][1]=a2[0][0]*abs(a2[0][1]-n);
    dp[1][0]=a2[0][0]*abs(a2[0][1]-1);

    ll ans=0;
    ll ko1,ko2;
    rep(i,n+1){
        if(i>1){
            rep(j,i+1){
                if(j==0){
                    dp[i][j]=dp[i-1][j]+a2[i-1][0]*abs(a2[i-1][1]-(i));
                }
                else if(j==i){
                    dp[i][j]=dp[i-1][j-1]+a2[i-1][0]*abs(a2[i-1][1]-(n-i+1));
                }
                else{
                ko1=dp[i-1][j-1]+a2[i-1][0]*abs(a2[i-1][1]-(n-j+1));
                ko2=dp[i-1][j]+a2[i-1][0]*abs(a2[i-1][1]-(i-j));
                dp[i][j]=max(ko1,ko2);
                
            }
                if(i==n){
                    ans=max(ans,dp[i][j]);
                }
                //cout << i << " " << j << " " << dp[i][j] << endl;

            }
        }
    }

    //cout << dp[1][0] << endl;

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 34656
#include<iostream>

using namespace std;

int main(){

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


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;

class fenwick_tree
{
public:
  vector<int> cnt; int n;
  fenwick_tree(int _n)
  {
    n = _n;
    cnt.assign(n + 5, 0);
  }
  void update(int i, int v)
  {
    for (; i <= n; i += i & -i)
      cnt[i] += v;
  }
  int sum(int i)
  {
    int res = 0;
    for (; i; i -= i & -i)
      res += cnt[i];
    return res;
  }
};

const int maxn = 1e5 + 5;

int N, M;
vector<int> d[maxn];
vector<int> era[maxn];
int ans[maxn], add[maxn];

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  if (fopen("A.INP", "r")){
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  }
  for (int i = 1; i < maxn; ++i){
    for (int j = i; j < maxn; j += i){
      d[j].pb(i);
    }
  }
  cin >> N >> M;
  fenwick_tree ft(M);
  while (N--){
    int l, r; cin >> l >> r;
    ++add[l]; era[r].pb(l);
  }
  for (int i = 1; i <= M; ++i){
    ft.update(i, add[i]);
    for (int x : d[i]){
      ans[x] += ft.sum(i) - ft.sum(i - x);
    }
    for (int x : era[i]){
      ft.update(x, -1);
    }
  }
  for (int i = 1; i <= M; ++i){
    cout << ans[i] << '\n';
  }
}


Measured memory_bytes: 17280
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int n,t,min=1000000009;
  cin>>n>>t;
  vector<int> a(n),b(n);
  std::map<int, int> mp;
  for (int i = 0; i < n; ++i)
  {
    cin>>a[i];
    b[i] = (min>a[i] ? 0:a[i]-min); 
    min=std::min(min,a[i]);
    mp[b[i]]++;
  }
  sort(b.begin(), b.end());
  cout<<mp[b.back()];
}

Measured memory_bytes: 5760
fn main() {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();

    let n = input.trim().parse::<i32>().unwrap();

    let mut cake = 0;
    loop {
        let nokori = n - cake * 4;
        if nokori < 0 {
            println!("No");
            return;
        }

        if nokori % 7 == 0 {
            println!("Yes");
            return;
        }

        cake += 1;
        continue;
    }
}


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

int main(){
    int a, b;
    string op;
    while(1){
        cin >> a >> op >> b;
        if (op == "?"){
            break;
        } else if (op == "+"){
            cout << a + b << endl;
        } else if (op == "-"){
            cout << a - b << endl;
        } else if (op == "/"){
            cout << a / b << endl;
        } else {
            cout << a * b << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3136
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define rep(i,l,n) for(int (i)=(l);(i)<(n);(i)++)
#define min(a,b) (a)<(b)?(a):(b)
#define max(a,b) (a)>(b)?(a):(b)
#define abs(a) (a)>0?(a):-(a)
#define ll long long

int main(){
	ll N,K; scanf("%lld %lld",&N,&K);
	N %= K;
	printf("%lld",min(N,abs(N-K)));
	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;
import java.util.stream.IntStream;
 
public class Main{
	static IntStream REPS(int v){return IntStream.range(0,v);}
	static IntStream REPS(int l,int r){return IntStream.rangeClosed(l,r);}
	static IntStream INS(int n) {return REPS(n).map(i->getInt());}
	static Scanner s=new Scanner(System.in);
	static int getInt(){return Integer.parseInt(s.next());}
 
	public static void main(String[]$){
		int
		a=getInt(),
		b=getInt(),
		c=getInt(),
		d=getInt(),
		e=getInt(),
		f=getInt();
 
		int rw=100*a,rs=0;
		double max=0;
 
		for(int i=0;true;++i) {
			int va=100*a*i;
			if(va>f)
				break;
			for(int j=0;true;++j) {
				int vb=100*b*j;
				if(va+vb>f)
					break;
				for(int k=0;true;++k) {
					int vc=c*k;
					if(va+vb+vc>f)
						break;
					for(int l=0;true;++l) {
						int vd=d*l;
						if(va+vb+vc+vd>f)
							break;
						if(max<calc(va+vb,vc+vd,e)) {
							max=calc(va+vb,vc+vd,e);
							rw=va+vb;
							rs=vc+vd;
						}
					}
				}
			}
		}
		System.out.println(rw+rs+" "+rs);
	}
	private static double calc(int w,int s,int e){
		double r=w==0?0:100.0*s/(w+s);
		return w/100*e<s?0:r;
	}
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
//#define int long long
int abs(int a,int b){
  int c=max(a,b)-min(a,b);
  return c;
}
priority_queue<int, vector<int>, greater<int> > qu;
signed main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a,b,c;
  int d=0,e=0;
  cin>>a>>b>>c;
  for(int i=0;i<c;i++){
    if(i%2==0){
      if(a%2==1) a--;
      a/=2;
      b+=a;
    }
    else{
      if(b%2==1) b--;
      b/=2;
      a+=b;
    }
  }
  cout<<a<<" "<<b<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using ll = long long;
using vll = vector<ll>;
const ll INF = 1e15 + 5;


int main() {
	int n; cin >> n;
	vector<double> p(n + 1);
	for (int i = 1; i <= n; i++) cin >> p[i];
	vector<vector<double>> dp(n + 1, vector<double>(n + 1));
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++){
		for (int j = 0; j <= i; j++){
			dp[i][j] = dp[i - 1][j] * (1 - p[i]);
			if (j){
				dp[i][j] += dp[i - 1][j - 1] * p[i];
			}
		}
	}
	double ans = 0;
	for (int i = n / 2 + 1; i <= n; i++){
		ans += dp[n][i];
	}
	cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 70784
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		for (int i = 1; i <= n; i++) {
			int tmp = i;

			if ( i % 3 == 0 ) {
				System.out.print(" " + i );
				continue;
			}

			while (tmp > 1) {
				if ( tmp % 10 == 3 ) {
					System.out.print(" " + i );
					break;
				}

				tmp /= 10;
			}
		}
		System.out.println();
		sc.close();

	}

}



Measured memory_bytes: 28616
N,M = map(int,input().split())

from heapq import heappush, heappop
INF = float("inf")
miti = [-1]*N
def dijkstra(N, G, s):
    dist = [INF] * N
    que = [(0, s)]
    dist[s] = 0
    while que:
        c, v = heappop(que)
        if dist[v] < c:
            continue
        for t, cost in G[v]:
            if dist[v] + cost < dist[t]:
                dist[t] = dist[v] + cost
                if miti[t] == -1:
                    miti[t] = v+1
                heappush(que, (dist[t], t))
    return dist

edge = [[] for _ in range(N)]

for _ in range(M):
    a,b = map(int,input().split())
    edge[a-1].append((b-1,1))
    edge[b-1].append((a-1,1))

dist = dijkstra(N,edge,0)

print("Yes")
for t in miti[1:]:
    print(t)

Measured memory_bytes: 107624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <cstdlib>
#include <random>
#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;

const ll MAX_N=2*100000;

ll N,a[MAX_N];

int main(){
  cin>>N;
  ll tmp;
  for(ll i=0;i<N;i++){
    cin>>tmp;
    if(i==0)a[i]=tmp;
    else a[i]=a[i-1]+tmp;
  }
  ll ans=inf;
  ll first_last=0,third_last=2;
  for(ll second_last=1;second_last<N-2;second_last++){
    while(a[first_last]<=a[second_last]-a[first_last])first_last++;
    //first_last--;
    while(a[third_last]-a[second_last]<=a[N-1]-a[third_last])third_last++;
    //third_last--;
    ll n_max=max(a[N-1]-a[third_last],max(a[third_last]-a[second_last],max(a[first_last],a[second_last]-a[first_last])));
    ll n_min=min(a[N-1]-a[third_last],min(a[third_last]-a[second_last],min(a[first_last],a[second_last]-a[first_last])));
    ans=min(ans,n_max-n_min);

    if(first_last!=0){
      n_max=max(a[N-1]-a[third_last],max(a[third_last]-a[second_last],max(a[first_last-1],a[second_last]-a[first_last-1])));
      n_min=min(a[N-1]-a[third_last],min(a[third_last]-a[second_last],min(a[first_last-1],a[second_last]-a[first_last-1])));
      ans=min(ans,n_max-n_min);
    }
    if(third_last-1!=second_last){
      n_max=max(a[N-1]-a[third_last-1],max(a[third_last-1]-a[second_last],max(a[first_last],a[second_last]-a[first_last])));
      n_min=min(a[N-1]-a[third_last-1],min(a[third_last-1]-a[second_last],min(a[first_last],a[second_last]-a[first_last])));
      ans=min(ans,n_max-n_min);
    }
    if(first_last!=0&&third_last-1!=second_last){
      n_max=max(a[N-1]-a[third_last-1],max(a[third_last-1]-a[second_last],max(a[first_last-1],a[second_last]-a[first_last-1])));
      n_min=min(a[N-1]-a[third_last-1],min(a[third_last-1]-a[second_last],min(a[first_last-1],a[second_last]-a[first_last-1])));
      ans=min(ans,n_max-n_min);
    }

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


Measured memory_bytes: 1792
#include<iostream>

using namespace std;

typedef long long ll;

const long maxn=200005;
const ll maxv=1e9+5;

long sum=0;

void Merge(ll*a,long left,long mid,long right)
{
    long n1=mid-left,n2=right-mid;
    ll *L,*R;
    L=new ll [n1+1];R=new ll [n2+1];
    for(long i=0;i<n1;i++)
        L[i]=a[left+i];
    for(long j=0;j<n2;j++)
        R[j]=a[mid+j];
    L[n1]=R[n2]=maxv;
    long m=0,n=0;
    for(long i=left;i<right;i++)
    {
        if(L[m]<=R[n]){a[i]=L[m];m++;}
        else
        {
            sum+=n1-m;
            a[i]=R[n];
            n++;
        }
    }
}

void Merge_Sort(ll*a,long left,long right)
{
    if(left<right-1)
    {
        long mid=(left+right)/2;
        Merge_Sort(a,left,mid);
        Merge_Sort(a,mid,right);
        Merge(a,left,mid,right);
    }
}


int main()
{
    long n;
    ll a[maxn];
    cin>>n;
    for(long i=0;i<n;i++)
        cin>>a[i];
    Merge_Sort(a,0,n);
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 40724
MOD = 2019

s = gets.chomp.chars.map(&:to_i)

d = Hash.new(0)
cur = s[-1]
d[0] += 1
d[cur] += 1

md = 1
(s.size - 1).times do |i|
  md = (md * 10) % MOD
  cur = (cur + s[- (i + 2)].to_i * md) % MOD
  d[cur] += 1
end

puts d.values.map {|v| v * (v - 1) / 2}.inject(:+)



Measured memory_bytes: 26368
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		int n=sc.nextInt();
		int[] in=new int[n];
		for (int i=0;sc.hasNext();i++)
			in[i]=sc.nextInt();
		
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < i; j++) {
				if (in[i] < in[j]) {
					int tmp = in[i];
					for (int l=i; l > j; l--)
						in[l] = in[l - 1];
					in[j] = tmp;break;
					}

			}System.out.print(in[0]);
					for (int l = 1; l < n; l++)
						System.out.print(" " + in[l]);
					System.out.println();
		}

	}

}

Measured memory_bytes: 24548
#include <stdio.h>
int main(void){
    // Your code here!
    
    int n,x;
    scanf("%d %d",&n,&x);
    
    int l[n],i,d=0;
    int c=0;
    for(i=0;i<n;i++) {
        scanf("%d",&l[i]);
    }
    
    for(i=0;i<n+1;i++){
        if(d <= x) c++;
        d += l[i];
    }
    
    printf("%d\n",c);
    
    return  0;
}

Measured memory_bytes: 128
#include <iostream>

int main()
{
    int x, y;
    std::cin >> x >> y;
    
    if (x > y) {
        std::cout << "a > b" << std::endl;
    } else if (x == y) {
        std::cout << "a == b" << std::endl;
    } else {
        std::cout << "a < b" << std::endl;
    }
}


Measured memory_bytes: 3120
// 2011/04/06 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int a, b, n;
		cin >> a;
		if(cin.eof())
			break;
		cin >> b >> n;

		int s = 0;
		a = a%b;
		for(int i=1; i<=n; i++){
			a *= 10;
			s += a/b;
			a = a%b;
		}

		cout << s << endl;
	}

	return 0;
}

Measured memory_bytes: 0
from heapq import heappush, heappop
INF = 10**10


def dijkstra(G, H, W):
    dist = [INF] * (10 ** 4)
    que = [(0, 0)]
    dist[0] = 0
    while que:
        c, v = heappop(que)
        if dist[v] < c:
            continue
        for t, cost in G[v]:
            if dist[v] + cost < dist[t]:
                dist[t] = dist[v] + cost
                heappush(que, (dist[t], t))
    return dist[(H-1)*100+W-1]


def Gragh(H, W, S):
    G = [[] for _ in range(10**4)]
    for i in range(H-1):
        for j in range(W-1):
            if S[i][j] == "." and S[i+1][j] == "#":
                G[100 * i + j].append((100 * (i + 1) + j, 1))
            else:
                G[100 * i + j].append((100 * (i + 1) + j, 0))

            if S[i][j] == "." and S[i][j+1] == "#":
                G[100 * i + j].append((100 * i + j + 1, 1))
            else:
                G[100 * i + j].append((100 * i + j + 1, 0))

        for i in range(H - 1):
            if S[i][-1] == "." and S[i+1][-1] == "#":
                G[100*i+W-1].append((100*(i+1)+W-1, 1))
            else:
                G[100 * i + W-1].append((100 * (i + 1) + W-1, 0))

        for j in range(W-1):
            if S[-1][j] == "." and S[-1][j + 1] == "#":
                G[100 * (H-1) + j].append((100 * (H-1) + j + 1, 1))
            else:
                G[100 * (H-1) + j].append((100 * (H-1) + j + 1, 0))
    return G


H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(input())

G = Gragh(H, W, S)

if S[0][0] == "#":
    ans = dijkstra(G, H, W) + 1
    print(ans)
else:
    ans = dijkstra(G, H, W)
    print(ans)

Measured memory_bytes: 59992
#include <stdio.h>


int main(void){

        int k;
        scanf("%d",&k);
        int a,b;
        scanf("%d%d",&a,&b);
        int judge = 0;

        for(int i=a;i<=b;i++){
                if(i%k == 0){ 
                        printf("OK\n");
                        judge = 1;
                        break;
                }   
        }   

        if(judge==0){
                printf("NG\n");
        }   

return 0;
}


Measured memory_bytes: 1664
#include <iostream>
// #include <cassert>
#include <vector>
#include <algorithm>
#include <climits>

// #include <stack>
// #include <queue>
// #include <deque>
// #include <set>
// #include <map>
// #include <string>
// #include <unordered_set>
// #include <unordered_map>

// #include <tuple>
// #include <cmath>
// #include <numeric>

using namespace std;
typedef long long ll;
typedef pair<long,long> pll;
typedef pair<int,int> pii;
typedef pair<int,long> pil;
typedef pair<long,int> pli;
typedef vector<vector<long long>> vvll;
typedef vector<vector<long>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;

#define emplace_back pb
const char el = '\n';

/*
Edge cases:


*/

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

    ll T; cin>>T; cin.ignore();

    ll happiness = 0;

    happiness += (T/500)*(ll)1000;
    happiness += ((T%500)/5)*(ll)5;

    cout<<happiness<<el;

}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int n;
	string s;
	cin >> s;
	n = s.size();
	reverse(s.begin(), s.end());
	int p = 2019;
	int t = 1;
	vector<int> c(n + 1);
	rep (i, n) {
	  c[i + 1] = t * (s[i] - '0');
	  t *= 10;
	  t %= p;
	}
	rep (i, n) {
	  c[i + 1] += c[i];
	  c[i + 1] %= p;
	}
	ll res = 0;
	map<int, int> mp;
	rep (i, n + 1) res += mp[c[i]]++;
	cout << res << endl;
    
    return 0;
}


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

int main()
{
	multiset<long long> s;	
	long q;

	cin >> q;

	for (long i = 0; i < q; i++) {
		int t;
		long long x;
		cin >> t >> x;

		if (t == 0) {
			s.insert(x);
			cout << s.size() << endl;
		}
		else if (t == 1)
			cout << s.count(x) << endl;
		else if (t == 2)
			s.erase(x);
		else if (t == 3) {
			long long y;
			std::set<long long>::iterator it;

			cin >> y;

			for (it = s.lower_bound(x); it != s.upper_bound(y); it++)
				cout << *it << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 12376
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <climits>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << -1; return;}
#define yes {cout << "Yes"; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if(0) cerr

void solve() {
    int n; cin >> n;
    string s; cin >> s;
    if (n % 2)
        cout << "No";
    else
        cout << (s.substr(0, n / 2) == s.substr(n / 2, n / 2) ? "Yes" : "No");
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3640
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	int n;
	while(cin >> n) {
		vector<int> a(n);
		REP(i,n) cin >> a[i];
		vector<int> cnt(101010);
		REP(i,n){
			cnt[a[i]]++;
			cnt[a[i]+1]++;
			cnt[a[i]+2]++;
		}
		int ans = 0;
		REP(i,SZ(cnt)){
			chmax(ans,cnt[i]);
		}
		cout << ans << endl;
	}
	return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin() x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin() x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, ans=0; cin>>n;
	vll h(n);
	rep(i, n) cin>>h[i];
	h.pb(0);
	rep(i, 100){
		ll left = 0, right;
		rep(i, n+1){
			if (h[i]==0){
				right = i-1;
				if (left<=right) ans++;
				left = i+1;
			}else{
				h[i]--;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++) 
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    //ll N; cin >> N;
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    int H,W;
    cin >> H >> W;
    int a[H][W];
    int b[H][W];
    int n=0;
    rep(i,H){
        rep(j,W){
            cin >> a[i][j];
          	b[i][j]=a[i][j];
        }
    }
    rep(i,H){
        rep(j,W){
            if(i%2==0 && a[i][j]%2==1){
                if(j==W-1 && i!=H-1){
                    a[i+1][j]++;
                    n++;
                }
                else if(j!=W-1){
                    a[i][j+1]++;
                    n++;
                }
            }
            else if(i%2==1 && a[i][W-j-1]%2==1){
                if(W-j-1==0 && i!=H-1){
                    a[i+1][W-j-1]++;
                    n++;
                }
                else if(W-j-1!=0){
                    a[i][W-j-2]++;
                    n++;
                }
            }
        }
    }
    cout << n << endl;
    rep(i,H){
        rep(j,W){
            if(i%2==0 && b[i][j]%2==1){
                if(j==W-1 && i!=H-1){
                    cout << i+1 << ' ' << j+1 << ' ' << i+2 << ' ' << j+1 << endl;
                    b[i+1][j]++;
                }
                else if(j!=W-1){
                    cout << i+1 << ' ' << j+1 << ' ' << i+1 << ' ' << j+2 << endl;
                    b[i][j+1]++;
                }
            }
            else if(i%2==1 && b[i][W-j-1]%2==1){
                if(W-j-1==0 && i!=H-1){
                    cout << i+1 << ' ' << W-j << ' ' << i+2 << ' ' << W-j << endl;
                    b[i+1][W-j-1]++;
                }
                else if(W-j-1!=0){
                    cout << i+1 << ' ' << W-j << ' ' << i+1 << ' ' << W-j-1 << endl;
                    b[i][W-j-2]++;
                }
            }
        }
    }

}

/*



 */



Measured memory_bytes: 4096
#include<iostream>
using namespace std;
#define MAX 260

int parent(int i) { return i / 2; }
int left(int i) { return 2 * i; }
int right(int i) { return 2 * i + 1; }

int main()
{
	int H, i, A[MAX + 1];
	cin >> H;
	for (i = 1; i <= H; i++) {
		cin >> A[i];
	}
	for (i = 1; i <= H; i++) {
		cout << "node " << i << ": key = " << A[i]<<", ";
		if (parent(i) >= 1) {
			cout << "parent key = " << A[parent(i)] << ", ";
		}
		if (left(i) <= H) {
			cout << "left key = " << A[left(i)] << ", ";
		}
		if (right(i) <= H) {
			cout << "right key = " << A[right(i)] << ", ";
		}
		cout << endl;
	}
    return 0;
}

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

class Program
{

    static int CountLetter(char s, List<char> letter2)
    {
        int count = 0;

        for (int i = 0; i < letter2.Count; i++)
        {
            if (letter2[i] == s || letter2[i] == Char.ToUpper(s))
            {
                count++;
            }
        }
        
        return count;
    }


    static void Main(string[] args)
    {
        string str = "abcdefghijklmnopqrstuvwxyz";
        var letter = new List<char>();
       
        do
        {           
            string input = Console.ReadLine();
            if (string.IsNullOrEmpty(input))
            {
                break;
            }

            foreach(var s in input)
            {
                letter.Add(s);
            }         
            
        } while (true);

        int count = 0;
      
        foreach (var s in str)
        {
            count = CountLetter(s, letter);
            Console.WriteLine($"{s} : {count}");
        }                                
    }
}


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

public class Program
{

	static void Main(string[] args)
	{
		var array = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
		var jumpArray = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
		var count = 1;
		var total = 0;
		for (int i = 0; i < array[0]; i++)
		{
			total += jumpArray[i];
			if (total <= array[1])
			{
				count++;
			}
		}

		Console.WriteLine(count);
	}
}


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

int to_bit(int n);

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

    bitset<10> b;
    b.set();
    int a;
    for(int i=0;i<k;i++){
        cin >> a;
        b.reset(a);
    }
    for(int i=n;i<10*n;i++){
        bitset<10> d(to_bit(i));
        if(b==(b | d)){
            cout << i << endl;
            break;
        }
    }
}

int to_bit(int n){
    int N = to_string(n).length();
    bitset<10> c;
    c.reset();
    while(n>0){
        int t = n%10;
        n /=10;
        c.set(t);
    }
    return c.to_ullong();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b, c;
    ll k;
    cin >> a >> b >> c >> k;
    if (k%2 == 0) cout << a - b << endl;
    else cout << b - a << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		int n = Integer.parseInt(str[0]);
		long m = Long.parseLong(str[1]);

		long a[] = new long[n];

		str = br.readLine().split(" ");
		for (int i = 0; i < n; i++) {
			a[i] = Long.parseLong(str[i]) / 2;
		}
		while (a[0] % 2 == 0) {
			for (int i = 0; i < n; ++i) {
				if (a[i] % 2 != 0) {
					System.out.println("0");
					return;
				}
				a[i] /= 2;
			}
			m /= 2;
		}

		for (int i = 0; i < n; ++i) {
			if (a[i] % 2 == 0) {
				System.out.println("0");
				return;
			}
		}

		long lcm = 1;
		for (int i = 0; i < n; ++i) {
			long g = gcd(lcm, a[i]);
			lcm = lcm / g * a[i];
			if (lcm > m) {
				System.out.println("0");
				return;
			}
		}
		System.out.println((m / lcm + 1) / 2);
	}

	static long gcd(long m, long n) {
		if (m < n)
			return gcd(n, m);
		if (n == 0)
			return m;
		return gcd(n, m % n);
	}

	static Map<Long, Integer> primeFactorization(long n) {
		Map<Long, Integer> map = new HashMap<>();
		for (long p = 2; p * p <= n; p++) {
			if (n % p != 0)
				continue;
			int cnt = 0;
			while (n % p == 0) {
				cnt++;
				n = n / p;
			}
			map.put(p, cnt);
		}
		if (n > 1)
			map.put(n, 1);

		return map;
	}
}


Measured memory_bytes: 46932