akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

struct MaxSegmentTree{
  int size_;
  int length_;
  vector<ll> data_;
  umap<int, int> par_info_;
  umap<int, pair<int, int>> chil_info_;

  MaxSegmentTree(int size, ll init = -(1e+18))
    :size_(CalcSize(size)), length_((size_+1)/2), data_(size_, init)
  { Init(); }
  
  int CalcSize(int size)
  { int n = 1; while(n < size)n *= 2; return 2 * n - 1; }
  void Init(){
    for(int i = (size_/2)-1; i >= 0; --i){
      int l = i*2 + 1, r = i*2 + 2;
      par_info_[l] = i;
      par_info_[r] = i;
      chil_info_[i] = {l,r};
    }
  }
  
  void Set(int idx, ll x){
    int pos = (size_/2)+idx;
    data_[pos] = x;
    while(pos != 0){
      pos = par_info_[pos];
      ll l, r;tie(l, r) = chil_info_[pos];
      data_[pos] = max(data_[l], data_[r]);
    }
  }
  
  ll GetMax(int target_l, int target_r, int idx = 0,
	    int range_l = 0, int range_r = -1){
    if(range_r == -1){
      range_r = length_;
      if(target_l > target_r || target_l < 0 || target_r > length_){
	cerr << "SegmentTree GetMin target index error\n";
	cerr << "target_l:" << target_l << " target_r:" << target_r << endl;
	return -(1e+18);
      }
    }
    
    if(target_r <= range_l || target_l >= range_r) return -(1e+18);
    if(target_r >= range_r && target_l <= range_l) return data_[idx];
    
    int l, r; tie(l, r) = chil_info_[idx];
    int mid = (range_l + range_r)/2;
    
    ll val_l = GetMax(target_l, target_r, l, range_l, mid);
    ll val_r = GetMax(target_l, target_r, r, mid, range_r);
    
    return max(val_l, val_r);
  }  
}; // [left, right)

int main(){
  int n; cin >> n;
  vector<int> h(n); cin >> h;
  vector<int> a(n); cin >> a;
  MaxSegmentTree mst(n+1);
  for(int i = 0; i < n; ++i){
    ll x = max(0LL,mst.GetMax(0, h[i]));
    mst.Set(h[i], x+a[i]);
  }
  cout << mst.GetMax(0,n+1) << endl;
  return 0;
}


Measured memory_bytes: 46696
#include<bits/stdc++.h>
#define ll long long 
#define hell 1000000007 
#define F first
#define re 15000000
#define S second
#define pb push_back
#define all(a)  (a).begin(),(a).end()
#define rep(i,a,b) for(ll int i = a;i<b;i++)
#define pi 3.1415926536
#define Mod 998244353
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	int a[n+1];
	memset(a,0,sizeof(a));
	for(int  i =0;i<m;i++)
	{
		int l,r;
		cin>>l>>r;
		a[l] = a[l]+1;	
		a[r+1] = a[r+1]-1;
	}
	for(int i = 1;i<=n;i++)
	{
		a[i] = a[i-1]+a[i];
	}
	int c= 0;
	for(int i = 1;i<=n;i++)
	{
		if(a[i] >= m)
			c++;

	}
	cout<<c;
}

Measured memory_bytes: 640
#include <cassert>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <stack>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<LL, LL> PII;

#define debug(args...) {vector<string> _v = split(#args, ','); err(_v.begin(), args); puts("");}
vector<string> split(const string& s, char c) {vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) v.push_back(x); return v;}
void err(vector<string>::iterator it) {}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args) {cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; err(++it, args...);}

#if (( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)
#define lld I64d
#else
#define lld lld
#endif

#define pb push_back
#define mp make_pair
#define all(x)  (x).begin(),(x).end()
#define tr(c, it)   for(auto it=c.begin(); it!=c.end(); it++)
#define clr(a, b)   memset(a, b, sizeof(a))
#define forn(i, n)   for(int i=0; i<n; i++)

const int INF = 0x3f3f3f3f;
LL h, w;

LL cal(LL pos, LL p, LL q, LL s1)
{
    LL s2 = pos * p;
    LL s3 = (q - pos) * p;

    LL maxi = max(s1, max(s2, s3));
    LL mini = min(s1, min(s2, s3));

    return maxi - mini;
}

LL fun(LL a, LL b)
{
    LL ret = min(a, b);

    for(LL i=1; i<a; i++)
    {
        LL s1 = i * b;

        if(b == 2)
        {
            LL s2 = a - i;
            LL cur = max(s1, s2) - min(s1, s2);
            ret = min(ret, cur);
            continue;
        }

        LL l = 1, r = b - 1;

        while(l + 1 < r)
        {
            LL mid = (l + r) / 2;
            LL mmid = (mid + r) / 2;
            //debug(l, r, mid, mmid);

            LL vmid = cal(mid, a-i, b, s1);
            LL vmmid = cal(mmid, a-i, b, s1);

            //debug(l, r, mid, mmid, vmid, vmmid);
            if(vmid < vmmid)
                r = mmid;
            else
                l = mid;
        }

        //debug(l ,r);


        LL vall = cal(l, a-i, b, s1);
        LL valr = cal(r, a-i, b, s1);
        LL pos;
        if(vall < valr) pos = l;
        else pos = r;
        //debug(pos)

        LL cur = cal(pos, a-i, b, s1);
        ret = min(cur, ret);

    }
    return ret;

}


int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
#endif

    while(cin >> h >> w)
    {
        if(h % 3 == 0 || w % 3 == 0)
        {
            cout << 0 << endl;
            continue;
        }

        //LL ans = fun(h, w);

        LL ans = min(fun(h, w), fun(w, h));

        cout << ans << endl;

    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

template <class T>
void VecRowShow(vector<T> vec) {
	rep(i, vec.size()) {
		if (i != vec.size() - 1) cout << vec[i] << " ";
		else cout << vec[i] << endl;
	}
}



int main() {
	string s;
	cin >> s;
	if (s[0] == 'A' &&s[1] == 'A' && s[2] == 'A') {
		cout << "No" << endl;
	}
	else if (s[0] == 'B' &&s[1] == 'B' && s[2] == 'B') {
		cout << "No" << endl;

	}
	else {

		cout << "Yes" << endl;
	}
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

int N;
int P[50];

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

    int m=0;
    rep(i,N){
        if(i+1!=P[i]) m++;
    }

    if(m<=2){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
using namespace std;

typedef long long ll;

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

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

ll N;
ll A[100001];
map<ll, ll> M;
vector<pair<ll, ll>> V;

int main() {

  cin >> N;
  rep(i, N) {
    cin >> A[i];
    ++M[A[i]];
  }

  ll res = 0;

  for(auto it : M) {
    if(it.second>=2) {
      V.push_back({it.first, it.second});
    }
  }

  ll size = V.size();
  if(size>0) {
    sort(V.begin(), V.end());
    if(V[size-1].second>=4)
      res = V[size-1].first*V[size-1].first;
    else
      res = V[size-1].first*V[size-2].first;
  }

  cout << res << endl;

  return 0;
}


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

namespace RoundOne
{
    class Program
    {
        static void Main(string[] args)
        {
            int A = int.Parse(Console.ReadLine());
            int B = int.Parse(Console.ReadLine());
            if (A + B == 3)
            {
                Console.WriteLine(3);
            } else if (A + B == 4)
            {
                Console.WriteLine(2);
            } else
            {
                Console.WriteLine(1);
            }
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>

using namespace std;

int main(){

    long long int ans=0;

    long long int a,b,n;

    cin>>n>>a>>b;

    if(a!=0){
        if(n%(a+b)<a){
            ans=(n/(a+b))*a+n%(a+b);
        }
        else{
            ans=(n/(a+b))*a+a;
        }
    }

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


Measured memory_bytes: 256
r,c=map(int,input().split())
m=[[]for i in range(r)]
for i in range(r):
    m[i]=list(map(int,input().split()))
sc=[0]*c
for i in range(r):
    for j in range(c):
        sc[j]+=m[i][j]
for er in m:
    print(*er,end=' ')
    print(sum(er))
print(*sc,end=' ')
print(sum(sc))


Measured memory_bytes: 6228
#include<stdio.h>
#include<stdlib.h>

typedef long long int int64;

#define POS(i,j) ((i)*a+(j))

int calc(int *a,int n,int64 *dp){
  int i,j;
  for(i=0;i<=50*n;i++) dp[i]=0;
  dp[0]=1;
  int sum=0;
  for(i=0;i<n;i++){
    for(j=sum;j>=0;j--){
      dp[j+a[i]]+=dp[j];
    }
    sum+=a[i];
  }
  return sum;
}

void run(void){
  int n,a;
  scanf("%d%d",&n,&a);
  int *minus=(int *)malloc(sizeof(int)*n);
  int *plus=(int *)malloc(sizeof(int)*n);
  int mlen=0;
  int plen=0;
  int eq=0;
  int i;
  for(i=0;i<n;i++){
    int x;
    scanf("%d",&x);
    if(x==a){
      eq++;
    } else if(x<a){
      minus[mlen++]=a-x;
    } else {
      plus[plen++]=x-a;
    }
  }
  int64 *minusDP=(int64 *)malloc(sizeof(int64)*(50*mlen+1));
  int64 *plusDP =(int64 *)malloc(sizeof(int64)*(50*mlen+1));
  int mUP=calc(minus,mlen,minusDP);
  int pUP=calc(plus,plen,plusDP);
  int64 ans=0;
  for(i=0;i<=mUP && i<=pUP;i++){
    ans+=minusDP[i]*plusDP[i];
  }
  ans=(ans<<eq)-1;
  printf("%lld\n",ans);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 128
from functools import lru_cache

H, W = map(int,input().split())
Map = [input() for _ in range(H)]
def black(r,c):
  return 1 if Map[r-1][c-1]=='#' else 0

@lru_cache(maxsize=20000)
def cost(r,c,b0):
  b = black(r,c)
  if b0==0:
    if r==1 and c==1: return b
    elif r==1: return cost(r,c-1,b)
    elif c==1: return cost(r-1,c,b)
    else: return min(cost(r-1,c,b),cost(r,c-1,b))
  elif b0==1 and b==1:
    if r==1 and c==1: return 1
    elif r==1: return cost(r,c-1,b)
    elif c==1: return cost(r-1,c,b)
    else: return min(cost(r-1,c,b),cost(r,c-1,b))
  else:
    if r==1 and c==1: return 1
    elif r==1: return cost(r,c-1,0) +1
    elif c==1: return cost(r-1,c,0) +1
    else: return min(cost(r-1,c,0),cost(r,c-1,0)) +1
    
print(cost(H,W,0))

Measured memory_bytes: 8724
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;



int main(void){
    int x,y;
    cin >> x >> y;
    cout << x*y << endl;
    return 0;
}

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

int expmod(int a, int b, int mod) {
	int rlt = 1;
	for (a %= mod; b; a = 1ll * a * a % mod, b >>= 1) if (b & 1) rlt = 1ll * rlt * a % mod;
	return rlt;
}

const int mod = 1000003;

int n, x, d;
#define N 1000003
int fac[N], rfac[N], ri[N];
void init() {
	fac[0] = 1;
	for (int i = 1; i < N; i ++) fac[i] = 1ll * fac[i-1] * i % mod;
	rfac[0] = rfac[1] = 1, ri[1] = 1;
   	for(int i = 2; i < N; i ++){
      		int t = mod / i;
      		ri[i] = (1ll * t * (mod - ri[mod % i])) % mod;
      		rfac[i] = (1ll * rfac[i-1] * ri[i]) % mod;
   	}
}


int main() {
	init();
	int q;
	scanf("%d", &q);
	while (q --) {
		scanf("%d%d%d", &x, &d, &n);
		int ans;
		if (d == 0) ans = expmod(x, n, mod);
		else {
			int now = 1ll * x * expmod(d, mod - 2, mod) % mod;
			if (mod <= now + n - 1) ans = 0;
			else {
				ans = 1ll * fac[now+n-1] * rfac[now-1] % mod * expmod(d, n, mod) % mod;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}


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


#define int  long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define eb emplace_back //FASTER THAN PUSH BACK!
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define mi multiset<int>
#define what_is(x) cerr << #x << " is " << x <<"\n";
// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()
// order_of_key returns number of elements less that parameter. If element exists, that order is its index
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>


using namespace __gnu_pbds;
using namespace std;


int modp(int a,int n,int m)
{
    if(n==0) return 1;
    if(n==1) return a%m;
    int res=modp(a,n/2,m);
    if(n%2==0) return (res*res)%m;
    else return (a*res*res)%m;
}



signed main()
{
    int t,n,m,i,k,l,j,s,sum,flag=0,count=0;
    string S,T,U;
    // cin>>t;
    // while(t--)
    {
        cin>>n>>k;
        int a[n];
        rep(i,0,n) cin>>a[i];
        int dp[n];
        rep(i,1,n) dp[i]=INT_MAX;
        dp[0]=0;

        rep(i,1,n)
        {
            rep(j,1,k+1)
            {
                if(i-j>=0) dp[i]=min(dp[i-j]+abs(a[i]-a[i-j]),dp[i]);
            }
        }
        cout<<dp[n-1];
    } 
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#define ll long long int

using namespace std;

int main(){
  ll N,sum=0;
  cin >> N;
  for(int i = 1;i <= N;i++){
    if(i % 3 == 0 || i % 5 == 0){
      continue;
    }else{
      sum += i;
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3592
def main():
    N = int(input())
    S = input()
    m = 0
    for i in range(N-1):
        A = z_algo(S[i:])
        m = max(m, max(min(i,v) for i, v in enumerate(A)))
    return m

def z_algo(S):
    N = len(S)
    A = [0]*N
    i = 1; j = 0
    A[0] = l = len(S)
    while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
        i += k; j -= k
    return A
print(main()) 


Measured memory_bytes: 57692
import heapq


x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
queue = []
heapq.heappush(queue, (-(a[0] + b[0] + c[0]), 0, 0, 0))
already = set([0, 0, 0])
ans = []
for _ in range(k):
    val, p, q, r = heapq.heappop(queue)
    ans.append(-val)
    if ((p + 1, q, r) not in already) and p + 1 < x:
        heapq.heappush(queue, (-(a[p+1] + b[q] + c[r]), p+1, q, r))
        already.add((p+1, q, r))
    if ((p, q+1, r) not in already) and q + 1 < y:
        heapq.heappush(queue, (-(a[p] + b[q+1] + c[r]), p, q+1, r))
        already.add((p, q+1, r))
    if ((p, q, r+1) not in already) and r + 1 < z:
        heapq.heappush(queue, (-(a[p] + b[q] + c[r+1]), p, q, r+1))
        already.add((p, q, r+1))
for i in ans:
    print(i)


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


int main() {
  int N,M;
  cin >> N >> M;
  vector< vector<int> > AB(M+1);

  for( int i=0; i<N; ++i) {
    int a,b;
    cin >> a >> b;
    if ( a > M ) continue;
    AB[M-a].push_back(b);
  }

  priority_queue<int> jobs;

  int64_t ans = 0;
  // M日目から探す
  for( int t=M-1; t>=0; --t) {
//    cout << "--- " << t << " ---" << endl;
    // 現在の日で受けれるもの(t+A<=M)の中で、B最大のものを選ぶ
    for ( auto b: AB[t] ) {
      jobs.push(b);
    }

    if ( !jobs.empty() ) {
      ans += jobs.top();
      jobs.pop();
    }
  }

  cout << ans << endl;

}


Measured memory_bytes: 5504
#include <stdio.h>

int main()
{
  int W, H, x, y, r;

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

  if(0 <= x-r &&  W >= x+r && 0 <= y-r && H >= y+r)
    puts("Yes");
  else
    puts("No");

  return 0;
}

Measured memory_bytes: 1808
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
typedef long long ll;
using namespace std;
int main()
{
    ll x,day=0,a=100;
    cin>>x;
    while(a<x){
        a+=a*0.01;
        day+=1;
    }
    cout<<day;
    return 0;
}


Measured memory_bytes: 3636
N, K = map(int, input().split())
D = list(map(str, input().split()))

while True:
    flag = True
    str_N = str(N)
    for i in range(len(str_N)):
        if str_N[i] in D:
            flag = False
    if flag:
        print(N)
        exit()
    N += 1

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
#define RET(ans) {cout<<ans<<endl;return 0;} 

    // 二次元ベクターの基本
    /*
    vector<vector<int>> dp; // 宣言
    dp.resize(n); // 1次元めの要素数決定
    dp[i].push_back(int); // プッシュバック
    rep(i,n){
        sort(dp[i].begin(),dp[i].end()); // 二次元めを昇順ソート
    }
    */

    // 整数スキャン（複数）
    /*
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s; cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s; cin >> s;
        slist.push_back(s);
    }
    */

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


    ll ans = 0;

    srep(i,1,1000001){
        if(n/i==n%i){
            ans += i;
        }
    }

    srep(i,1,1000000){
        ll nn = n - i;
        if(nn%i==0&&nn/i>1000000){
            ans += nn/i;
        }
    }


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


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

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define fst first
#define snd second

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

    int ans = 0;
    for(int i = 1; i < n; i++)
    {
        if(s[i] != s[i - 1])
            ans++;
    }

    cout << ans + 1;

    return 0;
}


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

int main(){
	int n;
	int x=0;
	while (cin >> n){
		for (int i = 0; i < 10; i++){
			for (int j = 0; j < 10; j++){
				for (int k = 0; k < 10; k++){
					for (int l = 0; l < 10; l++){
						if (n == i + j + k + l){
							x = x + 1;
						}
					}
				}
			}
		}
		cout << x << endl;
		x = 0;
	}
}


Measured memory_bytes: 3020
#include<bits/stdc++.h>
using namespace std;
int n,k;
int main(){
	cin>>n>>k;
	int tp=0;
	if(n%2==0) tp=n/2;
	else tp=(n+1)/2;
	if(tp>=k) 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)<(int)(n);++(i))
using ll = long long;
using P = pair<int, int>;
using namespace std;

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


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
// #include <bits/stdc++.h>
#include <vector>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <iostream>
#include <random>
#include <queue>
#include <algorithm>
#include <climits>
#include <map>
#include <set>
#include <stack>
#include <sstream>
#include <cstring>
#include <deque>

 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;
typedef vector<cd> vcd;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<vl> vvl;


#define FOR(i,a,b) for (int i=a; i<b; i++)
#define F0R(i,a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = b; i > a; i--)
#define F0Rd(i,a) for (int i = a; i > -1; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define pob pop_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define que queue
#define pa pair
#define ex(m,i) m.find(i)!=m.end()
#define nex(m,i) m.find(i)==m.end()


#define uniq(x) x.resize(unique(all(x))-x.begin())
 
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
const double epsilon = 1e-12;
const int ds[4][2] = {
    {-1,0},
    {1,0},
    {0,-1},
    {0,1}
};
 
vi cm, cr;

int finds(int ci1){
    if(cm[ci1]!=ci1){
        cm[ci1] = finds(cm[ci1]);
    }
    return cm[ci1];
}

void unions(int ci1, int ci2){
    int fs1 = finds(ci1), fs2 = finds(ci2);
    if(fs1!=fs2){
        if(cr[fs1]<cr[fs2]){
            cr[fs2]+=cr[fs1];
            cm[fs1]=fs2;
        }
        else{
            cr[fs1]+=cr[fs2];
            cm[fs2]=fs1;
        }
    }
}

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

    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    
    int n, m;
    cin >> n>> m;

    cm = vi(n+5,0), cr = vi(n+5,0);

    FOR(i,0,n+5){
        cm[i] = i;
        cr[i] = 1;
    }

    FOR(i,0,m){
        int n1, n2; cin >> n1 >> n2;
        unions(n1,n2);
    }

    int cmax = 0;
    FOR(i,0,n+5){
        cmax = max(cmax,cr[i]);
    }

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

    return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 4424
//
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <array>
#include <numeric>
#include <functional>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <complex>

using namespace std;

#define REP(i,m,n) for(int i=m;i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define ALL(x) (x).begin(),(x).end()

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

const ll inf = INT_MAX;
const double eps = 1e-10;
const double pi = acos(-1.0);
const int di[][2] = {{1,0},{0,1},{-1,0},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}};

int main(){

	string a,b,c;
	cin >>a>>b>>c;
	cout << a[0] << b[0] << c[0] << endl;
	return 0;
}


Measured memory_bytes: 256
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
using namespace std;
const ll mod =1e9+7;
const int N = 1e6+7;

 
int main()
{

	double x;
	cin>>x;

    unsigned long long sum=100;



	rep(i,1,1e8)
	{
	    sum+=(sum/100);
		
		if(sum>=x)
		{
			cout<<i<<endl;
			break;
		}

	}

	



}

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

int main() {
    int n;
    cin >> n;
    vector<double> v(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
    }

    double max_v = 0;
    sort(v.begin(), v.end());
    // do {
        double value = v[0];
        for(int i = 1; i < n; i++) {
            value = (value + v[i]) / 2.0;
        }
        max_v = max(max_v, value);
    // }while(next_permutation(v.begin(),v.end()));

    printf("%.7f\n",max_v);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int gcd(int x, int y){
        if(y == 0) return x;
        return gcd(y, x % y);
}

int main(){
        int n, x, res,ans = 0;
        cin >> n >> x;
        vector<int> v(n);
        for(int i = 0; i < n; i++) {
                cin >> res;
                v[i] = abs(x - res);
        }
        ans = v[0];
        for(int i = 1; i < n; i++) {
                ans = gcd(ans, v[i]);
        }
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 640
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String num = sc.nextLine();
        if(num == "0") {
            System.out.println("No");
        }
        else {
            long sum = 0;
            for(int i = 0; i < num.length(); i++) {
                char ch = num.charAt(i);
                sum += Integer.parseInt(String.valueOf(ch));
            }
            if (sum % 9 == 0) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }
    }
}


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

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a, b, c;
	cin >> a >> b >> c;
	c -= min(c, a - b);
	cout << c << "\n";

	return 0;
}


Measured memory_bytes: 256
n = input()
if n[-1] == '2' or n[-1] == '4' or n[-1] =='5' or n[-1] =='7' or n[-1] =='9':
    print('hon')
elif n[-1] == '0' or n[-1] =='1' or n[-1] =='6' or n[-1] =='8':
    print('pon')
else:
    print('bon')

Measured memory_bytes: 9120
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n,a,b;
  cin>>n>>a>>b;
  vint p(n);
  int ue=0,sit=0,man=0;
  rep(i,n){
      cin>>p[i];
      if(p[i]<=a){
          sit++;
      }
      else if(p[i]<=b){
          man++;
      }
      else{
          ue++;
      }
  }
  cout<<min(sit,min(man,ue))<<'\n';
  return(0);
}


Measured memory_bytes: 3620
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        Restaurant[] rs = new Restaurant[n];
        for(int i=0; i<n; i++) {
            Restaurant r = new Restaurant();
            r.name = in.next();
            r.score = in.nextInt();
            r.index = i+1;
            rs[i] = r;
        }
        Arrays.sort(rs);
        for(int i=0; i<n; i++) {
            System.out.println(rs[i].index);
        }
    }
}
class Restaurant implements Comparable<Restaurant>{
    String name;
    int score;
    int index;

    @Override
    public int compareTo(Restaurant o) {
        if(!this.name.equals(o.name)) {
            return this.name.compareTo(o.name);
        }
        return o.score - this.score;
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define inf (int)(3e18)
#define P pair<int,int>
#define mod (int)(1e9+7)

template<class T> inline void chmin(T &a, T b) {
	a = min(a, b);
}
template<class T> inline void chmax(T &a, T b) {
	a = max(a, b);
}

int gcd(int x, int y) {
	if (y == 0)
		return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

int k,q;
int d[5005];
signed main() {
	cin>>k>>q;
	rep(i,k)cin>>d[i];
	while(q--){
		int n,x,m;cin>>n>>x>>m;
		int sum=x%m;
		rep(i,k){
			int a=d[i]%m;
			if(a==0)a=m;
			sum+=a*((n-1)/k);
			if(i<(n-1)%k)sum+=a;
		}
		cout<<n-1-sum/m<<endl;
	}
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

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

    string s; cin >> s;
    uint k; cin >> k;
    
    uint idx1=0;
    uint val=1;
    for(uint i=0; i<s.size(); ++i){
        if( s[i]=='1' ){ idx1=i+1; continue; }
        val = s[i] - '0';
        break;
    }
    
    if(k<=idx1){
        cout << 1 << endl;
    }else{
        cout << val << endl;
    }
    
    return 0;
}

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

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_B&lang=jp

int main() {
	int n, q;
	cin >> n >> q;
	queue<string> names;
	queue<int> times;
	int current = 0;
	for (int i = 0; i < n; i++) {
		string str;
		int time;
		cin >> str >> time;
		names.push(str);
		times.push(time);
	}
	while (names.size() > 0) {
		string name = names.front(); names.pop();
		int time = times.front(); times.pop();
		if (time > q) {
			time -= q;
			names.push(name);
			times.push(time);
			current += q;
		} else {
			current += time;
			cout << name << " " << current << endl;
		}
	}
	
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = 0; i < (a); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  ll k;
  cin >> n >> k;
  VVI c(40, VI(2, 0));
  ll x = 0;
  VL a(n);
  rep(i, n) {
    cin >> a[i];
  }
  rep(i, n) {
    rep(j, 40) {
      c[j][a[i] >> j & 1]++;
    }
  }
  for(int i = 39; i >= 0; --i) {
    if(c[i][0] > c[i][1] && (x|(1LL << i)) <= k) x |= 1LL << i;
  }
  ll ans = 0;
  rep(i, n) ans += a[i] ^ x;
  out(ans);
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
typedef pair<int,int> P;
int x1[1000];
int y1[1000];
int x2[1000];
int y2[1000];
vector<int> xcmp;
vector<int> ycmp;
bool used[3002][3002];
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};
void bfs(int x,int y){
	used[x][y]=true;
	queue<P> que;
	que.push(P(x,y));
	while(!que.empty()){
		P p=que.front();
		que.pop();
		for(int i=0;i<4;i++){
			int nx=p.first+dx[i];
			int ny=p.second+dy[i];
			if(nx>=0&&nx<xcmp.size()&&ny>=0&&ny<ycmp.size()&&!used[nx][ny]){
				used[nx][ny]=true;
				que.push(P(nx,ny));
			}
		}
	}
}
int main(){
	int n;
	int i,j,k;
	int w,h;
	while(1){
	scanf("%d %d",&w,&h);
	if(w==0)return 0;
	scanf("%d",&n);
	xcmp.clear();
	ycmp.clear();
	xcmp.push_back(0);
	xcmp.push_back(w-1);
	ycmp.push_back(0);
	ycmp.push_back(h-1);
	for(i=0;i<n;i++){
		scanf("%d %d %d %d",&x1[i],&y1[i],&x2[i],&y2[i]);
		xcmp.push_back(x1[i]);
		xcmp.push_back(x2[i]-1);
		if(x2[i]<w)xcmp.push_back(x2[i]);
		ycmp.push_back(y1[i]);
		ycmp.push_back(y2[i]-1);
		if(y2[i]<h)ycmp.push_back(y2[i]);
	}
	sort(xcmp.begin(),xcmp.end());
	sort(ycmp.begin(),ycmp.end());
	xcmp.erase(unique(xcmp.begin(),xcmp.end()),xcmp.end());
	ycmp.erase(unique(ycmp.begin(),ycmp.end()),ycmp.end());
	for(i=0;i<xcmp.size();i++)for(j=0;j<ycmp.size();j++)used[i][j]=false;
	for(i=0;i<n;i++){
		x1[i]=find(xcmp.begin(),xcmp.end(),x1[i])-xcmp.begin();
		x2[i]=find(xcmp.begin(),xcmp.end(),x2[i])-xcmp.begin();
		y1[i]=find(ycmp.begin(),ycmp.end(),y1[i])-ycmp.begin();
		y2[i]=find(ycmp.begin(),ycmp.end(),y2[i])-ycmp.begin();
		for(j=x1[i];j<x2[i];j++){
			for(k=y1[i];k<y2[i];k++){
				used[j][k]=true;
			}
		}
	}
	int ans=0;
	for(i=0;i<xcmp.size();i++){
		for(j=0;j<ycmp.size();j++)if(!used[i][j]){
			ans++;
			bfs(i,j);
		}
	}
	printf("%d\n",ans);
	}
}

Measured memory_bytes: 5168
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=998244353;
ll n,tmp,a,b,d,k,x,y,a1,b1,ans=0,i,fac[300005],inv[300005];
ll C(ll a,ll b){return fac[a]*inv[b]%mod*inv[a-b]%mod;}
ll pow(ll a,ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
void exgcd(ll a,ll b,ll &d,ll &x,ll &y)
{
	if(b==0)x=1,y=0;
	else
	{
		exgcd(b,a%b,d,y,x);
		y-=a/b*x;
	}
}
int main()
{
	cin>>n>>a>>b>>k;
	fac[0]=1;
	for(i=1;i<=n;i++)fac[i]=fac[i-1]*i%mod;
	inv[n]=pow(fac[n],mod-2);
	for(i=n-1;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
	tmp=gcd(a,b);
	if(k%tmp)
	{
		cout<<"0"<<endl;
		return 0;
	}
	exgcd(a,b,d,x,y);
	if(x<0)swap(a,b),swap(x,y);
	a1=a/tmp;b1=b/tmp;
	x*=k/tmp;
	y*=k/tmp;
	k=x/b1;
	x-=k*b1;
	y+=k*a1;
	while(x<=n)
	{
		if(y>=0&&y<=n)ans=(ans+C(n,x)*C(n,y))%mod;
		x+=b1;
		y-=a1;
	}
	cout<<ans<<endl;
	return 0;
}

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

int INFp=1000000007;
const string minusinf ="-";
const int mininf = -1;
int cost[10]={0,
    2
    ,
    5
    ,
    5
    ,
    4
    ,
    5
    ,
    6
    ,
    3
    ,
    7
    ,
    6
};
void chmax(string &a,string b){
    if(a == minusinf) a=b;
    else if(a.size()<b.size()) a=b;
    else if(a.size()==b.size()){
        if(a<b) a=b;
    }
}


int main(){
    int n,m;
    int a[15];
    cin>>n>>m;
    for(int i=0;i<m;i++) cin>>a[i];
    
    //sort(a,a+m,greater<int>());
    
    //int dp[11000]={-1};//i本使うときの最大桁数
    
    int dp[11000];
    for(int i=0;i<10500;i++) dp[i]=-1;
    dp[0]=0;
    
    for(int i=0; i<=n; i++){
        if(dp[i] == -1)
            continue;
        
        int index;
        for(int j=0; j<m; j++){
            index = i + cost[a[j]];
            if(index > n)
                continue;
            
            dp[index] = max(dp[index], dp[i]+1);
        }
    }
    
    
    int costcount=n;
    
    vector<int> ans;
    int cnt = n;
    for(int i=0; i<dp[n]; i++){
        int select = -1;
        for(int j=0; j<m; j++){
            int dst = cnt - cost[a[j]];
            if(dst < 0 || dp[dst] == -1)
                continue;
            
            if(dp[cnt]-dp[dst] == 1)
                select = max(select, a[j]);
        }
        
        ans.push_back(select);
        cnt -= cost[select];
    }
    
    
    for(int i=0;i<ans.size();i++){
        cout<<ans[i];
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
typedef long long ll;
using namespace std;

int main()
{
    ll n, x; cin >> n >> x;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++){
        cin >> a[i];
    }
    
    ll ans = 0;
    for (ll i = 0; i < n - 1; i++){
        if(a[i] + a[i + 1] > x){
            ans += (a[i] + a[i + 1]) - x;
            if((a[i] + a[i + 1]) - x < a[i + 1]){
                a[i + 1] -= ((a[i] + a[i + 1]) - x);
            }
            else{
                a[i + 1] = 0;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
n,h=int(input()),list(map(int,input().split()))
dp=[0,abs(h[1]-h[0])]+[0]*(n-2)
for i in range(2,n):dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[n-1])

Measured memory_bytes: 13928
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;

int main(){
  ll n;
  cin >> n;
  
  ll min = n+1;
  rep2(i,1,(int)sqrt(n)+1){
    if(n%i==0){
      ll x = i + (n/i);
      if(x < min) min = x;
    }
  }
  
  cout << (min-2) << endl;
  
  return 0;
}

Measured memory_bytes: 256
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;

int main(){
  string S;
  int K;
  cin >> S >> K;
  int sl = S.size();

  set<string> box;

  for(int i = 0; i < sl; i++){
    for(int j = 0; j < 26; j++){
      if(S[i]=='a'+j){
        if(i < sl-4){
          for(int k = 1; k <= 5; k++){
            box.insert(S.substr(i,k));
          }
        }else{
          for(int k = 1; k <= sl-i; k++){
            box.insert(S.substr(i,k));
          }
        }
      }
    }
  }

  vector<string> chk(box.begin(),box.end());
  sort(chk.begin(),chk.end());
  cout << chk[K-1] << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>
#include <bitset>
#include <sstream>
#include <cassert>
#include <time.h>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}
void printvec (vec &v) {
    Rep (i, (ll)v.size()) {
        cout << v[i] << " \n"[i+1 == (ll)v.size()];
    }
}

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

    ll N;
    cin >> N;
    map<string, ll> cnt;
    while (N--) {
        string S;
        cin >> S;
        cnt[S]++;
    }

    cout << "AC x " << cnt["AC"] << "\n";
    cout << "WA x " << cnt["WA"] << "\n";
    cout << "TLE x " << cnt["TLE"] << "\n";
    cout << "RE x " << cnt["RE"] << "\n";
}

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

using namespace std;
const int maxn = 1e6+10;
vector<int> e[maxn];
int dp[maxn];
int dfs(int x){
	if(dp[x]) return dp[x];
	for(int i=0;i<(int)e[x].size();i++){
		int v=e[x][i];
		dp[x]=max(dp[x],dfs(v)+1);
	}
	return dp[x];
}
int main(){
	int n,m;
	cin>>n>>m;
	int u,v;
	for(int i=1;i<=m;i++){
		cin>>u>>v;
		e[u].push_back(v);
	}
	memset(dp,0,sizeof(dp));
	int ans=0;
	for(int i=1;i<=n;i++){
		ans=max(ans,dfs(i));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 32768
#include <bits/stdc++.h>
using namespace std;
#define INF 105

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n,s;
	scanf("%d%d",&n,&s);
	long long counter=0;
	for(int i=0;i<=n;i++)
	{
        for(int k=0;k<=n;k++)
        {
            int tot=i+k;
            if(s-tot<=n && s-tot>=0)
            {
                counter++;
            }
        }
	}
	printf("%lld\n",counter);
}


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


def output_string8(table, x, y):

    string8 = []

    string8.append(table[x-1][y+1])
    string8.append(table[x][y+1])
    string8.append(table[x+1][y+1])
    string8.append(table[x-1][y])
    string8.append(table[x+1][y])
    string8.append(table[x-1][y-1])
    string8.append(table[x][y-1])
    string8.append(table[x+1][y-1])

    return ''.join(string8)


H, W = map(int, input().split())
S = []

S.append('X' * (W+2))

for _ in range(H):
    line = 'X' + input() + 'X'
    S.append(line)

S.append('X' * (W+2))

BOMB = '#'

for y in range(1, H + 1):
    for x in range(1, W + 1):

        ch = S[y][x]

        if ch == BOMB:
            print(BOMB, end='')
            continue

        st = output_string8(S, y, x)
        print(st.count(BOMB), end='')

    print(end='\n')


Measured memory_bytes: 3444
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i < (n);++i)
using namespace std;
using ll = long long;
const ll mod = 1e9+7;

int g[15][15];//正直者かどうか

int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll ans = 0;
  rep(i,60) {
    ll x = 0;
    rep(j, n) if(a[j]>>i & 1) ++x;//i桁目が1ならカウント
    ll now = x*(n-x) % mod;
    rep(j, i) now = now * 2 % mod;
    ans += now;
    ans %= mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {
	
	int[] currency;
	int[] minCurrency;
	int maxProfit;

	public static void main(String[] args) {
		Main main = new Main();
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		main.currency = new int[n];
		main.minCurrency = new int[n];
		for (int i = 0; i < n; i++) {
			main.currency[i] = in.nextInt();
		}
		main.maxProfit = main.currency[1] - main.currency[0];
		if (main.currency[0] < main.currency[1]) {
			main.minCurrency[0] = main.currency[0];
		} else {
			main.minCurrency[0] = main.currency[1];
		}
		for (int i = 2; i < n; i++) {
			main.setMins(i);
		}
		System.out.println(main.maxProfit);
	}
	
	public void setMins(int index) {
		int min = this.minCurrency[index - 2];
		this.maxProfit = (currency[index] - min > maxProfit)? currency[index] - min : maxProfit;
		this.minCurrency[index - 1] = (this.currency[index] < min)? this.currency[index] : min;
	}

	public void printList(int[] list) {
		for (int i = 0; i < list.length; i++) {
			System.out.print(list[i] + " ");
		}
		System.out.println();
	}
	
}



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

int main(){
  int a,b,c,d,l,r;
  cin>>a>>b>>c>>d;
  l=a+b,r=c+d;
  if(l>r){
    cout<<"Left"<<endl;
  }else if(l==r){
    cout<<"Balanced"<<endl;
  }else{
    cout<<"Right"<<endl;
  }
}

Measured memory_bytes: 3592
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
//#include<bits/extc++.h>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pdd pair<double,double>
#define pb push_back
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-6
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define pi acos(-1)
#define index Index
#define Line pll
typedef long long LL;
LL dp[3005][3005];
int vis[3005][3005];
int a[3005];
LL DP(int l,int r){
    if(l>r)return 0;
    if(vis[l][r])return dp[l][r];
    dp[l][r]=max(a[r]-DP(l,r-1),a[l]-DP(l+1,r));
    vis[l][r]=1;
    return dp[l][r];
}
int main(){
    int n;
    scanf("%d",&n);
    MEM(vis);
    for(int i=1;i<=n;i++)
    scanf("%d",&a[i]);
    printf("%lld\n",DP(1,n));
}


Measured memory_bytes: 105088
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>

#define rep(i,n) for(int i=0; i<int(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

int main() {
	int d, c;
	cin >> d >> c;
	cout << d*c << endl;
	return 0;
}

Measured memory_bytes: 3100
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;

int main(void){
 int p[11];
 int c[11];
 int D,G;
 int cnt=0;
 int check=0;
 long long int sum=0;
 int ans=1000000000;
 
 cin>>D>>G;

 for(int i=1; i<=D; i++){
  cin>>p[i];
  cin>>c[i];
 }
 
 for(int bit=0; bit < (1<<(D+1));bit++){
   vector<int> A;
   cnt=0;
   sum=0;
   check=0;
   for(int i=1; i<=D; i++){
    if(bit & (1<<i)){
	 A.push_back(i);
	}
   }
   //std::cout<<"A"<<std::endl;
  /* for(int i=0; i<A.size();i++){
	std::cout<<A[i]<<std::endl;
   }
  */ 
   for(int i=0; i<A.size();i++){
    sum+=100*A[i]*p[A[i]]+c[A[i]];
    cnt+=p[A[i]];
   }
   //std::cout<<"sum" <<sum<<std::endl;
   if(sum>=G){
    ans=min(ans,cnt);
	check=1;
   }
   if(check==0){
    for(int i=D; i>=1; i--){
	 if(!(bit & (1<<i))){
	  for(int j=0; j<p[i];j++){
	   sum+=100*i;
	   cnt++;
	   if(sum>=G){
	    ans=min(ans,cnt);
		check=1;
		break;
	   }
	  }
	  check=1;
	 }
     if(check==1)break;	
    }
   }
 }
 std::cout<<ans<<std::endl; 
 return 0;
}

Measured memory_bytes: 256