akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
inline int max(int a , int  b){
  if(a > b) return a;
  else return b;

}
int min(int a , int b){
  if(a < b) return a;
  else return b;
}

long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int gcd(int a , int b){
  if (b == 0) 
        return a; 
    return gcd(b, a % b);
}

int32_t main() 
{ 
  fast;
  int a,b,v,w ,t;
  cin >> a >> v;
  cin >>  b >> w;
  cin >> t;
  if(w >= v) cout << "NO\n";
  else {
    if(a>b){
        if( a-t*v <= b-t*w) cout << "YES\n";
        else cout << "NO\n";
    }
    else{
        if(a+t*v >= b+t*w) cout << "YES\n";
        else cout << "NO\n";
    }
  } 
  return 0;
} 
/*
    x dia y shovels
  2*y + y = y emarald
  x + 2*x = x emarld
  2*y + x <=a 
  y+2*x <=b 
  500 + 250 
  2*a + b ~ x
  a + 2*b ~ y
  max(a+b)
  2*x+y
  x+2*y
  1-2-3
  [ 1-2 2-3 ]

   
   
  1-2-3-4

*/
 

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int main(){
  int N;  cin>>N;
  vector<int> a(N), b(N);
  rep(i,0,N) cin>>a[i]>>b[i];
  ll x=1;
  rep(i,1,N){
    x = max(((a[i-1]*x+a[i]-1))/a[i], ((b[i-1]*x+b[i]-1))/b[i]);
  }
  cout << (a.back()+b.back())*x << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
//#include<cstring>
using namespace std;
const int maxn=1e5+10;
int dp[maxn][5];
int main()
{
	int a[maxn],b[maxn],c[maxn];
	int n;
	cin>>n;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i]>>b[i]>>c[i];
	}
	//memset(dp,0,sizeof(0));
	dp[1][0]=a[1];
	dp[1][1]=b[1];
	dp[1][2]=c[1];
	for(int i=2;i<=n;++i)
	{
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
		dp[i][2]=max(dp[i-1][1],dp[i-1][0])+c[i];
		
			//cout<<dp[i][0]<<endl<<dp[i][1]<<endl<<dp[i][2]<<endl;
			//cout<<endl;
		
	}
	
	//cout<<dp[n][0]<<endl<<dp[n][1]<<endl<<dp[n][2]<<endl;
	
	dp[n][0]=max(dp[n][0],dp[n][1]);
	dp[n][0]=max(dp[n][0],dp[n][2]);
	cout<<dp[n][0]<<endl;
	return 0;
}

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

//LIFE IS NOT A PROBLEM TO BE SOLVED

#define rep(i,a,b) for( int i = (int) a; i < (int) b; i++ )
#define F first
#define S second
#define pb push_back
#define debug(a) cout << #a << " = " << a << endl;
#define debug2(a,b) cout << #a << " = " << a << " --- " << #b << " = " << b << endl;
#define debugP(a) cout << a.F << " " << a.S << endl;
#define debugM(mat,n,m) rep( i, 0, n ){ rep( j, 0, m ) cout << mat[i][j] << " "; cout << endl; }
#define all(s) s.begin(), s.end()

using namespace std;

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

int main(){

	int a, b, c; cin >> a >> b >> c;
	cout << min(c, b/a)	 << '\n';
	return 0;
}

Measured memory_bytes: 256
import math
n,p=map(int,input().split())
x=p
pf={}
for i in range(2,int(math.sqrt(p))+1):
    cnt=0
    while x%i==0:
        cnt+=1
        pf[i]=cnt
        x/=i
if x!=1:
    pf[int(x)]=1

ans=1
for i in pf:
    e=pf[i]//n
    if e!=0:
        ans*=(i**e)
print(ans)

Measured memory_bytes: 9136
//************************
//*  Date: 2018.9.22     *
//*  Problem:            *
//*  Author: xuziyuan    * 
//************************

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

string s,t;
int num[1000],num2[1000];

int main()
{
	cin>>s>>t;
	memset(num,-1,sizeof(num));
	memset(num2,-1,sizeof(num2));
	rep(i,s.size())
	{
		if(num[s[i]]==-1)
		{
			num[s[i]]=t[i];
			continue;
		}
		if(num[s[i]]!=t[i])
		{
			//cout<<i<<' '<<t[i]<<endl;
			puts("No");
			rt0;
		}
	}
	rep(i,s.size())
	{
		if(num2[t[i]]==-1)
		{
			num2[t[i]]=s[i];
			continue;
		}
		if(num2[t[i]]!=s[i])
		{
			//cout<<'p'<<i<<' '<<t[i]<<endl;
			puts("No");
			rt0;
		}
	}
	puts("Yes");
	rt0;
}

Measured memory_bytes: 776
int main(){
    int minus[200010],plus[200010];
    int a[200010];
	int n;
	scanf("%d",&n);
	long long ans=0;
	for(int i=0;i<n;i++)scanf("%d",a+i);
	for(int i=0;i<n;i++){
		if(i+a[i]<=n)ans+=minus[i+a[i]];
		if(i-a[i]>=0)ans+=plus[i-a[i]];
		if(i+a[i]<=n)plus[i+a[i]]++;
		if(i-a[i]>=0)minus[i-a[i]]++;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 4056
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<set>
#include<utility>
#include<queue>
#include<stdio.h>
//#include<sys/time.h>
#include<random>
#include<fstream>
#define INF 2000000000
using namespace std;
typedef std::pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
int n,ans;
signed main(){
	string s;
	cin>>s;
	if(s[s.size()-1]=='s')cout<<s<<"es"<<endl;
	else cout<<s<<"s"<<endl;
}


Measured memory_bytes: 3596
#include <stdio.h>
 
int main() {
  char ch[250]={0};
  char a[250] ={0};
  int h;
  int i,j,k,l,n,m;
 
 
  while(1){
    i=0;
    while(1){
       
      scanf("%c",&ch[i]);
      if(ch[i] == '\n') {    
    break;
      }
       
      i++;
    }
    
    if ( i == 1 && ch[0] == '-' ) break;
     
    scanf("%d",&m);
     
    for(j=0;j<m;j++){
      scanf("%d", &h );
       
      for(k=0;k<i-h;k++) {
    a[k] = ch[h+k];
      }
      for(k=0;k<h;k++){
    a[i-h+k] = ch[k];
      }
      for(k=0; k<i; k++){
    ch[k] = a[k];
      }
    }
    for(k=0;k<i;k++) {
      printf("%c",ch[k]);
    }
    printf("\n");
      scanf("%c",&ch[0]);
  }
   
   
  return 0;
   
}


Measured memory_bytes: 2056
N = int(input())

def get_soinsu(n,d = None):
    if d == None:
        d = {}
    if n == 1 :
        return d
    for i in (3,5,7,11,13):
        if n%i == 0:
            d[i] = d.get(i,0) + 1
            break
    else:
        return {n:1}
    return get_soinsu(n//i,d)

out = 0
for i in range(105,N+1,2):
    tmp = get_soinsu(i)
    p = 1
    for j in tmp.values():
        p *= (j+1)
    if p == 8:
        out += 1
print(out)

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, T = MAP()
A = LIST()

# 現在の状態での最大利益を求める
mn = INF
base = -INF
for a in A:
    base = max(base, a - mn)
    mn = min(mn, a)

# 最大を作れるペアがあったら潰していく
S = set()
ans = 0
for a in A:
    if a-base in S:
        ans += 1
        S.remove(a-base)
    S.add(a)
print(ans)


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


int main() {
 	unsigned long int n; 
	cin >> n;
	unsigned long int ans = 0;
    int a[n];
  	int max = 0;
  
  for(int i=0; i<n; i++) 
  {
    cin >> a[i];
  	if(a[i] > max)
    {
      max = a[i];
    }
    else
    {
      ans += max-a[i];
    }

  }

  cout << ans << endl;
}

Measured memory_bytes: 4400
n, m = map(int, input().split())
l = [0 for _ in range(n)]
ans = 0
for _ in range(m):
    s, c = map(int, input().split())
    if n > 1 and s == 1 and c == 0:
        ans = -1
    if l[s - 1] == 0 or l[s - 1] == c:
        l[s - 1] = c
    else:
        ans = -1
if n > 1 and l[0] == 0:
    l[0] = 1

if ans == -1:
    print(-1)
elif n == 3:
    print(l[0] * 100 + l[1] * 10 + l[2])
elif n == 2:
    print(l[0] * 10 + l[1])
else:
    print(l[0])


Measured memory_bytes: 3064
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <bitset>
#include <queue>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define sqr(x) (x)*(x)
typedef long long ll;

int main() {
    string s;
    cin >> s;
    sort(all(s));
    if(s.substr(0,1) == s.substr(1,1) && s.substr(2,1) == s.substr(3,1) && s.substr(0,1) != s.substr(3,1)) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}

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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

const int MOD = 998244353;

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> a(N, vector<int>(M));
    rep(i, N) rep(j, M) scanf("%d", &a[i][j]);
    int k = 0;
    rep(j, M) {
        int i0;
        for (i0 = k; i0 < N && !a[i0][j]; i0++);
        if (i0 == N) continue;
        swap(a[k], a[i0]);
        for (int i = k + 1; i < N; i++)
            if (a[i][j])
                rep(j, M)
                    a[i][j] ^= a[k][j];
        k++;
    }
    int rank = k;
    vector<ll> pow2(N + M + 1);
    pow2[0] = 1;
    rep(x, N + M) pow2[x + 1] = pow2[x] * 2 % MOD;
    ll ans = (pow2[N] - pow2[N - rank]) * pow2[M - 1] % MOD;
    cout << (ans + MOD) % MOD << endl;
}


Measured memory_bytes: 640
#include<iostream>

using namespace std;

int main() {
	int W, H, x, y, r;
	cin >> W;
	cin >> H;
	cin >> x;
	cin >> y;
	cin >> r;
	if (x >= r && y >= r && x <= W - r && y <= H - r) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e15+7;

signed main(){
	int n, m, q;
	cin >> n >> m >> q;
	vector<i64> a(n), b(m);
	for(auto& x : a)
		cin >> x;
	for(auto& x : b)
		cin >> x;
	for(int i = 0; i < 10; ++i){
		a.emplace_back(-INF - i);
		a.emplace_back(INF + i);
		b.emplace_back(-INF - i);
		b.emplace_back(INF + i);
	}

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

	for(int i = 0; i < q; ++i){
		i64 p;
		cin >> p;
		i64 ans = 1e18;
		// a1
		auto a2 = *lower_bound(a.begin(), a.end(), p);
		auto a21 = *prev(upper_bound(b.begin(), b.end(), a2));
		auto a22 = *lower_bound(b.begin(), b.end(), a2);
		ans = min(ans, abs(a2 - p) + abs(a2 - a21));
		ans = min(ans, abs(a2 - p) + abs(a2 - a22));

		auto a1 = *prev(upper_bound(a.begin(), a.end(), p));
		auto a11 = *prev(upper_bound(b.begin(), b.end(), a1));
		auto a12 = *lower_bound(b.begin(), b.end(), a1);
		ans = min(ans, abs(a1 - p) + abs(a1 - a11));
		ans = min(ans, abs(a1 - p) + abs(a1 - a12));


		auto b2 = *lower_bound(b.begin(), b.end(), p);
		auto b21 = *prev(upper_bound(a.begin(), a.end(), b2));
		auto b22 = *lower_bound(a.begin(), a.end(), b2);
		ans = min(ans, abs(b2 - p) + abs(b2 - b21));
		ans = min(ans, abs(b2 - p) + abs(b2 - b22));

		auto b1 = *prev(upper_bound(b.begin(), b.end(), p));
		auto b11 = *prev(upper_bound(a.begin(), a.end(), b1));
		auto b12 = *lower_bound(a.begin(), a.end(), b1);
		ans = min(ans, abs(b1 - p) + abs(b1 - b11));
		ans = min(ans, abs(b1 - p) + abs(b1 - b12));
		cout << ans << endl;
	}
}


Measured memory_bytes: 4192
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;

int w, h, x, y, r;

int main(){
	std::cin >> w >> h >> x >> y >> r;
	if (r <= x && x <= w - r && r <= y && y <= h - r)std::cout << "Yes" << std::endl;
	else std::cout << "No" << std::endl;
	return 0;
}

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

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define data asd09123jdf02i3h

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

int n;

int main() {
    read(n);int pre=-1,cnt=0,ans=0;
    for(int i=1;i<=n;i++) {
        int x;read(x);
        if(x!=pre) pre=x,ans+=cnt/2,cnt=1;
        else cnt++;
    }
    ans+=cnt/2;
    write(ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define mod 1000000007 
#define check exit(0)
#define nl cout<<endl;
#define inp 200005
#define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define deb(v) for(int i=0;i<v.size();i++) {cout<<v[i]; (i==v.size()-1) ? cout<<"\n":cout<<" "; }
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace __gnu_pbds;
using namespace std;

// Pick yourself up, 'cause...

int main()
{
    jaldi
 
    int n,w;
    cin>>n>>w;

    vector<int> weight(n),value(n);

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

    ll maxv = accumulate(value.begin(),value.end(),0ll);
    vector<ll> dp(maxv+1,INT_MAX);
    dp[0]=0;

    for(int i=0;i<n;i++)
    {
        int wi=weight[i] , vi=value[i];

        for(int j=maxv;j>=vi;j--) { dp[j] = min(dp[j] , dp[j-vi] + wi);  }
        //deb(dp);
    }

    for(int i=maxv;i>=0;i--)
    {
        if(dp[i]<=w) { cout<<i; break; }
    }
    return 0;
}


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


int ASCttenannoryaku(const void *a,const void *b) {
	return *(int *)a - *(int *)b;
}
int main(void)
{
	int n, a, b;
	int ans = 0, num = 0, digit = 0;
	scanf("%d%d%d",&n,&a,&b);
	for (int i = 0; i <= n; i++) {
		num = i;
		while (num) {
			digit += num % 10;
			num = num / 10;
		}
		if (digit <= b && a <= digit) {
			ans += i;
			//printf("%d\n",i);
		}
		digit = 0;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class C
{
	public static void Main()
	{
		int N = Int32.Parse(Console.ReadLine());
		int[] C = new int[N];
		int[] S = new int[N];
		int[] F = new int[N];
		for(int i = 0; i < N - 1; i++)
		{
			string[] args = Console.ReadLine().Split(' ');
			C[i] = Int32.Parse(args[0]);
			S[i] = Int32.Parse(args[1]);
			F[i] = Int32.Parse(args[2]);
		}

		for(int i = 0; i < N - 1; i++)
		{
			int ans = 0;
			for(int j = i; j < N - 1; j++)
			{
				if(ans <= S[j])
					ans = S[j];
				else
				{
					int over = (ans - S[j]) % F[j];
					if(over > 0)
						ans += F[j] - over;
				}
				ans += C[j];
			}
			Console.WriteLine(ans);
		}
		Console.WriteLine(0);
	}	
}





Measured memory_bytes: 11092
import java.util.*;

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

        int n = sc.nextInt();
        int l = sc.nextInt();

        int motoAji = 0;
        int min = l;
        int minAbs = Math.abs(l);
        for (int i = 1; i < n; i++) {
            int current = l + i;
            int currentAbs = Math.abs(current);
            if (minAbs > currentAbs) {
                minAbs = currentAbs;
                min = current;
            }
        }
        for (int i = 0; i < n; i++) {
            motoAji += (l + i);
        }
        System.out.println(motoAji - min);
    }
}


Measured memory_bytes: 20820
#include <bits/stdc++.h>
#define rg register
#define us unsigned
#define ll long long
#define ui <int>
#define pi <int, int>
#define tmpl template <typename typ>
#define oprt operator
#define sp putchar(32)
#define el putchar(10)
#define flin(x) freopen(x, "r", stdin)
#define flout(x) freopen(x, "w", stdout)
#define flio(x) flin(x".in"), flout(x".out")
#define ms(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define itrt iterator
using namespace std;
tmpl inline bool up(typ &x, const typ &y) { return x < y ? x = y, 1 : 0; }
tmpl inline bool dn(typ &x, const typ &y) { return y < x ? x = y, 1 : 0; }
tmpl inline bool inrange(const typ &x, const typ &l, const typ &r) { return !(x < l) && !(r < x); }
namespace orh {
inline void useios() { ios_base::sync_with_stdio(false); cin.tie(0); }
inline char rc() { rg char ch; while (!isgraph(ch = getchar())); return ch; }
tmpl typ ri() {
	rg typ x = 0; rg bool neg = false; rg char ch;
	while (!inrange(ch = getchar(), '0', '9')) neg |= ch == '-';
	do x = (x << 1) + (x << 3) + (ch ^ 48); while (inrange(ch = getchar(), '0', '9'));
	return neg ? -x : x;
}
tmpl typ ru() {
	rg typ x = 0; rg char ch;
	while (!inrange(ch = getchar(), '0', '9'));
	do x = (x << 1) + (x << 3) + (ch ^ 48); while (inrange(ch = getchar(), '0', '9'));
	return x;
}
tmpl void wi(rg typ x) {
	if (x < 0) { putchar('-'); x = -x; }
	static int sta[42]; rg int top = 0; rg typ t;
	do t = x / 10, sta[top++] = x - (t << 1) - (t << 3), x = t; while (x);
	while (top) putchar(sta[--top] ^ 48);
}
tmpl void wu(rg typ x) {
	static int sta[42]; rg int top = 0; rg typ t;
	do t = x / 10, sta[top++] = x - (t << 1) - (t << 3), x = t; while (x);
	while (top) putchar(sta[--top] ^ 48);
}
}

const int maxn = 100005;
int n, ans = 1;
struct robot {
	int l, r;
}a[maxn];

inline bool cmp(robot p, robot q) {
	return p.r < q.r;
}

signed main() {
	orh::useios();
	
	cin >> n;
	for (rg int i = 1; i <= n; ++i) {
		int p, q;
		cin >> p >> q;
		a[i].l = p - q, a[i].r = p + q;
	}
	sort(a + 1, a + n + 1, cmp);
	
	rg int j = 1;
	for (rg int i = 2; i <= n; ++i)
		if (a[i].l >= a[j].r) ++ans, j = i;
	
	cout << ans << endl;
	
	return 0; 
}

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

using namespace std;

int main(int argc, char *argv[])
{
    int N;
    cin >> N;
    vector<long> slimes(N);
    vector<long> S(N);
    for (int i = 0; i < N; i++) {
        cin >> slimes[i];
    }
    S[0] = slimes[0];
    for (int i = 1; i < N; i++) {
        S[i] = S[i - 1] + slimes[i];
    }
    auto sum = [&](int l, int r) -> long {
        if (l > r) return 0;
        return S[r] - (l == 0 ? 0 : S[l - 1]);
    };
    const long INF = 1e16;
    vector<vector<long>> dp(N + 1, vector<long>(N + 1, INF));
    for (int i = 0; i < N; i++) {
        dp[i][i] = 0;
    }
    for (int L = N - 1; L >= 0; L--) {
        for (int R = L; R < N; R++) {
            for (int k = L; k < R; k++) {
                long cost = sum(L, R);
                dp[L][R] = min(dp[L][R], dp[L][k] + dp[k + 1][R] + cost);
            }
        }
    }
    cout << dp[0][N - 1] << endl;
    return 0;
}


Measured memory_bytes: 1536
#include<stdio.h>

int main(void)

{

int a,b,c,t;

scanf("%d %d %d",&a,&b,&c);

if(a>b){

t=a;

a=b;

b=t;

}

if(b>c){

t=b;

b=c;

c=t;

}

if(a>b){

t=a;

a=b;

b=t;

}

printf("%d %d %d\n",a,b,c);

return 0;

}

Measured memory_bytes: 596
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        s: String,
        t: String,
    }
    println!("{}", s.chars().zip(t.chars()).filter(|&(a, b)| a == b).count());
}


Measured memory_bytes: 4352
package main

import (
	"bufio"
	"fmt"
	"strconv"
	"strings"
	"os"
)

// main
func main() {
	//testFunction()
	solve(bufio.NewScanner(os.Stdin))
}

// test
func testFunction() {
	input := `
3
`
	sc := bufio.NewScanner(strings.NewReader(strings.Trim(input, "\n")))
	solve(sc)
}



func fib(n int, dp map[int]int) int {
	if n == 0 || n == 1 {
		return 1
	}
		if v, ok := dp[n]; ok {
		return v
	}
	r := fib(n - 1, dp) + fib(n - 2, dp)
	dp[n] = r
	return r
}

// solve
func solve(sc *bufio.Scanner) {
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	dp := make(map[int]int)
	r := fib(n, dp)
	fmt.Println(r)
}



Measured memory_bytes: 1128
#include<iostream>
using namespace std;
int main() {
	int n, m; 
	while (cin >> n >> m, n, m) {
		int a[114], b[514];
		int asum = 0, bsum = 0;
		for (int i = 0; i < n; i++) { cin >> a[i]; asum += a[i]; }
		for (int i = 0; i < m; i++) { cin >> b[i]; bsum += b[i]; }
		int ansa = 114514, ansb = 114514;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (asum + b[j] - a[i] == bsum + a[i] - b[j]) {
					if (a[i] + b[j] <= ansa + ansb) {
						ansa = a[i];
						ansb = b[j];
					}
				}
			}
		}
		if (ansa != 114514)cout << ansa << ' ' << ansb << endl;
		else cout << "-1\n";
	}
}

Measured memory_bytes: 3092
#include<iostream>
#include<iomanip>

using namespace std;

int main() {
	double r,A,B;

	cin >> r;

	A = r * r * 3.141592653589;
	B = 2 * r * 3.141592653589;

	std::cout << std::fixed;
	std::cout << std::setprecision(6) << A << " " << B << endl;

	return 0;
}


Measured memory_bytes: 3260
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
const ll mod=1e9+7;


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

    ll q,h,s,d,n;
    cin>>q>>h>>s>>d>>n;
    n*=4;
    if(2*q<h)
        h=2*q;
    if(2*h<s)
        s=2*h;
    if(2*s<d)
        d=2*s;
    ll a[9];
    a[1]=q;a[2]=h;a[4]=s;a[8]=d;
    ll min=8,ans=0;
    while(n!=0){
        if(n<min)
            min/=2;
        n-=min;
        ans+=a[min];
    }
    cout<<ans;
    /*ll dp[n+1];
    memset(dp,0,sizeof(dp));
    dp[0]=1e10;
    dp[1]=q;
    for(ll i=2;i<=n;i++){
        ll a=0,b=0;
        a=min(dp[i-1]+q,dp[i-2]+h);
        if(i>=8) b=min(dp[i-4]+s,dp[i-8]+d);
        else if(i>=4) b=dp[i-4]+s;
        dp[i]=min(a,b);
    }
    cout<<dp[n];*/

    return 0;
}


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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long> VLL;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/

int main(){
    int s;cin>>s;
    V a(100000);
    V b(100000);
    a[0]=s;
    b[s]=1;
    int ans;
    int now=0;
    while(1){
        if(a[now]%2==0){
            a[now+1]=a[now]/2;
            b[a[now+1]]++;
        }else{
            a[now+1]=3*a[now]+1;
            b[a[now+1]]++;
        }
        if(b[a[now+1]]==2){
            ans=now+1;
            break;
        }
        now++;
    }
    cout<<ans+1<<endl;
}




Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(), m = sc.nextInt();
        PriorityQueue<P> q = new PriorityQueue<>();

        for (int i = 0; i < n; i++) q.add(new P(1, sc.nextInt()));

        for (int i = 0; i < m; i++) q.add(new P(sc.nextInt(), sc.nextInt()));

        long ans = 0;

        while (n > 0) {
            P cur = q.remove();

            if (n > cur.b) {
                n -= cur.b;
                ans += 1L * cur.b * cur.c;
            } else {
                ans += 1L * n * cur.c;
                n = 0;
            }
        }
        System.out.println(ans);
    }

    class P implements Comparable<P> {
        int b, c;
        P(int b, int c) {
            this.b = b;
            this.c = c;
        }

        @Override
        public int compareTo(P o) {
            return o.c - c;
        }
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }

}


Measured memory_bytes: 101856
#!python3

# input
N = int(input())
X = input()


def popcount(n):
    return bin(n).count("1")


def solve(n):
    if n == 0:
        return 0
    c = popcount(n)
    return 1 + solve(n % c)


def main():
    c = X.count("1")
    if c == 0:
        for _ in range(N):
            print(1)
        return
    a, b = 0, 0
    for i in range(N):
        if c == 1 and X[-1 - i] == "1":
            b = (b + pow(2, i, c + 1)) % (c + 1)
        elif X[-1 - i] == "1":
            a = (a + pow(2, i, c - 1)) % (c - 1)
            b = (b + pow(2, i, c + 1)) % (c + 1)
    for i in range(N):
        if c == 1 and X[i] == "1":
            print(0)
            continue
        if X[i] == "1":
            m = c - 1
            w = (a - pow(2, N - 1 - i, m)) % m
        else:
            m = c + 1
            w = (b + pow(2, N - 1 - i, m)) % m
        ans = solve(w) + 1
        print(ans)
            

if __name__ == "__main__":
    main()


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

int main() {
    int n;
    cin >> n;
    long long a;
    vector<long long> b(n);
    cin >> a;
    b[0] = a;
    for (int i = 1; i < n; i++) {
        cin >> a;
        b[i] = b[i-1] + a;
    }
    long long sum = b[n-1];
    long long ans = LLONG_MAX;
    for (int i = 0; i < n; i++) {
        long long tmp = abs (sum - 2*b[i]);
        ans = min (ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4808
#include<bits/stdc++.h>
using namespace std;
int main()
{
         long long int a,b,c,x,y,z;

         cin>>a;
         cin>>b;
         cin>>c;
         x=c-a-b;
         y=x*x;
         z=4*a*b;
         if(c>a+b&&y>z)cout<<"Yes"<<endl;
         else cout<<"No"<<endl;
         return 0;
}


Measured memory_bytes: 256
n,m=[int(s) for s in input().split()]
ls=[0 for _ in range(m+1)]
for i in range(n):
  ls2=[int(s) for s in input().split()]
  for j in range(ls2[0]):
    ls[ls2[j+1]]+=1
x=0
for i in range(m+1):
  if ls[i]==n:
    x+=1
print(x)

Measured memory_bytes: 38384
class UnionFind:
    def __init__(self, n: int) -> None:
        self.forest = [-1] * n

    def union(self, x: int, y: int) -> None:
        x = self.findRoot(x)
        y = self.findRoot(y)
        if x == y:
            return
        if self.forest[x] > self.forest[y]:
            x,y = y,x
        self.forest[x] += self.forest[y]
        self.forest[y] = x
        return

    def findRoot(self, x: int) -> int:
        if self.forest[x] < 0:
            return x
        else:
            self.forest[x] = self.findRoot(self.forest[x])
            return self.forest[x]

    def issame(self, x: int, y: int) -> bool:
        return self.findRoot(x) == self.findRoot(y)

    def size(self,x: int) -> int:
        return -self.forest[self.findRoot(x)]


n,m = map(int,input().split())
uf = UnionFind(n)
s = set()
for i in range(m):
    ai,bi = map(int,input().split())
    uf.union(ai-1,bi-1)

for i in range(n):
    s.add(uf.findRoot(i))
print(len(s)-1)

Measured memory_bytes: 17924
#include<iostream>
#include<algorithm>

using namespace std;

int cnt = 0;
int discoverd[100] = { 0 };
int finished[100] = { 0 };
int n = 0;

void dfs(int index, int** mat);

int main() {
	int row,size,tmp;
	cin >> n;
	int** mat = new int* [n];
	for (int i = 0;i < n;i++) {
		cin >> row >> size;
		mat[row - 1] = new int[n];
		for (int j = 0;j < n;j++) {
			mat[row - 1][j] = 0;
		}
		for (int j = 0;j < size;j++) {
			cin >> tmp;
			mat[row - 1][tmp - 1] = 1;
		}
	}
	for (int i = 0;i < n;i++) {
		if (discoverd[i] == 0)dfs(i, mat);
	}
	for (int i = 0;i < n;i++) {
		cout << i + 1 << " " << discoverd[i] << " " << finished[i] << endl;
	}
	
}

void dfs(int index, int** mat) {
	cnt++;
	discoverd[index] = cnt;
	for (int i = 0;i < n;i++) {
		if (mat[index][i] == 1 && discoverd[i] == 0) {
			dfs(i, mat);
		}
	}
	cnt++;
	finished[index] = cnt;
}


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

int main(){
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    if((x >= r && (x + r) <= W)&&(y >= r && (y + r) <= H)){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    return 0;
}


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

int main(){
   int N,K;
   cin>>N>>K;
   vector<int> A(N+1,0);
   for(int i=0;i<K;i++){
       int kk;
       cin>>kk;
       for(int j=0;j<kk;j++){
           int ss;
           cin>>ss;
           A[ss]++;
       }
   }
   int ans=0;
   for(int i=1;i<N+1;i++){
       if(A[i]==0)ans++;
   }
   cout<<ans<<endl;
}


Measured memory_bytes: 3588
import java.util.Scanner;
 
class Main {
public static void main(String[] args) {
  final Scanner sc = new Scanner(System.in);
  final Integer distance = sc.nextInt();
  final Integer time = sc.nextInt();
  final Integer velocity = sc.nextInt();  
  
  if(time >= (float)distance / (float)velocity) {
    System.out.println("Yes");
  } else {
    System.out.println("No");
  }
}
}

Measured memory_bytes: 35584
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
using namespace std;

int main ()
{
    int h, n, sum = 0, i, x;
    cin >> h >> n;
    for(i = 0;i < n;i++)
    {
        cin >> x;
        sum += x;
    }
    if(sum >= h)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String [] args) {
		Scanner stdIn = new Scanner(System.in);
		int min = 1000001, max = -1000001, n;
		long sum = 0;
		
		do {
			n = stdIn.nextInt();
		}while( n < 0 || n > 10000);
		
		int data[] = new int[n];
		
		for(int i = 0; i < n; i++) {
			do {
				data[i] = stdIn.nextInt();						
			}while( data[i] < -1000000 || data[i] > 1000000);
			
			
			if(min > data[i]) {
				min = data[i];
			}
			
			if(max < data[i]) {
				max = data[i];
			}
			
			sum += data[i];
			
		}
		

		
		System.out.println(min + " " + max + " " + sum);
		
	}
}



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

int main() {
  int h, w;
  cin >> h >> w;
  int n;
  cin >> n;
  vector<vector<int>> ans(h, vector<int>(w));
  vector<int> input(h*w);
  int total = 0;
  for(int i=1;i<=n;i++) {
    int a;
    cin >> a;
    for(int j=total;j<total+a;j++) {
      input[j] = i;
    }
    total += a;
  }

  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      ans[i][j] = input[i*w+j];
    }
  }

  for(int i=1;i<h;i+=2) {
    reverse(ans[i].begin(), ans[i].end());
  }

  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main(int argc, char **argv)
{
    int A, B;
    cin >> A >> B;
    if (A > 9 || B > 9) cout << -1 << endl;
    else cout << A * B << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    int[] a = new int[3*n];
    for(int i=0; i<a.length; i++){
      a[i] = sc.nextInt();
    }
    Arrays.sort(a);
    long sum = 0;
    int i = a.length-2;
    while(i >= n){
      sum += a[i];
      i -= 2;
    }
    
    System.out.println(sum);

    sc.close();
  }
}

Measured memory_bytes: 92308
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  for(int i = 0; i < n; i++){
    cin >> h[i];
  }
  
  int cnt = 0;
  int i = 0;
  while(i < n){
    if(h[i] == 0){
      i++;
      continue;
    }
    int j = i;
    while(j < n){
      if(h[j] == 0)
        break;
      j++;
    }
    
    for(int k = i; k < j; k++){
      h[k]--;
    }
    
    cnt++;
    
  }
  
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <cmath>
#include <functional>
using namespace std;
//typedef __int64 LL;
typedef long long int LL;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef pair<int,int> P;
//typedef pair<LL,LL> PL;


const int MOD=1000000007;
int INF=100100100;

LL beki(LL a,LL b)
{
	if(b==0)return 1;
	LL x=beki(a,b/2);
	if(b%2==0)return (x*x)%MOD;
	else return (((a*x)%MOD)*x)%MOD;
}

LL inv(LL a)
{
	return beki(a,MOD-2);
}

LL seki(LL a,LL b)
{
	return (a*b)%MOD;

}

LL wa(LL a,LL b)
{
	return (a+b)%MOD;
}
int main(){
        map<LL,LL> ma;
	LL n;cin>>n;
        for(LL i=0;i<n;i++)
	{
		LL a;cin>>a;
		for(LL j=0;j<62;j++)
		{
			if((a>>j)%2==1)ma[j]++;
		}
	}
	LL ans=0;
	for(LL i=0;i<62;i++)
	{
		
//		cout<<ans<<endl;
		ans=wa(ans,seki(seki(ma[i],n-ma[i]),beki(2,i)));
	}
//	cout<<ans<<endl;
	//ans=(ans*inv(2))%MOD;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

ll n, m, x;
vector<ll> c(n);
vector<vector<ll>> vec(n, vector<ll>(m));
vector<ll> res(m);
ll ans = -1;


void bit_full_search(int n)
{

    //2^n回ループ
    
    
    for (int bit = 0; bit < (1<<n); ++bit) {
        //cout << "{";
        ll count = 0;
        rep(j,m){
            res[j] = 0;
        }

        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) {
                //cout << " " << i << " ";
                count += c[i];
                rep(j,m){
                    res[j] += vec[i][j];
                }
            }
        }
        //cout << "}" << endl;
        ll flag = 0;
        rep(j,m){
            if(res[j] >= x){
                continue;
            }else{
                flag = 1;
            }
        }

        if(flag == 0){
            if(ans == -1){
                ans = count;
            }else{
                ans = min(ans, count);
            }
        }

    }
    
}


int main() {
    std::cout << std::fixed << std::setprecision(15);
    
    cin >> n >> m >> x;

    c.resize(n);
    vec.resize(n, vector<ll>(m));
    res.resize(m);

    rep(i,n){
        ll tmp;
        cin >> tmp;
        c[i] = tmp;
        rep(j,m){
            ll tmp2;
            cin >> tmp2;
            vec[i][j] = tmp2;
        }
    }

    bit_full_search(n);
    cout << ans << endl;
}

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

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

using namespace std;

int main(){
	char s[3][4]={"hon","pon","bon"};
	int f[]={1,1,0,2,0,0,1,0,1,0};
	int n; scanf("%d",&n);
	puts(s[f[n%10]]);
	return 0;
}


Measured memory_bytes: 3660
#include<iostream>
#include<array>
#include<vector>
#include<string>
#include<cstring>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<queue>
#include<stack>
#include<deque>
#include<algorithm>
#include<cmath>

using namespace std;
#define ll long long
#define ff first
#define ss second
#define e endl

void solve() {
	double d, t, s; cin >> d >> t >> s;
	double x = d/s;
	if(x <= t) cout << "Yes\n";
	else cout << "No\n";
}

int main()
{
	//ll t; cin >> t; while (t--)
	solve();
	
}

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

int cnt = 0;

void dfs(vector<int> h)
{
    if (h.size() == 0) return;

    int min_h = h[0];
    int idx = 0;
    rep(i, 0, h.size())
    {
        if (h[i] < min_h)
        {
            idx = i;
            min_h = h[i];
        }
    }
    cnt += min_h;

    vector<int> next_h;
    rep(i, 0, h.size())
    {
        int now_h = h[i] - min_h;
        if (now_h == 0)
        {
            dfs(next_h);
            next_h = {};
        }
        else
            next_h.push_back(now_h);
    }
    dfs(next_h);
}

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

    dfs(h);
    cout << cnt << endl;
    return 0;
}

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

    typedef long long ll;
    typedef long double ld;
    ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
    ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
    #define endl '\n'
    #define max3(a,b,c) max(a,max(b,c))
    #define min3(a,b,c) min(a,min(b,c))
    #define FOR(i,a,n,j) for(int i=a;i<n;i+=j)

    const int INF = 1e9+9;




    int main()
    {
        ll n,m,d,ans=0;
        set <int> s;
        set <int>::iterator it;
        cin>>n>>m;
        int h[n];
        s.clear();
        for(int i=1;i<=n;i++) {
            s.insert(i);
            cin>>h[i];
        }
        int a,b;
        for(int i=1;i<=m;i++){
            cin>>a>>b;
            if(h[a]==h[b]){
                s.erase(b);
                s.erase(a);
            }
            else if(h[a]<h[b]) {
                s.erase(a);
            }
            else {
                s.erase(b);
            }
        }
        cout<<s.size()<<endl;

    return 0;
    }
        // gotcha;


Measured memory_bytes: 8688
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <sstream>
#include <bitset>
using namespace std;

int main(void){
    int n;
    cin >> n;
    int a = n/1000; int b = (n-a*1000)/100; int c = (n-a*1000-b*100)/10; int d = n-a*1000-b*100-c*10;
    int ans[8];
    vector<string> s{"+++","++-","+-+","+--", "-++","-+-","--+","---"};
    ans[0]=a+b+c+d;
    ans[1]=a+b+c-d;
    ans[2]=a+b-c+d;
    ans[3]=a+b-c-d;
    ans[4]=a-b+c+d;
    ans[5]=a-b+c-d;
    ans[6]=a-b-c+d;
    ans[7]=a-b-c-d; 
    for(int i = 0; i < 8; i++){
        if(ans[i]==7){
            cout << a << s[i][0] << b << s[i][1] << c << s[i][2] << d;
            cout << "=7" << endl;
            break;
        }
    }          
    return 0;
}

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

min_a = 10 ** 9
negative_count = 0
ans = 0
for a in A:
    if a < 0:
        negative_count += 1
    a = abs(a)
    ans += a
    if a < min_a:
        min_a = a
if negative_count % 2 == 0:
    print(ans)
else:
    print(ans - 2 * min_a)


Measured memory_bytes: 14332
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

ll N,K;
vl A;

ll num(ll x){
    ll res=0;
    rep(i,N){
        res+=(A[i]-1)/x;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> K;
    A.resize(N);
    rep(i,N){
        cin >> A[i];
    }
    ll ok=1e9+1,ng=0;
    while(abs(ok-ng)>1){
        ll mid=(ok+ng)/2;
        if(num(mid)<=K){
            ok=mid;
        }
        else{
            ng=mid;
        }
    }
    cout << ok << endl;
}

Measured memory_bytes: 4688
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}

int main() {
    double r;
    cin >> r;
    cout <<fixed<<setprecision(20)<< r * 2 * 3.1415926535 << endl;
}


Measured memory_bytes: 3784
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    int n,k;
    cin >> n >> k;
    if(k==1){
        cout << 0 << endl; return 0;
    }
    cout << n-k << endl;
}

Measured memory_bytes: 256
n=int(input())
h=[0 for _ in range(n+1)]
h[1:]=list(map(int,input().split()))
h[0]=h[1]
# print(h)
cost=[0 for _ in range(n+1)]
for i in range(2,n+1):
    cost2=cost[i-2]+abs(h[i-2]-h[i])
    cost1=cost[i-1]+abs(h[i-1]-h[i])
    if cost2>cost1:
        cost[i]=cost1
    else:
        cost[i]=cost2
print(cost[n])

Measured memory_bytes: 15032
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n, m; cin >> n >> m;
  vector<int> cnt(n, 0);
  vector<bool> ac(n, false);
  int ans = 0, pen = 0;
  while (m--) {
    int p; string s; cin >> p >> s; --p;
    if (s == "AC") {
      if (!ac[p]) {
        ac[p] = true;
        ++ans;
        pen += cnt[p];
      }
    } else {
      ++cnt[p];
    }
  }
  cout << ans << ' ' << pen << '\n';
  return 0;
}


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

int main(){
  string S,T,U;
  int N,M,count;
  
  cin >> N >> M;
  
  cin >> T;
  
  for(int i = 0; i<N;i++){
    
  cin >> U;
  
  //Tの処理
  for(int j = 0;j<M;j++){
    count = 0;
    
    if(T.at(j) == '.'){
      
      if(S.size()>0){
      
        if(j-1>= 0){
          if(S.at(j-1) == '#')
            count++;
        }
        if(S.at(j) == '#')
            count++;
      
        if(j+1 < S.size()){
          if(S.at(j+1) == '#')
            count++;
        }
      }
    
      if(j-1>= 0){
        if(T.at(j-1) == '#')
          count++;
      }
      
      if(j+1 < T.size()){
        if(T.at(j+1) == '#')
          count++;
        }
      
      if( i != N-1 ){
      if(U.size()>0){
      
        if(j-1>= 0){
          if(U.at(j-1) == '#')
            count++;
        }
        if(U.at(j) == '#')
            count++;
      
        if(j+1 < U.size()){
          if(U.at(j+1) == '#')
            count++;
        }
      }
      }
    
    //Tの.を変更する。
    if(count == 0)
      T.at(j) = '0';
    if(count == 1)
      T.at(j) = '1';
    if(count == 2)
      T.at(j) = '2';
    if(count == 2)
      T.at(j) = '2';
    if(count == 3)
      T.at(j) = '3';
    if(count == 4)
      T.at(j) = '4';
    if(count == 5)
      T.at(j) = '5';
    if(count == 6)
      T.at(j) = '6';
    if(count == 7)
      T.at(j) = '7';
    if(count == 8)
      T.at(j) = '8';
    }
  }
  cout << T <<endl;
  
  S = T;
  T = U;
  }
}

Measured memory_bytes: 256